使用说明
🌤️ 气象MCP服务器
A. 模型上下文协议(MCP) 使用Open-Meteo API提供实时天气信息的服务器。
📋 特性
✨ 实时天气数据 -获取全球任何城市的当前天气状况
🌍 地理编码支持 -自动将城市名称转换为坐标
🔧 MCP协议 -基于模型上下文协议构建,实现无缝AI集成
⚡ 快速轻便 -最小的依赖关系,最大的性能
🛠️ TypeScript -完全打字,提供更好的开发人员体验
🚀 安装
先决条件
- Node.js v18或更高版本
- pnpm v10.24.0(或npm/yarn)
设置
-
克隆仓库
git clone https://github.com/yourusername/mcp-project.git cd mcp-project -
安装依赖项
pnpm install # or npm install
💻 用法
运行服务器
npx tsx main.ts
与MCP检查器一起使用
对于调试和测试,请使用MCP检查器:
npx @modelcontextprotocol/inspector npx tsx main.ts
这将:
- 启动MCP服务器
- 在浏览器中启动检查器UI
- 允许您以交互方式测试工具
🔌 API
可用工具
fetch-weather
获取指定城市的当前天气信息。
参数:
city(string,必填)-要获取天气的城市名称
请求示例:
{
"city": "London"
}
示例响应:
{
"content": [
{
"type": "text",
"text": "{
\"latitude\": 51.5074,
\"longitude\": -0.1278,
\"current\": {
\"temperature_2m\": 15.2,
\"precipitation\": 0,
\"rain\": 0,
\"is_day\": 1
},
\"hourly\": {
\"temperature_2m\": [...]
}
}"
}
]
}
🛠️ 发展
项目结构
mcp-project/
├── main.ts # Main server implementation
├── package.json # Project dependencies
├── README.md # This file
└── LICENSE # License information
关键依赖关系
- @模型上下文协议/sdk -MCP协议实现
- 黄道带 -参数的模式验证
- 多伦多证券交易所 -TypeScript执行
运作原理
- 服务器初始化:创建具有名称和版本的MCP服务器实例
- 工具注册:注册
fetch-weatherZod模式验证工具 - 地理编码:使用Open-Meteo Geocoding API将城市名称转换为坐标
- 天气预报:使用坐标检索当前天气数据
- 运输:使用STDIO传输与MCP客户端通信
🌐 使用的API
- Open-Meteo地理编码API -城市名称到坐标的转换
- 开放气象API -天气预报数据
📝 配置
服务器使用ES模块("type": "module" 在 package.json)支持顶级wait和现代JavaScript功能。
服务器配置
const server = new McpServer({
name: "Demo",
version: "1.0.0",
});
🤝 贡献
欢迎投稿!请随意:
- 复刻仓库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📄 许可证
该项目根据 MIT许可证 -看看 许可证 文件以获取详细信息。
🔗 资源
由...制作❤️ 使用模型上下文协议