API封装服务

一个轻量级的MCP服务器,封装任何API,提供发现、认证和文档三种稳定工具。

  • by GuruCloudAI
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 GuruCloudAI/mcp-api-wrapper

使用说明

MCP-as-API-振打器

包装任何API的精简MCP服务器。MCP服务器提供的不是工具,而是 3个稳定的工具 用于发现、身份验证和记录。完整的API在这个稳定层之后独立地发展。

想法

传统的MCP服务器公开了直接执行工作的工具。每一个新功能都意味着一个新工具,API更改需要服务器更新+客户端重新连接。

这颠倒了这种模式。 MCP服务器有三个永不改变的工具:

工具 目的
getAPIEndpoints 了解API的功能
getAuthToken 获取API访问的作用域承载令牌
getDocumentation 获取下载API完整文档的URL

客户端代理通过MCP连接一次,使用这3个工具进行引导,然后使用Bearer令牌直接与API对话。当API发展时,客户端只需重新匹配文档,不需要重新连接MCP。

建筑

┌─────────────┐     MCP Protocol     ┌──────────────────┐
│ Client Agent │◄───────────────────►│  Thin MCP Server  │
│  (MCP Client)│                     │   (3 tools only)  │
└──────┬───────┘                     └────────┬──────────┘
       │                                      │
       │  Direct API Calls                    │ Discovery
       │  (Bearer Token)                      │ + Auth
       │                                      │
       ▼                                      ▼
┌──────────────┐                     ┌──────────────────┐
│  API Server   │◄──── deploys ────│  Backend Agent     │
│  (Full API)   │                   │  (API Manager)    │
└──────────────┘                     └────────┬──────────┘
                                              │
                                     ┌────────▼──────────┐
                                     │  Message Queue     │
                                     │  (Agent Comms)     │
                                     └───────────────────┘

主要特点

  • 零重新连接 -API发展,MCP保持稳定
  • 解耦身份验证 -独立于MCP会话的API级身份验证(2FA、OAuth、RBAC)
  • 代理管理的API -后端代理响应客户端请求以发展API
  • 动态整合 --两个代理在运行时协商能力

快速开始

# Install
pip install -e ".[dev]"

# Run tests
pytest

# Run the MCP server (stdio mode)
mcp-api-wrapper

# Run the example API
uvicorn mcp_api_wrapper.api.example_api:create_example_api --factory --port 8000

项目结构

src/mcp_api_wrapper/
├── server/main.py          # The 3-tool MCP server
├── api/
│   ├── registry.py         # API endpoint registry
│   └── example_api.py      # Example FastAPI app
├── auth/
│   └── token_service.py    # JWT token generation/validation
├── queue/
│   └── message_queue.py    # Agent-to-agent message queue
├── schemas.py              # Shared Pydantic schemas
└── config.py               # Settings

许可证

麻省理工学院