Skip to content

Commit 2d139f7

Browse files
authored
Merge pull request #71 from esnible/tool-annotations
✨ Annotations for weather tool
2 parents c45f0db + 2654b3e commit 2d139f7

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

mcp/weather_tool/weather_tool.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
"Weather MCP tool example"
2+
13
import os
24
import json
35
import requests
46
from fastmcp import FastMCP
57

68
mcp = FastMCP("Weather")
79

8-
@mcp.tool()
10+
@mcp.tool(annotations={"readOnlyHint": True, "destructiveHint": False, "idempotentHint": True})
911
def get_weather(city: str) -> str:
1012
"""Get weather info for a city"""
1113
base_url = "https://geocoding-api.open-meteo.com/v1/search"
1214
params = {"name": city, "count": 1}
13-
response = requests.get(base_url, params=params)
15+
response = requests.get(base_url, params=params, timeout=10)
1416
data = response.json()
1517
if not data["results"]:
1618
return "City not found"
@@ -24,14 +26,15 @@ def get_weather(city: str) -> str:
2426
"temperature_unit": "fahrenheit",
2527
"current_weather": True
2628
}
27-
weather_response = requests.get(weather_url, params=weather_params)
29+
weather_response = requests.get(weather_url, params=weather_params, timeout=10)
2830
weather_data = weather_response.json()
2931

3032
return json.dumps(weather_data["current_weather"])
3133

3234
# host can be specified with HOST env variable
3335
# transport can be specified with MCP_TRANSPORT env variable (defaults to streamable-http)
3436
def run_server():
37+
"Run the MCP server"
3538
transport = os.getenv("MCP_TRANSPORT", "streamable-http")
3639
host = os.getenv("HOST", "0.0.0.0")
3740
port = int(os.getenv("PORT", "8000"))

0 commit comments

Comments
 (0)