Skip to content
Open
Show file tree
Hide file tree
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 @@ -31,6 +31,9 @@ public McpToolRegisterInput(StreamInput streamInput) throws IOException {
if (super.getType() == null) {
throw new IllegalArgumentException(TYPE_NOT_SHOWN_EXCEPTION_MESSAGE);
}
if (super.getName() == null) {
super.setName(super.getType());
}
}

public McpToolRegisterInput(
Expand All @@ -42,11 +45,10 @@ public McpToolRegisterInput(
Instant createdTime,
Instant lastUpdateTime
) {
super(name, type, description, parameters, attributes, createdTime, lastUpdateTime);
super(name == null ? type : name, type, description, parameters, attributes, createdTime, lastUpdateTime);
if (type == null) {
throw new IllegalArgumentException(TYPE_NOT_SHOWN_EXCEPTION_MESSAGE);
}

}

public static McpToolRegisterInput parse(XContentParser parser) throws IOException {
Expand Down Expand Up @@ -89,6 +91,10 @@ public static McpToolRegisterInput parse(XContentParser parser) throws IOExcepti
break;
}
}
// If name is null, default to type
if (name == null && type != null) {
name = type;
}
return new McpToolRegisterInput(name, type, description, params, attributes, createdTime, lastUpdateTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public McpStatelessServerFeatures.AsyncToolSpecification createToolSpecification
return new McpStatelessServerFeatures.AsyncToolSpecification(
new McpSchema.Tool(toolName, String.valueOf(description), schema),
(ctx, request) -> Mono.create(sink -> {
ActionListener<String> actionListener = ActionListener
.wrap(r -> sink.success(new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(r)), false)), e -> {
ActionListener<Object> actionListener = ActionListener
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious what is the reason for this change? Because it reads that adding the .toString() would still keep the same type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our tools return a generic Object type when executed (see run function in tools, example). Most of the tools have a string response and the string is wrapped in a generic type before returning.

Hence when the MCP execute tool expects a String, the generic type returned back from the Tool execution is converted back to String in line 86 without an issue.

But with the latest Output processors that are added in 3.3, the final return type might not be a string wrapped in a generic type anymore, for example Extract JSON converts the string into a map object when processed. The direct tool execution is not impacted because the HashMap type is wrapped in a generic

But when we execute a tool with the output processors via the MCP server, the server tries to convert the type to a string. which will fail now since the object inside is not a string anymore, it is a hashmap which cannot be casted into a string.

Hence I made this change which accepts any Object type and the .toString() converts it back to a string data type which is required by the MCP SDK dependency.

I hope this clarifies your question, please let me know if I need to add more details

.wrap(r -> sink.success(new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(r.toString())), false)), e -> {
log.error("Failed to execute tool, tool name: {}", toolName, e);
sink.error(e);
});
Expand Down
Loading