Skip to content

Add a way to customize default request handlers for Stateless server #525

@mikegron

Description

@mikegron

Expected Behavior

Currently using the Stateless server. We need a way to override the behavior of a single request handler, for instance the tools/list request to provide custom tool descriptions.

Current Behavior

The McpStatelessAsyncServer constructor currently creates a DefaultMcpStatelessServerHandler as mcpHandler for the ServerTransport with private methods as handlers with private variables.
We can currently override the mcpHandler after-the-fact using McpStatelessServerTransport::setMcpHandler, but it would be nice to override only a single handler, for example adding a couple of getters:

var serverTransport = WebMvcStatelessServerTransport.builder() [...] .build();
...
var server = McpServer.sync(serverTransport).tools(tools) [...] .build();

// Override default request handler
serverTransport.getMcpHandler()
               .getRequestHandlers()
               .put(McpSchema.METHOD_TOOLS_LIST, myCustomToolsList(tools));

What do you think?

Context

We want customizable tool descriptions per-user with minimal code duplication of the SDK.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions