Skip to content

Commit f9712d0

Browse files
committed
🥅 Update error handling
Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>
1 parent 36d70f1 commit f9712d0

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

mcp/weather_tool/weather_tool.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
@mcp.tool(annotations={"readOnlyHint": True, "destructiveHint": False, "idempotentHint": True})
1515
def get_weather(city: str) -> str:
1616
"""Get weather info for a city"""
17-
logger.info(f"Getting weather info for city '{city}'.")
17+
logger.debug(f"Getting weather info for city '{city}'.")
1818
base_url = "https://geocoding-api.open-meteo.com/v1/search"
1919
params = {"name": city, "count": 1}
2020
response = requests.get(base_url, params=params, timeout=10)
2121
data = response.json()
22-
if not data["results"]:
23-
logger.error(f"City {city} not found")
24-
return "City not found"
22+
if not data or not "results" in data:
23+
return [{"error": f"City {city} not found"}]
2524
latitude = data["results"][0]["latitude"]
2625
longitude = data["results"][0]["longitude"]
2726

0 commit comments

Comments
 (0)