fix(everything): allow re-registration of session resources #3252
+20
−3
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
gzip-file-as-resourcemultiple times with the same output nameProblem
When a tool that creates session resources (like
gzip-file-as-resource) is called multiple times with the same output name, the server throws:This is particularly problematic because:
gzip-file-as-resourcetool has a default name ofREADME.md.gzSolution
The fix tracks registered session resources by URI in a Map, and before registering a new resource, it checks if one already exists with the same URI. If so, it uses the SDK's
remove()method to unregister the old resource first, then registers the new one.Test plan
gzip-file-as-resource10 times with default parameters - all succeedHow this was found
This bug was discovered using Bellwether, an open-source MCP server validation and documentation tool. Bellwether runs automated schema validation and behavioral testing against MCP servers, which caught this regression when repeatedly testing the
gzip-file-as-resourcetool.🤖 Generated with Claude Code