analytics-selfhosted-mcp
Provides tools for interacting with Google Analytics Admin and Data APIs, enabling AI agents to manage properties, run reports (including compact/paged forms), list custom dimensions/metrics, annotations, and Google Ads links, and perform real-time, funnel, and conversion analysis.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@analytics-selfhosted-mcpList my Google Analytics accounts and property IDs."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
analytics-selfhosted-mcp
Unofficial / community project. This is not an official Google product.
Official Google Analytics MCP (local stdio only):
googleanalytics/google-analytics-mcp (PyPI:analytics-mcp).
Self-host the same GA Admin/Data tools over Streamable HTTP on Modal, so clients that only accept a public URL (Cursor remote MCP, agents, etc.) can call Google Analytics with an API key — plus token-efficient report compaction that upstream does not ship.
Official Google MCP | This project | |
Status | Official | Unofficial wrapper / host |
Transport | stdio | Streamable HTTP ( |
Runs on | Your laptop | Modal (or any host you deploy) |
Auth to MCP | Process trust | Shared API key |
Extra | — | Compact reports + paged rows |
When to use official: one machine, Cursor/Claude Desktop via command + stdio.
When to use this: you need a URL-addressable Analytics MCP.
ClickUp App Center auth works but tools do not load yet (client never calls tools/list). Details: docs/CLICKUP_ISSUE.md.
Quick path (what “done” looks like)
Step | Done when… |
0. Prerequisites |
|
1. Env file |
|
2. Google credentials | SA (or ADC) can list GA accounts |
3. Modal secret | Secret |
4. Deploy |
|
5. MCP smoke |
|
6. GA smoke |
|
7. Cursor | Chat can call |
Do not skip the Done when checks — each later step depends on the previous one.
Related MCP server: analytics-mcp
Use cases and suggested queries
Ask these in Cursor (or any MCP client) after step 7. Complexity increases downward.
Level 1 — Connectivity & inventory
Use case | Suggested prompt |
Prove MCP works | “Call |
List what I can access | “Use |
Inspect one property | “Call |
Pass: you get real account/property names (not 401 / empty / credential errors).
Level 2 — Simple reporting
Use case | Suggested prompt |
Last 7 days traffic | “For property |
Top channels | “Same property, last 28 days: dimension |
Realtime | “Call |
Pass: summary includes a report_id (compact) or clear row values; numbers look plausible vs GA UI.
Level 3 — Metadata & quality
Use case | Suggested prompt |
Custom definitions | “Use |
Annotations | “Call |
Ads links | “List Google Ads links for |
Pass: tool returns structured data (or a clear empty list if none configured).
Level 4 — Funnels, conversions, large data
Use case | Suggested prompt |
Conversions | “Use |
Funnel | “Build a |
Large report without blowing context | “Run a high-cardinality report with |
Pass: compact path returns small summary + report_id; paging returns slices; discard succeeds.
Level 5 — Analysis workflows
Use case | Suggested prompt |
Week-over-week | “Compare this week vs last week sessions and users for |
Landing page triage | “Top landing pages by sessions last 14 days; flag pages with high sessions and low engagement (use engagement metrics available on the property).” |
Incident narrative | “Combine annotations + daily sessions for the last 60 days into a short incident timeline.” |
Pass: answers cite tool results (property id, dates, metrics), not invented UI screenshots.
Step-by-step setup
Step 0 — Prerequisites
Install:
# Python 3.12+ recommended
curl -LsSf https://astral.sh/uv/install.sh | sh
uv tool install modal
modal setup # browser loginIn Google Cloud (same project you will put in .env):
Enable Google Analytics Admin API
Enable Google Analytics Data API
Done when:
uv --version # prints a version
modal --version # prints a version
modal profile current # shows your logged-in profile / workspaceIf it fails: re-run modal setup; confirm the GCP project has billing/API enablement as required by Google.
Step 1 — Clone and create .env
git clone https://github.com/YOUR_GITHUB_USER/analytics-selfhosted-mcp.git
cd analytics-selfhosted-mcp
cp .env.example .envEdit .env:
GOOGLE_PROJECT_ID=your-gcp-project-id
MCP_API_KEY=$(openssl rand -hex 24)
ANALYTICS_MCP_API_KEY=$MCP_API_KEY # must match MCP_API_KEYDone when:
set -a && source .env && set +a
test -n "$GOOGLE_PROJECT_ID" && test -n "$MCP_API_KEY" && test "$MCP_API_KEY" = "$ANALYTICS_MCP_API_KEY" && echo "env ok"
git check-ignore -v .env # must show .gitignore ruleIf it fails: keys empty or mismatched — fix .env. If .env is not ignored, stop and fix .gitignore before any commit.
Step 2 — Google credentials (service account recommended)
GCP → IAM → Service Accounts → create SA in
GOOGLE_PROJECT_IDCreate a JSON key → save as e.g.
~/secrets/ga-mcp-sa.json(outside this repo)GA Admin → Account/Property access → add SA email as Viewer on every property you need
Done when (local check):
export GOOGLE_APPLICATION_CREDENTIALS=~/secrets/ga-mcp-sa.json
# Optional: quick Admin API sanity via gcloud / any GA client you prefer.
# On Modal, success is verified in Step 6 (get_account_summaries).
ls -la "$GOOGLE_APPLICATION_CREDENTIALS" # file exists, contains "client_email"If it fails later with empty accounts / 403: SA missing Viewer on the GA property, or wrong JSON in the Modal secret.
Temporary alternative: user ADC (gcloud auth application-default login with Analytics readonly scopes). Prefer SA for cloud.
Step 3 — Modal secret
Secret name must be exactly analytics-mcp-creds:
set -a && source .env && set +a
modal secret create analytics-mcp-creds \
MCP_API_KEY="$MCP_API_KEY" \
GOOGLE_PROJECT_ID="$GOOGLE_PROJECT_ID" \
GOOGLE_APPLICATION_CREDENTIALS_JSON="$(cat ~/secrets/ga-mcp-sa.json)" \
--forceDone when:
modal secret list | grep analytics-mcp-credsIf it fails: path to JSON wrong; or JSON not pasted as file contents (must start with {, not a filesystem path string).
Step 4 — Deploy
modal deploy modal_ga_mcp.pyNote the printed web URL:
https://YOUR_WORKSPACE--analytics-mcp-ga-web.modal.run(The Modal app id remains analytics-mcp-ga so existing deployments keep a stable hostname.)
Done when:
curl -sS "https://YOUR_WORKSPACE--analytics-mcp-ga-web.modal.run/healthz"
# Expect: {"status":"ok","app":"analytics-mcp-ga"}If it fails: check Modal dashboard logs for import/boot errors; confirm secret name spelling.
Optional: set in .env:
MODAL_MCP_URL=https://YOUR_WORKSPACE--analytics-mcp-ga-web.modal.run/mcpStep 5 — Verify MCP protocol (auth + tools)
set -a && source .env && set +a
URL="${MODAL_MCP_URL:-https://YOUR_WORKSPACE--analytics-mcp-ga-web.modal.run/mcp}"
KEY="$MCP_API_KEY"
curl -sS -D /tmp/mcp.hdr -o /tmp/mcp.init -X POST "$URL" \
-H "Authorization: $KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"setup","version":"0"}}}'
# Expect HTTP 200 and a mcp-session-id header
grep -i mcp-session-id /tmp/mcp.hdr
cat /tmp/mcp.init
SID=$(awk 'BEGIN{IGNORECASE=1} /^mcp-session-id:/{print $2}' /tmp/mcp.hdr | tr -d '\r')
curl -sS -X POST "$URL" \
-H "Authorization: $KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "mcp-session-id: $SID" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' \
| tee /tmp/mcp.toolsDone when: /tmp/mcp.tools lists 15 tools, including:
Upstream (9):
get_account_summaries,list_google_ads_links,get_property_details,list_property_annotations,get_custom_dimensions_and_metrics,run_report,run_realtime_report,run_funnel_report,run_conversions_reportHost (6):
ping,run_report_compact,get_report_rows,get_report_summary,get_report_full,discard_report
If it fails:
Symptom | Likely cause | Fix |
HTTP 401 | Wrong key | Match |
HTTP 307 loop | Old client hitting wrong slash handling | Use |
HTTP 406 | Accept header | Send |
Empty / error body on initialize | App crash on boot | Modal logs for the |
Fewer than 15 tools | Stale deploy | Re-run |
Step 6 — Verify Google Analytics access
set -a && source .env && set +a
export MODAL_MCP_URL="${MODAL_MCP_URL:-https://YOUR_WORKSPACE--analytics-mcp-ga-web.modal.run/mcp}"
modal run modal_ga_mcp.py::test_account_summaries
# Then pick a property id from the output:
modal run modal_ga_mcp.py::test_run_report --property-id=YOUR_GA4_PROPERTY_ID
modal run modal_ga_mcp.py::test_run_report_compact --property-id=YOUR_GA4_PROPERTY_IDDone when: account summaries show your properties; report/compact tests print row data / a report_id.
If it fails:
Symptom | Likely cause | Fix |
Empty | SA not granted on GA | Add Viewer on account/property |
403 / permission errors | Wrong project or APIs off | Enable Admin + Data APIs; fix |
Credential JSON errors | Bad secret payload | Secret value must be raw JSON object |
Step 7 — Connect Cursor
cp .cursor/mcp.json.example .cursor/mcp.json
# Edit url → your Modal /mcp URL{
"mcpServers": {
"analytics-selfhosted-mcp": {
"url": "https://YOUR_WORKSPACE--analytics-mcp-ga-web.modal.run/mcp",
"headers": {
"x-api-key": "${env:ANALYTICS_MCP_API_KEY}"
}
}
}
}Cursor does not load project .env for remote MCP headers. Export before launching Cursor:
set -a && source .env && set +a
export ANALYTICS_MCP_API_KEY
# launch Cursor from this shell, or put ANALYTICS_MCP_API_KEY in your shell profile / direnvReload MCP servers in Cursor.
Done when: MCP shows tools; in chat: “Call ping” → pong.
If it fails:
Symptom | Fix |
Unauthorized / tools missing | Env var not visible to Cursor — launch from a shell where |
Wrong URL | Must end with |
Stale config | Restart Cursor or reload MCP after editing |
Some hosts prefer Authorization instead of x-api-key (raw key or Bearer …). This server accepts both.
How data moves (read once)
Client --tools/call--> Modal MCP --GA API--> Google
^ |
+---- tool result JSON ---+Tool results still enter the model context. Large run_report payloads can blow the context window.
Prefer for big reports:
run_report_compact→ summary +report_id(full payload stored server-side)get_report_rows→ page rowsdiscard_reportwhen finishedget_report_full(..., confirm=true)only if you intentionally want everything in-context
Troubleshooting (cheat sheet)
Problem | Check |
401 on | Key mismatch |
Healthz OK, MCP fails | Auth headers; path |
Tools list OK, GA empty | SA Viewer on property; APIs enabled |
Cursor can’t auth |
|
ClickUp “no tools” | Known client gap — docs/CLICKUP_ISSUE.md |
High Modal bill |
|
Still stuck: Modal function logs for analytics-mcp-ga / web, plus the curl transcript from Step 5.
Security
Never commit: .env, ADC/SA JSON, client_secret_*.json, .cursor/mcp.json.
Checklist: docs/PUBLISHING.md.
openssl rand -hex 24 # rotate MCP_API_KEY → update .env + Modal secret + CursorRepo layout
Path | Role |
Production MCP (parity + compaction) | |
Summary / paging helpers | |
Optional ping-only deploy | |
Env template | |
Cursor template | |
ClickUp tools/list issue | |
Public-repo security checklist |
Optional ping-only: modal deploy modal_mcp_ping.py (same analytics-mcp-creds secret).
License
MIT. GA tool callables come from Google’s analytics-mcp; this repo hosts them remotely and adds compaction. Not affiliated with Google.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityBmaintenanceMCP server for querying Google Analytics accounts, properties, reports, and realtime data using the Data API and Admin API.Apache 2.0
- Alicense-qualityFmaintenanceMCP server that provides tools to interact with Google Analytics APIs, enabling account and property retrieval, report running, and custom dimension/metrics access.Apache 2.0
- Flicense-qualityCmaintenanceProduction-ready MCP server integrating Google Search Console, GA4, and PageSpeed Insights for SEO and analytics intelligence, enabling natural-language queries to Google analytics data.
- Flicense-qualityDmaintenanceMCP server providing access to Google Analytics Data API, enabling LLMs to retrieve reports, real-time data, and metadata from GA4 properties.
Related MCP Connectors
Hosted MCP server for Mini Accountant: invoices, expenses, customers, analytics, tax estimates.
Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.
Streamable HTTP MCP server for Google Calendar and Sheets with OAuth login.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/ukituki/analytics-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server