mcp-http工具
通过YAML配置将任何HTTP API转换为MCP工具。无需代码。
在YAML文件中定义你的工具——每个工具都映射到一个HTTP请求。MCP服务器读取配置,公开工具,并将请求代理到您的API。
快速开始
pnpm install创建 ~/.config/mcp-http-tools/config.yaml:
tools:
- name: check_health
description: Check if the API is healthy
url: http://localhost:3000/health
response:
type: text
- name: query_metrics
description: Run a PromQL query
url: http://localhost:9090/api/v1/query
params:
- name: query
description: PromQL expression
required: true
response:
type: json
path: data.result运行服务器:
node index.js要在一次运行中使用不同的配置文件,请执行以下操作:
node index.js --config /path/to/config.yaml如果显式配置文件丢失或YAML无效,启动将失败,而不是退回到空的工具列表。
配置参考
每个工具支持:
| 字段 | 必填 | 默认 | 描述 |
|---|---|---|---|
name | 是 | MCP工具名称 | |
description | 没有 | "" | 向LLM展示 |
url | 是 | 目标HTTP端点。支持 {param} 占位符和 {+path} 原始路径占位符,包括连字符名称,如 {user-id} | |
method | 没有 | GET | HTTP方法(GET, POST, PUT, PATCH,或 DELETE) |
auth.bearer_env | 没有 Authorization: Bearer ${ENV_VAR}。该值必须是仅包含字母、数字和下划线的环境变量名称 | ||
headers | 无 | 静态标头。支持 ${ENV_VAR} 替代品 | |
params | 没有 | [] | 刀具输入参数(见下文) |
response.type | 没有 | text | text (未加工)或 json (解析) |
response.path | no | 要从JSON中提取的点路径(例如。 data.result) |
参数
| 字段 | 必填 | 默认 | 描述 |
|---|---|---|---|
name | yes | 参数名称 | |
description | 否 | 显示给LLM | |
type | 没有 | string | JSON模式类型(string, number, boolean) |
required | 没有 | false | LLM是否必须提供此信息 |
default | 没有 | 省略参数时使用的值 |
params如何映射到请求
- 获取:params成为URL查询参数
- 发布:params成为JSON正文中的键
- URL占位符:
{param}在URL中使用参数值(不作为查询参数或正文键发送) - 原始路径占位符:
{+path}蜜饯/分隔符,同时仍对每个路径段进行编码 - 原始路径安全:
{+path}拒绝空段./..分段,因此调用者无法转义配置的URL前缀 - 原始路径配置合同:使用的参数
{+path}必须required: true或者有一个安全的非空default - 占位符名称:占位符匹配使用参数
name,所以名字像{user-id}和{+file-path}有效
看 docs/raw-path-plath-owners.md 确切地说 {+path} 合同。
例子
使用查询参数进行GET
- name: search_logs
description: Search logs via LogQL
url: http://localhost:3100/loki/api/v1/query_range
params:
- name: query
description: LogQL query
required: true
- name: limit
default: "50"
response:
type: json
path: data.result带有JSON正文的POST
- name: create_alert
description: Create an alert silence
method: POST
url: http://localhost:9093/api/v2/silences
params:
- name: matchers
required: true
- name: comment
required: true
response:
type: jsonURL路径参数
- name: get_label_values
description: List values for a Loki label
url: http://localhost:3100/loki/api/v1/label/{label}/values
params:
- name: label
description: Label name (e.g. app, job)
required: true
response:
type: json
path: data通过环境变量进行身份验证
- name: list_alerts
description: List active alerts
url: http://localhost:9093/api/v2/alerts
auth:
bearer_env: ALERTMANAGER_TOKEN
response:
type: json明确的 headers.Authorization 如果您需要非承载方案或完全自定义的值,仍然会获胜。
配置位置
配置从以下位置加载(第一个找到的获胜):
~/.config/mcp-http-tools/config.yaml./config.yaml(回购根)
如果两者都不存在,则服务器启动时没有工具。
通过 --config /path/to/config.yaml 或 --config=/path/to/config.yaml 覆盖搜索路径并仅加载一个文件。需要显式重写:如果该文件丢失或无效的YAML,服务器将退出并出错。
与Claude Desktop一起使用
经由 超级通道 对于SSE运输:
pnpm dlx supergateway --stdio "node /path/to/mcp-http-tools/index.js --config /path/to/config.yaml" --port 9191添加 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"mcp-http-tools": {
"url": "http://localhost:9191/sse"
}
}
}与Claude Code一起使用
添加 .claude/settings.json 或用作stdio MCP服务器:
{
"mcpServers": {
"mcp-http-tools": {
"command": "node",
"args": ["/path/to/mcp-http-tools/index.js", "--config", "/path/to/config.yaml"]
}
}
}测试
pnpm test推到 main 拉取请求也会运行 pnpm test 在GitHub操作中。
释放
main 由GitHub Actions通过语义发布发布。常规承诺 main 确定下一个版本,创建GitHub版本,并将包发布到npm。当维护人员需要在GitHub上重新运行发布时,也可以从GitHub Actions手动触发相同的工作流 main.
发布工作流使用GitHub Actions中的npm可信发布,因此该工作需要 id-token: write 权限和包必须在npm中为此存储库配置为受信任的发布者。
堆栈
- Node.js ESM
- @模型上下文协议/sdk --MCP协议
- js yaml --配置解析
许可证
麻省理工学院
