Skip to content

Commit f8e8e99

Browse files
docs: promote managed MCP integration as recommended approach (strands-agents#496)
Co-authored-by: Strands Agent <217235299+strands-agent@users.noreply.github.com>
1 parent 01511fe commit f8e8e99

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

docs/user-guide/concepts/tools/mcp-tools.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ MCP enables communication between agents and MCP servers that provide additional
2121
)
2222
))
2323

24-
# Use with context manager for lifecycle management
25-
with mcp_client:
26-
tools = mcp_client.list_tools_sync()
27-
agent = Agent(tools=tools)
28-
agent("What is AWS Lambda?")
24+
# Pass MCP client directly to agent - lifecycle managed automatically
25+
agent = Agent(tools=[mcp_client])
26+
agent("What is AWS Lambda?")
2927
```
3028

3129
=== "TypeScript"
@@ -38,9 +36,9 @@ MCP enables communication between agents and MCP servers that provide additional
3836

3937
=== "Python"
4038

41-
**Manual Context Management**
39+
**Managed Integration (Recommended)**
4240

43-
Python requires explicit context management using `with` statements to manage the MCP connection lifecycle:
41+
The `MCPClient` implements the `ToolProvider` interface, enabling direct usage in the Agent constructor with automatic lifecycle management:
4442

4543
```python
4644
from mcp import stdio_client, StdioServerParameters
@@ -54,26 +52,20 @@ MCP enables communication between agents and MCP servers that provide additional
5452
)
5553
))
5654

57-
# Manual lifecycle management
58-
with mcp_client:
59-
tools = mcp_client.list_tools_sync()
60-
agent = Agent(tools=tools)
61-
agent("What is AWS Lambda?") # Must be within context
55+
# Direct usage - connection lifecycle managed automatically
56+
agent = Agent(tools=[mcp_client])
57+
response = agent("What is AWS Lambda?")
6258
```
6359

64-
This approach provides direct control over the MCP session lifecycle but requires careful management to avoid connection errors.
65-
66-
**Managed Integration (Experimental)**
67-
68-
!!! warning "Experimental Feature"
69-
The managed integration feature is experimental and may change in future versions. For production applications, use the manual context management approach.
60+
**Manual Context Management**
7061

71-
The `MCPClient` implements the experimental `ToolProvider` interface, enabling direct usage in the Agent constructor with automatic lifecycle management:
62+
For cases requiring explicit control over the MCP session lifecycle, use context managers:
7263

7364
```python
74-
# Direct usage - connection lifecycle managed automatically
75-
agent = Agent(tools=[mcp_client])
76-
response = agent("What is AWS Lambda?")
65+
with mcp_client:
66+
tools = mcp_client.list_tools_sync()
67+
agent = Agent(tools=tools)
68+
agent("What is AWS Lambda?") # Must be within context
7769
```
7870

7971
=== "TypeScript"
@@ -250,7 +242,7 @@ Combine tools from multiple MCP servers in a single agent:
250242
tools = sse_mcp_client.list_tools_sync() + stdio_mcp_client.list_tools_sync()
251243
agent = Agent(tools=tools)
252244

253-
# Managed approach (experimental)
245+
# Managed approach
254246
agent = Agent(tools=[sse_mcp_client, stdio_mcp_client])
255247
```
256248

0 commit comments

Comments
 (0)