Skip to content

Reactive tool support #4648

@bcersows

Description

@bcersows

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions