
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)
Installation
Install the required packages for Mastra and MCP integration: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.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-remoteis installed:npm list -g mcp-remote - Check your API key
- Ensure Node.js is properly installed and accessible
- Test connectivity with
npx mcp-remotedirectly
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