气象MCP服务器
使用TypeScript开发的天气MCP(模型上下文协议)服务器,提供模拟天气数据和相关功能。
特性
- 🌤️ 获取当前天气信息
- 📅 多日天气预报
- ⚠️ 天气警报系统
- 🔍 位置搜索功能
- 📊 天气统计
- 🎭 模拟数据支持
再进行
pnpm install🚀 用法
安装和建造
# Install dependencies
pnpm install
# Build project
pnpm run build启动方法
1.MCP协议(stdio)
# For MCP client integration
pnpm start2.HTTP API服务器🆕
# Start HTTP server (default port 8080)
pnpm run start:http
# Start HTTP server (specified port 3001)
pnpm run start:http:3001
# Or specify port directly
node dist/http-server.js 80803.简单HTTP服务器(推荐)🚀
# Start with default port 8080
pnpm run start:simple
# Start with specific ports
pnpm run start:simple:3000 # Development port
pnpm run start:simple:5000 # Alternative port
pnpm run start:simple:9000 # High port
# Or use the serve commands
pnpm run serve # Default port 8080
pnpm run serve:dev # Development port 3000
pnpm run serve:prod # Production port 8080
# Or specify any port directly
node dist/simple-http-server.js 4000动态端口支持
简单的HTTP服务器支持动态端口配置:
# Use any port you want
node dist/simple-http-server.js 3000
node dist/simple-http-server.js 5000
node dist/simple-http-server.js 9000
node dist/simple-http-server.js 12345服务器将自动:
- 如果未指定端口,则使用端口8080作为默认端口
- 接受任何有效的端口号作为命令行参数
- 在启动消息和文档中显示实际端口
HTTP API使用示例
启动HTTP服务器后,您可以通过以下方式使用它:
浏览器访问
- 打开
http://localhost:8080查看API文档 - 直接点击链接测试各种API
curl命令
# Get current weather for Hong Kong
curl "http://localhost:8080/weather?location=Hong Kong"
# Get 5-day weather forecast for Tokyo
curl "http://localhost:8080/forecast?location=Tokyo&days=5"
# Get weather alerts
curl "http://localhost:8080/alerts?location=Hong Kong"
# Search locations
curl "http://localhost:8080/locations?q=kong"
# Get statistics
curl "http://localhost:8080/stats"JavaScript/提取
// Get weather data
const response = await fetch('http://localhost:8080/weather?location=Tokyo');
const weather = await response.json();
console.log(weather);发展模式
# Watch mode compilation
pnpm run dev可用工具
1.get_current_weather
获取指定位置的当前天气信息
参数:
location(string):位置名称
例子:
{
"location": "Hong Kong"
}2.获取天气预报
获取指定位置的天气预报
参数:
location(string):位置名称days(数字,可选):预测天数(1-7天,默认3天)
例子:
{
"location": "Tokyo",
"days": 5
}3.获取食物警报
获取天气警报信息
参数:
location(字符串,可选):位置名称
例子:
{
"location": "Hong Kong"
}4.搜索位置
搜索支持的位置
参数:
query(string):搜索关键字
例子:
{
"query": "kong"
}5.获取_死亡_开始
获取天气统计数据
参数: 无
支持的地点
目前支持以下位置的详细天气数据:
- 香港
- 东京、大阪、京都、广岛、札幌、福冈(日本)
- 伦敦(英国)
- 纽约(美国)
- 悉尼(澳大利亚)
其他位置将返回随机生成的模拟数据。
技术规格
- 语言:TypeScript
- 程序包管理器:pnpm
- MCP-SDK:@modelcontextprotocol/sdk
- Node.js: >=18
项目结构
src/
├── index.ts # MCP server main file (stdio)
├── http-server.ts # HTTP API server
├── simple-http-server.ts # Simple HTTP server
├── weather-service.ts # Weather service logic
├── mock-data.ts # Mock data
└── types.ts # TypeScript type definitionsHTTP API终结点
| 端点 | 方法 | 参数 | 描述 |
|---|---|---|---|
/ | 获取 | - | neneneba API文档页 |
/mcp | POST | JSON-RPC 2.0 | MCP协议端点 |
/weather | GET | 位置(必填) | 获取当前天气 |
/forecast | GET | 位置(必填),天数(可选) | 获取天气预报 |
/alerts | GET | 位置(可选) | 获取天气警报 |
/locations | GET | q(必填) | 搜索位置 |
/stats | GET | - | 获取统计数据 |
许可证
MIT许可证
