fix(everything): scope session resources to their server - #4810
Open
Tiancheng-Xu wants to merge 1 commit into
Open
Tiancheng-Xu wants to merge 1 commit into
Tiancheng-Xu wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped to in-memory bookkeeping, aligns with the issue’s expected behavior, and includes targeted regression coverage.
Pull request overview
This PR fixes cross-session eviction of “session-scoped” resources in the everything server by scoping the in-memory registration bookkeeping to each McpServer instance, preventing independent sessions from unregistering each other’s resources when URIs collide.
Changes:
- Replace the global session resource registry with a
WeakMap<McpServer, Map<uri, RegisteredResource>>so re-registration only affects resources on the same server instance. - Add regression tests covering (1) identical URIs across two servers not evicting each other and (2) same-server re-registration still replacing the prior registration.
File summaries
| File | Description |
|---|---|
| src/everything/resources/session.ts | Scope session resource tracking per McpServer using WeakMap, avoiding cross-server eviction while preserving same-server replacement behavior. |
| src/everything/tests/resources.test.ts | Add regression tests for cross-server URI collisions and same-server replacement. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite (auto)
Note
Copilot is running an experiment and ran this review at Lite.
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
4
to
8
| /** | ||
| * Tracks registered session resources by URI to allow updating/removing on re-registration. | ||
| * This prevents "Resource already registered" errors when a tool creates a resource | ||
| * with the same URI multiple times during a session. | ||
| */ |
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
Fixes #4808.
Session resource registrations were tracked in a module-level map keyed only by URI. When two independent
McpServerinstances used the same session-resource URI, registering the second resource removed the first server's registration. The registry is now scoped byMcpServerusing aWeakMap, while repeated registration of the same URI on one server still replaces the previous registration.Server Details
Motivation and Context
Independent server sessions can legitimately generate the same resource name. Their registrations must not evict one another.
How Has This Been Tested?
npm testinsrc/everything: 5 test files, 109 tests passed.npm run buildinsrc/everythingpassed.Breaking Changes
None.
Types of changes
Checklist
Additional context
The change is limited to the ownership of the in-memory registration bookkeeping; URI generation and resource behavior are unchanged.