使用说明
模型上下文协议(MCP)服务器
这个项目是 轻型标准化桥梁 通过Anthropic将Claude和其他LLM连接到现实世界的API **模型上下文协议(MCP)**该服务器实现了人工智能应用程序和外部数据源之间的无缝集成,而无需为每个API进行自定义集成工作。
项目概述
MCP服务器实现Anthropic的开放标准协议,通过统一的接口公开多种API功能(工具、资源和提示)。这允许任何兼容MCP的AI应用程序与各种外部服务进行交互,包括财务数据、天气信息、新闻提要和GitHub存储库。
邮差收藏: 邮递员收藏链接
未包含视频,因为在录制织布机视频之前,OpenAI API密钥无效
建筑
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Claude/LLM │◄──►│ MCP Server │◄──►│ External APIs │
│ Application │ │ (This Project) │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌──────────────────┐
│ API Handlers │
│ ┌─────────────┐ │
│ │ Finance API │ │
│ │ Weather API │ │
│ │ News API │ │
│ │ GitHub API │ │
│ └─────────────┘ │
└──────────────────┘
特性
Multi-API支持
- 财务数据:实时股票价格、市场数据和财务分析
- 气象服务:当前状况、预报和天气警报
- 新闻整合:最新新闻文章、标题和内容聚合
- GitHub集成:存储库数据、提交、问题和开发人员统计信息
MCP协议实现
- 通过MCP规范标准化工具曝光
- 外部API数据的资源管理
- 常见API交互的提示模板
- 统一的请求/响应处理
智能请求路由
- 混合提示处理程序 (
/mcp):处理跨越多个API的复杂查询 - 专用端点:用于特定用例的单个API访问点
- 基于用户意图和查询分析的智能路由
性能和可靠性
- 缓存策略:基于Redis的频繁访问数据缓存
- 速率限制:针对API配额耗尽的内置保护
- 错误处理:强大的错误恢复和优雅的降级
- 综合录井:用于调试的详细请求/响应日志记录
开发者体验
- 基于JSON的简单请求格式
- 所有端点的API响应一致
- 用于类型安全的TypeScript实现
- 全面的文档和示例
技术栈
核心技术
- Node.js 随着 TypeScript:服务器运行时和类型安全
- Express.js:Web框架和路由
- MCP协议:Anthropic的标准化AI-API桥梁规范
外部API集成
- 金融API:雅虎财经
- 天气APIOpenWeatherMap:
- 新闻API新闻API
- GitHub API:GitHub个人访问令牌(PAT)
基础设施
- 雷迪斯:缓存层用于性能优化
- 码头工人:容器化,便于部署
- 普罗米修斯:指标收集和监测
- 格拉法纳:可视化Prometheus收集的指标
项目结构
src/
├── mcpHandler/ # MCP protocol handlers
│ ├── financeHandler.ts
│ ├── githubHandler.ts
│ ├── mcpHandler.ts # Mixed prompt processor
│ ├── newsHandler.ts
│ └── weatherHandler.ts
├── routes/ # API route definitions
│ ├── financeRoute.ts
│ ├── githubRoute.ts
│ ├── mcpRoute.ts # Main MCP endpoint
│ ├── newsRoute.ts
│ └── weatherRoute.ts
├── services/ # External API service clients
│ ├── financeService.ts
│ ├── githubService.ts
│ ├── mcpService.ts
│ ├── newsService.ts
│ ├── openai.ts
│ └── weatherService.ts
├── utils/
│ └── redis.ts # Redis configuration
└── index.ts # Application entry point
API终点
混合提示处理程序
POST /mcp
处理可能需要来自多个API的数据的复杂查询。
单个API终点
POST /news - News and article queries
POST /github - GitHub repository and developer data
POST /weather - Weather conditions and forecasts
POST /finance - Financial data and market information
请求格式
所有端点都接受一个简单的JSON有效载荷:
{
"userMessage": "Your query or request here"
}
在本地运行
整个系统可以使用Docker Compose通过一个命令在本地运行。
# Build and run with Docker Compose
docker-compose up --build
# Run specific services
docker-compose up redis mcp-server
配置
环境变量
# Server Configuration
PORT=3000
# Redis Configuration
REDIS_URL=redis://localhost:6379
# API Keys
OPENAI_API_KEY=your_openai_key
ALPHA_VANTAGE_API_KEY=your_finance_key
WEATHER_API_KEY=your_weather_key
NEWS_API_KEY=your_news_key
GITHUB_TOKEN=your_github_token
使用示例
财务数据查询
curl -X POST http://localhost:3000/finance \
-H "Content-Type: application/json" \
-d '{"userMessage": "What is the current price of AAPL stock?"}'
混合查询(多个API)
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-d '{"userMessage": "What is the weather like in New York and what are the latest tech news?"}'
GitHub存储库分析
curl -X POST http://localhost:3000/github \
-H "Content-Type: application/json" \
-d '{"userMessage": "Show me the latest commits in the React repository"}'
