调用 MCP 服务中的指定工具,并传入工具参数。
接口
POST
/api/v1/mcp/servers/{mcpCode}/tools/call路径参数
mcpCodestring必填MCP 编码
请求体
tool_namestring必填工具名称,使用查询工具列表返回的名称
tool_paramsobject可选工具参数,键和值按工具 schema 传入;省略时按空对象处理
响应字段
isErrorboolean / null工具是否执行出错
contentarray<Content> / null工具返回内容
content[].typestring / null内容类型,例如 text
content[].textstring / null文本内容
请求示例
curl -X POST "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/mcp/servers/mcp-a1b2c3d4e5f6g7h8/tools/call" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"tool_name": "get_weather",
"tool_params": {
"city": "杭州"
}
}'
响应示例
{
"success": true,
"error_code": null,
"error_msg": null,
"data": {
"isError": false,
"content": [
{
"type": "text",
"text": "杭州今天晴,气温 18~26℃"
}
]
},
"request_id": "6f1c2a8e-3b0d-4c55-9a0e-2f7d1c9b8a11"
}
错误码
| HTTP 状态码 | error_code | 说明 |
|---|---|---|
| 400 | InvalidParameter | tool_name 缺失,或 tool_params 不是 JSON 对象 |
| 400 | - | MCP 服务调用失败,错误码由服务返回 |
说明工具自身执行出错时,接口可能返回 200、success=true、data.isError=true。请同时检查 HTTP 状态码和 data.isError。
该文章对您有帮助吗?