MCP Gateway

Integrations

  • Provides a configuration format for defining MCP tool mappings to HTTP APIs, allowing users to specify server settings and tool definitions through structured YAML files.

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。

服务器控制

更改端口

在命令行中提供参数--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 包含两部分, servertoolsserver定义了网关服务器使用的基本信息。 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 {{.config.xxx}}引用的键/值对

工具

tools是 MCP 工具映射列表。单个工具属性定义如下:

物品描述
姓名工具名称(函数名称),提供给LLM。
描述工具描述,LLM 可以通过它了解该工具的功能。
参数工具的参数(函数参数)。
请求模板请求映射到目标 HTTP API。
响应模板目标 HTTP API 响应的响应映射。

单参数道具定义如下:

物品类型描述
姓名参数名称,提供给 LLM。
描述论证描述,LLM 可以通过它来理解并决定应该填充什么值。
必需的布尔值是否需要参数。

请求模板道具定义如下:

物品描述
方法HTTP 方法
网址目标 HTTP API URL 模板
标题HTTP 标头

HTTP 标头定义如下:

物品描述
钥匙标题键
价值标头值模板

响应模板 props 定义如下:

物品描述
身体响应主体模板

贡献

欢迎各种形式的贡献。

-
security - not tested
A
license - permissive license
-
quality - not tested

将模型上下文协议 (MCP) 工具调用转换为传统 HTTP API 请求的服务器,允许现有的 HTTP API 通过可配置的映射集成到 MCP 区域。

  1. Getting Started
    1. Server Control
      1. Change Port
      2. stdio Transport
    2. Configuration File
      1. Server
      2. Tools
    3. Contribution

      Appeared in Searches

      ID: fizi08hz6v