You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -38,9 +36,9 @@ MCP enables communication between agents and MCP servers that provide additional
38
36
39
37
=== "Python"
40
38
41
-
**Manual Context Management**
39
+
**Managed Integration (Recommended)**
42
40
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:
44
42
45
43
```python
46
44
from mcp import stdio_client, StdioServerParameters
@@ -54,26 +52,20 @@ MCP enables communication between agents and MCP servers that provide additional
54
52
)
55
53
))
56
54
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?")
62
58
```
63
59
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**
70
61
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:
72
63
73
64
```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
77
69
```
78
70
79
71
=== "TypeScript"
@@ -250,7 +242,7 @@ Combine tools from multiple MCP servers in a single agent:
0 commit comments