Skip to content

Resources and prompts cannot be added after server start #17

Closed
@marianogonzalez

Description

@marianogonzalez

Bug description
The request handlers for resources, templates and prompts are only added if any are provided at the moment of building the server. Although methods like addResource() do function as expected, request with methods such as resources/list or resources/read fail with no such method errors because the handlers are not there, even if the server does support the capability.

Environment
Java SDK, async server

Steps to reproduce

Create a server like this:

return McpServer.async(createTransport())
          .serverInfo(config.getServerName(), config.getServerVersion())
          .capabilities(new ServerCapabilities(
                                               emptyMap(),
                                               null,
                                               null,
                                               new ResourceCapabilities(
                                                                        config.getResourceCapabilities().isSubscribe(),
                                                                        config.getResourceCapabilities().isListChanged()),
                                               new ServerCapabilities.ToolCapabilities(config.getToolCapabilities()
                                                   .isListChanged())))
          .build();

Afterwards, add a resource like this:

server.addResource(new AsyncResourceRegistration(
new McpSchema.Resource(uri, name, description, mimeType, null), mono -> {....});

Expected behavior
The resource can be accessed and listed after being added

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions