Weather MCP Server

Weather MCP Server

Provides real-time weather forecasts, current conditions, and smart umbrella recommendations through MCP tools, backed by the Open-Meteo API.

Category
访问服务器

README

Overview

This project implements a Model Context Protocol (MCP) server that exposes weather forecast tools, backed by the Open-Meteo API. It can be deployed as a Databricks App and integrated with Agent Bricks to answer natural-language weather questions.

Architecture

┌────────────────────────────────────────────┐
│  Weather MCP Server (Databricks App)      │
│  ┌──────────────────────────────────────┐ │
│  │  weather_mcp_server.py               │ │
│  │  - FastMCP with @mcp.tool decorators │ │
│  │  - get_current_weather()             │ │
│  │  - get_forecast()                    │ │
│  │  - predict_umbrella_needed()         │ │
│  └──────────────────────────────────────┘ │
│             ↓                              │
│  ┌──────────────────────────────────────┐ │
│  │  weather_broker.py                   │ │
│  │  - HTTP calls to Open-Meteo API      │ │
│  │  - Geocoding (city → lat/lon)        │ │
│  │  - Weather code decoding (WMO)       │ │
│  │  - Error handling                    │ │
│  └──────────────────────────────────────┘ │
└────────────────────────────────────────────┘
                   ↓ MCP protocol
┌────────────────────────────────────────────┐
│  Agent Bricks Agent                        │
│  - Uses weather tools via MCP              │
│  - Answers natural language questions      │
│  - Makes recommendations                   │
└────────────────────────────────────────────┘

Project Structure

weather_mcp_server/
├── weather_mcp_server.py   # FastMCP server with tool decorators
├── weather_broker.py        # API adapter (HTTP calls, parsing)
├── app.yaml                 # Databricks App configuration
├── requirements.txt         # Python dependencies
└── README.md                # This file

MCP Tools (3 Required)

1. get_current_weather(location: str)

Purpose: Fetch real-time weather conditions for any location.

Arguments:

  • location (str): City name or "City, Country" format

Returns: JSON with temperature (C/F), conditions, humidity, wind speed, precipitation, cloud cover

Example:

get_current_weather("Chicago")
# Returns: {"location": {"name": "Chicago", "country": "United States"}, 
#           "current": {"temperature_c": 22.5, "conditions": "Partly cloudy", ...}}

2. get_forecast(location: str, days: int = 7)

Purpose: Multi-day weather forecast (1-16 days ahead).

Arguments:

  • location (str): City name
  • days (int): Number of forecast days (1-16, default 7)

Returns: JSON with daily high/low temps, precipitation chance/amount, conditions, wind speed

Example:

get_forecast("Seattle", 3)
# Returns: {"location": {...}, "forecast": [
#   {"date": "2026-08-09", "temp_max_c": 24.0, "precipitation_chance": 60, ...},
#   {...}, {...}
# ]}

3. predict_umbrella_needed(location: str, date: str = None, threshold_percent: int = 40)

Purpose: Smart recommendation - should you bring an umbrella?

Arguments:

  • location (str): City name
  • date (str, optional): Target date in "YYYY-MM-DD" format (default: tomorrow)
  • threshold_percent (int, optional): Precipitation probability threshold (default: 40)

Decision Logic (NOT just a passthrough):

  • Recommends umbrella if EITHER:
    1. Precipitation chance > threshold_percent (default 40%), OR
    2. Expected rainfall >= 2mm

Returns: JSON with recommendation, reasoning, forecast details, and decision rule explanation

Example:

predict_umbrella_needed("Portland", "2026-08-15")
# Returns: {
#   "recommendation": "Yes, bring an umbrella",
#   "reasoning": "High chance of rain (65% > 40% threshold) with significant rainfall...",
#   "forecast_details": {"precipitation_chance": 65, "precipitation_mm": 4.5, ...},
#   "decision_rule": "Umbrella recommended if: (precipitation_chance > 40%) OR (expected_rainfall >= 2mm)"
# }

Weather API Details

API Used: Open-Meteo
Authentication: None required (free tier, up to ~10,000 calls/day for non-commercial use)
Endpoints Used:

  • Geocoding API: https://geocoding-api.open-meteo.com/v1/search
  • Forecast API: https://api.open-meteo.com/v1/forecast

Why Open-Meteo?

  • No signup or API key required
  • Free and reliable
  • Returns WMO weather codes (decoded to human-readable strings)
  • Supports both current conditions and multi-day forecasts

Setup Instructions

Step 1: Deploy the MCP Server as a Databricks App

  1. Navigate to Databricks Apps:

    • In your Databricks workspace, go to ComputeApps
  2. Create a new app:

    databricks apps create weather-mcp-server \
      --source-code-path /Workspace/Users/<your-email>/weather_mcp_server
    
  3. Deploy the app:

    databricks apps deploy weather-mcp-server
    
  4. Get the app URL:

    databricks apps get weather-mcp-server
    

    Note the url field - you'll need this for Agent Bricks registration.

