Google Analytics MCP Server for LLMs 200+ Metrics
Access Google Analytics through an MCP server to aggregate 200+ dimensions and metrics for LLM analysis and actionable insights.
npx -y @surendranb/google-analytics-mcpOverview
This MCP (Model Context Protocol) server exposes Google Analytics (GA4) reporting as a tool that LLMs can call programmatically. It translates LLM tool calls into Google Analytics Data API requests and returns structured, model-friendly JSON containing up to 200+ dimensions and metrics. The server is intended to bridge LLMs and analytics systems so models can generate data-informed insights, summaries, or next-step suggestions without embedding credentials or ad-hoc scraping logic.
Using an MCP-compatible HTTP endpoint keeps the LLM integration simple: the model requests a named tool with a JSON payload describing the report (metrics, dimensions, date ranges, and filters). The server handles authentication, batching, aggregation, and pagination against the GA Data API and normalizes results for use in prompts, chain-of-thought, or downstream analysis.
Features
- Exposes Google Analytics (GA4) metrics and dimensions through an MCP-compatible HTTP API
- Supports 200+ GA4 dimensions and metrics via the Google Analytics Data API
- Authentication via Google service account (Application Default Credentials)
- Date range, filters, segments, and dimension combinations supported
- Batch requests and automatic pagination handling for large reports
- Results normalized into compact JSON suitable for LLM consumption
- Docker and local development workflows
- Simple request schema that maps cleanly to LLM tool-calling patterns
Installation / Configuration
Prerequisites:
- Python 3.9+
- Google Cloud project with a service account and GA4 property
- Google Analytics Data API enabled (for GA4)
- Clone the repo and install dependencies:
Create and configure a Google service account and download the JSON key. Enable the Analytics Data API for your project and grant the service account access to your GA4 property.
Set environment variables (example .env):
# Optionally:
- Run locally (example using uvicorn):
- Or run with Docker:
Environment variables summary:
| Variable | Purpose |
|---|---|
| GOOGLE_APPLICATION_CREDENTIALS | Path to Google service account JSON |
| GA4_PROPERTY_ID | GA4 property identifier (e.g., properties/123456789) |
| MCP_PORT | Server port (default 8080) |
| LOG_LEVEL | Optional logging level (debug/info/error) |
Available Resources
- Repository: https://github.com/surendranb/google-analytics-mcp
- Google Analytics Data API (GA4): https://developers.google.com/analytics/devguides/reporting/data/v1
- MCP (Model Context Protocol) concept: use the server as an LLM-invokable tool that returns structured JSON
The server implements endpoints that map directly to report requests. Typical endpoints:
- POST /mcp/query — submit a metrics/dimensions request (MCP tool call)
- GET /mcp/manifest — describe available metrics/dimensions and sample payloads
Example Request / Response
Example request payload (LLM tool call format):
Example trimmed response:
Use Cases
- Funnel analysis for prompt engineering: An LLM can request stepwise conversion rates (sessions → add-to-cart → purchase) by asking the MCP server for relevant event counts and time windows, then generate suggestions to improve conversion.
- Anomaly detection and alerts: Periodically query critical metrics (e.g., active users, error events) with the MCP API and let the model produce human-readable explanations and recommended remediation steps when a drop/spike is detected.
- Revenue attribution summaries: Aggregate revenue and purchase metrics by medium, campaign, or country, so an LLM can synthesize attribution narratives (top-performing campaigns, ROI highlights).
- Cohort comparison and retention: Retrieve cohort size and retention metrics for different acquisition channels, enabling the model to summarize which cohorts retain best and suggest focused growth experiments.
- Enrich conversational analytics: When integrated into a chat or assistant, the model can answer questions like “How did mobile revenue trend last month vs. the previous month?” by calling the MCP server, receiving structured data, and returning a concise explanation.
Notes and Best Practices
- This server uses the GA4 Data API — ensure you use GA4 (not Universal Analytics).
- Limit data exposure in prompts: return compact, relevant rows/aggregates rather than entire raw tables.
- Implement rate limiting or caching when calling the GA Data API from automated LLM workflows to avoid quota hits.
- Inspect the /mcp/manifest endpoint to learn exact metric/dimension identifiers supported by the server.
For full details, examples, and advanced configuration, see the GitHub repository: https://github.com/surendranb/google-analytics-mcp.