使用说明
气象MCP服务器
一种模型上下文协议(MCP)服务器,为各个城市提供天气信息。
概述
这是一个基于TypeScript的MCP服务器,它实现了与天气相关的工具和资源。它使与MCP协议兼容的AI代理和工具能够以标准化的方式访问天气数据。
特性
- get_weather工具:检索支持城市的当前天气状况
- weather://cities资源:有可用天气数据的支持城市列表
支持城市
- 伦敦(22°C,阳光明媚)
- 巴黎(25°C,多云)
先决条件
- Node.js 18+
- npm或纱线
安装
# Install dependencies
npm install
发展
构建
# Compile TypeScript to JavaScript
npx tsc
跑
# Execute the server
node server.js
或者使用tsx直接执行:
npx tsx server.ts
项目结构
.
├── server.ts # Main server implementation with tools and resources
├── package.json # Project dependencies and metadata
├── package-lock.json # Locked dependency versions
├── .gitignore # Git ignore rules
└── .github/
└── copilot-instructions.md # AI agent development guidelines
建筑
此项目遵循MCP服务器架构:
- 服务器安装程序:用途
McpServer来自官方MCP SDK - 工具注册:使用Zod输入验证定义的天气工具
- 资源管理:列出可用天气数据的静态资源
- 类型安全:具有严格模式的完整TypeScript
API 参考
工具
get_weather
检索指定城市的当前天气。
输入架构:
{
city: string // City name (e.g., "London", "Paris")
}
答复:
{
"temp": "22° C",
"conditions": "Sunny"
}
资源
weather://cities
返回天气查询支持的城市列表。
配置
所有配置都在 package.json。服务器使用:
@modelcontextprotocol/sdk-MCP协议实现zod-运行时模式验证typescript-型式安全与编译
开发指南
看 .github/copilot-instructions.md 为从事此项目的AI代理和开发人员提供详细说明。
贡献
添加新工具时:
- 使用Zod定义输入模式
- 使用正确的MCP ContentBlock结构注册处理程序
- 用新功能更新此README
许可证
国际学生委员会