从 MCP 客户端调用¶
通过指定智能体的 MCP HTTP 入口列出或调用当前任务允许使用的工具。此接口必须使用任务范围的 RuntimeGrant;个人访问令牌不能替代该凭据。
POST https://api.moi.matrixorigin.cn/v5/workspaces/{workspace_id}/agents/{agent_id}/mcp/http
调用前准备¶
准备与当前运行时任务匹配的 RuntimeGrant,以及路径中的工作区 ID 和智能体 ID。个人访问令牌不能替代 RuntimeGrant。
请求头必须提供唯一的 Authorization: Bearer <RUNTIME_GRANT>。JSON-RPC 请求不接受未知顶层字段。
请求体¶
curl -X POST "https://api.moi.matrixorigin.cn/v5/workspaces/$WORKSPACE_ID/agents/$AGENT_ID/mcp/http" \
-H "Authorization: Bearer $RUNTIME_GRANT" \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"id": "<REQUEST_ID>",
"method": "tools/list"
}'
字段 |
类型 |
必填 |
说明 |
|---|---|---|---|
|
string |
是 |
固定为 2.0。 |
|
string 或 number |
否 |
调用方生成的 JSON-RPC 请求 ID;响应会回显该值。 |
|
string |
是 |
tools/list 或 tools/call。 |
|
object |
否 |
方法参数。tools/list 仅接受省略、null 或空对象。 |
|
string |
tools/call 时是 |
要调用的工具名称。必须使用 tools/list 返回的 name。 |
|
object |
否 |
工具输入。 |
|
string |
否 |
调用方关联本次工具调用的 ID。 |
|
object |
否 |
协议元数据。 |
请求参数¶
curl -X POST "https://api.moi.matrixorigin.cn/v5/workspaces/$WORKSPACE_ID/agents/$AGENT_ID/mcp/http" \
-H "Authorization: Bearer $RUNTIME_GRANT" \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"id": "<REQUEST_ID>",
"method": "tools/list"
}'
字段 |
类型 |
必填 |
说明 |
|---|---|---|---|
|
string |
是 |
RuntimeGrant 对应的工作区 ID。 |
|
string |
是 |
目标智能体 ID。 |
成功响应¶
{
"jsonrpc": "2.0",
"id": "req_01",
"result": {
"tools": [
{
"id": "tool_01",
"name": "tool_01",
"kind": "function",
"description": "查询销售数据",
"side_effect_class": "read",
"input_schema": {
"type": "object"
}
}
]
}
}
成功时返回 200 和 JSON-RPC 响应。tools/list 仅返回当前 RuntimeGrant 允许的工具;tools/call 的 structuredContent 是机器可读的调用结果。
本文中,字段路径中的 [] 表示数组中的每一项。例如,items[].name 表示 items 数组中每一项的 name 字段。
tools/call 的成功结果示例如下:
{
"jsonrpc": "2.0",
"id": "req_01",
"result": {
"content": [
{
"type": "text",
"text": "{\"call_id\":\"call_01\",\"tool_id\":\"tool_01\",\"output\":{}}"
}
],
"structuredContent": {
"call_id": "call_01",
"tool_id": "tool_01",
"output": {},
"created_at": "2026-08-18T01:00:00Z"
}
}
}
某些可由模型修正的工具错误仍返回 200,并在 result.isError 中标记为 true;请读取 result.content 后修正工具参数。
字段 |
类型 |
说明 |
|---|---|---|
|
string |
固定为 2.0。 |
|
string 或 number 或 null |
与请求中的 JSON-RPC ID 对应。 |
字段 |
类型 |
说明 |
|---|---|---|
|
array of object |
tools/list 返回的允许调用的工具。 |
|
string |
工具 ID。 |
|
string |
可调用的工具名称;调用时必须原样传入 params.name。 |
|
string |
工具类型;未设置时不返回。 |
|
string |
工具说明;未设置时不返回。 |
|
string |
工具副作用分类。 |
|
object |
输入和输出 JSON Schema;未设置时不返回。 |
|
object |
输入和输出 JSON Schema;未设置时不返回。 |
|
object |
MCP 协议元数据;仅在服务端提供时返回。 |
|
array of object |
面向仅消费文本内容的客户端的结果。 |
|
object |
tools/call 的机器可读结果。 |
|
string |
工具调用 ID。 |
|
string |
实际调用的工具 ID。 |
|
object |
工具输出。 |
|
object |
调用元数据;存在时返回。 |
|
array |
调用生成的产物;存在时返回。 |
|
string |
调用结果创建时间;存在时返回。 |
错误响应¶
{
"jsonrpc": "2.0",
"id": "req_01",
"error": {
"code": -32602,
"message": "invalid params"
}
}
MCP 网关错误使用 JSON-RPC error 对象。
字段 |
类型 |
说明 |
|---|---|---|
|
|
请求体无法解析、 |
|
|
RuntimeGrant 缺失、无效、已过期、被拒绝,或与路径中的工作区不匹配。建议:使用未过期且工作区匹配的 RuntimeGrant。 |
|
|
调用工具所需的凭据不可用。建议:检查运行时任务和工具所需的凭据配置。 |
|
|
请求体超过网关允许大小。建议:缩小请求体。 |
|
|
工具不受支持。建议:先调用 |
|
|
网关或工具执行出现未分类错误。建议:记录请求 ID 和错误信息后重试。 |
|
|
MCP 网关未配置。建议:稍后重试,或检查运行时部署。 |
后续操作¶
先调用 tools/list,再调用 tools/call。不要缓存其他 RuntimeGrant 的工具列表或跨任务复用 RuntimeGrant。