feat: add remove_prompt(), remove_resource(), and remove_resource_template()#2335
Open
rgoldstein1989 wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
Conversation
…plate() Add removal APIs for prompts, resources, and resource templates to match the existing remove_tool() pattern. This completes the CRUD symmetry for all three MCP primitives, enabling per-instance filtering without reaching into private internals. Fixes modelcontextprotocol#2331 Github-Issue:modelcontextprotocol#2331
…cuted The test_remove_resource_and_read and test_remove_prompt_and_get tests call the resource/prompt before removing it, so the function bodies are covered. Remove the pragma to satisfy strict-no-cover.
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
Add removal APIs for prompts, resources, and resource templates to match the existing
remove_tool()pattern. This completes the CRUD symmetry for all three MCP primitives, enabling per-instance filtering without reaching into private internals.MCPServer.remove_prompt(name)/PromptManager.remove_prompt(name)— raisesPromptErrorMCPServer.remove_resource(uri)/ResourceManager.remove_resource(uri)— raisesResourceErrorMCPServer.remove_resource_template(uri_template)/ResourceManager.remove_template(uri_template)— raisesResourceErrorPromptErrorexception for symmetry withToolErrorandResourceErrorDifferences from #2333
This PR covers the same scope as #2333 but adds:
remove_tooltest patterns: remove existing, remove nonexistent (error path), remove-and-list via client, and remove-and-access via client for all three primitives. Required to pass CI's 100% coverage gate.AnyUrl | strtype onremove_resource— Resources are stored viastr(resource.uri)whereurican beAnyUrl. Theremove_resourcemethod normalizes withstr(uri)before lookup, matching howget_resource()handles it, so callers can pass either type.Use case
Multi-tenant / multi-instance deployments where the same server image serves different clients. Today users can filter tools per-instance via
remove_tool(), but for prompts and resources they're forced to delete from private_manager._prompts/_resourcesdicts directly.Fixes #2331