The mcp_client tool allows agents to autonomously connect to external Model Context Protocol (MCP) servers at runtime.
SECURITY WARNING: This allows agents to connect to external servers and execute untrusted code. Use with extreme caution in production.
Supported transports:
stdio: Connect via command and arguments (e.g., running a local python script).sse: Connect via a Server-Sent Events URL.streamable_http: Connect via a streamable HTTP endpoint with optional headers and timeout.
Actions:
connect: Establish a connection using a connection_id.list_tools: List tools available on a connected server.call_tool: Execute a specific tool on the server.load_tools: Load MCP tools directly into the agent's registry for direct access (e.g., agent.tool.tool_name()).
from strands import Agent
from strands_tools import mcp_client
agent = Agent(tools=[mcp_client])
# Connect via stdio
agent.tool.mcp_client(
action="connect",
connection_id="my_tools",
transport="stdio",
command="python",
args=["my_mcp_server.py"]
)
# List tools
tools = agent.tool.mcp_client(
action="list_tools",
connection_id="my_tools"
)
# Call a tool
result = agent.tool.mcp_client(
action="call_tool",
connection_id="my_tools",
tool_name="calculate",
tool_args={"x": 10, "y": 20}
)
# Load tools for direct access
agent.tool.mcp_client(action="load_tools", connection_id="my_tools")
# Now call directly: agent.tool.calculate(x=10, y=20)