fix(everything): remove dead code in resource template URI validation and subscription cleanup#4104
Open
1060996408 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Conversation
…cription cleanup resources/templates.ts: - `parseResourceId` had a guard that compared the URI against both `textUriBase` and `blobUriBase` with `&&`. Those prefixes are mutually exclusive, so the condition is always false and the branch is dead. Drop it; the SDK's template-based routing already guarantees the URI prefix is one of the two before the handler runs. The remaining positive-integer check on `resourceId` is preserved. resources/subscriptions.ts: - `sendSimulatedResourceUpdates` had an `else` branch that called `subscribers.delete(sessionId)` whenever the session wasn't in a URI's subscriber set, with a comment claiming the session had disconnected. That conclusion doesn't follow — a session not subscribed to URI A can still be subscribed to URI B — and the delete is a no-op when the element is absent anyway. Remove the branch. No behavioral change. Existing 95 / 95 tests in `__tests__` still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Description
Two small dead-code removals in
src/everything's resource layer. No behavioral change. 95 / 95 tests still pass.Server Details
everything(reference server)Motivation and Context
Two unreachable branches in the resource handlers were doing more harm than good — once misread, they suggest invariants that don't actually hold.
resources/templates.ts—parseResourceIdThe guard
is dead.
textUriBaseandblobUriBaseare mutually exclusive prefixes, so the&&is never true. The SDK's template-based routing already guarantees the URI prefix is one of the two before the handler runs, so the surrounding "unknown URI" error path can't trigger either. Reduced to the only check that still does work —resourceIdmust be a positive integer.resources/subscriptions.ts—sendSimulatedResourceUpdatesThe
elsedeletessessionIdfromsubscriberswhenever the session isn't in one specific URI's subscriber set. The comment claims the session has disconnected, but that doesn't follow: a session subscribed to URI A but not URI B will hit theelsefor URI B every iteration. AndSet.deleteof an absent element is a no-op, so the branch never had useful effect. Removed.How Has This Been Tested?
npm testinsrc/everything: 95 / 95 passeverythingserver with an LLM client (Claude Code) —read-resource, subscribe / unsubscribe flows, and template-routedtext/{id}andblob/{id}reads all behave as before.Breaking Changes
None.
Types of changes
Checklist
Additional context
subscriptions.ts,templates.ts),+19 / −27lines.