modelcontextprotocol / modelcontextprotocol/python-sdk

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

オープン
#2,331 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

enhancement needs decision P3
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

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)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず既存の remove_tool() の実装とそのテストを読み、次に PromptManager、ResourceManager、MCPServer、exceptions.py を調査します。説明されているとおり、対応する削除メソッドと PromptError を追加し、削除の成功、および存在しない名前や URI をカバーするテストを追加します。private な manager にアクセスせず、公開 MCPServer API を通じて prompt、resource、resource template を削除できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend-api-design
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
72/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。