Jofthomas commited on
Commit
d38c7c4
·
verified ·
1 Parent(s): 69779b2

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +28 -2
server.py CHANGED
@@ -3,12 +3,38 @@ from mcp.server.fastmcp import FastMCP
3
 
4
  # Create an MCP server
5
  mcp = FastMCP(
6
- name="Calculator",
7
  host="0.0.0.0", # only used for SSE transport
8
  port=7860, # only used for SSE transport (HF expect 7860 as a port)
9
  )
10
 
11
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Add a simple calculator tool
13
  @mcp.tool()
14
  def add(a: int, b: int) -> int:
 
3
 
4
  # Create an MCP server
5
  mcp = FastMCP(
6
+ name="MCPTEST",
7
  host="0.0.0.0", # only used for SSE transport
8
  port=7860, # only used for SSE transport (HF expect 7860 as a port)
9
  )
10
 
11
+ @mcp.tool()
12
+ def get_weather(city: str) -> dict:
13
+ """Retrieves the current weather report for a specified city.
14
+
15
+ Args:
16
+ city (str): The name of the city (e.g., "New York", "London", "Tokyo").
17
+
18
+ Returns:
19
+ dict: A dictionary containing the weather information.
20
+ Includes a 'status' key ('success' or 'error').
21
+ If 'success', includes a 'report' key with weather details.
22
+ If 'error', includes an 'error_message' key.
23
+ """
24
+ print(f"--- Tool: get_weather called for city: {city} ---") # Log tool execution
25
+ city_normalized = city.lower().replace(" ", "") # Basic normalization
26
+
27
+ # Mock weather data
28
+ mock_weather_db = {
29
+ "newyork": {"status": "success", "report": "The weather in New York is sunny with a temperature of 25°C."},
30
+ "london": {"status": "success", "report": "It's cloudy in London with a temperature of 15°C."},
31
+ "tokyo": {"status": "success", "report": "Tokyo is experiencing light rain and a temperature of 18°C."},
32
+ }
33
+
34
+ if city_normalized in mock_weather_db:
35
+ return mock_weather_db[city_normalized]
36
+ else:
37
+ return {"status": "error", "error_message": f"Sorry, I don't have weather information for '{city}'."}
38
  # Add a simple calculator tool
39
  @mcp.tool()
40
  def add(a: int, b: int) -> int: