Skip to content

Commit 53f7b77

Browse files
committed
refactor: Replace Map<String, Object> with CallToolRequest in StructuredOutputCallToolHandler
Follow up to #357 to update tool call handler signature from Map<String, Object> to McpSchema.CallToolRequest for consistency with changes in #375. - Change BiFunction parameter from Map<String, Object> to McpSchema.CallToolRequest for better type safety - Update method signature to accept CallToolRequest instead of raw arguments map - Replace toolSpecification.call() with toolSpecification.callHandler() - Migrate to builder pattern for AsyncToolSpecification construction Signed-off-by: Christian Tzolov <[email protected]>
1 parent b04c30b commit 53f7b77

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,17 @@ public Mono<Void> addTool(McpServerFeatures.AsyncToolSpecification toolSpecifica
313313
}
314314

315315
private static class StructuredOutputCallToolHandler
316-
implements BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> {
316+
implements BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> {
317317

318-
private final BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> delegateCallToolResult;
318+
private final BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> delegateCallToolResult;
319319

320320
private final JsonSchemaValidator jsonSchemaValidator;
321321

322322
private final Map<String, Object> outputSchema;
323323

324324
public StructuredOutputCallToolHandler(JsonSchemaValidator jsonSchemaValidator,
325325
Map<String, Object> outputSchema,
326-
BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> delegateHandler) {
326+
BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> delegateHandler) {
327327

328328
Assert.notNull(jsonSchemaValidator, "JsonSchemaValidator must not be null");
329329
Assert.notNull(delegateHandler, "Delegate call tool result handler must not be null");
@@ -334,9 +334,9 @@ public StructuredOutputCallToolHandler(JsonSchemaValidator jsonSchemaValidator,
334334
}
335335

336336
@Override
337-
public Mono<CallToolResult> apply(McpAsyncServerExchange exchange, Map<String, Object> arguments) {
337+
public Mono<CallToolResult> apply(McpAsyncServerExchange exchange, McpSchema.CallToolRequest request) {
338338

339-
return this.delegateCallToolResult.apply(exchange, arguments).map(result -> {
339+
return this.delegateCallToolResult.apply(exchange, request).map(result -> {
340340

341341
if (outputSchema == null) {
342342
if (result.structuredContent() != null) {
@@ -398,7 +398,7 @@ private static List<McpServerFeatures.AsyncToolSpecification> withStructuredOutp
398398
private static McpServerFeatures.AsyncToolSpecification withStructuredOutputHandling(
399399
JsonSchemaValidator jsonSchemaValidator, McpServerFeatures.AsyncToolSpecification toolSpecification) {
400400

401-
if (toolSpecification.call() instanceof StructuredOutputCallToolHandler) {
401+
if (toolSpecification.callHandler() instanceof StructuredOutputCallToolHandler) {
402402
// If the tool is already wrapped, return it as is
403403
return toolSpecification;
404404
}
@@ -408,9 +408,11 @@ private static McpServerFeatures.AsyncToolSpecification withStructuredOutputHand
408408
return toolSpecification;
409409
}
410410

411-
return new McpServerFeatures.AsyncToolSpecification(toolSpecification.tool(),
412-
new StructuredOutputCallToolHandler(jsonSchemaValidator, toolSpecification.tool().outputSchema(),
413-
toolSpecification.call()));
411+
return McpServerFeatures.AsyncToolSpecification.builder()
412+
.tool(toolSpecification.tool())
413+
.callHandler(new StructuredOutputCallToolHandler(jsonSchemaValidator,
414+
toolSpecification.tool().outputSchema(), toolSpecification.callHandler()))
415+
.build();
414416
}
415417

416418
/**

0 commit comments

Comments
 (0)