MCP 网关
MCP(模型上下文协议)网关可以将 MCP 工具调用转换为传统的 HTTP API 请求。它提供了一种可配置的方式,将现有的 HTTP API 接入 MCP 领域。
入门
从config.example.yaml创建配置文件:
$ cp config.example.yaml config.yaml编辑config.yaml文件,将所有 API 映射到 MCP 工具。
然后开始使用 SSE 传输启动它:
$ uv run mcp-gateway
INFO: Started server process [15400]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:3001 (Press CTRL+C to quit)默认值为 3001。
Related MCP server: MCP-OpenAPI
服务器控制
更改端口
在命令行中提供参数--port=<port_no>将更改端口为 SSE 传输。
使用端口 3002 启动网关:
$ uv run mcp-gateway --port=3002
INFO: Started server process [15400]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:3002 (Press CTRL+C to quit)stdio 传输
在命令行中提供参数--transport=stdio将把传输更改为stdio。
例如:
$ uv run mcp-gateway --transport=stdio在 stdio transport 中手动启动网关是没有意义的。你可以在 Cursor 或者 Cline 中进行如下配置:
{
"mcpServers": {
"mcp-gateway": {
"command": "uv",
"args": ["run", "mcp-gateway", "--transport=stdio"]
}
}
}或者使用表单值的 MCP 检查器:
物品 | 价值 |
运输类型 | 标准输出 |
命令 | 紫外线 |
参数 | 运行 mcp-gateway --transport=stdio |
配置文件
配置 YAML 包含两部分, server和tools 。 server定义了网关服务器使用的基本信息。 tools定义了从单个 MCP 工具到 HTTP API 请求的映射。
server:
name: rest-amap-server
config:
apiKey: foo
tools:
- name: maps-geo
description: "将详细的结构化地址转换为经纬度坐标。支持对地标性名胜景区、建筑物名称解析为经纬度坐标"
args:
- name: address
description: "待解析的结构化地址信息"
required: true
- name: city
description: "指定查询的城市"
required: false
requestTemplate:
url: "https://restapi.amap.com/v3/geocode/geo?key={{.config.apiKey}}&address={{.args.address}}&city={{.args.city}}&source=ts_mcp"
method: GET
headers:
- key: x-api-key
value: "{{.config.apiKey}}"
- key: Content-Type
value: application/json
responseTemplate:
body: |
# 地理编码信息
{{- range $index, $geo := .Geocodes }}
## 地点 {{add $index 1}}
- **国家**: {{ $geo.Country }}
- **省份**: {{ $geo.Province }}
- **城市**: {{ $geo.City }}
- **城市代码**: {{ $geo.Citycode }}
- **区/县**: {{ $geo.District }}
- **街道**: {{ $geo.Street }}
- **门牌号**: {{ $geo.Number }}
- **行政编码**: {{ $geo.Adcode }}
- **坐标**: {{ $geo.Location }}
- **级别**: {{ $geo.Level }}
{{- end }}服务器
物品 | 描述 |
姓名 | 服务器名称 |
配置 | 模板中可以通过 var |
工具
tools是 MCP 工具映射列表。单个工具属性定义如下:
物品 | 描述 |
姓名 | 工具名称(函数名称),提供给LLM。 |
描述 | 工具描述,LLM 可以通过它了解该工具的功能。 |
参数 | 工具的参数(函数参数)。 |
请求模板 | 请求映射到目标 HTTP API。 |
响应模板 | 目标 HTTP API 响应的响应映射。 |
单参数道具定义如下:
物品 | 类型 | 描述 |
姓名 | 参数名称,提供给 LLM。 | |
描述 | 论证描述,LLM 可以通过它来理解并决定应该填充什么值。 | |
必需的 | 布尔值 | 是否需要参数。 |
请求模板道具定义如下:
物品 | 描述 |
方法 | HTTP 方法 |
网址 | 目标 HTTP API URL 模板 |
标题 | HTTP 标头 |
HTTP 标头定义如下:
物品 | 描述 |
钥匙 | 标题键 |
价值 | 标头值模板 |
响应模板 props 定义如下:
物品 | 描述 |
身体 | 响应主体模板 |
贡献
欢迎各种形式的贡献。
This server cannot be installed
Resources
Looking for Admin?
Admins can modify the Dockerfile, update the server description, and track usage metrics. If you are the server author, to access the admin panel.