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)
You’ll need valid Membit API credentials and the MCP remote URL. If you don’t have access yet, get your API key to get started.

Installation

Install the required packages for CrewAI and MCP integration:
# Install CrewAI tools
pip install 'crewai-tools[mcp]'

# Install MCP remote client (requires Node.js)
npm install -g mcp-remote
We recommend using a virtual environment to manage your Python dependencies and avoid conflicts.

Quick Start

1

Import required modules

Import the necessary components for CrewAI and MCP integration:
from crewai import Agent, Task, Crew
from crewai_tools import MCPServerAdapter
from mcp import StdioServerParameters
2

Configure MCP server parameters

Set up the connection to Membit’s MCP server:
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>,
    },
)
Make sure you have mcp-remote installed globally via npm for this to work.
Replace <your-api-key> with your actual Membit API key. Keep this credential secure and don’t share it with unauthorized users.
3

Create your Membit-powered agent

Use the MCPServerAdapter to connect Membit tools to your CrewAI agent:
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,
    )
4

Define your analysis task

Create a task that leverages Membit’s real-time data:
    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",
    )
5

Execute your crew

Create and run your CrewAI crew:
    # Create and execute the crew
    crew = Crew(
        agents=[analyst_agent],
        tasks=[analysis_task]
    )

    result = crew.kickoff()
    print(result)
Your CrewAI agent is now powered by real-time social media context from Membit!

Complete Example

Here’s a full working example that demonstrates the integration:
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