使用说明
mcp警卫
mcp-guard 是一个小型反向代理,位于现有MCP HTTP端点之前,并强制执行一些安全默认值:
- CORS分配列表(无通配符
*,无反射来源) - 请求车身尺寸防护
- 可选的不记名代币门
它是 语言不可知论:您的上游可以是通过HTTP公开MCP端点的任何服务器。
跑
cd /Users/theodornengoy/Projects/mcp-guard
npm install
npm test
# Example: guard http://localhost:8788/mcp and expose it on http://localhost:8787/mcp
UPSTREAM_URL="http://localhost:8788/mcp" \
ALLOWED_ORIGINS="https://chatgpt.com,https://chat.openai.com" \
npm start
配置
环境变量:
PORT(默认值:8787)MCP_PATH(默认值:/mcp)UPSTREAM_URL(必填):上游MCP端点的完整URL(例如。http://127.0.0.1:8788/mcp)ALLOWED_ORIGINS(可选):逗号分隔的起源。默认值包括ChatGPT来源。MAX_BODY_BYTES(默认值:200000)AUTH_BEARER_TOKEN(可选):如果设置,则需要Authorization: Bearer <token>对于所有MCP请求UPSTREAM_TIMEOUT_MS(默认值:30000)
码头工人
# Pull prebuilt image
docker run --rm -p 8787:8787 \\
-e UPSTREAM_URL="http://host.docker.internal:8788/mcp" \\
-e ALLOWED_ORIGINS="https://chatgpt.com,https://chat.openai.com" \\
ghcr.io/theodornengoy/mcp-guard:v0
# Or build locally
docker build -t mcp-guard .
docker run --rm -p 8787:8787 \\
-e UPSTREAM_URL="http://host.docker.internal:8788/mcp" \\
-e ALLOWED_ORIGINS="https://chatgpt.com,https://chat.openai.com" \\
mcp-guard
为何这很重要
工具服务器中最常见的高严重性错误是许可CORS。 mcp-guard 让您在不重写上游服务器的情况下减少暴露。
