#!/usr/bin/env python3 """ MCP Weather Server - Provides hardcoded weather data for cities via stdio """ from fastmcp import FastMCP # Initialize MCP server mcp = FastMCP("weather-server") # Hardcoded weather data WEATHER_DATA = { "paris": { "city": "Paris", "temperature": 15, "condition": "Partly cloudy", "humidity": 65, "wind_speed": 12 }, "london": { "city": "London", "temperature": 12, "condition": "Rainy", "humidity": 80, "wind_speed": 18 }, "new york": { "city": "New York", "temperature": 20, "condition": "Sunny", "humidity": 55, "wind_speed": 10 }, "tokyo": { "city": "Tokyo", "temperature": 18, "condition": "Clear", "humidity": 60, "wind_speed": 8 } } @mcp.tool() def get_weather(city: str) -> dict: """ Get the current weather for a specific city. Args: city: The name of the city to get weather for Returns: A dictionary containing weather information including temperature, condition, humidity, and wind speed """ city_lower = city.lower() if city_lower in WEATHER_DATA: return WEATHER_DATA[city_lower] else: return { "city": city, "error": f"Weather data not available for {city}", "available_cities": list(WEATHER_DATA.keys()) } if __name__ == "__main__": # Run the MCP server using stdio transport mcp.run(transport="stdio")