Skip to content

Conversation

@rithin-pullela-aws
Copy link
Contributor

@rithin-pullela-aws rithin-pullela-aws commented Nov 3, 2025

Description

Changes

  • Modified type conversion in MCP server to use .toString() instead of direct string casting. Updated line 86 McpToolsHelper.java to handle non-string objects returned by output processors
  • When Tool Name is not provided we automatically take the tool type as name

Background

With the addition of output processors in 3.3, tools can now return non-string objects (e.g., Extract JSON returns HashMap). The existing MCP server code assumed all tool responses were strings wrapped in generic types, causing ClassCastException when trying to cast HashMap to String.

Solution

Changed the conversion logic to accept any Object type and convert to string using .toString(), maintaining compatibility with both legacy string responses and new output processor results.

This ensures MCP server works with all tool types while preserving existing
functionality.

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

(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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants