Skip to content

MCPServer: expose public get_tool(name) method #3162

Description

@and-win

Problem

MCPServer has add_tool() and remove_tool() as public methods, but no public get_tool(name) to retrieve a registered tool by name.

ToolManager already exposes a public get_tool(name: str) -> Tool | None:

https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/server/mcpserver/tools/tool_manager.py#L31

But MCPServer._tool_manager is private, so downstream consumers must access mcp._tool_manager.get_tool(name) — which relies on an internal attribute.

Use Case

Downstream projects need to modify a tool's inputSchema after registration. For example, attaching oneOf discriminated action schemas after initial tool registration.

Currently, the only way to get a tool's schema is via list_tools() (returns all tools, must filter by name). There is no way to update a schema without accessing private internals.

Proposed Solution

Add a public method:

class MCPServer:
    def get_tool(self, name: str) -> Tool | None:
        """Get a registered tool by name."""
        return self._tool_manager.get_tool(name)

Optionally, also consider exposing list_tools() directly on MCPServer (currently delegated through _handle_list_tools), and/or an update_tool_input_schema() method for the schema-update use case.

Why This Matters

  1. Completeness: add_tool / remove_tool / get_tool form a natural CRUD trio
  2. Encapsulation: consumers should not depend on _tool_manager internals
  3. Forward compatibility: if _tool_manager is refactored, downstream breaks

Version

mcp==2.0.0b1 — checked that ToolManager.get_tool is already public.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions