Repository navigation
feat: add remove_prompt(), remove_resource(), and remove_resource_template() - #2335
Closed
rgoldstein1989 wants to merge 4 commits into
Closed
rgoldstein1989 wants to merge 4 commits into
rgoldstein1989 wants to merge 4 commits into
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 is useful for my use-case since I can dynamically add prompts to the running server but removing isn't as simple. As a workaround I do this but it's a bit nasty mcp._prompt_manager._prompts.pop(name, None) |
Contributor
|
Thanks for the PR, and sorry it sat here without a proper review. We're closing most of the open PR backlog. v2 is out and changed a lot of the SDK, so many older PRs no longer apply as written, and we're a small team that realistically doesn't have the capacity to work through the rest. If this still matters to you on v2, the most useful thing you can do is open an issue (or comment on the existing one) with your use case and a repro. Hearing why it matters to you is what we use to decide what to prioritise. |
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