Skip to content

refactor: Replace Map<String, Object> with CallToolRequest in StructuredOutputCallToolHandler #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,17 @@ public Mono<Void> addTool(McpServerFeatures.AsyncToolSpecification toolSpecifica
}

private static class StructuredOutputCallToolHandler
implements BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> {
implements BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> {

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

private final JsonSchemaValidator jsonSchemaValidator;

private final Map<String, Object> outputSchema;

public StructuredOutputCallToolHandler(JsonSchemaValidator jsonSchemaValidator,
Map<String, Object> outputSchema,
BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> delegateHandler) {
BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> delegateHandler) {

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

@Override
public Mono<CallToolResult> apply(McpAsyncServerExchange exchange, Map<String, Object> arguments) {
public Mono<CallToolResult> 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) {
Expand Down Expand Up @@ -398,7 +398,7 @@ private static List<McpServerFeatures.AsyncToolSpecification> 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;
}
Expand All @@ -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();
}

/**
Expand Down