MCP Servers as Tools in CrewAI
Learn how to integrate MCP servers as tools in your CrewAI agents using the crewai-tools
library.
Overview
The Model Context Protocol (MCP) provides a standardized way for AI agents to provide context to LLMs by communicating with external services, known as MCP Servers.
The crewai-tools
library extends CrewAI’s capabilities by allowing you to seamlessly integrate tools from these MCP servers into your agents.
This gives your crews access to a vast ecosystem of functionalities.
We currently support the following transport mechanisms:
- Stdio: for local servers (communication via standard input/output between processes on the same machine)
- Server-Sent Events (SSE): for remote servers (unidirectional, real-time data streaming from server to client over HTTP)
- Streamable HTTP: for remote servers (flexible, potentially bi-directional communication over HTTP, often utilizing SSE for server-to-client streams)
Video Tutorial
Watch this video tutorial for a comprehensive guide on MCP integration with CrewAI:
Installation
Before you start using MCP with crewai-tools
, you need to install the mcp
extra crewai-tools
dependency with the following command:
Key Concepts & Getting Started
The MCPServerAdapter
class from crewai-tools
is the primary way to connect to an MCP server and make its tools available to your CrewAI agents. It supports different transport mechanisms and simplifies connection management.
Using a Python context manager (with
statement) is the recommended approach for MCPServerAdapter
. It automatically handles starting and stopping the connection to the MCP server.
This general pattern shows how to integrate tools. For specific examples tailored to each transport, refer to the detailed guides below.
Explore MCP Integrations
Stdio Transport
Connect to local MCP servers via standard input/output. Ideal for scripts and local executables.
SSE Transport
Integrate with remote MCP servers using Server-Sent Events for real-time data streaming.
Streamable HTTP Transport
Utilize flexible Streamable HTTP for robust communication with remote MCP servers.
Connecting to Multiple Servers
Aggregate tools from several MCP servers simultaneously using a single adapter.
Security Considerations
Review important security best practices for MCP integration to keep your agents safe.
Checkout this repository for full demos and examples of MCP integration with CrewAI! 👇
GitHub Repository
CrewAI MCP Demo
Staying Safe with MCP
Always ensure that you trust an MCP Server before using it.
Security Warning: DNS Rebinding Attacks
SSE transports can be vulnerable to DNS rebinding attacks if not properly secured. To prevent this:
- Always validate Origin headers on incoming SSE connections to ensure they come from expected sources
- Avoid binding servers to all network interfaces (0.0.0.0) when running locally - bind only to localhost (127.0.0.1) instead
- Implement proper authentication for all SSE connections
Without these protections, attackers could use DNS rebinding to interact with local MCP servers from remote websites.
For more details, see the Anthropic’s MCP Transport Security docs.
Limitations
- Supported Primitives: Currently,
MCPServerAdapter
primarily supports adapting MCPtools
. Other MCP primitives likeprompts
orresources
are not directly integrated as CrewAI components through this adapter at this time. - Output Handling: The adapter typically processes the primary text output from an MCP tool (e.g.,
.content[0].text
). Complex or multi-modal outputs might require custom handling if not fitting this pattern.