Google Analytics 4 MCP Server for Mastra AIGive Mastra AI instant access to 12 tools to Batch Run Reports, Check Compatibility, Get Conversions, and more
Mastra AI is a TypeScript-native agent framework built for modern web stacks. Connect Google Analytics 4 through Vinkius and Mastra agents discover all tools automatically. type-safe, streaming-ready, and deployable anywhere Node.js runs.
Ask AI about this App Connector for Mastra AI
The Google Analytics 4 app connector for Mastra AI is a standout in the Industry Titans category — giving your AI agent 12 tools to work with, ready to go from day one.
Vinkius delivers Streamable HTTP and SSE to any MCP client
import { Agent } from "@mastra/core/agent";
import { createMCPClient } from "@mastra/mcp";
import { openai } from "@ai-sdk/openai";
async function main() {
// Your Vinkius token. get it at cloud.vinkius.com
const mcpClient = await createMCPClient({
servers: {
"google-analytics-4": {
url: "https://edge.vinkius.com/[YOUR_TOKEN_HERE]/mcp",
},
},
});
const tools = await mcpClient.getTools();
const agent = new Agent({
name: "Google Analytics 4 Agent",
instructions:
"You help users interact with Google Analytics 4 " +
"using 12 tools.",
model: openai("gpt-4o"),
tools,
});
const result = await agent.generate(
"What can I do with Google Analytics 4?"
);
console.log(result.text);
}
main();
* Every MCP server runs on Vinkius-managed infrastructure inside AWS - a purpose-built runtime with per-request V8 isolates, Ed25519 signed audit chains, and sub-40ms cold starts optimized for native MCP execution. See our infrastructure
About Google Analytics 4 MCP Server
Connect your Google Analytics 4 property to any AI agent and access web analytics through natural conversation.
Mastra's agent abstraction provides a clean separation between LLM logic and Google Analytics 4 tool infrastructure. Connect 12 tools through Vinkius and use Mastra's built-in workflow engine to chain tool calls with conditional logic, retries, and parallel execution. deployable to any Node.js host in one command.
What you can do
- Custom Reports — Run fully customizable GA4 reports with any combination of dimensions, metrics, and date ranges
- Real-Time Analytics — Monitor active users and current page views in real time
- Page Performance — Retrieve the top 25 pages ranked by views for any time period
- Traffic Sources — Analyze session sources and mediums to understand where visitors come from
- User Demographics — View user distribution by country for geographic insights
- Device Breakdown — See user distribution across desktop, mobile, and tablet
- Conversions — Track conversion events with counts and revenue data
- Advanced Reporting — Run pivot reports and batch multiple reports in a single request
- Metadata & Compatibility — List all available dimensions and metrics, and verify compatibility before building reports
The Google Analytics 4 MCP Server exposes 12 tools through the Vinkius. Connect it to Mastra AI in under two minutes — no API keys to rotate, no infrastructure to provision, no vendor lock-in. Your configuration, your data, your control.
All 12 Google Analytics 4 tools available for Mastra AI
When Mastra AI connects to Google Analytics 4 through Vinkius, your AI agent gets direct access to every tool listed below — spanning web-analytics, event-tracking, conversion-analysis, and more. Every call is secured with network, filesystem, subprocess, and code evaluation entitlements inside a sandboxed runtime. Beyond a simple connection, you get a full AI Gateway with real-time visibility into agent activity, enterprise governance, and optimized token usage.
Batch run reports
Check report compatibility
Get conversions
Get device breakdown
Get available dimensions and metrics
Get top pages by views
Get traffic sources
Get user demographics
List audience exports
Run pivot report
Run realtime report
Data JSON must include dateRanges, dimensions, and metrics arrays. Run a custom report
Connect Google Analytics 4 to Mastra AI via MCP
Follow these steps to wire Google Analytics 4 into Mastra AI. The entire setup takes under two minutes — your credentials stay safe behind the Vinkius.
Install dependencies
npm install @mastra/core @mastra/mcp @ai-sdk/openaiReplace the token
[YOUR_TOKEN_HERE] with your Vinkius tokenRun the agent
agent.ts and run with npx tsx agent.tsExplore tools
Why Use Mastra AI with the Google Analytics 4 MCP Server
Mastra AI provides unique advantages when paired with Google Analytics 4 through the Model Context Protocol.
Mastra's agent abstraction provides a clean separation between LLM logic and tool infrastructure. add Google Analytics 4 without touching business code
Built-in workflow engine chains MCP tool calls with conditional logic, retries, and parallel execution for complex automation
TypeScript-native: full type inference for every Google Analytics 4 tool response with IDE autocomplete and compile-time checks
One-command deployment to any Node.js host. Vercel, Railway, Fly.io, or your own infrastructure
Google Analytics 4 + Mastra AI Use Cases
Practical scenarios where Mastra AI combined with the Google Analytics 4 MCP Server delivers measurable value.
Automated workflows: build multi-step agents that query Google Analytics 4, process results, and trigger downstream actions in a typed pipeline
SaaS integrations: embed Google Analytics 4 as a first-class tool in your product's AI features with Mastra's clean agent API
Background jobs: schedule Mastra agents to query Google Analytics 4 on a cron and store results in your database automatically
Multi-agent systems: create specialist agents that collaborate using Google Analytics 4 tools alongside other MCP servers
Example Prompts for Google Analytics 4 in Mastra AI
Ready-to-use prompts you can give your Mastra AI agent to start working with Google Analytics 4 immediately.
"Show me the top 10 pages by views this month and where the traffic is coming from."
"How many conversions did we get this week and which pages drove them?"
"What devices are our users on and which countries are generating the most traffic?"
Troubleshooting Google Analytics 4 MCP Server with Mastra AI
Common issues when connecting Google Analytics 4 to Mastra AI through the Vinkius, and how to resolve them.
createMCPClient not exported
npm install @mastra/mcpGoogle Analytics 4 + Mastra AI FAQ
Common questions about integrating Google Analytics 4 MCP Server with Mastra AI.
How does Mastra AI connect to MCP servers?
MCPClient with the server URL and pass it to your agent. Mastra discovers all tools and makes them available with full TypeScript types.