modelcontextprotocol / modelcontextprotocol/typescript-sdk

McpServer re-registers capabilities after connect, blocking dynamic registration even when capabilities were supplied at construction

Open
#893 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug fix proposed P2 ready for work
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

Summary

When creating McpServer with ServerOptions.capabilities that include resources and tools, calling registerResource or registerTool after connect() fails with “Cannot register capabilities after connecting to transport”. The high-level server re-calls server.registerCapabilities(...) the first time handlers are installed, even post-connect.

Steps to Reproduce
  1. Create McpServer with capabilities:
const capabilities = {
  resources: { subscribe: true, listChanged: true },
  tools: { listChanged: true },
};
const server = new McpServer({ name: "demo", version: "1.0.0" }, { capabilities });
  1. await server.connect(transport);
  2. After connect, call server.registerResource(...) (or server.registerTool(...))
  3. Observe HTTP 500 with error “Cannot register capabilities after connecting to transport”
Expected Behavior
  • If capabilities were provided at construction, registering resources/tools/prompts after connect should work. The server should not attempt to re-register capabilities post-connect.
Actual Behavior
  • First registration after connect triggers handler initialization in McpServer, which unconditionally calls server.registerCapabilities(...). Since Server.registerCapabilities forbids post-connect, it throws.
Notes
  • Calls occur in typescript-sdk/src/server/mcp.ts within:
    • setResourceRequestHandlers()this.server.registerCapabilities({ resources: { listChanged: true } })
    • setToolRequestHandlers()this.server.registerCapabilities({ tools: { listChanged: true } })
    • setPromptRequestHandlers()this.server.registerCapabilities({ prompts: { listChanged: true } })
  • Guard that throws is in typescript-sdk/src/server/index.ts registerCapabilities().
Proposed Fix
  • Make this.server.registerCapabilities(...) idempotent if capabilities are already registered.
Environment
  • @modelcontextprotocol/sdk 1.17.3
  • Transport: Streamable HTTP (client error surfaced as HTTP 500)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the handler setup in typescript-sdk/src/server/mcp.ts, then trace the post-connect guard in typescript-sdk/src/server/index.ts through setResourceRequestHandlers(), setToolRequestHandlers(), and setPromptRequestHandlers(). Reproduce the construction, connect, and registration sequence from the issue; done means resources, tools, and prompts can be registered after connect when capabilities were supplied at construction, without the post-connect error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.