Overview
CrewAIโs MCP DSL (Domain Specific Language) integration provides the simplest way to connect your agents to MCP (Model Context Protocol) servers. Just add anmcps
field to your agent and CrewAI handles all the complexity automatically.
This is the recommended approach for most MCP use cases. For advanced scenarios requiring manual connection management, see MCPServerAdapter.
Basic Usage
Add MCP servers to your agent using themcps
field:
Supported Reference Formats
External MCP Remote Servers
Specific Tool Selection
Use the#
syntax to select specific tools from a server:
CrewAI AMP Marketplace
Access tools from the CrewAI AMP marketplace:Complete Example
Hereโs a complete example using multiple MCP servers:Tool Naming and Organization
CrewAI automatically handles tool naming to prevent conflicts:Error Handling and Resilience
The MCP DSL is designed to be robust and user-friendly:Graceful Server Failures
Timeout Protection
All MCP operations have built-in timeouts:- Connection timeout: 10 seconds
- Tool execution timeout: 30 seconds
- Discovery timeout: 15 seconds
Performance Features
Automatic Caching
Tool schemas are cached for 5 minutes to improve performance:On-Demand Connections
Tool connections are established only when tools are actually used:Integration with Existing Features
MCP tools work seamlessly with other CrewAI features:Best Practices
1. Use Specific Tools When Possible
2. Handle Authentication Securely
3. Plan for Server Failures
4. Use Descriptive Agent Roles
Troubleshooting
Common Issues
No tools discovered:Advanced: MCPServerAdapter
For complex scenarios requiring manual connection management, use theMCPServerAdapter
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.