Skip to content

refactor!: make tool registration object-based#1

Closed
mplemay wants to merge 24 commits intomainfrom
manager-consistency
Closed

refactor!: make tool registration object-based#1
mplemay wants to merge 24 commits intomainfrom
manager-consistency

Conversation

@mplemay
Copy link
Copy Markdown
Owner

@mplemay mplemay commented Apr 9, 2026

Summary

Refactor tool registration so MCPServer.add_tool() and ToolManager.add_tool() accept prebuilt Tool objects, matching the resource registration pattern. The @mcp.tool() decorator still provides the ergonomic callable-based path by constructing the Tool internally.

Changes

  • MCPServer.add_tool() now takes a Tool instance and forwards it directly to the tool manager.
  • ToolManager.add_tool() now stores Tool instances directly and preserves duplicate handling.
  • MCPServer.tool() now builds tools with Tool.from_function(...) before registration.
  • Tool name validation now runs on Tool construction so direct Tool(...) usage keeps the same checks.
  • Updated tool-manager/server tests to register Tool objects explicitly.
  • Added a migration note describing the breaking API change and the new registration pattern.

Verification

  • uv run --frozen pytest tests/server/mcpserver/tools/test_base.py tests/server/mcpserver/test_tool_manager.py tests/server/mcpserver/test_server.py
  • uv 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.py
  • uv 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.py

Migration

Existing mcp.add_tool(my_callable) / manager.add_tool(my_callable) calls should move to Tool.from_function(...) or the @mcp.tool() decorator.

maxisbey and others added 24 commits March 12, 2026 12:52
…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#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.
@mplemay
Copy link
Copy Markdown
Owner Author

mplemay commented Apr 9, 2026

Superseded by upstream PR modelcontextprotocol#2415

@mplemay mplemay closed this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants