modelcontextprotocol / modelcontextprotocol/python-sdk

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

Đang mở
#2,331 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

enhancement needs decision P3
Ngôn ngữ chính
Python
Star
24.3k
Fork
4k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
31

Mô tả

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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách đọc phần triển khai hiện có của remove_tool() và các bài kiểm thử của nó, sau đó kiểm tra PromptManager, ResourceManager, MCPServer và exceptions.py. Thêm các phương thức xóa tương ứng và PromptError như mô tả, cùng với các bài kiểm thử bao quát việc xóa thành công và các tên hoặc URI không tồn tại. Hoàn tất khi prompt, resource và resource template có thể được xóa thông qua API công khai của MCPServer mà không cần truy cập các manager private.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend-api-design
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
72/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.