[v1.x backport] fix(server): respect explicit listChanged: false in McpServer#1937
Open
Zelys-DFKH wants to merge 2 commits intomodelcontextprotocol:v1.xfrom
Open
[v1.x backport] fix(server): respect explicit listChanged: false in McpServer#1937Zelys-DFKH wants to merge 2 commits intomodelcontextprotocol:v1.xfrom
Zelys-DFKH wants to merge 2 commits intomodelcontextprotocol:v1.xfrom
Conversation
…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
🦋 Changeset detectedLatest 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 |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of #1513 to
v1.x.Constructing
McpServerwithcapabilities: { tools: { listChanged: false } }had no effect. The three lazy-init methods (setToolRequestHandlers,setResourceRequestHandlers,setPromptRequestHandlers) each callregisterCapabilitieswith a hardcodedlistChanged: true, overwriting whatever the user passed at construction time. Stateless servers can't opt out of list-change notifications onv1.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
resourcesandprompts.Server.getCapabilities()changed fromprivatetopublicsoMcpServercan read the current value. The?? truedefault keeps existing behavior for servers that don't setlistChangedat all.Test plan
Added 4 tests to
test/server/mcp.test.ts, run against both Zod v3 and v4 viadescribe.each:should default tools.listChanged to true when not explicitly setshould respect tools.listChanged: false when explicitly setshould respect resources.listChanged: false when explicitly setshould respect prompts.listChanged: false when explicitly set6 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