modelcontextprotocol / modelcontextprotocol/python-sdk
feat: enhance dynamic tool management with notifications and enable/disable
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 24.3k
- 派生
- 4k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 31
描述
Summary
Enhance the Python SDK's dynamic tool management capabilities to match the TypeScript SDK by adding:
- Automatic
tools/list_changednotifications when tools are added/removed - Tool enable/disable functionality (temporary hiding without removal)
Background
The Python SDK currently supports adding and removing tools dynamically (see #1322), but lacks two key features present in the TypeScript SDK:
1. List Changed Notifications
The TypeScript SDK automatically sends notifications/tools/list_changed when tools are modified. This allows clients to know when they should refresh their tool list.
Python SDK gap: Currently, when calling add_tool() or remove_tool(), clients are not notified of the change and may show stale tool lists.
2. Enable/Disable Tools
The TypeScript SDK provides enable() and disable() methods on tools:
const tool = server.tool("myTool", ..., async () => { ... });
tool.disable() // Hides from list_tools, blocks calls
tool.enable() // Re-enables the tool
tool.remove() // Permanently removes
Benefits:
- Temporarily hide tools without losing registration
- Re-enable tools without re-registering
- Useful for permission-based or state-based tool visibility
Python SDK gap: Only permanent removal via remove_tool() is supported. No way to temporarily disable/re-enable tools.
References
- Related PR: #1322 (adds
remove_toolmethod) - TypeScript SDK Dynamic Servers: https://github.com/modelcontextprotocol/typescript-sdk#dynamic-servers
- MCP spec supports
notifications/tools/list_changed
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从 Python SDK 中 add_tool()、remove_tool()、list_tools() 和工具调用的入口开始,然后将其行为与所引用的 TypeScript SDK dynamic-server 实现进行比较。完成的标准是:添加和移除工具会触发 tools/list_changed 通知,同时禁用的工具会被隐藏并阻止调用,可以重新启用,并且仍然可以移除。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python, typescript
- 领域
- api, backend
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100