API Aggregator MCP Server
A Model Context Protocol (MCP) Server that provides unified access to multiple external APIs (weather, news, financial data) through a single, consistent interface for AI agents and LLMs.
README
API Aggregator MCP Server
A Model Context Protocol (MCP) Server that provides unified access to multiple external APIs through a single, consistent interface. Built for AI agents and LLMs, this server aggregates weather, news, and financial data into standardized tool calls.
Features
- ✅ MCP Protocol Compliant: Full JSON-RPC 2.0 support with proper tool discovery
- ✅ Multiple API Integrations: Weather, news, and stock market data
- ✅ Unified Error Handling: Consistent error responses across all APIs
- ✅ Type-Safe: Full type hints and Pydantic validation
- ✅ Async Support: High-performance async/await throughout
- ✅ Structured Logging: Rich, structured logs for monitoring
- ✅ Environment-Based Config: Secure API key management
Quick Start
1. Installation
# Clone the repository
git clone <repository-url>
cd api-aggregator-mcp
# Install dependencies
pip install -r requirements.txt
2. Configuration
Create a .env file with your API keys:
# Required for weather data
OPENWEATHER_API_KEY=your_openweather_api_key_here
# Required for news data
NEWS_API_KEY=your_news_api_key_here
# Required for stock data
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_key_here
# Optional server configuration
MCP_SERVER_HOST=localhost
MCP_SERVER_PORT=8000
MCP_SERVER_DEBUG=true
LOG_LEVEL=INFO
3. Get API Keys
- OpenWeatherMap: Get free API key
- News API: Get free API key
- Alpha Vantage: Get free API key
4. Run the Server
python -m src.main
The server will start at http://localhost:8000
Available Tools
🌤️ Weather Tool: get_weather
Get current weather information for any city.
Parameters:
city(required): City namecountry(optional): Country code (e.g., "US", "GB")units(optional): Temperature units - "metric" (default), "imperial", or "kelvin"
Example:
{
"city": "London",
"country": "GB",
"units": "metric"
}
Response:
{
"location": {
"city": "London",
"country": "GB",
"coordinates": {"latitude": 51.5074, "longitude": -0.1278}
},
"weather": {
"condition": "Clouds",
"description": "overcast clouds"
},
"temperature": {
"current": 15.2,
"feels_like": 14.8,
"unit": "°C"
},
"humidity": "73%",
"wind": {"speed": "3.5 m/s", "direction": "240°"}
}
📰 News Tool: get_news (Coming Soon)
Get latest news headlines by topic or region.
📈 Stock Tool: get_stock_price (Coming Soon)
Get current stock prices and financial data.
API Endpoints
Health Check
GET /
List Available Tools
GET /tools
Invoke Tool (REST)
POST /tools/{tool_name}
Content-Type: application/json
{
"city": "New York",
"units": "imperial"
}
MCP Protocol Endpoint
POST /mcp
Content-Type: application/json
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": {
"city": "Tokyo",
"country": "JP"
}
},
"id": "1"
}
Development
Project Structure
api-aggregator-mcp/
├── src/
│ ├── main.py # Application entry point
│ ├── server.py # MCP server implementation
│ ├── tools/ # API tool implementations
│ │ ├── weather.py # Weather API integration
│ │ ├── news.py # News API integration (TODO)
│ │ └── stock.py # Stock API integration (TODO)
│ └── utils/
│ ├── config.py # Configuration management
│ └── errors.py # Error handling utilities
├── tests/ # Unit tests
├── requirements.txt # Dependencies
└── README.md # This file
Running Tests
pytest tests/
Code Quality
# Format code
black src/
# Lint code
flake8 src/
# Type checking
mypy src/
Adding New Tools
- Create a new file in
src/tools/ - Implement the service class and handler function
- Define the tool schema
- Register in
src/main.py
Example tool template:
# src/tools/example.py
async def example_handler(parameters: Dict[str, Any]) -> Dict[str, Any]:
"""Handler for example tool."""
# Validate parameters
# Call external API
# Return normalized data
pass
EXAMPLE_TOOL_SCHEMA = {
"type": "object",
"properties": {
"param1": {"type": "string", "description": "..."},
},
"required": ["param1"],
}
Error Handling
All errors are returned in JSON-RPC format:
{
"jsonrpc": "2.0",
"error": {
"code": -32001,
"message": "API key missing for OpenWeatherMap",
"data": {"api": "OpenWeatherMap"}
},
"id": "1"
}
Common error codes:
-32001: API key missing-32002: API key invalid-32003: External API error-32004: Rate limit exceeded-32602: Invalid parameters
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
MIT License - see LICENSE file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。