Skip to content

feat: add remove_prompt(), remove_resource(), and remove_resource_template()#2335

Open
rgoldstein1989 wants to merge 2 commits intomodelcontextprotocol:mainfrom
rgoldstein1989:feat/remove-prompt-resource-template
Open

feat: add remove_prompt(), remove_resource(), and remove_resource_template()#2335
rgoldstein1989 wants to merge 2 commits intomodelcontextprotocol:mainfrom
rgoldstein1989:feat/remove-prompt-resource-template

Conversation

@rgoldstein1989
Copy link

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) — raises PromptError
  • MCPServer.remove_resource(uri) / ResourceManager.remove_resource(uri) — raises ResourceError
  • MCPServer.remove_resource_template(uri_template) / ResourceManager.remove_template(uri_template) — raises ResourceError
  • New PromptError exception for symmetry with ToolError and ResourceError

Differences from #2333

This PR covers the same scope as #2333 but adds:

  1. Tests — 11 tests mirroring the existing remove_tool test 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.
  2. AnyUrl | str type on remove_resource — Resources are stored via str(resource.uri) where uri can be AnyUrl. The remove_resource method normalizes with str(uri) before lookup, matching how get_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 / _resources dicts directly.

Fixes #2331

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add remove_prompt() and remove_resource() for parity with remove_tool()

1 participant