Skip to content

工具列表

工具列表

会话初始化完成后,调用 tools/list 方法获取当前服务实例可用的全部工具及其参数 schema。

请求示例

{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}

响应结构

返回包含所有可用的仿真工具及其参数说明:

{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "calculate_distillation",
"description": "执行蒸馏塔稳态仿真,返回塔板温度/组成分布",
"inputSchema": {
"type": "object",
"properties": {
"feed_composition": { "type": "object", "description": "进料组成(摩尔分数)" },
"stages": { "type": "integer", "description": "理论塔板数" },
"pressure": { "type": "number", "description": "操作压力(kPa)" }
},
"required": ["feed_composition", "stages", "pressure"]
}
}
]
}
}

调用工具

获取工具列表后,可通过 tools/call 方法调用具体工具:

{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "calculate_distillation",
"arguments": {
"feed_composition": { "ethanol": 0.5, "water": 0.5 },
"stages": 20,
"pressure": 101.325
}
}
}

工具发现建议

  • 缓存工具列表:工具列表变更不频繁,客户端可在会话内缓存,避免重复拉取
  • 订阅变更通知:若服务端声明 tools.listChanged: true,可通过订阅 notifications/tools/list_changed 感知工具增删
  • 校验 inputSchema:调用前按 inputSchema 校验参数,避免无效请求