MCP Access Point
MCP Access Point 是一个轻量级的协议转换网关工具,旨在为传统的 HTTP 服务和 MCP (Model Context Protocol) 客户端之间建立通信桥梁。它使得 MCP 客户端无需对现有 HTTP 服务的服务器端接口进行任何修改,即可直接与之交互。
引言
本项目基于 Pingora 构建,Pingora 是一个超高性能的网关代理库,能够支持大规模的请求代理服务。Pingora 已被用于构建处理 Cloudflare 平台核心流量的服务,多年来持续为互联网提供每秒超过 4000 万次的请求服务。它已成为支持 Cloudflare 平台绝大部分流量的技术基石。
HTTP 到 MCP 转换
这种模式允许像 Cursor Desktop 这样的客户端通过 SSE 与远程 HTTP 服务器通信,即使这些服务器本身不支持 SSE 协议。
示例配置包括两个服务:
* 服务 1 在本地运行于 127.0.0.1:8090
* 服务 2 在远程运行于 api.example.com
通过 MCP Access Point,这两个服务无需任何代码修改即可转换为 MCP 服务。客户端通过 MCP 协议与 Service 1 和 Service 2 进行通信。MCP Access Point 会自动区分 MCP 请求并将其转发到相应的后端服务。
以下是通信流程示意图:
“`mermaid
graph LR
A[“Cursor Desktop”] <–> |sse| B[“MCP Access Point”]
B <–> |http 127.0.0.1:8090| C1[“现有 API 服务器”]
B <–> |http api.example.com| C2[“现有 API 服务器”]
style A fill:#ffe6f9,stroke:#333,color:black,stroke-width:2px
style B fill:#e6e6af,stroke:#333,color:black,stroke-width:2px
style C1 fill:#e6ffe6,stroke:#333,color:black,stroke-width:2px
style C2 fill:#e6ffd6,stroke:#333,color:black,stroke-width:2px
“`
传输类型 (规范)
目前支持 SSE 和 Streamable HTTP 协议。
- ✅ Streamable HTTP(无状态)
- ✅ SSE 2024-11-05
使用 IP:PORT/sse 用于 SSE
使用 IP:PORT/mcp/ 用于 Streamable HTTP
快速开始
安装
“`bash
从源代码安装
git clone https://github.com/sxhxliang/mcp-access-point.git
cd mcp-access-point
cargo run — -c config.yaml
“`
“`bash
使用检查器进行调试(需先启动服务)
npx @modelcontextprotocol/inspector node build/index.js
访问 http://127.0.0.1:6274/
选择 “see” 并输入 0.0.0.0:8080/sse,然后点击连接
或选择 “Streamable HTTP” 并输入 0.0.0.0:8080/mcp/
“`
参数详情:
-c config.yaml
-c
(或--config
) 指定配置文件路径 (config.yaml)。- 此文件定义了多个 MCP 服务及其配置。
config.yaml 示例
“`yaml
config.yaml example (支持多个服务)
mcps:
– id: service-1 # 服务标识符
upstream_id: 1
upstream_config: # 上游服务配置(可选)
headers:
X-API-Key: “12345-abcdef”
Authorization: “Bearer token123”
User-Agent: “MyApp/1.0”
Accept: “application/json”
nodes:
“127.0.0.1:8090”: 1 # 必须与 upstreams 中的 upstream id 相同
path: openapi_for_demo_patch1.json # 本地 OpenAPI 文件路径
– id: web-api-2 # 服务标识符
upstream_id: 2
path: https://petstore.swagger.io/v2/swagger.json # 支持网络路径
routes: # 自定义路由(附加路由)
– id: 1
operation_id: test_custom_route # 操作标识符
uri: /api/v1/{id} # 匹配路径 (例如,/api/v1/*)
method: GET
meta:
name: test_custom_route
description: test by ID
inputSchema: # 输入模式验证(可选)
type: object
required:
– id
properties:
id:
type: integer
minimum: 1
upstreams: # 上游服务配置必须在此定义
– id: 1
nodes: #(例如,一个 web 服务器或 API 服务器)
“127.0.0.1:8090”: 1 # 地址及权重
– id: 2 # 另一个上游服务
nodes:
“127.0.0.1:8091”: 1
“`
使用以下命令运行 MCP Access Point 并指定配置文件:bash
cargo run -- -c config.yaml
核心特性
- 协议转换:实现 HTTP 和 MCP 协议之间的无缝转换。
- 零侵入式集成:与现有 HTTP 服务完全兼容,无需修改其代码。
- 增强客户端能力:使 MCP 客户端能够直接调用标准的 HTTP 服务。
- 轻量级代理:架构简洁,协议转换效率高。
通过 Docker 运行
构建 Docker 镜像(可选)
“`bash
克隆仓库
git clone https://github.com/sxhxliang/mcp-access-point.git
cd mcp-access-point
构建镜像
docker build -t liangshihua/mcp-access-point:latest .
“`
运行 Docker 容器
“`bash
使用环境变量 (服务运行在宿主机)
注意:将 /path/to/your/config.yaml 替换为实际路径
docker run -d –name mcp-access-point –rm \
-p 8080:8080 \
-e port=8080 \
-v /path/to/your/config.yaml:/app/config/config.yaml \
sxhxliang/mcp-access-point:latest
“`
环境变量
port
:MCP Access Point 监听端口 (默认值: 8080)。
典型使用场景
- 逐步架构迁移:方便从 HTTP 逐步过渡到 MCP 架构。
- 混合架构支持:在混合架构中复用现有 [内容不完整]。