|
26 | 26 | import io.modelcontextprotocol.client.McpAsyncClient;
|
27 | 27 | import io.modelcontextprotocol.client.McpSyncClient;
|
28 | 28 | import io.modelcontextprotocol.server.McpServerFeatures;
|
29 |
| -import io.modelcontextprotocol.server.McpServerFeatures.AsyncToolSpecification; |
30 | 29 | import io.modelcontextprotocol.server.McpSyncServerExchange;
|
31 | 30 | import io.modelcontextprotocol.spec.McpSchema;
|
32 | 31 | import io.modelcontextprotocol.spec.McpSchema.Role;
|
@@ -170,21 +169,21 @@ public static McpServerFeatures.SyncToolSpecification toSyncToolSpecification(To
|
170 | 169 | var tool = new McpSchema.Tool(toolCallback.getToolDefinition().name(),
|
171 | 170 | toolCallback.getToolDefinition().description(), toolCallback.getToolDefinition().inputSchema());
|
172 | 171 |
|
173 |
| - return new McpServerFeatures.SyncToolSpecification(tool, (exchange, request) -> { |
| 172 | + return McpServerFeatures.SyncToolSpecification.builder().tool(tool).callHandler((exchange, request) -> { |
174 | 173 | try {
|
175 | 174 | String callResult = toolCallback.call(ModelOptionsUtils.toJsonString(request),
|
176 | 175 | new ToolContext(Map.of(TOOL_CONTEXT_MCP_EXCHANGE_KEY, exchange)));
|
177 | 176 | if (mimeType != null && mimeType.toString().startsWith("image")) {
|
178 |
| - return new McpSchema.CallToolResult(List |
179 |
| - .of(new McpSchema.ImageContent(List.of(Role.ASSISTANT), null, callResult, mimeType.toString())), |
180 |
| - false); |
| 177 | + McpSchema.Annotations annotations = new McpSchema.Annotations(List.of(Role.ASSISTANT), null); |
| 178 | + return new McpSchema.CallToolResult( |
| 179 | + List.of(new McpSchema.ImageContent(annotations, callResult, mimeType.toString())), false); |
181 | 180 | }
|
182 | 181 | return new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(callResult)), false);
|
183 | 182 | }
|
184 | 183 | catch (Exception e) {
|
185 | 184 | return new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(e.getMessage())), true);
|
186 | 185 | }
|
187 |
| - }); |
| 186 | + }).build(); |
188 | 187 | }
|
189 | 188 |
|
190 | 189 | /**
|
@@ -287,10 +286,13 @@ public static McpServerFeatures.AsyncToolSpecification toAsyncToolSpecification(
|
287 | 286 |
|
288 | 287 | McpServerFeatures.SyncToolSpecification syncToolSpecification = toSyncToolSpecification(toolCallback, mimeType);
|
289 | 288 |
|
290 |
| - return new AsyncToolSpecification(syncToolSpecification.tool(), |
291 |
| - (exchange, map) -> Mono |
292 |
| - .fromCallable(() -> syncToolSpecification.call().apply(new McpSyncServerExchange(exchange), map)) |
293 |
| - .subscribeOn(Schedulers.boundedElastic())); |
| 289 | + return McpServerFeatures.AsyncToolSpecification.builder() |
| 290 | + .tool(syncToolSpecification.tool()) |
| 291 | + .callHandler((exchange, request) -> Mono |
| 292 | + .fromCallable( |
| 293 | + () -> syncToolSpecification.callHandler().apply(new McpSyncServerExchange(exchange), request)) |
| 294 | + .subscribeOn(Schedulers.boundedElastic())) |
| 295 | + .build(); |
294 | 296 | }
|
295 | 297 |
|
296 | 298 | /**
|
|
0 commit comments