GA4 Analytics MCP V2
Provides tools for interacting with Google Analytics 4, enabling operators to list accessible GA4 properties, manage the active property, retrieve metadata, and run historical and real-time reports.
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., "@GA4 Analytics MCP V2run a report for the last 7 days on the active property"
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.
GA4 Analytics MCP V2
Multi-operator Google Analytics 4 connector for Claude.ai Custom Connectors, hosted on Google Cloud Run.
This is Version 2. It is a separate application from V1. Do not reuse V1 secrets, OAuth clients, Cloud Run services, or Git remotes.
Operator A or Operator B
→ same Claude Custom Connector URL
→ https://<v2-host>/mcp
→ MCP OAuth (Claude → V2)
→ Google OAuth (operator's own Google account)
→ operator credentials + active GA4 property in Firestore
→ GA4 Admin / Data APIsThere is no local stdio server and no Supabase.
Architecture
Two OAuth layers are linked:
Claude → V2: MCP OAuth 2.1 (protected resource metadata, DCR, CIMD, PKCE).
V2 → Google: Google sign-in happens inside MCP authorize. The MCP access token
subis the Google account subject (sub). Email is display-only.
Each operator has:
their own encrypted Google refresh token
their own accessible GA4 property list (from Google Admin API)
their own persisted active property
Operator A cannot use Operator B's Google credential or select a property that Google account A cannot access.
MCP tools
Tool | Purpose |
| Authenticated operator (email + internal operatorId). No tokens. |
| Properties visible to that Google account, with |
| Currently selected property |
| Switch after a live allow-list check |
| Dimensions/metrics for the active or newly authorized property |
| Historical GA4 report |
| Last ~30 minutes |
Report tools use the stored active property when propertyId is omitted. A supplied propertyId is accepted only if the authenticated Google account can access it, and then becomes the new active property.
Local development
cd D:\MCP_Servers\Ga4McpV2
npm install
copy .env.example .env.localFill in .env.local with V2 values. Do not copy V1 secrets.
Optional Firestore emulator:
gcloud emulators firestore start --host-port=localhost:8080Set FIRESTORE_EMULATOR_HOST=localhost:8080 and FIRESTORE_PROJECT_ID in .env.local.
npm run dev
npm test
npm run buildApp:
http://localhost:3000MCP:
http://localhost:3000/mcpHealth:
http://localhost:3000/healthGoogle callback:
http://localhost:3000/oauth/google/callback
Claude.ai cannot reach localhost. Deploy V2 to Cloud Run before adding the Custom Connector.
Environment variables
Variable | Required | Purpose |
| Yes | Public origin, no trailing slash |
| Yes | V2 Google OAuth web client |
| Yes | V2 Google OAuth secret |
| No | Defaults to |
| Yes | Signs MCP JWTs |
| Yes | Signs Google state and encrypts pending-authorize cookies |
| Yes | Encrypts Google refresh tokens at rest |
| Production | Firestore project |
| Local/test | Firestore emulator host |
| No | Optional pre-registered Claude confidential client |
| No | Pair for the optional confidential client |
V2 does not use GOOGLE_REFRESH_TOKEN or MCP_AUTH_TOKEN.
Google Cloud configuration
Use a new Google Cloud project when possible. If you share a project with V1, still create a distinct Cloud Run service, Artifact Registry repo, OAuth client, and secrets.
Enable:
Cloud Run
Cloud Build
Artifact Registry
Firestore
Secret Manager
Google Analytics Admin API
Google Analytics Data API
Suggested resource names (placeholders — replace with your project):
Cloud Run service:
ga4-mcp-v2Artifact Registry:
ga4-mcp-v2Firestore collection:
operators
Cloud Run service account should have:
roles/datastore.useron the V2 Firestore databaseroles/secretmanager.secretAccessoron V2 secrets only
Do not grant the service account Secret Manager admin or access to V1 secrets.
Google OAuth client (V2 only)
Create a new OAuth Web application. Do not edit the V1 client.
Consent screen:
User type: External (or Internal for Workspace-only)
App name: something like
GA4 MCP Connector V2Scopes:
openidemailhttps://www.googleapis.com/auth/analytics.readonly
Add test users while the app is in Testing
Publishing is required for non-test users because Analytics scopes are sensitive
Authorized redirect URI:
https://<v2-cloud-run-url>/oauth/google/callbackLocally:
http://localhost:3000/oauth/google/callbackClaude Custom Connector
Deploy V2 and set
APP_BASE_URLto the Cloud Run URL.In Claude, add a Custom Connector.
URL:
https://<v2-host>/mcpEach operator completes Google sign-in from their own Claude account.
If the Google account has multiple GA4 properties, they pick one. That choice persists until they switch.
Testing
npm testUnit tests cover:
MCP OAuth metadata, DCR, PKCE, and Google-bound JWT
subOperator isolation (credentials and property allow-lists)
Persistent active property
Token refresh / rotation
Revoked Google grants
Structured log redaction
No live V1 credentials are used.
Deployment (do not run until requested)
Documented only. V1 deployment must stay untouched.
.\scripts\cloud-run-setup.ps1 -ProjectId YOUR_V2_PROJECT_ID
.\scripts\cloud-run-deploy.ps1 -ProjectId YOUR_V2_PROJECT_ID
.\scripts\cloud-run-set-env.ps1 `
-ProjectId YOUR_V2_PROJECT_ID `
-AppBaseUrl https://YOUR_V2_CLOUD_RUN_URL `
-GoogleClientId YOUR_V2_CLIENT_ID `
-GoogleClientSecret YOUR_V2_CLIENT_SECRET `
-McpTokenSecret YOUR_MCP_TOKEN_SECRET `
-OauthStateSecret YOUR_OAUTH_STATE_SECRET `
-TokenEncryptionKey YOUR_TOKEN_ENCRYPTION_KEYPrefer Secret Manager references for production secrets instead of plaintext env values when you wire the service.
After deploy:
Add the Cloud Run callback URI to the V2 OAuth client.
Confirm Firestore is created in Native mode.
Add
https://<v2-host>/mcpin Claude.
Security considerations
Refresh tokens are encrypted with AES-256-GCM before Firestore writes.
MCP tools never return access tokens, refresh tokens, or authorization codes.
Logs redact tokens, secrets, cookies, and authorization codes.
Property IDs from Claude are checked against the live Admin API list for that operator.
Tools fail closed if no operator context is bound to the request.
HTTPS-only cookies in production.
Git
This repository is V2 only. The V1 remote is git@github.com:devopsbrandmirchi/Ga4McpServer.git and must never be added here. Create a new GitHub repository when you are ready to publish V2.
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 Connectors
GA4 conversion analyst inside Claude — funnel drops, traffic anomalies, device gaps, with numbers.
WHOOP recovery, strain, sleep and workouts in Claude via official WHOOP OAuth. Free, open source.
Self-hosted MCP gateway: turn any API, database or MCP server into AI connectors — no code.
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/devopsbrandmirchi/Ga4McpV2'
If you have feedback or need assistance with the MCP directory API, please join our Discord server