Skip to content

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

Closed
rgoldstein1989 wants to merge 4 commits into
modelcontextprotocol:mainfrom
rgoldstein1989:feat/remove-prompt-resource-template
Closed

rgoldstein1989 wants to merge 4 commits into
modelcontextprotocol:mainfrom
rgoldstein1989:feat/remove-prompt-resource-template

Conversation

@rgoldstein1989

Copy link
Copy Markdown

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.
@S0yKaf

S0yKaf commented Apr 24, 2026 •

Copy link
Copy Markdown

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)

@maxisbey

maxisbey commented Oct 5, 2026

Copy link
Copy Markdown
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.

AI Disclaimer

@maxisbey maxisbey closed this Oct 5, 2026
@maxisbey maxisbey added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants