Spaces:
Sleeping
Sleeping
Create tools/weather.py
Browse files- tools/weather.py +31 -0
tools/weather.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from mcp.server.fastmcp import FastMCP
|
| 2 |
+
|
| 3 |
+
mcp = FastMCP("Weather")
|
| 4 |
+
|
| 5 |
+
@mcp.tool()
|
| 6 |
+
def get_current_weather(location: str) -> dict:
|
| 7 |
+
"""Get current weather for a location (mock implementation)"""
|
| 8 |
+
# This is a mock implementation - replace with real weather API
|
| 9 |
+
return {
|
| 10 |
+
"location": location,
|
| 11 |
+
"temperature": "22°C",
|
| 12 |
+
"condition": "sunny",
|
| 13 |
+
"humidity": "65%",
|
| 14 |
+
"message": f"Mock weather data for {location}"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
@mcp.tool()
|
| 18 |
+
def get_forecast(location: str, days: int = 3) -> dict:
|
| 19 |
+
"""Get weather forecast for specified days"""
|
| 20 |
+
return {
|
| 21 |
+
"location": location,
|
| 22 |
+
"forecast_days": days,
|
| 23 |
+
"forecast": [
|
| 24 |
+
{"day": 1, "temperature": "23°C", "condition": "sunny"},
|
| 25 |
+
{"day": 2, "temperature": "20°C", "condition": "cloudy"},
|
| 26 |
+
{"day": 3, "temperature": "18°C", "condition": "rainy"}
|
| 27 |
+
][:days]
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
mcp.run()
|