modelcontextprotocol / modelcontextprotocol/python-sdk
Add remove_prompt() and remove_resource() for parity with remove_tool()
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 24.3k
- 派生
- 4k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 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)— raisesPromptErrorif not foundResourceManager.remove_resource(uri: str)— raisesResourceErrorif not foundResourceManager.remove_template(uri_template: str)— raisesResourceErrorif not foundMCPServer.remove_prompt(name)— thin wrapper delegating to the managerMCPServer.remove_resource(uri)— thin wrapper delegating to the managerMCPServer.remove_resource_template(uri_template)— thin wrapper delegating to the managerPromptErrorexception class inexceptions.py(for symmetry withToolErrorandResourceError)
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)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读现有的 remove_tool() 实现及其测试,然后检查 PromptManager、ResourceManager、MCPServer 和 exceptions.py。按描述添加相应的移除方法和 PromptError,并添加涵盖成功移除以及名称或 URI 不存在情况的测试。当可以通过公开的 MCPServer API 移除 prompts、resources 和 resource templates,且无需访问私有 manager 时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend-api-design
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 72/100