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
* WIP transport support mcp
* refactor: streamline MCP tool loading and error handling
* linted
* Self type from typing with typing_extensions in MCP transport modules
* added tests for mcp setup
* added tests for mcp setup
* docs: enhance MCP overview with detailed integration examples and structured configurations
* feat: implement MCP event handling and logging in event listener and client
- Added MCP event types and handlers for connection and tool execution events.
- Enhanced MCPClient to emit events on connection status and tool execution.
- Updated ConsoleFormatter to handle MCP event logging.
- Introduced new MCP event types for better integration and monitoring.
@@ -11,9 +11,13 @@ The [Model Context Protocol](https://modelcontextprotocol.io/introduction) (MCP)
11
11
12
12
CrewAI offers **two approaches** for MCP integration:
13
13
14
-
### Simple DSL Integration** (Recommended)
14
+
### 🚀 **Simple DSL Integration** (Recommended)
15
15
16
-
Use the `mcps` field directly on agents for seamless MCP tool integration:
16
+
Use the `mcps` field directly on agents for seamless MCP tool integration. The DSL supports both **string references** (for quick setup) and **structured configurations** (for full control).
17
+
18
+
#### String-Based References (Quick Setup)
19
+
20
+
Perfect for remote HTTPS servers and CrewAI AMP marketplace:
17
21
18
22
```python
19
23
from crewai import Agent
@@ -32,6 +36,46 @@ agent = Agent(
32
36
# MCP tools are now automatically available to your agent!
33
37
```
34
38
39
+
#### Structured Configurations (Full Control)
40
+
41
+
For complete control over connection settings, tool filtering, and all transport types:
42
+
43
+
```python
44
+
from crewai import Agent
45
+
from crewai.mcp import MCPServerStdio, MCPServerHTTP, MCPServerSSE
46
+
from crewai.mcp.filters import create_static_tool_filter
47
+
48
+
agent = Agent(
49
+
role="Advanced Research Analyst",
50
+
goal="Research with full control over MCP connections",
51
+
backstory="Expert researcher with advanced tool access",
That's it! The MCP tools are automatically discovered and available to your agent.
100
184
101
185
## MCP Reference Formats
102
186
103
-
The `mcps` field supports various reference formats for maximum flexibility:
187
+
The `mcps` field supports both **string references** (for quick setup) and **structured configurations** (for full control). You can mix both formats in the same list.
104
188
105
-
### External MCP Servers
189
+
### String-Based References
190
+
191
+
#### External MCP Servers
106
192
107
193
```python
108
194
mcps=[
@@ -117,7 +203,7 @@ mcps=[
117
203
]
118
204
```
119
205
120
-
### CrewAI AMP Marketplace
206
+
####CrewAI AMP Marketplace
121
207
122
208
```python
123
209
mcps=[
@@ -133,17 +219,166 @@ mcps=[
133
219
]
134
220
```
135
221
222
+
### Structured Configurations
223
+
224
+
#### Stdio Transport (Local Servers)
225
+
226
+
Perfect for local MCP servers that run as processes:
227
+
228
+
```python
229
+
from crewai.mcp import MCPServerStdio
230
+
from crewai.mcp.filters import create_static_tool_filter
- 📊 **Transparent Integration**: Works seamlessly with existing CrewAI features
390
+
- 🔧 **Full Transport Support**: Stdio, HTTP/Streamable HTTP, and SSE transports
391
+
- 🎯 **Advanced Filtering**: Static and dynamic tool filtering capabilities
392
+
- 🔐 **Flexible Authentication**: Support for headers, environment variables, and query parameters
155
393
156
394
## Error Handling
157
395
158
-
The MCP DSL integration is designed to be resilient:
396
+
The MCP DSL integration is designed to be resilient and handles failures gracefully:
159
397
160
398
```python
399
+
from crewai import Agent
400
+
from crewai.mcp import MCPServerStdio, MCPServerHTTP
401
+
161
402
agent = Agent(
162
403
role="Resilient Agent",
163
404
goal="Continue working despite server issues",
164
405
backstory="Agent that handles failures gracefully",
165
406
mcps=[
407
+
# String references
166
408
"https://reliable-server.com/mcp", # Will work
167
409
"https://unreachable-server.com/mcp", # Will be skipped gracefully
168
-
"https://slow-server.com/mcp", # Will timeout gracefully
169
-
"crewai-amp:working-service"# Will work
410
+
"crewai-amp:working-service", # Will work
411
+
412
+
# Structured configs
413
+
MCPServerStdio(
414
+
command="python",
415
+
args=["reliable_server.py"], # Will work
416
+
),
417
+
MCPServerHTTP(
418
+
url="https://slow-server.com/mcp", # Will timeout gracefully
419
+
),
170
420
]
171
421
)
172
422
# Agent will use tools from working servers and log warnings for failing ones
173
423
```
174
424
425
+
All connection errors are handled gracefully:
426
+
-**Connection failures**: Logged as warnings, agent continues with available tools
427
+
-**Timeout errors**: Connections timeout after 30 seconds (configurable)
428
+
-**Authentication errors**: Logged clearly for debugging
429
+
-**Invalid configurations**: Validation errors are raised at agent creation time
430
+
175
431
## Advanced: MCPServerAdapter
176
432
177
433
For complex scenarios requiring manual connection management, use the `MCPServerAdapter` class from `crewai-tools`. Using a Python context manager (`with` statement) is the recommended approach as it automatically handles starting and stopping the connection to the MCP server.
0 commit comments