We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/tunamsyar/ollama-mcp-py'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
"""
Weather tool using Open-Meteo API
"""
import requests
def get_weather(city: str):
"""Get current weather for a city using Open-Meteo API (free, no API key required)."""
try:
# First, get coordinates for the city using a geocoding service
geocode_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1"
geo_response = requests.get(geocode_url, timeout=10)
geo_data = geo_response.json()
if not geo_data.get("results"):
return {"error": f"City '{city}' not found"}
location = geo_data["results"][0]
lat = location["latitude"]
lon = location["longitude"]
city_name = location["name"]
country = location.get("country", "")
# Get weather data from Open-Meteo
weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t=temperature_2m,relative_humidity_2m,apparent_temperature,weather_code,wind_speed_10m&timezone=auto"
weather_response = requests.get(weather_url, timeout=10)
weather_data = weather_response.json()
if weather_response.status_code != 200:
return {"error": "Weather API request failed"}
current = weather_data["current"]
# Map weather codes to descriptions (Open-Meteo WMO codes)
weather_codes = {
0: "Clear sky", 1: "Mainly clear", 2: "Partly cloudy", 3: "Overcast",
45: "Fog", 48: "Depositing rime fog", 51: "Light drizzle", 53: "Moderate drizzle",
55: "Dense drizzle", 56: "Light freezing drizzle", 57: "Dense freezing drizzle",
61: "Slight rain", 63: "Moderate rain", 65: "Heavy rain", 66: "Light freezing rain",
67: "Heavy freezing rain", 71: "Slight snow", 73: "Moderate snow", 75: "Heavy snow",
77: "Snow grains", 80: "Slight rain showers", 81: "Moderate rain showers",
82: "Violent rain showers", 85: "Slight snow showers", 86: "Heavy snow showers",
95: "Thunderstorm", 96: "Thunderstorm with slight hail", 99: "Thunderstorm with heavy hail"
}
weather_code = current.get("weather_code", 0)
description = weather_codes.get(weather_code, "Unknown")
return {
"city": f"{city_name}, {country}",
"temperature": f"{current['temperature_2m']}°C",
"feels_like": f"{current['apparent_temperature']}°C",
"humidity": f"{current['relative_humidity_2m']}%",
"wind_speed": f"{current['wind_speed_10m']} km/h",
"description": description,
"coordinates": f"{lat:.2f}, {lon:.2f}"
}
except Exception as e:
return {"error": f"Failed to get weather: {str(e)}"}
# Tool metadata for automatic discovery
TOOL_INFO = {
"name": "get_weather",
"description": "Get current weather for a city using Open-Meteo API (free, no API key required).",
"function": get_weather,
"parameters": {
"city": {
"type": "str",
"required": True,
"description": "Name of the city to get weather for"
}
}
}