spring-projects / spring-projects/spring-ai
Reactive tool support
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Expected Behavior
I would love to be able to pass Reactor context to tool definitions/processing, so stuff like this would work:
@Tool(name = "greeter")
public Mono<String> greet(
@ToolParam(description = "...") final String language
) {
return Mono.deferContextual(contextView-><do stuff based on context>);
}
I am having a filter sitting in front of the actual tool execution that does some stuff like authorization based on the received call's meta data, and would like to pass the authorized user details into the tools that require it. As that is no real MCP parameter, I cannot pass it any other way.
So (at least for ASYNC mode) having the McpToolUtils#toAsyncToolSpecification not do a Mono.fromCallable, but instead have the call chain toSyncToolSpecification -> toSharedSyncToolSpecification also handle reactive publishers for the callHandlers would be great.
Yet another approach would be to map the callbacks into AsyncMcpToolMethodCallback.
Current Behavior
Due to the wrapping of async tools first into sync and then shared tools, any reactive context added before the handling is lost.
Context
Being able to pass arbitrary data between filters and the actual tools would be great. Alternatively, just allow for the user to pass data to the ToolContext created in toSharedSyncToolSpecification (or enrich it with the whole reactor context as well).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with McpToolUtils#toAsyncToolSpecification and trace the toSyncToolSpecification → toSharedSyncToolSpecification wrapping described in the issue, along with AsyncMcpToolMethodCallback. Compare how async tool callHandlers are processed and verify that reactive context added before handling reaches the tool in ASYNC mode; done when this behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100