
mastra.ai MCP agent
This Actor is paid per event

mastra.ai MCP agent
This Actor is paid per event
🤖 AI agent using mastra.ai with Apify MCP Server. 🚀 Runs queries via OpenAI models, taps Apify Actors for web data, and outputs to datasets. 🛠️
Actor Metrics
1 monthly user
No reviews yet
No bookmarks yet
Created in Mar 2025
Modified 19 hours ago
Mastra AI Agent with Apify MCP Server
The Mastra AI Agent with Apify MCP Server is a generic AI agent designed to demonstrate the power of the mastra.ai framework when paired with the Apify MCP Server. This Actor leverages the Model Context Protocol (MCP) to connect AI-driven workflows with Apify’s extensive library of Actors, enabling seamless data extraction, web scraping, and task automation.
Built with TypeScript and the Apify SDK, this Actor serves as a flexible starting point for developers looking to create custom AI agents that tap into real-time web data and tools.
🎯 Features
- 🤖 AI-powered assistance: Uses the mastra.ai framework to process queries with OpenAI models (e.g.,
gpt-4o
,gpt-4o-mini
). - 🌐 Apify MCP integration: Connects to the Apify MCP Server to access tools like
clockworks/free-tiktok-scraper
and more. - 💰 Pay-per-event pricing: Flexible, usage-based billing for Actor runs and task completions.
🔄 How it works
-
📥 Input
- Query (e.g., "Analyze posts from @openai and summarize AI trends")
- Model selection (
gpt-4o
orgpt-4o-mini
) - Actors included (e.g.,
["clockworks/free-tiktok-scraper"]
) - list of Apify Actors to be served by the MCP server outside of the default list
-
🤖 Processing with Mastra
- Initializes a
Helpful Assistant Agent
using the mastra.ai framework. - Connects to the Apify MCP Server via Server-Sent Events (SSE).
- Fetches available tools (e.g., TikTok scrapers, web browsers) dynamically.
- Executes the query, leveraging MCP tools as needed.
- Initializes a
-
📤 Output
- Returns the agent’s response as text.
- Stores results in an Apify dataset with the query and response.
💰 Pricing
This Actor uses the Pay Per Event (PPE) model for cost-effective, usage-based pricing.
Event | Price (USD) |
---|---|
Actor start | $0.10 |
Task completion | $0.40 |
Input Example
1{ 2 "query": "Analyze the posts of @openai and summarize current trends in AI.", 3 "modelName": "gpt-4o-mini", 4 "actorsIncluded": ["clockworks/free-tiktok-scraper"] 5}
Output Example
Dataset entry:
1{ 2 "query": "Analyze the posts of @openai and summarize current trends in AI.", 3 "response": "Here’s a summary of the recent posts from OpenAI's Instagram account, highlighting current trends in AI..." 4}
🔧 Technical highlights
- Mastra.ai framework: Powers the AI agent.
- Apify MCP Server: Exposes Apify Actors as tools via the Model Context Protocol.
- Apify SDK: Ensures seamless integration with the Apify platform.
- TypeScript: Provides type safety and modern JavaScript features.
🤖 Under the hood with mastra.ai
This Actor uses the mastra.ai framework to create a generic AI agent that interacts with the Apify ecosystem:
👤 The agent
- Helpful Assistant Agent:
1new Agent({ 2 name: 'Helpful Assistant Agent', 3 instructions: 'You are a helpful assistant who aims to help users with their questions and tasks.', 4 model: openai(modelName), 5});
- Goal: Answer queries accurately and leverage MCP tools when needed.
- Tools: Dynamically fetched from the Apify MCP Server (e.g.,
clockworks/free-tiktok-scraper
).
🔄 Workflow
-
Initialization:
- Starts the MCP Server if it’s not already running.
- Connects via SSE using the
MastraMCPClient
.
-
Execution:
- Queries the agent with user input.
- Integrates MCP tools into the agent’s toolset.
- Processes the response using the selected OpenAI model.
-
Output:
- Logs token usage and the agent's response.
- Saves results to the dataset.
🛠️ Tools
Expandable to any Apify Actor from the Apify Store via the MCP Server configuration.
⚙️ Usage
Running on Apify
- Clone the repository.
- Push the Actor to the Apify platform:
apify push
- Set Actor
OPENAI_API_KEY
environment variable. - Run the Actor with your input via the Apify Console or API.
Local development
- Install dependencies:
npm install
- Run locally:
OPENAI_API_KEY=<your-openai-api-key> apify run -i '{"query": "Show me latest post from @openai TikTok profile", "actorsIncluded": ["clockworks/free-tiktok-scraper"]}'
📖 Learn more
- Mastra.ai Framework
- Apify MCP Server
- Apify Platform
- Apify SDK Documentation
- What is MCP?
- What are AI agents?
- How to build an AI agent on Apify
🚀 Get started
Ready to build your own AI agent? Deploy this Actor on Apify, tweak the query, and explore the possibilities of mastra.ai and MCP! 🤖✨
🌐 Open source
This Actor is open-source, hosted on GitHub. Want to add features? Open an issue or submit a pull request!