Skip to main content
Cover Image Enhance your Mastra 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 Mastra agents
  • 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 Mastra and MCP integration:
Mastra works best with TypeScript. Make sure your project is configured for TypeScript development.

Quick Start

1

Import required modules

Import the necessary components for Mastra and MCP integration:
2

Initialize MCP client

Create an MCP client to connect to Membit’s tools:
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

Create a Mastra agent with Membit tools and memory:
4

Use your agent

Execute your agent with social media analysis tasks:
Your Mastra agent is now powered by real-time social media context from Membit!

Complete Example

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

Troubleshooting

Problem: Cannot connect to Membit MCP serverSolutions:
  • 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
Problem: mcp.getTools() returns empty or failsSolutions:
  • Ensure MCP client is properly configured with correct server parameters
  • Check network connectivity and firewall settings
  • Verify your Membit API credentials are valid
  • Try initializing the MCP client in a try-catch block
Problem: Agents don’t use Membit tools effectivelySolutions:
  • Make agent instructions more explicit about tool usage
  • Test with simpler, more direct queries first
  • Check that tools are properly loaded: console.log(await mcp.getTools())
  • Verify the agent’s memory storage is accessible