> ## Documentation Index
> Fetch the complete documentation index at: https://docs.membit.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CrewAI

> Integrate real-time context to your CrewAI agents via Membit MCP.

<img src="https://mintcdn.com/membit/4JB7OCBLDkpjkRT-/images/cover/crewai.png?fit=max&auto=format&n=4JB7OCBLDkpjkRT-&q=85&s=c183c386f56edebd37c84b2481dff3ea" alt="Cover Image" className="rounded-lg" noZoom width="1402" height="463" data-path="images/cover/crewai.png" />

Enhance your CrewAI applications with real-time social media context from Membit. This integration allows your AI agents to access up-to-the-minute discussions, trends, and insights from platforms like X (Twitter), Farcaster, and more.

## Prerequisites

Before you begin, ensure you have:

* Python 3.10 or higher installed
* A Membit account with API access
* Basic familiarity with CrewAI agents and crews
* Node.js installed (for MCP remote client)

<Warning>
  You'll need valid Membit API credentials and the MCP remote URL. If you don't
  have access yet, [get your API key](/access-and-auth) to get started.
</Warning>

## Installation

Install the required packages for CrewAI and MCP integration:

```bash theme={null}
# Install CrewAI tools
pip install 'crewai-tools[mcp]'

# Install MCP remote client (requires Node.js)
npm install -g mcp-remote
```

<Tip>
  We recommend using a virtual environment to manage your Python dependencies
  and avoid conflicts.
</Tip>

## Quick Start

<Steps>
  <Step title="Import required modules">
    Import the necessary components for CrewAI and MCP integration:

    ```python theme={null}
    from crewai import Agent, Task, Crew
    from crewai_tools import MCPServerAdapter
    from mcp import StdioServerParameters
    ```
  </Step>

  <Step title="Configure MCP server parameters">
    Set up the connection to Membit's MCP server:

    ```python theme={null}
    server_params = StdioServerParameters(
        command="npx",
        args=[
            "mcp-remote",
            "https://mcp.membit.ai/mcp",
            "--header",
            "X-Membit-Api-Key:${MEMBIT_API_KEY}",
        ],
        env={
            "MEMBIT_API_KEY": <your-api-key>,
        },
    )
    ```

    <Note>
      Make sure you have `mcp-remote` installed globally via npm for this to work.
    </Note>

    <Warning>
      Replace `<your-api-key>` with your actual Membit API key. Keep this credential secure and don't share it with unauthorized users.
    </Warning>
  </Step>

  <Step title="Create your Membit-powered agent">
    Use the MCPServerAdapter to connect Membit tools to your CrewAI agent:

    ```python theme={null}
    with MCPServerAdapter(server_params) as membit_tools:
        # Create an agent with Membit tools
        analyst_agent = Agent(
            role="Social Media Data Analyst",
            goal="Analyze trending social media data and provide insights using Membit tools",
            backstory="You are an experienced social media analyst with expertise in identifying trends and understanding online conversations.",
            allow_code_execution=False,
            tools=membit_tools,
        )
    ```
  </Step>

  <Step title="Define your analysis task">
    Create a task that leverages Membit's real-time data:

    ```python theme={null}
    analysis_task = Task(
        description="Find the most trending discussions today about AI technology. Use cluster_search to identify hot topics and provide insights with source URLs.",
        agent=analyst_agent,
        expected_output="A comprehensive analysis of trending AI discussions with key insights and source URLs",
    )
    ```
  </Step>

  <Step title="Execute your crew">
    Create and run your CrewAI crew:

    ```python theme={null}
    # Create and execute the crew
    crew = Crew(
        agents=[analyst_agent],
        tasks=[analysis_task]
    )

    result = crew.kickoff()
    print(result)
    ```

    <Check>
      Your CrewAI agent is now powered by real-time social media context from Membit!
    </Check>
  </Step>
</Steps>

## Complete Example

Here's a full working example that demonstrates the integration:

```python theme={null}
from crewai import Agent, Task, Crew
from crewai_tools import MCPServerAdapter
from mcp import StdioServerParameters

def main():
    server_params = StdioServerParameters(
        command="npx",
        args=[
            "mcp-remote",
            "https://mcp.membit.ai/mcp",
            "--header",
            "X-Membit-Api-Key:${MEMBIT_API_KEY}",
        ],
        env={
            # Replace `<your-api-key>` with your actual Membit API key.
            "MEMBIT_API_KEY": <your-api-key>,
        },
    )

    with MCPServerAdapter(server_params) as membit_tools:
        # Create a social media analyst agent
        analyst_agent = Agent(
            role="Social Media Data Analyst",
            goal="Analyze trending social media data and provide actionable insights",
            backstory="You are an expert social media analyst who specializes in identifying trends, analyzing sentiment, and understanding online conversations across platforms.",
            allow_code_execution=False,
            tools=membit_tools,
        )

        # Create analysis task
        analysis_task = Task(
            description="What are the most trending discussions today related to Bitcoin? Use cluster_search to find hot topics and provide the best conversations to follow with URLs.",
            agent=analyst_agent,
            expected_output="A detailed analysis of trending Bitcoin discussions with source URLs and key insights",
        )

        # Execute the crew
        crew = Crew(agents=[analyst_agent], tasks=[analysis_task])
        result = crew.kickoff()

        print("Analysis Results:")
        print(result)

if __name__ == "__main__":
    main()
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="MCP Connection Issues">
    **Problem**: Cannot connect to Membit MCP server

    **Solutions**:

    * Verify `mcp-remote` is installed: `npm list -g mcp-remote`
    * Check your API key
    * Ensure Node.js is properly installed and accessible
    * Test connectivity with `npx mcp-remote` directly
  </Accordion>

  <Accordion title="Tool Loading Failures">
    **Problem**: MCPServerAdapter fails to load tools

    **Solutions**:

    * Ensure the MCP server parameters are correct
    * Check network connectivity and firewall settings
    * Verify your Membit API credentials are valid
    * Try running the MCP server manually to test connection
  </Accordion>

  <Accordion title="Agent Execution Issues">
    **Problem**: Agents fail to use Membit tools effectively

    **Solutions**:

    * Be explicit in task descriptions about which tools to use
    * Set `allow_code_execution=False` unless specifically needed
    * Use verbose mode to see tool usage during execution
    * Ensure agents have clear, specific roles and goals
  </Accordion>
</AccordionGroup>
