Skip to content

feat(mcpserver): expose public get_tool(name) on MCPServer - #3232

Closed
arimu1 wants to merge 1 commit into
modelcontextprotocol:mainfrom
arimu1:feat/3162-mcpserver-get-tool
Closed

feat(mcpserver): expose public get_tool(name) on MCPServer#3232
arimu1 wants to merge 1 commit into
modelcontextprotocol:mainfrom
arimu1:feat/3162-mcpserver-get-tool

Conversation

@arimu1

@arimu1 arimu1 commented Aug 1, 2026

Copy link
Copy Markdown

Summary

Adds a public MCPServer.get_tool(name) -> Tool | None that delegates to the existing ToolManager.get_tool, so callers can look up a registered tool without using the private _tool_manager.

This completes the public tool registration surface next to add_tool() / remove_tool().

Use case (from #3162): after registration, update a tool's inputSchema (e.g. attach oneOf / discriminated action schemas) via the returned tool's mutable parameters dict.

tool = mcp.get_tool("act")
if tool is not None:
    tool.parameters = {...}  # advertised on tools/list

Fixes #3162

Notes on issue discussion

Maintainer asked whether customizing inputSchema at registration time would be enough. This PR still implements the issue's proposed API (get_tool) because:

  1. It is the minimal CRUD completion (add / get / remove)
  2. It enables post-registration inspection and mutation without new registration kwargs
  3. An optional input_schema= override on add_tool / @tool remains a possible follow-up and is orthogonal

Test plan

  • test_get_tool_returns_registered_tool_or_none
  • test_get_tool_exposes_mutable_parameters_for_schema_updates
  • Neighboring TestServerTools add/remove tests still pass
  • ruff + pyright clean on touched files
uv run --frozen pytest \
  tests/server/mcpserver/test_server.py::test_get_tool_returns_registered_tool_or_none \
  tests/server/mcpserver/test_server.py::test_get_tool_exposes_mutable_parameters_for_schema_updates \
  -q

AI disclosure

Assisted by AI (Grok / Cursor) for implementation and tests; human-reviewed before submit.

Add MCPServer.get_tool to retrieve a registered tool by name without
using the private _tool_manager, completing the add/remove CRUD surface.

Fixes modelcontextprotocol#3162
@arimu1 arimu1 changed the title test-draft-delete-me feat(mcpserver): expose public get_tool(name) on MCPServer Aug 1, 2026
@arimu1

arimu1 commented Aug 1, 2026

Copy link
Copy Markdown
Author

Recreating as non-draft (API could not convert draft→ready under current token permissions).

@arimu1 arimu1 closed this Aug 1, 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.

MCPServer: expose public get_tool(name) method

1 participant