fix(server): honor disable() on resource templates across list, read and completion requests - #2697
Open
Grit03 wants to merge 9 commits into
Open
Conversation
…tted from resources/list
…ources/templates/list
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
🦋 Changeset detectedLatest commit: cd3d9e1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
disable() on resource templates across list, read and completion requests
Grit03
marked this pull request as ready for review
August 21, 2026 14:13
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.
Motivation and Context
Tools, prompts, resources and resource templates registered on
McpServercan all be toggled withenable()/disable(). A disabled one drops out of its list verb and is rejected when invoked.McpServer#247 added this for all four primitives at once.Resource templates are the exception.
RegisteredResourceTemplatehas theenabledfield anddisable()does flip it, but none of these four handlers read it.As a result, a disabled resource template is still exposed in the four responses above.
In order to fix, the missing
enabledcheck at all four sites, in two shapes:resources/listandresources/templates/listfilter disabled templates out. Nothing was addressed specifically, so there is nobody to report a failure to.resources/readandcompletion/completethrowProtocolError(InvalidParams), since the client named a specific resource template.How Has This Been Tested?
Four tests in
test/integration/test/server/mcp.test.ts, one per request path, each committed ahead of its fix so it can be checked red → green.resources/list: a disabled static resource and a disabled template drop out, the enabled template staysresources/templates/list: the disabled template's URI pattern is goneresources/read: a URI matching a disabled template is rejected withInvalidParams+disabledcompletion/complete: a completion aimed at a disabled template is rejected the same wayThe first testcase(
resources/list) also covers the static-resource filtering. That already worked, but it sits in the same handler as the template path, so pinning it down keeps a fix on one side from breaking the other.pnpm --filter @modelcontextprotocol/test-integration exec vitest run test/server/mcp.test.tspnpm check:allBreaking Changes
No API change.
Types of changes
Checklist
Additional context
For
completion/completeI went with throwing, following the disabled prompt case. The branch below in the same handler returnsEMPTY_COMPLETION_RESULTfor static resources.If that's the better fit here, I'm happy to change it. Let me know.
fixes: #2696