Skip to content

MCP 服务 API ​

提供 MCP(Model Context Protocol)服务的连通性检测功能。

基础路径 ​

/projects/:projectId/mcp

认证方式 ​

所有端点均需要 JWT Bearer Token 认证(combinedAuth 中间件)。

限流策略 ​

所有 MCP 端点受限流保护:每用户每分钟 5 次请求。


端点列表 ​

1. 测试 MCP 服务连通性 ​

POST /projects/:projectId/mcp/test-connection

测试指定 MCP 服务的连通性,验证远程 MCP 服务器是否可达并正常响应。

内置 SSRF 防护:URL 不允许指向私网地址。

Path 参数

参数类型必填说明
projectIdstring是项目 ID

Body 参数(JSON)

参数类型必填说明
namestring是MCP 服务名称
urlstring是MCP 服务 URL(必须为合法 URL 格式,且不能指向私网地址)
headersRecord<string, string>否自定义请求头(如认证信息)
timeoutnumber否连接超时时间(毫秒)

请求示例

json
{
  "name": "my-mcp-service",
  "url": "https://mcp.example.com/sse",
  "headers": {
    "Authorization": "Bearer xxx"
  },
  "timeout": 10000
}

响应 200

连接测试结果,包含连接状态和可用工具列表。

json
{
  "success": true,
  "tools": [
    {
      "name": "search",
      "description": "Search the web",
      "inputSchema": { ... }
    }
  ]
}

错误码

状态码说明
400参数缺失、JSON 格式无效、URL 格式错误或指向私网地址
401未认证
403无项目访问权限
429超出限流(每分钟 5 次)

源码 ​

  • 路由:apps/backend/src/routes/mcp.ts
  • MCP 连接测试:apps/backend/src/executor/mcp/mcp-host.ts
  • URL 校验:apps/backend/src/utils/url-validator.ts
  • 参考文档:MCP 集成配置(内部文档 docs/features/mcp-integrations.md)

AI Workflow Editor