modelcontextprotocol / modelcontextprotocol/python-sdk

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

Offen
#2,331 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

enhancement needs decision P3
Vorherrschende Sprache
Python
Sterne
24.3k
Forks
4k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
31

Beschreibung

Description

MCPServer exposes remove_tool(name) (added in #1322) but has no equivalent for prompts or resources. This was part of the original ask in #711 ("removing a tool or resource dynamically"), which was closed when remove_tool() landed — but the resource and prompt sides were never addressed.

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 reach into private internals:

# Current workaround — fragile, undocumented
del mcp._prompt_manager._prompts["some_prompt"]
del mcp._resource_manager._resources[str(uri)]

(This is the same pattern @lukehsiao described in https://github.com/modelcontextprotocol/python-sdk/issues/711#issuecomment-2790042502 for tools, before remove_tool() existed.)

Current state
Primitive add_* remove_*
Tool add_tool() / @tool() remove_tool()
Prompt add_prompt() / @prompt() missing
Resource add_resource() / @resource() missing
Resource Template add_template() missing
Proposed API

Add these methods, mirroring the existing remove_tool() pattern exactly:

  • PromptManager.remove_prompt(name: str) — raises PromptError if not found
  • ResourceManager.remove_resource(uri: str) — raises ResourceError if not found
  • ResourceManager.remove_template(uri_template: str) — raises ResourceError if not found
  • MCPServer.remove_prompt(name) — thin wrapper delegating to the manager
  • MCPServer.remove_resource(uri) — thin wrapper delegating to the manager
  • MCPServer.remove_resource_template(uri_template) — thin wrapper delegating to the manager
  • PromptError exception class in exceptions.py (for symmetry with ToolError and ResourceError)

This is ~15 lines of implementation across 4 source files, plus tests. Purely additive, no breaking changes.

References
  • #711 — Original issue requesting dynamic tool/resource removal (closed, only tools were addressed)
  • #1322 — PR that added remove_tool() (the pattern this proposal follows)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die bestehende Implementierung von remove_tool() und ihre Tests zu lesen, und untersuche anschließend PromptManager, ResourceManager, MCPServer und exceptions.py. Füge wie beschrieben entsprechende Entfernungsmethoden und PromptError hinzu, mit Tests, die eine erfolgreiche Entfernung sowie fehlende Namen oder URIs abdecken. Die Aufgabe ist abgeschlossen, wenn Prompts, Ressourcen und Ressourcenvorlagen über die öffentliche MCPServer API entfernt werden können, ohne auf private Manager zuzugreifen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend-api-design
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
72/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.