fix(everything): allow re-registration of session resources#3252
Open
dotsetgreg wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix(everything): allow re-registration of session resources#3252dotsetgreg wants to merge 1 commit intomodelcontextprotocol:mainfrom
dotsetgreg wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
When a tool like `gzip-file-as-resource` is called multiple times with the same output name (especially the default `README.md.gz`), the server would throw "Resource already registered" because the SDK doesn't allow registering duplicate URIs. This fix: - Tracks registered resources by URI in a module-level Map - Before registering a new resource, checks if the URI already exists - If it does, removes the old resource using the SDK's `remove()` method - Then registers the new resource with fresh content This allows tools to be called repeatedly with the same parameters without errors, which is important for LLM agents that may retry tool calls. Found using Bellwether (https://bellwether.sh), an MCP server validation tool. Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.
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