Weather MCP Server
MCP server that provides weather forecasting tools for Databricks Agent Bricks, including current conditions, forecasts, and umbrella recommendations using OpenMeteo.
README
Weather MCP Server
A Model Context Protocol (MCP) server that exposes weather forecasting tools for Databricks Agent Bricks. Built with FastMCP and OpenMeteo's free weather API.
Features
MCP Tools
-
get_forecast(location, days) - Get hourly weather forecast for the next X days
- Temperature, humidity, and wind speed data
- Returns structured data with coordinates and forecast period
-
get_current_weather(location) - Get current weather conditions
- Real-time temperature, wind speed, and weather conditions
- Includes location coordinates and timestamp
-
predict_umbrella_needed(location, date) - Intelligent umbrella recommendation
- Analyzes precipitation probability, rainfall amount, and duration
- Returns YES/MAYBE/NO recommendation with detailed reasoning
- Includes confidence level (high/medium/low)
Additional Features
- Automatic tracing - All MCP calls are logged to Lakebase with session IDs, timing, and results
- User identity tracking - Captures end-user email from Databricks App headers
- Error handling - Comprehensive error handling with structured error responses
- Geocoding - Automatic city name to coordinates conversion using OpenStreetMap
Project Structure
weather-mcp-server/
├── mcp_server/
│ ├── openmeteo_mcp_server.py # FastMCP server with tool definitions
│ ├── openmeteo_broker.py # Weather API client functions
│ ├── lakebase.py # Database connection utilities
│ ├── app.yaml # Databricks App configuration
│ └── requirements.txt # Python dependencies
├── .env # Environment variables (not in git)
└── README.md # This file
Setup
1. Install Dependencies
pip install -r requirements.txt
2. Configure Environment Variables
Create a .env file in the project root:
LAKEBASE_URL="postgresql://user:password@host.cloud.databricks.com/databricks_postgres?sslmode=require"
3. Test Locally
python -m mcp_server.openmeteo_mcp_server
The server will start on port 8000 and initialize the weather_mcp_traces table in Lakebase.
Deployment as Databricks App
Option 1: Using Databricks CLI
# Ensure LAKEBASE_URL is set in your environment
export LAKEBASE_URL="your-connection-string"
# Deploy the app
databricks apps deploy weather-mcp-server
Option 2: Using Databricks Workspace UI
- Go to Apps in your Databricks workspace
- Click Create App
- Select this directory:
/Users/madanadi0305@gmail.com/weather-mcp-server - Databricks will automatically detect
app.yamland deploy
Register with Agent Bricks
Once deployed, register the MCP server with your Agent Bricks agent:
- Get the app URL from the Databricks Apps console
- In Agent Bricks, add external MCP server:
- URL:
https://<your-app-url> - Name:
weather-mcp-server
- URL:
Usage Examples
Get 7-Day Forecast
result = get_forecast("London", 7)
print(result["location"]) # "London"
print(result["coordinates"]) # {"latitude": 51.5074, "longitude": -0.1278}
print(result["data"]["hourly"]["temperature_2m"][0]) # 15.2
Get Current Weather
result = get_current_weather("Tokyo")
current = result["data"]["current_weather"]
print(f"Temperature: {current['temperature']}°C") # Temperature: 18.5°C
Check If Umbrella Needed
result = predict_umbrella_needed("Seattle", "2024-03-20")
print(result["recommendation"]) # "YES - Bring an umbrella ☔"
print(result["reasoning"]) # "High precipitation probability (85%)..."
print(result["confidence"]) # "high"
Database Schema
The server automatically creates a weather_mcp_traces table in Lakebase:
CREATE TABLE weather_mcp_traces (
session_id VARCHAR(36) PRIMARY KEY,
tool_name VARCHAR(100) NOT NULL,
user_email VARCHAR(255),
input_params JSONB,
start_time TIMESTAMP NOT NULL,
end_time TIMESTAMP,
duration_ms INTEGER,
status VARCHAR(20),
error_message TEXT,
result_summary JSONB,
created_at TIMESTAMP DEFAULT NOW()
)
API Documentation
OpenMeteo API
This server uses two OpenMeteo endpoints:
- Current Weather:
https://api.open-meteo.com/v1/forecast - Forecast:
https://historical-forecast-api.open-meteo.com/v1/forecast
Both are free and require no API key.
Geocoding
City-to-coordinates conversion uses OpenStreetMap's Nominatim API:
- Endpoint:
https://nominatim.openstreetmap.org/search - Free, no API key required
- Respects usage policies with proper User-Agent header
Development
Running Tests
# Test database connection
python mcp_server/lakebase.py
# Test weather API functions
python mcp_server/openmeteo_broker.py
Adding New Tools
To add a new MCP tool:
- Add the function to
openmeteo_broker.py - Wrap it as an MCP tool in
openmeteo_mcp_server.py:
@mcp.tool
@trace_mcp_call
def my_new_tool(param: str) -> dict:
"""Tool description for Agent Bricks."""
return openmeteo_broker.my_new_function(param)
Troubleshooting
Connection Issues
- Verify
LAKEBASE_URLis set correctly in.env - Test connection:
python mcp_server/lakebase.py - Check firewall/security group settings
Import Errors
- Ensure all dependencies are installed:
pip install -r requirements.txt - Verify you're in the correct directory when running
MCP Server Not Responding
- Check logs in Databricks Apps console
- Verify port 8000 is accessible
- Test locally first before deploying
Known Issues
User Identity Tracking
- The
RequestContextMiddlewareis currently disabled due to FastMCP validation issues - This means
user_emailfield inweather_mcp_tracestable will be NULL - Impact: Cannot track which end-user made each MCP call
- Status: Investigating FastMCP-compatible middleware approach
Workaround Options
- Add user context to tool parameters: Modify tools to accept optional
user_emailparameter - Use session-based tracking: Track sessions instead of individual users
- Wait for FastMCP middleware fix: Monitor FastMCP updates for middleware compatibility
Performance Notes
- Geocoding cache: City-to-coordinates lookups are cached in memory for the app lifetime
- API rate limits: OpenMeteo and Nominatim are free services with fair-use policies
- Database performance: Each MCP call writes one trace record to Lakebase (async recommended)
Security Considerations
- LAKEBASE_URL: Contains database credentials - keep
.envfile secure and out of version control - MCP endpoint: Publicly accessible at
/mcp- authentication handled by Databricks Apps OAuth - User headers: The app receives
x-forwarded-emailfrom Databricks - trust this for identity
Next Steps
- [ ] Re-enable user tracking with FastMCP-compatible middleware
- [ ] Add caching layer for weather API responses
- [ ] Implement additional weather tools (air quality, UV index, etc.)
- [ ] Add monitoring and alerting for API failures
- [ ] Create automated tests for all three tools
License
MIT License - see LICENSE file for details
Contributing
Contributions welcome! Please open an issue or pull request.
Support
For issues or questions:
- Check the Troubleshooting section above
- Review logs:
databricks apps logs mcp-server-openmeteo-weather - Open an issue in the project repository
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。