Skip to content

feat: Add MCP client tool #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Strands Agents Tools provides a powerful set of tools for your agents to use. It
- ⏱️ **Task Scheduling** - Schedule and manage cron jobs
- 🧠 **Advanced Reasoning** - Tools for complex thinking and reasoning capabilities
- 🐝 **Swarm Intelligence** - Coordinate multiple AI agents for parallel problem solving with shared memory
- 🔌 **MCP Client** - Connect to any Model Context Protocol server and access remote tools
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we edit this to callout that we are allowing an agent to autonomously perform this connection and dynamic loading. This was brought up on a client call and, as expected, this was called out as being potentially dangerous.

This tool is useful, I want to prevent customers from accidentally doing something like the following instead of using the MCPClient approach in the SDK

agent = Agent(tools=[mcp_client, use_browser])
agent.tool.mcp_client("connect")
# Agent uses the browser, then connects and downloads tools from an attackers mcp_server.

This be be documentation, but I also have concerns with this tool being called mcp_client. I would bet that we will get customers asking us "should I use mcp_client tool or MCPClient" because of this.

- 🔄 **Multiple tools in Parallel** - Call multiple other tools at the same time in parallel with Batch Tool

## 📦 Installation
Expand Down Expand Up @@ -120,6 +121,7 @@ Below is a comprehensive table of all available tools, how to use them with an a
| stop | `agent.tool.stop(message="Process terminated by user request")` | Gracefully terminate agent execution with custom message |
| use_llm | `agent.tool.use_llm(prompt="Analyze this data", system_prompt="You are a data analyst")` | Create nested AI loops with customized system prompts for specialized tasks |
| workflow | `agent.tool.workflow(action="create", name="data_pipeline", steps=[{"tool": "file_read"}, {"tool": "python_repl"}])` | Define, execute, and manage multi-step automated workflows |
| mcp_client | `agent.tool.mcp_client(action="connect", connection_id="my_server", transport="stdio", command="python", args=["server.py"])` | Connect to any MCP server via stdio, sse, or streamable_http, list tools, and call remote tools with simplified configuration |
| batch| `agent.tool.batch(invocations=[{"name": "current_time", "arguments": {"timezone": "Europe/London"}}, {"name": "stop", "arguments": {}}])` | Call multiple other tools in parallel. |

## 💻 Usage Examples
Expand All @@ -137,6 +139,63 @@ agent.tool.file_write(path="output.txt", content="Hello, world!")
agent.tool.editor(command="view", path="script.py")
```

### MCP Client Integration

```python
from strands import Agent
from strands_tools import mcp_client

agent = Agent(tools=[mcp_client])

# Connect to a custom MCP server via stdio
agent.tool.mcp_client(
action="connect",
connection_id="my_tools",
transport="stdio",
command="python",
args=["my_mcp_server.py"]
)

# List available tools on the server
tools = agent.tool.mcp_client(
action="list_tools",
connection_id="my_tools"
)

# Call a tool from the MCP server
result = agent.tool.mcp_client(
action="call_tool",
connection_id="my_tools",
tool_name="calculate",
tool_args={"x": 10, "y": 20}
)

# Connect to a SSE-based server
agent.tool.mcp_client(
action="connect",
connection_id="web_server",
transport="sse",
server_url="http://localhost:8080/sse"
)

# Connect to a streamable HTTP server
agent.tool.mcp_client(
action="connect",
connection_id="http_server",
transport="streamable_http",
server_url="https://api.example.com/mcp",
headers={"Authorization": "Bearer token"},
timeout=60
)

# Load MCP tools into agent's registry for direct access
agent.tool.mcp_client(
action="load_tools",
connection_id="my_tools"
)
# Now you can call MCP tools directly as: agent.tool.mcp_my_tools_calculate(x=10, y=20)
```

### Shell Commands

```python
Expand Down Expand Up @@ -425,6 +484,12 @@ The Mem0 Memory Tool supports three different backend configurations:
|----------------------|-------------|---------|
| ENV_VARS_MASKED_DEFAULT | Default setting for masking sensitive values | true |

#### MCP Client Tool

| Environment Variable | Description | Default |
|----------------------|-------------|---------|
| STRANDS_MCP_TIMEOUT | Default timeout in seconds for MCP operations | 30.0 |

#### File Read Tool

| Environment Variable | Description | Default |
Expand Down
Loading