CLAUDE.md
此文件为使用此存储库中的代码时的Claude Code(Claude.ai/Code)提供了指导。
项目概述
这是一个包含用TypeScript编写的模型上下文协议(MCP)服务器的存储库。存储库包含两个MCP服务器实现:
- 天气mcp -提供美国天气数据访问的天气信息服务器
- bfl mcp -黑森林实验室集成服务器(当前为空/占位符)
这两台服务器都是使用 @modelcontextprotocol/sdk 并通过MCP协议提供工具。
建筑
气象mcp服务器
- 位置:
weather-mcp/ - 目的:为美国各地提供天气警报和预报
- API集成:使用美国国家气象局(NWS)API
- 工具:
- get_alerts:获取美国某州的天气警报 - get_forecast:获取坐标的天气预报
bfl-mcp服务器
- 位置:
bfl-mcp/ - 目的:黑森林实验室集成占位符
- 状态:空的实施准备发展
开发命令
建筑
# Build weather-mcp
cd weather-mcp && npm run build
# Build bfl-mcp
cd bfl-mcp && npm run build安装
# Install dependencies for weather-mcp
cd weather-mcp && npm install
# Install dependencies for bfl-mcp
cd bfl-mcp && npm install编码结构
气象mcp结构
weather-mcp/
├── src/
│ ├── index.ts # Main server entry point
│ ├── vars.ts # Constants (API base URLs, user agent)
│ ├── helpers.ts # Utility functions and types
│ └── tools/
│ ├── get_alerts.ts # Weather alerts tool implementation
│ └── get_forecast.ts # Weather forecast tool implementation
├── build/ # Compiled JavaScript output
├── package.json
└── tsconfig.json关键组件
MCP服务器设置
- 用途
McpServer从@modelcontextprotocol/sdk/server/mcp.js - 通过以下方式进行沟通
StdioServerTransport - 工具注册使用
server.tool()方法
TypeScript配置
- 目标:ES2022
- 模块:Node16
- 输出目录:
./build - 严格模式已启用
错误处理
- 所有API请求都包装在try-chatch块中
- 向MCP客户端返回优美的错误响应
- 用于调试的控制台错误日志记录
开发说明
天气API集成
- weather-mcp服务器与美国国家气象局API集成
- 仅支持美国位置(纬度/经度坐标)
- API请求需要正确的User-Agent头
- 实施API速率限制和错误处理
工具实现模式
- 工具在中作为单独的模块实现
src/tools/ - 每个工具导出一个
ToolCallback函数 - 用于参数验证的Zod模式
- 与内容数组一致的响应格式
构建过程
- TypeScript编译到
build/目录 - 在生成输出上设置可执行权限
- ES模块配置(
"type": "module")
测试
要在构建后测试MCP服务器,请执行以下操作:
# Run weather server
./weather-mcp/build/index.js
# Test with MCP client (Claude Desktop, etc.)
# Add server configuration pointing to build/index.js