Skip to content

[v1.x backport] fix(server): respect explicit listChanged: false in McpServer#1937

Open
Zelys-DFKH wants to merge 2 commits intomodelcontextprotocol:v1.xfrom
Zelys-DFKH:fix/listchanged-v1x-backport
Open

[v1.x backport] fix(server): respect explicit listChanged: false in McpServer#1937
Zelys-DFKH wants to merge 2 commits intomodelcontextprotocol:v1.xfrom
Zelys-DFKH:fix/listchanged-v1x-backport

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Summary

Backport of #1513 to v1.x.

Constructing McpServer with capabilities: { tools: { listChanged: false } } had no effect. The three lazy-init methods (setToolRequestHandlers, setResourceRequestHandlers, setPromptRequestHandlers) each call registerCapabilities with a hardcoded listChanged: true, overwriting whatever the user passed at construction time. Stateless servers can't opt out of list-change notifications on v1.x.

Root cause (src/server/mcp.ts:134, 496, 576):

 this.server.registerCapabilities({
-    tools: { listChanged: true }
+    tools: { listChanged: this.server.getCapabilities().tools?.listChanged ?? true }
 });

Same fix applied to resources and prompts. Server.getCapabilities() changed from private to public so McpServer can read the current value. The ?? true default keeps existing behavior for servers that don't set listChanged at all.

Test plan

Added 4 tests to test/server/mcp.test.ts, run against both Zod v3 and v4 via describe.each:

  • should default tools.listChanged to true when not explicitly set
  • should respect tools.listChanged: false when explicitly set
  • should respect resources.listChanged: false when explicitly set
  • should respect prompts.listChanged: false when explicitly set

6 of 8 fail on pre-fix code (the default test passes on both Zod variants; the three false-respecting tests fail). All 8 pass after. Full suite: 1587/1587, no regressions.

Fixes #1819

…ity registration

Backport of modelcontextprotocol#1513 to v1.x. The three lazy-init methods in McpServer
(setToolRequestHandlers, setResourceRequestHandlers, setPromptRequestHandlers)
unconditionally registered listChanged: true when called, overwriting any
explicit listChanged: false passed in capabilities at construction time.

Fixed by reading the current capability value via Server.getCapabilities()
and applying it with nullish coalescing so that undefined still defaults
to true (backwards compatible), but explicit false is preserved.

Also made Server.getCapabilities() public to allow McpServer to read it.

Fixes modelcontextprotocol#1819
@Zelys-DFKH Zelys-DFKH requested a review from a team as a code owner April 20, 2026 19:11
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 20, 2026

🦋 Changeset detected

Latest commit: 9bf5831

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 20, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@1937

commit: 9bf5831

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant