Skip to content

[v2] Server: print warning if sendResourceUpdated is used but subscribe is not set #2545

Description

@tobiasBora

What happened?

I lost a few hours to realize that if I want to subscribe to a resource, I need to explicitly put in the server:

  const server = new McpServer({ name: 'proofdiag', version: '0.0.1' }, {
    capabilities: {
      tools: {},
      resources: { subscribe: true, listChanged: true }, // <--- this is the important line
    }
  });
  // Later someone calls
  await server.server.sendResourceUpdated({ uri }).catch((e) => {console.log("Error in sendResourceUpdated", e)});

Otherwise, when subscribing the client would just receive an acknowledgment with an empty notifications, which is really hard to debug. As such, I would expect maybe some warning/errors if the declared capabilities do not allow to call a functionality (here when calling sendResourceUpdated or when receiving from the client the subscribe message), or otherwise capabilities should be changed based on what the server defines.

What did you expect?

An error/warning.

Code to reproduce

MWE with resource subscription.

SDK version

2.0.0-beta.4

Area

Server

Metadata

Metadata

Assignees

No one assigned

    Labels

    v2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions