MCP (0.1.3)

Download OpenAPI specification:

MCP(Model Context Protocol)Server 的注册、管理与代理调用。这里的 MCP 有两个 方向,别混:

  • 接入外部 MCP:把别人的 MCP Server 登记进平台,然后通过 /mcp/proxy/{mcp_id}/... 代为列工具、调工具。
  • 对外提供 MCP:把平台里的工具打包成一个 MCP Server 暴露出去,端点在 /mcp/app/{mcp_id}/...,MCP 客户端(Cursor / Claude Desktop 等)直接连它。

creation_type 区分这两类:custom 是登记的外部服务,tool_imported 是由 平台工具箱里的工具组装出来的。

运行模式 mode 在新增与更新时可选范围不同(服务端 validate 标签不一致):

接口 可选值
POST /mcp/ 新增 ssestream
PUT /mcp/{mcp_id} 更新 ssestreamstdio_uvstdio_npx

也就是说 stdio 类模式没法直接新建,只能建完再改过去。这不像有意设计,接入时 留意。

时间戳一律是纳秒:所有 *_time 字段用 time.Now().UnixNano() 生成, 形如 1784880971306127803。按毫秒解析会得到 1970 年附近的日期。

认证Authorization: Bearer <token>(OAuth access token 或 bak_ 前缀的 AppKey)。

MCP

探测外部 MCP Server

在登记之前先连一次目标 MCP Server,把它的工具列表与初始化信息取回来, 用于前端预览「这个服务里有什么」。不落库,纯探测。

接口名叫 parse/sse 是历史原因,modestream 同样可用。

Authorizations:
OAuth2AppKey
Request Body schema: application/json
required
mode
required
string (MCPMode)
Enum: "sse" "stream" "stdio_uv" "stdio_npx"

运行模式。**新增接口只接受 sse / stream**,stdio_* 只能通过更新接口设置。

url
required
string <uri>

目标 MCP Server 地址。

object

连接时携带的请求头。

Responses

Request samples

Content type
application/json
{}

Response samples

Content type
application/json
{
  • "tools": [
    ],
  • "init_info": { }
}

新增 MCP Server

登记一个 MCP Server。

路径带尾斜杠——路由注册的就是 /mcp/,不是 /mcp。Gin 默认会把 /mcp 重定向到 /mcp/,但重定向会丢 POST body 的客户端不在少数,直接写 全路径最稳。

mode 此处只接受 sse / stream(见文件头说明)。creation_typetool_imported 时用 tool_configs 指定要打包哪些工具。

Authorizations:
OAuth2AppKey
header Parameters
x-business-domain
required
string

业务域 ID。MCP Server 按业务域隔离,缺失返回 400。

Request Body schema: application/json
required
mode
string (MCPMode)
Enum: "sse" "stream" "stdio_uv" "stdio_npx"

运行模式。**新增接口只接受 sse / stream**,stdio_* 只能通过更新接口设置。

url
string <uri>

目标服务地址。sse / stream 模式用。

object

连接时携带的请求头,如上游的鉴权凭据。

command
string

启动命令。stdio_* 模式用。

args
Array of strings

启动参数。stdio_* 模式用。

object

环境变量。stdio_* 模式用。

name
required
string

MCP Server 名称。

description
string
creation_type
required
string (MCPCreationType)
Enum: "custom" "tool_imported"

创建类型:custom 登记的外部 MCP Server;tool_imported 由平台工具箱里的 工具组装而成。

source
string
Default: "custom"

来源。

category
string
Default: "other_category"

分类。

is_internal
boolean
Default: false

是否内置。

Array of objects (MCPToolConfig)

creation_type=tool_imported 时指定要打包的工具。

Responses

Request samples

Content type
application/json
Example
{
  • "creation_type": "custom",
  • "name": "天气服务",
  • "description": "提供天气查询",
  • "mode": "stream",
}

Response samples

Content type
application/json
{
  • "mcp_id": "string",
  • "status": "string"
}

分页查询 MCP Server

按业务域分页列出已登记的 MCP Server,支持按名称、来源、分类、状态、运行模式过滤。

Authorizations:
OAuth2AppKey
query Parameters
page
integer >= 1
Default: 1

页码,从 1 开始。

page_size
integer [ 1 .. 100 ]
Default: 10

每页数量,1–100。

