Skip to main content
Cover Image Enhance your VoltAgent 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:
  • Node.js 20 or higher installed
  • A Membit account with API access
  • Basic familiarity with VoltAgent agents and workflows
  • TypeScript knowledge (recommended)
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 VoltAgent and MCP integration:
# Install VoltAgent core packages
npm install @voltagent/core
VoltAgent works best with TypeScript and structured logging. Make sure your project is configured accordingly.

Quick Start

1

Import required modules

Import the necessary components for VoltAgent and MCP integration:
import { VoltAgent, Agent, MCPConfiguration } from "@voltagent/core";
import { createPinoLogger } from "@voltagent/logger";
import { VercelAIProvider } from "@voltagent/vercel-ai";
import { openai } from "@ai-sdk/openai";
2

Configure MCP connection

Set up the MCP configuration to connect to Membit’s tools:
const mcpConfig = new MCPConfiguration({
  servers: {
    membit: {
      type: "stdio",
      command: "npx",
      env: {
        MEMBIT_API_KEY: <your-api-key>,
      },
      args: [
        "mcp-remote",
        "https://mcp.membit.ai/mcp",
        "--header",
        "X-Membit-Api-Key:${MEMBIT_API_KEY}",
      ],
    },
  },
});
VoltAgent supports streamable HTTP transport for efficient MCP connections.
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

Create a VoltAgent agent with Membit tools:
const membitAgent = new Agent({
  name: "social-media-analyst",
  instructions:
    "You are a social media analyst with access to real-time data. Use cluster_search to find trending discussions, cluster_info for detailed analysis, and post_search for specific posts.",
  llm: new VercelAIProvider(),
  model: openai("gpt-4o-mini"),
  tools: await mcpConfig.getTools(),
});
4

Initialize VoltAgent system

Create the VoltAgent system with your agent:
// Initialize VoltAgent with your agent(s)
new VoltAgent({
  agents: {
    membitAgent,
  },
});
Your VoltAgent is now powered by real-time social media context from Membit!

Complete Example

Here’s a full working example that demonstrates the integration:
import { VoltAgent, Agent, MCPConfiguration } from "@voltagent/core";
import { createPinoLogger } from "@voltagent/logger";
import { VercelAIProvider } from "@voltagent/vercel-ai";
import { openai } from "@ai-sdk/openai";

// Configure MCP connection to Membit
const mcpConfig = new MCPConfiguration({
  servers: {
    membit: {
      type: "stdio",
      command: "npx",
      env: {
        MEMBIT_API_KEY: <your-api-key>,
      },
      args: [
        "mcp-remote",
        "https://mcp.membit.ai/mcp",
        "--header",
        "X-Membit-Api-Key:${MEMBIT_API_KEY}",
      ],
    },
  },
});

// Create Membit-powered agent
const socialAnalyst = new Agent({
  name: "membit-social-analyst",
  instructions: `You are an expert social media analyst with access to real-time trending data.
Use cluster_search to find trending discussions, cluster_info to dive deeper into specific conversations,
and post_search to find individual posts. Always provide context and source URLs.`,
  llm: new VercelAIProvider(),
  model: openai("gpt-4o-mini"),
  tools: await mcpConfig.getTools(),
});

// Initialize VoltAgent
const voltAgent = new VoltAgent({
  agents: {
    socialAnalyst,
  },
});

Troubleshooting

Problem: Cannot connect to Membit MCP serverSolutions:
  • Verify your API key
  • Check network connectivity and firewall settings
  • Ensure the streamable HTTP endpoint is accessible
  • Try increasing the timeout value in MCPConfiguration
Problem: mcpConfig.getTools() returns empty or failsSolutions:
  • Ensure MCP configuration is correct with proper server settings
  • Check that the Membit API key is valid
  • Verify the MCP server URL is accessible
  • Try initializing the MCP config in a try-catch block
Problem: Workflows fail or don’t execute properlySolutions:
  • Check agent dependencies and execution order
  • Verify all required agents are properly registered
  • Use structured logging to debug workflow steps
  • Ensure agents have access to required tools