MCP 网关
MCP(模型上下文协议)网关可以将 MCP 工具调用转换为传统的 HTTP API 请求。它提供了一种可配置的方式,将现有的 HTTP API 接入 MCP 领域。
入门
从config.example.yaml
创建配置文件:
编辑config.yaml
文件,将所有 API 映射到 MCP 工具。
然后开始使用 SSE 传输启动它:
默认值为 3001。
服务器控制
更改端口
在命令行中提供参数--port=<port_no>
将更改端口为 SSE 传输。
使用端口 3002 启动网关:
stdio 传输
在命令行中提供参数--transport=stdio
将把传输更改为stdio。
例如:
在 stdio transport 中手动启动网关是没有意义的。你可以在 Cursor 或者 Cline 中进行如下配置:
或者使用表单值的 MCP 检查器:
物品 | 价值 |
---|---|
运输类型 | 标准输出 |
命令 | 紫外线 |
参数 | 运行 mcp-gateway --transport=stdio |
配置文件
配置 YAML 包含两部分, server
和tools
。 server
定义了网关服务器使用的基本信息。 tools
定义了从单个 MCP 工具到 HTTP API 请求的映射。
服务器
物品 | 描述 |
---|---|
姓名 | 服务器名称 |
配置 | 模板中可以通过 var {{.config.xxx}} 引用的键/值对 |
工具
tools
是 MCP 工具映射列表。单个工具属性定义如下:
物品 | 描述 |
---|---|
姓名 | 工具名称(函数名称),提供给LLM。 |
描述 | 工具描述,LLM 可以通过它了解该工具的功能。 |
参数 | 工具的参数(函数参数)。 |
请求模板 | 请求映射到目标 HTTP API。 |
响应模板 | 目标 HTTP API 响应的响应映射。 |
单参数道具定义如下:
物品 | 类型 | 描述 |
---|---|---|
姓名 | 参数名称,提供给 LLM。 | |
描述 | 论证描述,LLM 可以通过它来理解并决定应该填充什么值。 | |
必需的 | 布尔值 | 是否需要参数。 |
请求模板道具定义如下:
物品 | 描述 |
---|---|
方法 | HTTP 方法 |
网址 | 目标 HTTP API URL 模板 |
标题 | HTTP 标头 |
HTTP 标头定义如下:
物品 | 描述 |
---|---|
钥匙 | 标题键 |
价值 | 标头值模板 |
响应模板 props 定义如下:
物品 | 描述 |
---|---|
身体 | 响应主体模板 |
贡献
欢迎各种形式的贡献。
Related MCP Servers
- -securityAlicense-qualityMCP Server simplifies the implementation of the Model Context Protocol by providing a user-friendly API to create custom tools and manage server workflows efficiently.Last updated -43TypeScriptMIT License
- -securityAlicense-qualityMCP Server provides a simpler API to interact with the Model Context Protocol by allowing users to define custom tools and services to streamline workflows and processes.Last updated -132TypeScriptMIT License
- -securityAlicense-qualityAn MCP server that exposes HTTP methods defined in an OpenAPI specification as tools, enabling interaction with APIs via the Model Context Protocol.Last updated -2PythonMIT License
- -securityAlicense-qualityA Model Context Protocol (MCP) server that enables Claude or other LLMs to fetch content from URLs, supporting HTML, JSON, text, and images with configurable request parameters.Last updated -PythonMIT License