diff --git a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java index d873a7fd..7131b10f 100644 --- a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java +++ b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java @@ -313,9 +313,9 @@ public Mono addTool(McpServerFeatures.AsyncToolSpecification toolSpecifica } private static class StructuredOutputCallToolHandler - implements BiFunction, Mono> { + implements BiFunction> { - private final BiFunction, Mono> delegateCallToolResult; + private final BiFunction> delegateCallToolResult; private final JsonSchemaValidator jsonSchemaValidator; @@ -323,7 +323,7 @@ private static class StructuredOutputCallToolHandler public StructuredOutputCallToolHandler(JsonSchemaValidator jsonSchemaValidator, Map outputSchema, - BiFunction, Mono> delegateHandler) { + BiFunction> delegateHandler) { Assert.notNull(jsonSchemaValidator, "JsonSchemaValidator must not be null"); Assert.notNull(delegateHandler, "Delegate call tool result handler must not be null"); @@ -334,9 +334,9 @@ public StructuredOutputCallToolHandler(JsonSchemaValidator jsonSchemaValidator, } @Override - public Mono apply(McpAsyncServerExchange exchange, Map arguments) { + public Mono apply(McpAsyncServerExchange exchange, McpSchema.CallToolRequest request) { - return this.delegateCallToolResult.apply(exchange, arguments).map(result -> { + return this.delegateCallToolResult.apply(exchange, request).map(result -> { if (outputSchema == null) { if (result.structuredContent() != null) { @@ -398,7 +398,7 @@ private static List withStructuredOutp private static McpServerFeatures.AsyncToolSpecification withStructuredOutputHandling( JsonSchemaValidator jsonSchemaValidator, McpServerFeatures.AsyncToolSpecification toolSpecification) { - if (toolSpecification.call() instanceof StructuredOutputCallToolHandler) { + if (toolSpecification.callHandler() instanceof StructuredOutputCallToolHandler) { // If the tool is already wrapped, return it as is return toolSpecification; } @@ -408,9 +408,11 @@ private static McpServerFeatures.AsyncToolSpecification withStructuredOutputHand return toolSpecification; } - return new McpServerFeatures.AsyncToolSpecification(toolSpecification.tool(), - new StructuredOutputCallToolHandler(jsonSchemaValidator, toolSpecification.tool().outputSchema(), - toolSpecification.call())); + return McpServerFeatures.AsyncToolSpecification.builder() + .tool(toolSpecification.tool()) + .callHandler(new StructuredOutputCallToolHandler(jsonSchemaValidator, + toolSpecification.tool().outputSchema(), toolSpecification.callHandler())) + .build(); } /**