使用说明
MCP气象服务器
一个简单的模型上下文协议(MCP)服务器,为GitHub Copilot等AI代理提供实时天气数据。
快速开始
克隆存储库:
git clone https://github.com/debs-obrien/mcp-weather-server-demo.git
cd mcp-weather-server-demo
1.安装依赖项
npm install
2.运行服务器
MCP检验员测试:
npx -y @modelcontextprotocol/inspector npx -y tsx main.ts
3.与VS代码一起使用
- 打开
mcp.json文件在.vscode文件夹 - 单击第4行上方的启动服务器按钮
- 打开聊天模式,选择代理,然后选择支持MCP的模式,如Claude Sonnet
- 在聊天中键入或说话,询问您所在城市的天气情况
特性
- 🌤️ 任何城市的实时天气数据
- 🌍 不需要API密钥(使用Open-Meteo)
- 🤖 与GitHub Copilot和其他MCP兼容的AI工具配合使用
- ⚡ 易于使用MCP检查器进行测试
使用示例
询问GitHub Copilot:
- “东京的天气怎么样?”
- “今天伦敦的天气怎么样?”
- “告诉我巴黎目前的天气”
运作原理
服务器提供 get-weather 该工具:
- 使用地理编码将城市名称转换为坐标
- 从Open-Meteo API获取当前天气数据
- 返回AI代理可以完美格式化的结构化数据
编码结构
// Creates MCP server with weather tool
const server = new McpServer({
name: "Weather Server",
version: "1.0.0"
});
// Defines the get-weather tool
server.tool('get-weather', 'Tool to get the weather of a city', ...);
// Connects via stdio transport
const transport = new StdioServerTransport();
server.connect(transport);
依赖项
@modelcontextprotocol/sdk-MCP服务器框架zod-架构验证
使用API
- Open Meteo -免费天气API,无需身份验证