调用 MCP 服务中的指定工具,并传入工具参数。
接口
POST /api/v1/mcp/servers/{mcpCode}/tools/call
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| mcpCode | string | 是 | MCP 编码 |
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| tool_name | string | 是 | 工具名称,使用查询工具列表返回的名称 |
| tool_params | object | 否 | 工具参数,键和值按工具 schema 传入;省略时按空对象处理 |
{"tool_name":"工具名称"},不能省略请求体。
响应
| 字段 | 类型 | 说明 |
|---|---|---|
| isError | boolean / null | 工具是否执行出错 |
| content | array<Content> / null | 工具返回内容 |
| content[].type | string / null | 内容类型,例如 text |
| content[].text | string / null | 文本内容 |
示例
错误
| HTTP 状态码 | error_code | 说明 |
|---|---|---|
| 400 | InvalidParameter | tool_name 缺失,或 tool_params 不是 JSON 对象 |
| 400 | - | MCP 服务调用失败,错误码由服务返回 |
工具自身执行出错时,接口可能返回
200、success=true、data.isError=true。请同时检查 HTTP 状态码和 data.isError。