strands.tools.mcp.mcp_agent_tool
MCP Agent Tool module for adapting Model Context Protocol tools to the agent framework.
This module provides the MCPAgentTool class which serves as an adapter between MCP (Model Context Protocol) tools and the agent framework’s tool interface. It allows MCP tools to be seamlessly integrated and used within the agent ecosystem.
MCPAgentTool
Section titled “MCPAgentTool”class MCPAgentTool(AgentTool)Defined in: src/strands/tools/mcp/mcp_agent_tool.py:24
Adapter class that wraps an MCP tool and exposes it as an AgentTool.
This class bridges the gap between the MCP protocol’s tool representation and the agent framework’s tool interface, allowing MCP tools to be used seamlessly within the agent framework.
__init__
Section titled “__init__”def __init__(mcp_tool: MCPTool, mcp_client: "MCPClient", name_override: str | None = None, timeout: timedelta | None = None) -> NoneDefined in: src/strands/tools/mcp/mcp_agent_tool.py:32
Initialize a new MCPAgentTool instance.
Arguments:
mcp_tool- The MCP tool to adaptmcp_client- The MCP server connection to use for tool invocationname_override- Optional name to use for the agent tool (for disambiguation) If None, uses the original MCP tool nametimeout- Optional timeout duration for tool execution
tool_name
Section titled “tool_name”@propertydef tool_name() -> strDefined in: src/strands/tools/mcp/mcp_agent_tool.py:56
Get the name of the tool.
Returns:
str- The agent-facing name of the tool (may be disambiguated)
tool_spec
Section titled “tool_spec”@propertydef tool_spec() -> ToolSpecDefined in: src/strands/tools/mcp/mcp_agent_tool.py:65
Get the specification of the tool.
This method converts the MCP tool specification to the agent framework’s ToolSpec format, including the input schema, description, and optional output schema.
Returns:
ToolSpec- The tool specification in the agent framework format
tool_type
Section titled “tool_type”@propertydef tool_type() -> strDefined in: src/strands/tools/mcp/mcp_agent_tool.py:88
Get the type of the tool.
Returns:
str- The type of the tool, always “python” for MCP tools
stream
Section titled “stream”@overrideasync def stream(tool_use: ToolUse, invocation_state: dict[str, Any], **kwargs: Any) -> ToolGeneratorDefined in: src/strands/tools/mcp/mcp_agent_tool.py:97
Stream the MCP tool.
This method delegates the tool stream to the MCP server connection, passing the tool use ID, tool name, and input arguments.
Arguments:
tool_use- The tool use request containing tool ID and parameters.invocation_state- Context for the tool invocation, including agent state.**kwargs- Additional keyword arguments for future extensibility.
Yields:
Tool events with the last being the tool result.