Google Analytics 4 MCP server — exposes GA4 metrics to AI agents over @modelcontextprotocol/sdk and parallel REST endpoints, with daily/monthly time breakdowns
Config is the same across clients — only the file and path differ.
{
"mcpServers": {
"ga4-mcp-server": {
"command": "<see-readme>",
"args": []
}
}
}Are you the author?
Add this badge to your README to show your security score and help users find safe servers.
Google Analytics 4 MCP server — exposes GA4 metrics to AI agents over @modelcontextprotocol/sdk and parallel REST endpoints, with daily/monthly time breakdowns
No automated test available for this server. Check the GitHub README for setup instructions.
Five weighted categories — click any category to see the underlying evidence.
No known CVEs.
No package registry to scan.
Click any tool to inspect its schema.
This server is missing a description.If you've used it, help the community.
Add informationBe the first to review
Have you used this server?
Share your experience — it helps other developers decide.
Sign in to write a review.
Others in analytics / ai-ml
Persistent memory using a knowledge graph
MCP Server for GCP environment for interacting with various Observability APIs.
Privacy-first. MCP is the protocol for tool access. We're the virtualization layer for context.
An open-source AI agent that brings the power of Gemini directly into your terminal.
MCP Security Weekly
Get CVE alerts and security updates for Ga4 Mcp Server and similar servers.
Start a conversation
Ask a question, share a tip, or report an issue.
Sign in to join the discussion.
This server provides access to Google Analytics 4 data through both MCP (Model Context Protocol) and REST endpoints. It allows you to fetch various analytics metrics for specific URLs, including page views, engagement metrics, traffic sources, and conversions.
At a glance — A small, focused MCP server that exposes Google Analytics 4 data to AI agents. Built on the official
@modelcontextprotocol/sdk(Streamable HTTP transport) over Express, with the same tool surface available as plain REST endpoints for non-MCP clients. Five tools:getUrlAnalytics,getUrlEngagement,getUrlSourceTraffic,getUrlConversions,getUrlPageViews.What this repo demonstrates
- A real MCP server — uses the actual
@modelcontextprotocol/sdk(McpServer+StreamableHTTPServerTransport), not a sketch. Same tools available via MCP and REST, no schema duplication.- GA4 Data API integration —
BetaAnalyticsDataClientfrom@google-analytics/datawith service-account auth, and a small URL-path → GA filter abstraction so callers ask "what happened on/about" rather than "give me apagePathPlusQueryStringfilter expression."- Useful response shape — every endpoint returns the headline numbers plus a
timeBreakdown.dailyandtimeBreakdown.monthlyseries so an agent can answer "how did that change over the period?" without a follow-up call.- Honest dev experience — Zod-validated env, structured debug logging behind a
DEBUGflag, Jest tests, anmcp-inspector-driven smoke script (pnpm test:mcp), and a parallel REST smoke script (pnpm test:rest).Quickstart
pnpm install cp .env.example .env # fill in GA_PROPERTY_ID + path to service-account JSON pnpm dev # http://localhost:3001 pnpm test:rest # smoke-test the REST endpointsFull setup, endpoint reference, response schema, and error handling are documented below.
pnpm install
.env:GA_PROPERTY_ID=your_ga4_property_id
GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credentials.json
PORT=3001 # optional, defaults to 3001
DEBUG=true # optional, for debug logging
The server provides two ways to access analytics data:
The MCP endpoint is available at /mcp and supports the Model Context Protocol for streaming communication.
Example using the MCP client:
import { McpClient } from "@modelcontextprotocol/sdk/client/mcp.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
// Initialize MCP client
const transport = new StreamableHTTPClientTransport({
url: "http://localhost:3001/mcp"
});
const client = new McpClient();
await client.connect(transport);
// Example: Get URL analytics
const response = await client.callTool("getUrlAnalytics", {
url: "/about",
timeframe: "this month",
trafficSourceLimit: 5
});
console.log(JSON.parse(response.content[0].text));
The server also provides traditional REST endpoints for simpler integration:
// Get comprehensive analytics for a URL
const response = await fetch(
"http://localhost:3001/getUrlAnalytics?url=/about&timeframe=this+month&trafficSourceLimit=5",
{
headers: {
'Accept': 'application/json'
}
}
);
const data = await response.json();
// Get engagement metrics
const response = await fetch(
"http://localhost:3001/getUrlEngagement?url=/about&timeframe=last+week",
{
headers: {
'Accept': 'application/json'
}
}
);
const data = await response.json();
// Get traffic sources
const response = await fetch(
"http
... [View full README on GitHub](https://github.com/spindle79/ga4-mcp-server#readme)