Weather API MCP Server
Single-file HTTP MCP Server for WeatherAPI.com to get current weather, forecasts, and location data. Supports bearer token authentication and exposes MCP tools for weather data retrieval.
README
Weather API MCP Server
Single-file HTTP MCP Server for WeatherAPI.com to get current weather, forecasts, and location data, powered by Bun.
- Bearer token authentication – uses your WeatherAPI.com API key via Authorization header
- Current weather data – get real-time weather conditions for any location
- Weather forecasting – get 1-3 day weather predictions
- Location search – find and validate location names
- Single file implementation – complete MCP server in
simple-mcp-server.ts - All capabilities are exposed as MCP tools over a Bun HTTP server
💡 Don't have Bun? Install it from https://bun.com/
🏗️ Built With
This single-file MCP server uses:
- Bun's built-in HTTP server - Ultra-fast native HTTP handling with zero dependencies
- Zod - TypeScript-first schema validation for bulletproof input validation
- WeatherAPI.com - RESTful API for weather data and forecasts
- Native fetch - Built-in HTTP client for API calls
🔐 Authentication
This MCP server uses Bearer token authentication with your WeatherAPI.com API key:
Authorization Header Authentication
Include your WeatherAPI.com API key in the Authorization header:
Authorization: Bearer your-weatherapi-key-here
MCP Client Integration
When adding this MCP server to MCP clients (Cursor, Claude Desktop, etc.):
- Server URL:
http://localhost:3000/mcp - Headers: Add Authorization header with your API key:
{ "Authorization": "Bearer your-weatherapi-key-here" }
Connecting to Cursor
Cursor is an excellent MCP client that can integrate with this weather API MCP server. Here's how to set it up:
1. Configure Cursor's MCP Settings
Create or edit your Cursor MCP configuration file at ~/.cursor/mcp.json:
{
"mcpServers": {
"weather": {
"type": "http",
"url": "http://localhost:3000/mcp",
"headers": {
"Authorization": "Bearer your-weatherapi-key-here"
}
}
}
}
Important: Replace your-weatherapi-key-here with your actual WeatherAPI.com API key.
2. Start Your MCP Server
In a terminal, start the weather API MCP server:
cd weather-api-mcp-server
bun run simple-mcp-server.ts
The server will start on http://localhost:3000/mcp.
3. Restart Cursor
After updating the MCP configuration, restart Cursor completely for the changes to take effect.
4. Verify Connection
Once connected, you can ask Cursor to use the weather tools:
- "What's the current weather in London?"
- "Get a 3-day forecast for Tokyo"
- "Search for locations named Springfield"
Cursor will automatically use the appropriate MCP tool from your weather server to fetch the data.
5. Troubleshooting
If the connection fails:
- Check server status: Ensure your MCP server is running on port 3000
- Verify API key: Make sure your WeatherAPI.com API key is correct
- Check Cursor logs: Look for MCP connection errors in Cursor's developer console
- Test manually: Use the MCP Inspector to verify your server works independently
Getting Your API Key
- Sign up for free at WeatherAPI.com
- Verify your email address
- Copy your API key from the dashboard
- Use it in the Authorization header as shown above
✨ Features
| Capability | WeatherAPI.com endpoint |
|---|---|
| Get current weather | GET /v1/current.json with location parameter |
| Get weather forecast | GET /v1/forecast.json with location and days |
| Search for locations | GET /v1/search.json with query parameter |
🗂 Repo layout
.
├─ simple-mcp-server.ts # Complete single-file MCP server
├─ package.json # Dependencies (bun, zod)
├─ tsconfig.json # TypeScript configuration
└─ README.md # This file
The entire MCP server is implemented in a single TypeScript file (simple-mcp-server.ts) that handles WeatherAPI.com integration.
⚙️ Prerequisites
-
WeatherAPI.com API key
- Sign up for free at https://www.weatherapi.com/signup.aspx
- Verify your email address
- Get your API key from the dashboard
- Free tier includes 1 million calls per month
-
Bun ≥ 1.2.2 installed locally.
🌍 Configuration
| Name | Example | Required | Description |
|---|---|---|---|
PORT |
3000 |
❌ | Server port (defaults to 3000) |
🔑 Authentication: API key provided via Authorization header only - no environment variables needed!
🧪 Development & Testing
You can use the official MCP Inspector to interactively test this server.
-
Start the server in one terminal:
bun run simple-mcp-server.ts -
Run the inspector in another terminal:
npx @modelcontextprotocol/inspector http://localhost:3000/mcp -
Add your API key in the inspector's headers section:
{ "Authorization": "Bearer your-weatherapi-key-here" }
This will launch a web UI where you can see all available tools and manually trigger them with different parameters.
▶️ Running locally
# Install Bun (if you don't have it)
curl -fsSL https://bun.sh/install | bash
# Install deps
bun install
# Run server on port 3000
bun run simple-mcp-server.ts
Send a request with curl if you feel like it:
curl -X POST "http://localhost:3000/mcp" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-weatherapi-key-here" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "getCurrentWeather",
"arguments": {
"location": "London"
}
}
}'
Additional endpoints
| Route | Method | Purpose |
|---|---|---|
/healthz |
GET/HEAD | Simple health-check (returns 200 OK) |
All responses include Access-Control-Allow-Origin: * so the MCP can be called from a browser without extra CORS configuration.
🛠️ MCP tool set
| Tool | Purpose | Input → Output |
|---|---|---|
getCurrentWeather |
get current weather conditions | { location } → current weather data |
getWeatherForecast |
get weather forecast | { location, days? } → forecast data (1-3 days) |
searchLocations |
find location names | { query } → array of matching locations |
🔍 Parameters:
- location: City name, ZIP code, coordinates (lat,lon), or IP address
- days: Number of forecast days (1-3, defaults to 3)
- query: Search term for location names (partial matches work)
📊 Response Data:
- Current weather: Temperature, conditions, humidity, wind, feels-like temperature
- Forecast: Daily high/low temperatures, conditions, precipitation chance
- Location data: Resolved location name, country, coordinates, timezone
Then use the Authorization header in your requests:
Authorization: Bearer your-weatherapi-key-here
Usage Examples
Current Weather:
# Get current weather for London
{ "location": "London" }
# Use coordinates
{ "location": "40.7128,-74.0060" }
# Use ZIP code
{ "location": "10001" }
Weather Forecast:
# 3-day forecast (default)
{ "location": "Tokyo" }
# 1-day forecast
{ "location": "Paris", "days": 1 }
# 2-day forecast
{ "location": "Sydney", "days": 2 }
Location Search:
# Find cities named "Springfield"
{ "query": "Springfield" }
# Partial match
{ "query": "Albuquer" }
# International locations
{ "query": "München" }
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。