Step 2: Register the MCP Server with Agent Bricks

  1. Navigate to Agent Bricks:

    • In Databricks, go to Machine LearningAgents
  2. Create a new agent or edit an existing one

  3. Add External Tool:

    • Click "Add Tool" → "External MCP Tool"
    • Tool URL: <your-app-url> (from Step 1)
    • Tool Type: MCP
  4. Configure System Prompt:

    You are a weather assistant powered by real-time weather data.
    
    Available tools:
    - get_current_weather(location): Get current conditions
    - get_forecast(location, days): Get multi-day forecast (1-16 days)
    - predict_umbrella_needed(location, date, threshold_percent): Smart umbrella recommendation
    
    Guidelines:
    - Always call tools to get data - never guess or hallucinate weather information
    - If a location cannot be found, ask the user to clarify or provide a different location
    - For umbrella predictions, explain the reasoning based on the decision rule
    - Present temperatures in both Celsius and Fahrenheit
    - If an API call fails, inform the user clearly rather than making up data
    
  5. Save and test!

Step 3: Test the Agent

Try these example queries:

  1. Current conditions:

    • "What's the weather like in Chicago right now?"
    • "Tell me the current temperature in Tokyo"
  2. Forecasts:

    • "Will it rain in Seattle this weekend?"
    • "What's the 5-day forecast for Austin?"
  3. Recommendations:

    • "Should I bring an umbrella to Boston tomorrow?"
    • "Do I need a jacket in San Francisco on August 12th?"

Key Design Decisions

1. Separation of Concerns

  • weather_broker.py: All HTTP calls, geocoding, error handling
  • weather_mcp_server.py: Thin MCP tool wrappers, JSON serialization
  • Benefit: MCP tools stay clean and testable; broker can be mocked

2. No Hardcoded Credentials

  • Open-Meteo requires no API key
  • If using a different API, follow this pattern:
    from databricks.sdk import WorkspaceClient
    
    def _get_api_key():
        w = WorkspaceClient()
        return w.secrets.get_secret(scope="weather", key="api_key").value
    

3. Error Handling

  • Custom WeatherBrokerError exception
  • All tools return JSON (never raise exceptions to MCP client)
  • Clear error messages: {"error": "Location 'XYZ' not found"}

4. Prediction Tool Design

  • NOT just a passthrough of raw forecast data
  • Applies business logic: (precip_chance > threshold) OR (precip_mm >= 2mm)
  • Explains reasoning in natural language
  • Includes decision rule in output for transparency

Testing Locally (Optional)

You can test the MCP server locally before deploying:

# Install dependencies
pip install -r requirements.txt

# Run the server
python weather_mcp_server.py

# Server will start on http://localhost:8000
# Use MCP client or curl to test tools

Example Agent Interactions

Example 1: Current Weather

User: "What's the weather in London right now?"

Agent:
→ Calls get_current_weather("London")
← Returns: {"current": {"temperature_c": 18.5, "temperature_f": 65.3, "conditions": "Partly cloudy", ...}}
Response: "In London, it's currently 18.5°C (65.3°F) with partly cloudy skies. Humidity is at 72%, and winds are light at 12 km/h."


Example 2: Forecast Query

User: "Will it rain in Portland this week?"

Agent:
→ Calls get_forecast("Portland", 7)
← Returns: {"forecast": [{"date": "2026-08-09", "precipitation_chance": 65, ...}, ...]}
Response: "Looking at Portland's 7-day forecast, rain is likely on:

  • Aug 9: 65% chance, 4.5mm expected (Moderate rain)
  • Aug 11: 40% chance, 2.1mm expected (Light rain showers)

The rest of the week looks mostly dry!"


Example 3: Umbrella Recommendation

User: "Should I bring an umbrella to Austin tomorrow?"

Agent:
→ Calls predict_umbrella_needed("Austin", "tomorrow")
← Returns: {"recommendation": "No umbrella needed", "reasoning": "Low precipitation chance (15% <= 40% threshold) and minimal expected rainfall (0.2mm < 2mm)..."}
Response: "No umbrella needed for Austin tomorrow (Aug 9)! There's only a 15% chance of rain with minimal expected rainfall (0.2mm). Conditions will be mainly clear with highs of 34°C (93°F)."


Stretch Features (Not Implemented, Ideas for Extra Credit)

  1. Severe weather alerts (using NWS API for US locations)
  2. Historical weather lookup ("What was the weather in NYC last Christmas?")
  3. Multi-city comparison ("Which is warmer this weekend, Miami or LA?")
  4. Packing recommendations ("What should I pack for a trip to Iceland next week?")
  5. Dashboard app showing recent agent queries and predictions

Troubleshooting

Problem: "Location 'XYZ' not found"
Solution: Try a more specific location (e.g., "Springfield, Illinois" instead of "Springfield")

Problem: MCP tools not showing up in Agent Bricks
Solution: Verify the app is deployed and the URL is correct. Check app logs: databricks apps logs weather-mcp-server

Problem: "Forecast API error: timeout"
Solution: Open-Meteo may be temporarily unavailable. Retry after a minute.


推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选