Skip to main content
Glama

Weather Agent MCP Server

weather_agent.py1 kB
import os import requests from dotenv import load_dotenv from fastmcp import FastMCP load_dotenv() API_KEY = os.getenv("WEATHER_API_KEY") if not API_KEY: raise ValueError("WEATHER_API_KEY environment variable not set") mcp = FastMCP("Weather Bot", "Get current weather information for a given city.") @mcp.tool def get_weather(city: str) -> str: """Get the current weather for a given city.""" url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}&units=metric" response = requests.get(url) if response.status_code != 200: return f"Error: Unable to fetch weather data for {city}." data = response.json() weather_desc = data['weather'][0]['description'] temp = data['main']['temp'] humidity = data['main']['humidity'] return (f"The current weather in {city} is {weather_desc} with a temperature of " f"{temp}°C and humidity of {humidity}%.") if __name__ == "__main__": mcp.run(transport="stdio")

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Dineshkumar-Ponnusamy/MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server