
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
MCP Connection Issues
MCP Connection Issues
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
Tool Loading Failures
Tool Loading Failures
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
Agent Generation Issues
Agent Generation Issues
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