modelcontextprotocol / modelcontextprotocol/python-sdk
Add remove_prompt() and remove_resource() for parity with remove_tool()
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 24.3k
- Forks
- 4k
- Merge médio
- 1d 1h
- PRs com merge (30d)
- 31
Descrição
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)
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece lendo a implementação existente de remove_tool() e seus testes; em seguida, inspecione PromptManager, ResourceManager, MCPServer e exceptions.py. Adicione os métodos de remoção correspondentes e PromptError conforme descrito, com testes cobrindo a remoção bem-sucedida e nomes ou URIs inexistentes. A tarefa estará concluída quando prompts, recursos e templates de recursos puderem ser removidos pela API pública de MCPServer sem acessar managers privados.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend-api-design
- Tipo de issue
- Funcionalidade
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Pouca atividade
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 72/100