sort_by
string
Default: "update_time"
Enum: "update_time" "create_time" "name"

排序字段。

sort_order
string
Default: "desc"
Enum: "asc" "desc"

排序方向。

name
string

按名称过滤。

source
string

按来源过滤。

category
string

按分类过滤。

status
string

按状态过滤。

create_user
string

按创建人过滤。

is_internal
boolean

只看内置。

mode
string (MCPMode)
Enum: "sse" "stream" "stdio_uv" "stdio_npx"

按运行模式过滤。

all
boolean

忽略分页返回全部。

header Parameters
x-business-domain
required
string

业务域 ID。MCP Server 按业务域隔离,缺失返回 400。

Responses

Response samples

Content type
application/json
{}

查询 MCP Server 详情

取详情。响应分两块:base_info 是配置本身,connection_info平台为 它生成的对外连接地址sse_url / stream_url)——MCP 客户端要连的是 这两个地址,不是 base_info.url(那是上游服务的地址)。

stream_url 为空表示该服务不支持流式。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

Responses

Response samples

Content type
application/json
{
  • "base_info": {
    },
  • "connection_info": {
    }
}

更新 MCP Server

整体更新配置。这里的 mode 接受四个值(含 stdio_uv / stdio_npx), 比新增时宽——stdio 类模式只能通过更新设置。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

Request Body schema: application/json
required
mcp_id
string

MCP Server ID。与路径参数一致即可。

name
string
description
string
creation_type
required
string (MCPCreationType)
Enum: "custom" "tool_imported"

创建类型:custom 登记的外部 MCP Server;tool_imported 由平台工具箱里的 工具组装而成。

mode
string (MCPMode)
Enum: "sse" "stream" "stdio_uv" "stdio_npx"

运行模式。**新增接口只接受 sse / stream**,stdio_* 只能通过更新接口设置。

url
string <uri>
object
command
string
args
Array of strings
object
source
string
category
string
Array of objects (MCPToolConfig)

Responses

Request samples

Content type
application/json
{
  • "mcp_id": "string",
  • "name": "string",
  • "description": "string",
  • "creation_type": "custom",
  • "mode": "sse",
  • "headers": {
    },
  • "command": "string",
  • "args": [
    ],
  • "env": {
    },
  • "source": "string",
  • "category": "string",
  • "tool_configs": [
    ]
}

Response samples

Content type
application/json
{
  • "mcp_id": "string",
  • "status": "unpublish"
}

删除 MCP Server

删除登记的 MCP Server。已被 Agent 挂载的服务删除后调用方会拿到 404。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

header Parameters
x-business-domain
required
string

业务域 ID。MCP Server 按业务域隔离,缺失返回 400。

Responses

Response samples

Content type
application/json
{
  • "code": "Public.BadRequest",
  • "description": "string",
  • "solution": "string",
  • "link": "string",
  • "details": null
}

更新 MCP Server 状态

发布 / 下架。改成 published 后该服务出现在 MCP 市场,offline 则下架。 与算子共用同一套生命周期状态。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

Request Body schema: application/json
required
status
required
string (BizStatus)
Enum: "unpublish" "published" "offline" "editing"

生命周期状态,与算子共用同一套。

Responses

Request samples

Content type
application/json
{
  • "status": "unpublish"
}

Response samples

Content type
application/json
{
  • "mcp_id": "string",
  • "status": "unpublish"
}

调试 MCP 工具

用给定参数真实调用一次该 MCP Server 上的某个工具,看返回什么。

失败不体现在 HTTP 状态码上:工具报错时接口仍是 200,is_errortrue,错误内容在 content 里。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

tool_name
required
string

工具名。

Request Body schema: application/json
required
object

工具入参,结构由该工具自己的 input schema 决定。

Responses

Request samples

Content type
application/json
{
  • "parameters": { }
}

Response samples

Content type
application/json
{
  • "content": [
    ],
  • "is_error": true
}

MCP 市场列表

已发布的 MCP Server 列表。比 /mcp/list 多一个 release_user 过滤条件, 其余参数一致。

Authorizations:
OAuth2AppKey
query Parameters
page
integer >= 1
Default: 1

页码,从 1 开始。

page_size
integer [ 1 .. 100 ]
Default: 10

每页数量,1–100。

sort_by
string
Default: "update_time"
Enum: "update_time" "create_time" "name"

排序字段。

