天气API服务

一个基于MCP协议的天气API服务器,提供通过Bearer令牌认证的天气API访问,支持AI代理和LLMs的标准化工具交互。

  • by Traia-IO
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Traia-IO/weather-api-complete-mcp-server

使用说明

Weather API完整MCP服务器

这是一个MCP(模型上下文协议)服务器,通过承载令牌访问Weather API Complete API来提供身份验证。它使人工智能代理和LLM能够通过标准化工具与Weather API Complete进行交互。

特性

  • 🔧 MCP协议:基于模型上下文协议构建,实现无缝的人工智能集成
  • 🌐 API完全访问:提供用于与Weather API完整终结点交互的工具
  • 🔐 安全认证:支持通过Bearer令牌进行API密钥身份验证
  • 🐳 Docker支持:使用Docker和Docker Compose轻松部署
  • ⚡ 异步操作:内置FastMCP,实现高效异步处理

API文档

可用工具

此服务器提供以下工具:

  • example_tool:占位符工具(待实施)
  • get_api_info:获取有关API服务和身份验证状态的信息

注:更换 example_tool 与实际天气API完整的API工具的基础上的文件。

安装

使用Docker(推荐)

  1. 克隆此存储库:

    git clone https://github.com/Traia-IO/weather-api-complete-mcp-server.git
    cd weather-api-complete-mcp-server
    
  2. 设置API密钥:

    export WEATHER_API_COMPLETE_API_KEY="your-api-key-here"
    
  3. 使用Docker运行:

    ./run_local_docker.sh
    

使用Docker Compose

  1. 创建一个 .env 使用您的配置文件:

WEATHER_API_COMPLETE_API_KEY=您所在的位置 端口=8000


2. Start the server:
```bash
docker-compose up

手动安装

  1. 使用安装依赖项 uv:

    uv pip install -e .
    
  2. 运行服务器:

WEATHER_API_COMPLETE_API_KEY=“your-API-KEY-here”uv运行python-m服务器


## Usage

### Health Check

Test if the server is running:
```bash
python mcp_health_check.py

使用CrewAI

from traia_iatp.mcp.traia_mcp_adapter import create_mcp_adapter_with_auth

# Connect with authentication
with create_mcp_adapter_with_auth(
    url="http://localhost:8000/mcp/",
    api_key="your-api-key"
) as tools:
    # Use the tools
    for tool in tools:
        print(f"Available tool: {tool.name}")
        
    # Example usage
    result = await tool.example_tool(query="test")
    print(result)

认证

此服务器需要API密钥身份验证。客户端必须在 Authorization 头球

Authorization: Bearer YOUR_API_KEY

然后,API密钥用于对Weather API Complete API的请求进行身份验证。

发展

测试服务器

  1. 在本地启动服务器
  2. 运行健康检查: python mcp_health_check.py
  3. 使用CrewAI适配器测试单个工具

添加新工具

要添加新工具,请编辑 server.py 以及:

  1. 为Weather API完整终结点创建API客户端函数
  2. 添加 @mcp.tool() 装饰功能
  3. 使用新工具更新此README
  4. 更新 deployment_params.json 工具名称位于功能数组中

部署

部署配置

这 deployment_params.json 文件包含此MCP服务器的部署配置:

{
  "github_url": "https://github.com/Traia-IO/weather-api-complete-mcp-server",
  "mcp_server": {
    "name": "weather-api-complete-mcp",
    "description": "Weather api integration",
    "server_type": "streamable-http",
"requires_api_key": true,
    "api_key_header": "Authorization",
"capabilities": [
      // List all implemented tool names here
      "example_tool",
      "get_api_info"
    ]
  },
  "deployment_method": "cloud_run",
  "gcp_project_id": "traia-mcp-servers",
  "gcp_region": "us-central1",
  "tags": ["weather api complete", "api"],
  "ref": "main"
}

重要:始终更新 capabilities 添加或删除工具时使用数组!

谷歌云运行

此服务器旨在部署在Google Cloud Run上。部署将:

  1. 从Dockerfile构建一个容器
  2. 使用指定配置部署到Cloud Run
  3. 暴露 /mcp 客户端连接的端点

环境变量

  • PORT:服务器端口(默认值:8000)
  • STAGE:环境阶段(默认:MAINNET,选项:MAINNET、TESTNET)
  • LOG_LEVEL:日志记录级别(默认值:INFO)
  • WEATHER_API_COMPLETE_API_KEY:您的天气API完整API密钥(必需)

故障排除

  1. 服务器未启动:使用以下命令检查Docker日志 docker logs <container-id>
  2. 身份验证错误:确保在环境中正确设置了API密钥
  3. API错误:验证您的API密钥是否具有必要的权限3。 工具错误:检查服务器日志以获取详细的错误消息

贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 实施新工具或改进
  4. 更新README和deployment_params.json
  5. 提交拉取请求

许可证

MIT许可证