MCP接入点
MCP Access Point 是一种轻量级的协议转换网关工具,旨在在传统协议之间建立通信桥梁 HTTP 服务和 MCP (模型上下文协议)客户端。它使MCP客户端能够直接与现有的HTTP服务交互,而不需要任何服务器端接口修改。
引言
该项目建立在 Pingora -一个能够支持大规模请求代理服务的超高性能网关代理库。Pingora已被用于构建处理Cloudflare平台核心流量的服务,多年来一直在互联网上每秒处理超过4000万个请求。它已成为支持Cloudflare平台上很大一部分流量的技术基石。
HTTP到MCP
此模式允许以下客户端 Cursor Desktop 通过以下方式与远程HTTP服务器通信 SSE,即使服务器本身不支持SSE协议。
- 示例设置包括两个服务:
- 服务1在本地运行 127.0.0.1:8090 - 服务2在以下位置远程运行 api.example.com
- 穿过
MCP Access Point,这两种服务都可以转换为MCP服务,而无需任何代码修改。 - 客户与
Service 1和Service 2通过MCP协议。MCP接入点自动区分MCP请求并将其转发到适当的后端服务。
graph LR
A["Cursor Desktop"] |SSE| B["MCP Access Point"]
A2["Other Desktop"] |Streamable Http| B["MCP Access Point"]
B |http 127.0.0.1:8090| C1["Existing API Server"]
B |https//api.example.com| C2["Existing API Server"]
style A2 fill:#ffe6f9,stroke:#333,color:black,stroke-width:2px
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 协议:
- ✅ 流式HTTP(无状态)2025-03-26
- 所有服务: ip:port/mcp - 单一服务: ip:port/api/{service_id}/mcp
- ✅ 上海时间2024年11月5日
- 所有服务: ip:port/sse - 单一服务: ip:port/api/{service_id}/sse
使用 IP:PORT/sse 为了 SSE 使用 IP:PORT/mcp 为了 Streamable HTTP
支持的MCP客户端
核心功能
- 协议转换:HTTP和MCP协议之间的无缝转换
- 零侵入式集成:与现有HTTP服务完全兼容
- 客户授权:使MCP客户端能够直接调用标准HTTP服务
- 轻量级代理:具有高效协议转换的极简主义架构
- 多租户技术:每个租户的独立配置和端点
- 运行时配置管理:动态配置更新,无需重新启动服务
- 管理员API:用于实时配置管理的RESTful API
快速开始
安装
# Install from source
git clone https://github.com/sxhxliang/mcp-access-point.git
cd mcp-access-point
cargo run -- -c config.yaml
# Use inspector for debugging (start service first)
npx @modelcontextprotocol/inspector node build/index.js
# Access http://127.0.0.1:6274/
# Select "SSE" and enter 0.0.0.0:8080/sse, then click connect
# or select "Streamable HTTP" and enter 0.0.0.0:8080/mcp多租户支持
MCP接入网关支持多租户,每个租户可以通过以下方式配置多个可访问的MCP服务:
/api/{mcp-service-id}/sse(适用于苏格兰和南方能源公司)/api/{mcp-service-id}/mcp(适用于流式HTTP)
配置示例:
# config.yaml example (supports multiple services)
mcps:
- id: service-1 # Access via /api/service-1/sse or /api/service-1/mcp
... # Service configuration
- id: service-2 # Access via /api/service-2/sse or /api/service-2/mcp
... # Service configuration
- id: service-3 # Access via /api/service-3/sse or /api/service-3/mcp
... # Service configuration要同时访问所有服务,请使用:
0.0.0.0:8080/mcp(流式HTTP)0.0.0.0:8080/sse上海证券交易所
配置详情
-c config.yaml
- -c (或 --config)指定配置文件路径(config.yaml). - 此文件定义了MCP接入点将代理和转换的API。
config.yaml示例
配置文件支持多租户,允许独立配置上游服务和每个MCP服务的路由规则。关键配置项包括:
- 兆赫 -MCP服务列表
- id:用于生成访问路径的唯一服务标识符 - upstream_id:关联的上游服务ID - path:OpenAPI规范文件路径。支持本地文件(例如。, config/openapi.json)以及远程HTTP/HTTPS URL(例如。, https://petstore.swagger.io/v2/swagger.json).支持JSON和YAML格式。 - routes:自定义路由配置(可选) - upstream:上游服务特定配置(可选)
- 上游 -上游服务配置
- id:上游服务ID - nodes:后端节点地址和权重 - type:负载平衡算法(循环/随机/ip_hash) - scheme:上游协议(http/https) - pass_host:HTTP主机标头处理 - upstream_host:覆盖主机标头值
完整配置示例:
# config.yaml example (supports multiple services)
mcps:
- id: service-1 # Unique identifier, accessible via /api/service-1/sse or /api/service-1/mcp
upstream_id: 1
path: config/openapi_for_demo_patch1.json # Local OpenAPI spec path
- id: service-2 # Unique identifier
upstream_id: 2
path: https://petstore.swagger.io/v2/swagger.json # Remote OpenAPI spec
- id: service-3
upstream_id: 3
routes: # Custom routing
- id: 1
operation_id: get_weather
uri: /points/{latitude},{longitude}
method: GET
meta:
name: Get Weather
description: Retrieve weather information by coordinates
inputSchema: # Optional input validation
type: object
required:
- latitude
- longitude
properties:
latitude:
type: number
minimum: -90
maximum: 90
longitude:
type: number
minimum: -180
maximum: 180
upstreams: # Required upstream configuration
- id: 1
headers: # Headers to send to upstream service
X-API-Key: "12345-abcdef" # API key
Authorization: "Bearer token123" # Bearer token
User-Agent: "MyApp/1.0" # User agent
Accept: "application/json" # Accept header
nodes: # Backend nodes (IP or domain)
"127.0.0.1:8090": 1 # Format: address:weight
- id: 2
nodes:
"127.0.0.1:8091": 1
- id: 3
nodes:
"api.weather.gov": 1
type: roundrobin # Load balancing algorithm
scheme: https # Protocol
pass_host: rewrite # Host header handling
upstream_host: api.weather.gov # Override Host要使用配置文件运行MCP接入网关,请执行以下操作:
cargo run -- -c config.yaml通过Docker运行
在本地运行以快速启动
# Note: Replace /path/to/your/config.yaml with actual path
docker run -d --name mcp-access-point --rm \
-p 8080:8080 \
-e port=8080 \
-v /path/to/your/config.yaml:/app/config/config.yaml \
ghcr.io/sxhxliang/mcp-access-point:main构建Docker镜像(可选)
- 安装docker
- 克隆存储库并构建映像
# Clone repository
git clone https://github.com/sxhxliang/mcp-access-point.git
cd mcp-access-point
# Build image
docker build -t liangshihua/mcp-access-point:latest .- 运行Docker容器
# Using environment variables (service running on host)
# Note: Replace /path/to/your/config.yaml with actual path
docker run -d --name mcp-access-point --rm \
-p 8080:8080 \
-e port=8080 \
-v /path/to/your/config.yaml:/app/config/config.yaml \
liangshihua/mcp-access-point:latest环境变量
port:MCP接入点侦听端口(默认值:8080)
典型使用案例
- 渐进式架构迁移:促进从HTTP到MCP的逐步过渡
- 混合架构支持:在MCP生态系统中重用现有的HTTP基础设施
- 协议兼容性:构建支持两种协议的混合系统
示例场景:\ 当基于MCP的AI客户端需要与传统的HTTP微服务交互时,MCP接入网关充当中间件层,实现无缝协议转换。
非常感谢 @林克林 写一篇有实例的文章:https://limcheekin.medium.com/building-your-first-no-code-mcp-server-the-fabric-integration-story-90da58cdbe1f
运行时配置管理
MCP接入点现在通过RESTful Admin API支持动态配置管理,允许您在不重新启动服务的情况下更新配置。
管理员API功能
- 实时配置更新:动态修改上游、服务、路线和其他资源
- 依赖性验证:更改前自动验证资源依赖关系
- 批量操作:以原子方式执行多个配置更改
- 配置验证:应用前验证更改的干运行模式
- 资源统计:监控和跟踪配置状态
管理员API配置
将以下内容添加到您的 config.yaml 启用管理API:
access_point:
admin:
address: "127.0.0.1:8081" # Admin API listening address
api_key: "your-api-key" # Optional API key for authentication管理员API端点
资源管理
GET /admin/resources-获取资源摘要和统计信息GET /admin/resources/{type}-列出特定类型的所有资源GET /admin/resources/{type}/{id}-获取特定资源POST /admin/resources/{type}/{id}-创建新资源PUT /admin/resources/{type}/{id}-更新现有资源DELETE /admin/resources/{type}/{id}-删除资源
高级操作
POST /admin/validate/{type}/{id}-验证资源配置POST /admin/batch-执行批处理操作POST /admin/reload/{type}-重新加载特定资源类型POST /admin/reload/config-从文件重新加载完整配置(默认为config.yaml).可选JSON正文:{ "config_path": "path/to/config.yaml" }
支持的资源类型
upstreams-后端服务器配置services-服务定义routes-路由规则global_rules-全局插件规则mcp_services-MCP服务配置ssls-SSL证书配置
管理员API示例
创建新的上游
curl -X POST http://localhost:8081/admin/resources/upstreams/my-upstream \
-H "Content-Type: application/json" \
-d '{
"id": "my-upstream",
"type": "RoundRobin",
"nodes": ["127.0.0.1:8001", "127.0.0.1:8002"],
"timeout": {
"connect": 5,
"read": 10,
"send": 10
}
}'创建服务
curl -X POST http://localhost:8081/admin/resources/services/my-service \
-H "Content-Type: application/json" \
-d '{
"id": "my-service",
"upstream_id": "my-upstream",
"hosts": ["api.example.com"]
}'批量操作
curl -X POST http://localhost:8081/admin/batch \
-H "Content-Type: application/json" \
-d '{
"dry_run": false,
"operations": [
{
"operation_type": "create",
"resource_type": "upstreams",
"resource_id": "batch-upstream",
"data": {
"id": "batch-upstream",
"type": "Random",
"nodes": ["192.168.1.10:8080"]
}
},
{
"operation_type": "create",
"resource_type": "services",
"resource_id": "batch-service",
"data": {
"id": "batch-service",
"upstream_id": "batch-upstream"
}
}
]
}'获取资源统计信息
curl http://localhost:8081/admin/resources管理员仪表板UI
- 路线:
GET /admin提供内置仪表板(static/admin_dashboard.html).
1. mcp_services, 2) ssls, 3) global_rules, 4) routes, 5) upstreams, 6) services.
- 每张卡显示
count以及格式化last_updated源自API响应。
从文件重新加载配置
# Uses default config.yaml
curl -X POST http://localhost:8081/admin/reload/config \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key"
# Or specify a different config path
curl -X POST http://localhost:8081/admin/reload/config \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key" \
-d '{"config_path": "./config.yaml"}'测试管理员API
使用提供的测试脚本验证管理API功能:
# Make the test script executable
chmod +x test-admin-api.sh
# Run comprehensive API tests
./test-admin-api.sh有关管理API的详细文档,请参阅 运行时间_CONFIG_API.md.
贡献指南
- 分叉此存储库。
- 创建一个分支并提交您的更改。
- 创建一个pull请求并等待它被合并。
- 确保你的代码遵循Rust编码标准。
