Skip to main content
This example demonstrates how to use Composio with CrewAI to create collaborative AI agent teams that can execute complex tasks using MCP (Model Context Protocol).

Overview

In this example, you’ll learn how to:
  • Integrate Composio with CrewAI using MCP
  • Create agents with access to Composio tools
  • Define tasks for agents to complete
  • Execute crew workflows with tool access

Prerequisites

1

Install dependencies

2

Set up environment variables

Create a .env file with your API keys:
3

Authenticate with Gmail

Complete Example

How It Works

1

Create Composio Session

Initialize Composio and create a session for your user. This provides an MCP server endpoint with all connected tools.
2

Configure MCP Server

Create an MCPServerHTTP instance that connects to Composio’s MCP endpoint. This gives the agent access to all Composio tools.
3

Create Agent with Tools

Define an agent with a specific role, goal, and backstory. Add the MCP server to the mcps parameter to give it access to Composio tools.
4

Define Tasks

Create tasks with clear descriptions and expected outputs. CrewAI will automatically select the appropriate tools to complete each task.
5

Execute Crew

Create a Crew with your agents and tasks, then call kickoff() to start execution.

Multi-Agent Example

Build a crew with multiple specialized agents:

Expected Output

Agent Configuration

string
required
The role or title of the agent (e.g., “Email Specialist”, “Data Analyst”)
string
required
The agent’s objective and what it aims to accomplish
string
required
The agent’s background and expertise context
list[MCPServer]
List of MCP servers providing tools to the agent
bool
default:"false"
Whether to print detailed execution logs

Task Configuration

string
required
Detailed description of what the task should accomplish
string
required
Clear specification of what the task output should look like
Agent
required
The agent responsible for executing this task

Process Types

CrewAI supports different execution processes:

Crew Collaboration

Agents can collaborate on complex tasks:

Custom MCP Configuration

Configure MCP servers with advanced options:

Error Handling

Best Practices

Specific Roles: Give agents clear, specific roles to improve task execution quality
Clear Expected Outputs: Define precise expected outputs to guide agent behavior
Task Dependencies: Use context parameter to create task dependencies when needed
Verbose Mode: Enable verbose mode during development to understand agent decisions

Advanced Features

CrewAI agents can maintain memory across executions:
Combine Composio tools with custom CrewAI tools:
Monitor crew execution with callbacks:

Next Steps

Custom Tools

Create custom Python tools for CrewAI

LangChain Example

Use Composio with LangChain