| 98 | } |
| 99 | |
| 100 | public ToolOutput callToolOutput(String toolName, String argumentsJson) throws IOException { |
| 101 | JsonNode args; |
| 102 | if (argumentsJson == null || argumentsJson.isBlank()) { |
| 103 | args = JsonNodeFactory.instance.objectNode(); |
| 104 | } else { |
| 105 | args = MAPPER.readTree(argumentsJson); |
| 106 | } |
| 107 | ObjectNode params = McpCallToolRequest.toJson(toolName, args); |
| 108 | JsonNode result = rpc.request("tools/call", params, 60); |
| 109 | McpCallToolResult callResult = MAPPER.treeToValue(result, McpCallToolResult.class); |
| 110 | ToolOutput output = callResult.toToolOutput(); |
| 111 | if (callResult.isError()) { |
| 112 | return new ToolOutput("MCP 工具返回错误: " + output.text(), output.imageParts()); |
| 113 | } |
| 114 | return output; |
| 115 | } |
| 116 | |
| 117 | public List<McpResourceDescriptor> listResources() throws IOException { |
| 118 | try { |