refactor!: make tool registration object-based#1
Closed
Conversation
…1 directory (modelcontextprotocol#2290) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…odelcontextprotocol#2292) Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
…odelcontextprotocol#2311) Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Felix Weinberger <felixweinberger@users.noreply.github.com>
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
…ss 1 directory (modelcontextprotocol#2350) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
BREAKING CHANGE: MCPServer.add_tool() and ToolManager.add_tool() now require prebuilt Tool objects. Use Tool.from_function() or the @mcp.tool() decorator to construct tools before registration.
Owner
Author
|
Superseded by upstream PR modelcontextprotocol#2415 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactor tool registration so
MCPServer.add_tool()andToolManager.add_tool()accept prebuiltToolobjects, matching the resource registration pattern. The@mcp.tool()decorator still provides the ergonomic callable-based path by constructing theToolinternally.Changes
MCPServer.add_tool()now takes aToolinstance and forwards it directly to the tool manager.ToolManager.add_tool()now storesToolinstances directly and preserves duplicate handling.MCPServer.tool()now builds tools withTool.from_function(...)before registration.Toolconstruction so directTool(...)usage keeps the same checks.Toolobjects explicitly.Verification
uv run --frozen pytest tests/server/mcpserver/tools/test_base.py tests/server/mcpserver/test_tool_manager.py tests/server/mcpserver/test_server.pyuv run --frozen ruff check src/mcp/server/mcpserver/tools/base.py src/mcp/server/mcpserver/tools/tool_manager.py src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_tool_manager.py tests/server/mcpserver/test_server.pyuv run --frozen pyright src/mcp/server/mcpserver/tools/base.py src/mcp/server/mcpserver/tools/tool_manager.py src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_tool_manager.py tests/server/mcpserver/test_server.pyMigration
Existing
mcp.add_tool(my_callable)/manager.add_tool(my_callable)calls should move toTool.from_function(...)or the@mcp.tool()decorator.