sort_order
string
Default: "desc"
Enum: "asc" "desc"

排序方向。

name
string

按名称过滤。

release_user
string

按发布人过滤。

category
string

按分类过滤。

all
boolean

忽略分页返回全部。

header Parameters
x-business-domain
required
string

业务域 ID。MCP Server 按业务域隔离,缺失返回 400。

Responses

Response samples

Content type
application/json
{
  • "total": 0,
  • "page": 0,
  • "page_size": 0,
  • "total_pages": 0,
  • "has_next": true,
  • "has_prev": true,
  • "data": [
    ]
}

MCP 市场详情

市场视角的 MCP Server 详情,结构与 GET /mcp/{mcp_id} 一致。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

Responses

Response samples

Content type
application/json
{
  • "base_info": {
    },
  • "connection_info": {
    }
}

批量取 MCP Server 的指定字段

一次取多个 MCP Server 的部分字段,两个参数都走路径且都是逗号分隔 的列表——不是 query 参数,别写成 ?mcp_ids=a,b

fields 只能从这份白名单里选:mcp_idnamedescriptionsourcecategorymodeis_internalcreate_usercreate_timeupdate_userupdate_timerelease_timerelease_user。 不在白名单里的字段名会被静默忽略,不报错。

响应是按请求字段投影后的裸 map 数组,字段随 fields 变化, 因此这里不给固定 schema。

Authorizations:
OAuth2AppKey
path Parameters
mcp_ids
required
string
Example: 5a09efa5-d315-4450-adb3-5b2799d50b7f,7c9e6679-7425-40de-944b-e07fc1f90ae7

MCP Server ID 列表,逗号分隔。

fields
required
string
Example: mcp_id,name,category

要取的字段名,逗号分隔。只接受白名单内的字段。

Responses

Response samples

Content type
application/json
[
  • { }
]

代理:列出该 MCP Server 的工具

由平台代为连接目标 MCP Server 并取回工具列表。调用方不必自己实现 MCP 握手,也不需要能直连目标服务。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

Responses

Response samples

Content type
application/json
{
  • "tools": [
    ]
}

代理:调用该 MCP Server 的工具

由平台代为调用目标 MCP Server 上的工具。与 /mcp/{mcp_id}/tool/{tool_name}/debug 的差别只在定位方式:那边工具名走 路径、语义是「调试」;这边工具名在请求体里、语义是「生产调用」。 两者的返回结构一致,同样是**工具报错也返回 200,看 is_error**。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

Request Body schema: application/json
required
tool_name
required
string

工具名。

required
object

工具入参。

Responses

Request samples

Content type
application/json
{
  • "tool_name": "string",
  • "parameters": { }
}

Response samples

Content type
application/json
{
  • "content": [
    ],
  • "is_error": true
}

对外 MCP 端点(Streamable HTTP)

这是给 MCP 客户端连的端点,不是给业务代码调的 REST 接口。平台把该 mcp_id 对应的服务以标准 MCP Streamable HTTP 暴露出来,Cursor / Claude Desktop 等直接填这个地址即可。

实际地址以 GET /mcp/{mcp_id} 返回的 connection_info.stream_url 为准。

该路由注册为 Any,GET / POST / DELETE 都由 MCP 协议语义决定,请求与 响应结构见 MCP 规范,本文档不复述。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

Responses

Response samples

Content type
{ }

对外 MCP 端点(SSE)

SSE 传输的 MCP 端点,给只支持 SSE 的客户端用。实际地址以 GET /mcp/{mcp_id} 返回的 connection_info.sse_url 为准。

SSE 是单向下行通道,客户端的请求要发到配套的 POST /mcp/app/{mcp_id}/message

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

Responses

Response samples

Content type
application/json
{
  • "code": "Public.BadRequest",
  • "description": "string",
  • "solution": "string",
  • "link": "string",
  • "details": null
}

对外 MCP 端点(SSE 的上行消息)

/mcp/app/{mcp_id}/sse 配套:SSE 只负责下行,客户端的 JSON-RPC 请求 走这里上行。单独调它没有意义,必须先建立 SSE 连接。

Authorizations:
OAuth2AppKey
path Parameters
mcp_id
required
string

MCP Server ID。

Request Body schema: application/json
required
property name*
additional property
any

Responses

Request samples

Content type
application/json
{ }

Response samples

Content type
application/json
{ }