Skip to content

fix(everything): remove dead code in resource template URI validation and subscription cleanup#4104

Open
1060996408 wants to merge 1 commit intomodelcontextprotocol:mainfrom
1060996408:fix/everything-server-cleanups
Open

fix(everything): remove dead code in resource template URI validation and subscription cleanup#4104
1060996408 wants to merge 1 commit intomodelcontextprotocol:mainfrom
1060996408:fix/everything-server-cleanups

Conversation

@1060996408
Copy link
Copy Markdown

Description

Two small dead-code removals in src/everything's resource layer. No behavioral change. 95 / 95 tests still pass.

Server Details

  • Server: everything (reference server)
  • Changes to: resources

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.tsparseResourceId

The guard

if (uri.toString().startsWith(textUriBase) && uri.toString().startsWith(blobUriBase)) {
  throw new Error(uriError);
}

is dead. textUriBase and blobUriBase are 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 — resourceId must be a positive integer.

resources/subscriptions.tssendSimulatedResourceUpdates

if (subscribers.has(sessionId)) {
  await server.server.notification(...);
} else {
  subscribers.delete(sessionId); // subscriber has disconnected
}

The else deletes sessionId from subscribers whenever 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 the else for URI B every iteration. And Set.delete of an absent element is a no-op, so the branch never had useful effect. Removed.

How Has This Been Tested?

  • npm test in src/everything: 95 / 95 pass
  • Spot-checked the everything server with an LLM client (Claude Code) — read-resource, subscribe / unsubscribe flows, and template-routed text/{id} and blob/{id} reads all behave as before.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follow MCP security best practices
  • I have updated the server's README accordingly (no user-facing change)
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options (none changed)

Additional context

  • 1 commit, 2 files (subscriptions.ts, templates.ts), +19 / −27 lines.
  • No new dependencies, no API surface change.

…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>
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