Coding-With-Raptor/Likendin-Agent
0
1from mcp.server.fastmcp import FastMCP2 3# Create server4mcp = FastMCP(5 name="Weather MCP Server",6 description="A basic MCP server for HTTP client demonstration.",7 stateless_http=True, # Makes the server treat each HTTP request independently8 json_response=True, # Allows single JSON responses for non-streaming calls (optimization)9 port=8001,10 host="0.0.0.0",11)12 13 14@mcp.tool("get_weather")15def get_weather(city: str) -> dict:16 """17 Get current weather data for a specified city using wttr.in API.18 19 Args:20 city (str): Name of the city to get weather for21 22 Returns:23 dict: Weather data including temperature, humidity, description etc.24 """25 import requests26 27 # API endpoint28 base_url = f"https://wttr.in/{city}?format=j1"29 30 try:31 # Make API request32 response = requests.get(base_url)33 response.raise_for_status()34 35 # Parse response36 weather_data = response.json()37 current = weather_data["current_condition"][0]38 39 # Extract relevant information40 result = {41 "city": city,42 "temperature": float(current["temp_C"]),43 "feels_like": float(current["FeelsLikeC"]),44 "humidity": int(current["humidity"]),45 "description": current["weatherDesc"][0]["value"],46 "wind_speed": float(current["windspeedKmph"]),47 }48 49 return result50 51 except requests.exceptions.RequestException as e:52 return {"error": f"Failed to fetch weather data: {str(e)}"}53 54 55if __name__ == "__main__":56 mcp.run(transport="streamable-http")57 