Extend CrewAI with MCP protocol support for custom agent and tool development in Python
CrewAI MCP Adapter is a Python library that extends CrewAI’s adapter ecosystem, providing native integration and adapter patterns for Model Context Protocol (MCP) support. This powerful toolkit facilitates the seamless incorporation of various tools into AI applications through a comprehensive set of APIs, enabling developers to build sophisticated AI-driven workflows with ease.
The CrewAI MCP Adapter offers several key features that enhance its utility in the development and deployment of intelligent workflows:
Native CrewAI Integration: The adapter seamlessly integrates with CrewAI's infrastructure, ensuring that both traditional and new agents can leverage MCP-supported tools.
MCP Protocol Support for Tool Integration: By adhering to the Model Context Protocol, the adapter enables a wide range of AI applications to interact with various tools and data sources through a standardized interface. This ensures compatibility across different platforms and tools, making the development process more efficient and scalable.
Easy-to-Use Interface for Extending Adapters: The library provides a user-friendly API that allows developers to extend existing adapters or create new ones with minimal effort, leading to faster deployment cycles and greater flexibility.
Type-Safe Implementation with Pydantic: Utilizing Pydantic ensures that all tool interactions are type-safe, reducing bugs and improving the overall robustness of applications built on top of MCP.
JSON Schema Validation for Tool Parameters: Ensuring that tool parameters adhere to a strict schema helps maintain consistency and improves user experience by preventing errors due to invalid input.
Async/Await Support: Support for asynchronous operations is crucial in modern software development, as it enables non-blocking behavior and optimized performance critical for real-time applications.
Detailed Execution Metadata: Providing comprehensive metadata during execution helps developers monitor the status of tasks, identify issues quickly, and optimize workflows effectively.
The CrewAI MCP Adapter operates within a structured architecture that leverages the Model Context Protocol to facilitate seamless interaction between AI applications, adaptors, and tools. The protocol flow can be visualized as follows:
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
The MCP Client acts as a bridge between the AI application and the actual protocol execution. It initializes communication with the MCP Server, which then coordinates interactions with external data sources or tools.
Imagine an AI-driven dashboard that automates data analysis tasks by leveraging external tools like Excel or SQL databases. Using CrewAI MCP Adapter, developers can create adaptable agents that interact with these tools via the Model Context Protocol, ensuring seamless integration and improving user experience.
# Example Usage in Python
from crewai import Agent, Task
from crewai_adapters import CrewAIAdapterClient
from crewai_adapters.types import AdapterConfig
async def main():
async with CrewAIAdapterClient() as client:
# Connect to MCP Server
await client.connect_to_mcp_server(
"data_analyze",
command="python",
args=["analyze_data.py"]
)
# Create agent with tools
agent = Agent(
name="Data Analyst",
goal="Perform Data Analysis",
tools=client.get_tools()
)
# Execute task
task = Task(
description="Generate Monthly Sales Report",
agent=agent
)
result = await task.execute()
print(f"Result: {result}")
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Consider a chatbot designed to provide financial advice. By integrating custom tools through the CrewAI MCP Adapter, the chatbot can perform complex calculations without needing to rewrite existing code.
# Example Usage in Python
from crewai import Agent, Task
from crewai_adapters import CrewAIAdapterClient
from crewai_adapters.types import AdapterConfig
async def main():
async with CrewAIAdapterClient() as client:
# Connect to MCP Server
await client.connect_to_mcp_server(
"financial_tools",
command="python",
args=["financial_calculator.py"]
)
# Create agent with tools
agent = Agent(
name="Financial Advisor",
goal="Provide Financial Advice",
tools=client.get_tools()
)
# Execute task
task = Task(
description="Calculate Investment Returns for a 5-Year Term",
agent=agent
)
result = await task.execute()
print(f"Result: {result}")
if __name__ == "__main__":
import asyncio
asyncio.run(main())
To get started, you can install the CrewAI MCP Adapter using either PyPI or directly from GitHub:
pip install crewai-adapters
pip install git+https://github.com/dshivendra/crewai_mcp_adapter.git
The CrewAI MCP Adapter enables developers to build more versatile and powerful AI applications by integrating various tools seamlessly. Some key use cases include:
The CrewAI MCP Adapter supports integration with various MCP clients, ensuring compatibility across a wide range of AI applications. Currently supported clients include:
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ | Full Support |
Continue | ✅ | ✅ | ✅ | Full Support |
Cursor | ❌ | ✅ | ❌ | Tools Only |
The CrewAI MCP Server is designed to ensure high performance and broad compatibility. The server has been rigorously tested to support a wide range of use cases, environments, and tool configurations.
Developers can configure the CrewAI MCP Adapter using various parameters such as environment variables, command-line arguments, and custom schemas. For additional security measures, the adapter supports secure connections, authentication mechanisms, and rate limiting to prevent abuse.
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
Q: What are the system requirements for using CrewAI MCP Adapter?
A: CrewAI MCP Adapter requires Python 3.11 or higher, along with the crewai
, pydantic
, and mcp
packages.
Q: How does the CrewAI MCP Adapter ensure protocol compliance? A: The adapter adheres to the Model Context Protocol by implementing its standards for tool interaction and data exchange.
Q: Can the CrewAI MCP Server handle multiple MCP clients simultaneously? A: Yes, the server is designed to support concurrent connections from multiple MCP clients, making it ideal for multi-user environments.
Q: How do I troubleshoot issues with the CrewAI MCP Adapter? A: Detailed logs and error messages are available for debugging purposes. For more assistance, refer to the official documentation or seek support from the community forums.
Q: Is there any performance overhead with using the CrewAI MCP Adapter? A: While some initialization overhead is present, the adapter optimizes performance through asynchronous operations and efficient data handling.
Contributions to the CrewAI MCP Adapter are welcome! Please refer to the CONTRIBUTING.md
file for more detailed information on how to get started. Whether you're fixing bugs or adding new features, your contributions can greatly enhance the library.
To discover more about Model Context Protocol and its ecosystem, visit the official website: Model Context Protocol. Additionally, explore the official documentation and community forums for further resources and support.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods