Cover image
Try Now
2025-04-08

MCP网关 - 将MCP工具呼叫转换为HTTP请求

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

MCP Gateway

MCP (Model Context Protocol) Gateway can translate MCP tool callings to traditional HTTP API requests. It can provide a configurable way to get existing HTTP API to MCP territory.

Getting Started

Create config file from config.example.yaml:

$ cp config.example.yaml config.yaml

Edit config.yaml file, map all APIs to MCP tools.

Then start launch it with SSE transport:

$ 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)

Default is 3001.

Server Control

Change Port

Provide parameter --port=<port_no> in command line will change the port to SSE transport.

Launch gateway with port 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

Provide parameter --transport=stdio in command line will change the transport to stdio.

E.G.:

$ uv run mcp-gateway --transport=stdio

It's meaningless to manually launch gateway in stdio transport. You can configure in Cursor or Cline like:

{
    "mcpServers": {
        "mcp-gateway": {
          "command": "uv",
          "args": ["run", "mcp-gateway", "--transport=stdio"]
        }
      }
}

Or MCP Inspector with form values:

Item Value
Transport Type STDIO
Command uv
Arguments run mcp-gateway --transport=stdio

Configuration File

There is two parts in configuration YAML, server and tools. server defines the basic info for gateway server use. tools defines the mapping from single MCP tool to HTTP API request.

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 }}

Server

Item Description
name Server name
config Key/Value pairs that can be referenced by var {{.config.xxx}} in templates

Tools

tools is list of MCP tools mapping. Single tool props. are defined as follows:

Item Description
name Tool name (Function name), which is provided to LLM.
description Tool description through which LLM can understand what the tool could do.
args Arguments of tool (Function arguments).
requestTemplate Request mapping to target HTTP API.
responseTemplate Response mapping for response of target HTTP API.

Single argument props. are defined as follows:

Item Type Description
name Argument name, which is provided to LLM.
description Argument description through which LLM can understand and decide what value should be filled.
required Boolean Required argument or not.

Request template props. are defined as follows:

Item Description
method HTTP method
url Target HTTP API url template
headers HTTP headers

HTTP headers are defined as follows:

Item Description
key Header key
value Header value template

Response template props are defined as follows:

Item Description
body Response body template

Contribution

All kinds of contribution are welcomed.

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • appcypher
  • 很棒的MCP服务器 - 模型上下文协议服务器的策划列表

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

    Reviews

    3 (1)
    Avatar
    user_gyydD1N8
    2025-04-18

    I've been using the mcp-gateway by Timandes, and it has significantly streamlined my application development. The integration process is seamless, and the documentation is comprehensive. It's highly efficient and I appreciate the open-source nature of the project. Kudos to Timandes for such a fantastic tool! Check it out at https://github.com/Timandes/mcp-gateway.