GA4 MCP Server
Provides tools for querying Google Analytics 4 data, including running reports, realtime data, listing properties, and comparing periods.
Click on "Deploy 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 MCP Servercompare this week's users to last week for my ecommerce 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 MCP Server
Production-ready, multi-tenant Google Analytics 4 MCP server for Claude.
This is the first connector in a larger platform. Shared infrastructure (auth, clients, Google OAuth token storage, authorization, logging, errors) is reusable. GA4-specific code stays under src/connectors/ga4 and src/mcp/ga4. Do not treat this as a monolithic Google Marketing MCP.
Architecture
Claude
| MCP OAuth 2.1 + Streamable HTTP
v
Next.js / Vercel (/mcp)
|-- MCP tools (ga4_*)
|-- Authorization (client_members only)
|-- GA4 service
|-- Google OAuth token manager
v
Supabase
|-- clients
|-- client_members (application identity)
|-- google_connections (Google credential, not app identity)
|-- ga4_propertiesApplication users are Supabase Auth users. Tenant access is only client_members(user_id, client_id, role). A Google-connected account is a client-owned credential and is never the application user.
Related MCP server: Delmain GA4 MCP
Local setup
npm install
cp .env.example .env.local
# fill in the values documented below
npx supabase start # or link a remote project
npx supabase db reset --local
npm run devOpen http://localhost:3000, create an application account, create a client, then connect Google Analytics.
Google Cloud setup
Create or select a Google Cloud project.
Enable Google Analytics Data API and Google Analytics Admin API.
Configure the OAuth consent screen (External or Internal).
Create OAuth 2.0 Client ID credentials (Web application).
Authorized redirect URI:
Local:
http://localhost:3000/api/auth/google/callbackProduction:
https://<your-domain>/api/auth/google/callback
Request only GA4 scopes:
https://www.googleapis.com/auth/analytics.readonlyopenidemail
Do not add DV360 or Google Ads scopes to this connector.
GA4 setup
Sign in to this app with email/password (application identity).
Create a client (you become
ownerinclient_members).Optionally add other application users as
ownerormember.Click Connect Google Analytics. This attaches a Google credential to the client.
Link one or more GA4 properties discovered from that Google account.
A member who did not click Connect can still query the client if they have a client_members row.
Supabase setup
This repo includes SQL migrations in supabase/migrations. Create them with the CLI; do not invent filenames.
Local:
npx supabase start
npx supabase db reset --localRemote:
npx supabase link --project-ref <project-ref>
npx supabase db pushThe service role key is server-only. Never expose SUPABASE_SERVICE_ROLE_KEY or Google refresh tokens to the browser.
Environment variables
See .env.example. Required:
Variable | Purpose |
| Supabase project URL |
| Browser/server user client |
| Server-side admin (never |
| Google OAuth app |
| Must match Google Cloud |
| GA4-only scopes |
| Public origin, e.g. |
| Signs MCP access tokens |
| 64 hex chars (32 bytes) for Google token encryption |
Do not put a GA4 property ID in .env. Properties belong to clients in Supabase.
Generate a token encryption key:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"MCP setup (Claude)
Remote endpoint:
https://<your-domain>/mcpThis server implements MCP OAuth 2.1:
Protected resource metadata:
/.well-known/oauth-protected-resourceAuthorization server metadata:
/.well-known/oauth-authorization-serverAuthorize:
/oauth/authorize(application login + consent)Token:
/oauth/token(authorization_code + refresh_token, PKCE S256)Register:
/oauth/register(DCR fallback)CIMD is advertised (
client_id_metadata_document_supported)
In Claude: Settings → Connectors → Add custom connector → paste https://<your-domain>/mcp. Claude will run OAuth. After you approve, tools are available.
Local inspector:
npx @modelcontextprotocol/inspectorConnect with Streamable HTTP to http://localhost:3000/mcp. You still need a valid MCP Bearer token from the OAuth flow.
Tools
Tool | Purpose |
| Primary report (dates, metrics, dimensions, limit, order, basic filter) |
| Realtime active users / traffic breakdown |
| Discover metrics and dimensions for a property |
| Properties visible to the client's Google connection |
| Current vs previous period with abs/% change |
Every tool requires client_id. Property-scoped tools also require a linked property_id. Authorization always checks client_members before Google is called.
Example: ga4_run_report
{
"client_id": "11111111-1111-1111-1111-111111111111",
"property_id": "123456789",
"date_start": "2026-08-01",
"date_end": "2026-08-15",
"dimensions": ["country"],
"metrics": ["activeUsers", "sessions", "totalRevenue"],
"limit": 10
}Example: ga4_compare_periods
{
"client_id": "11111111-1111-1111-1111-111111111111",
"property_id": "123456789",
"current_start": "2026-08-01",
"current_end": "2026-08-15",
"previous_start": "2026-07-17",
"previous_end": "2026-07-31",
"metrics": ["activeUsers", "sessions", "totalRevenue"]
}Claude can then answer questions such as:
How many users did we have yesterday?
Top 10 countries this month
Compare this month with last month
How many active users are on the site right now?
Testing
npm testTests use mocked Google and Supabase. They never use production OAuth tokens.
Vercel
Deploy the Next.js app and set the same environment variables. MCP_BASE_URL and GOOGLE_REDIRECT_URI must use the production domain. The /mcp route runs on the Node.js runtime with a 60s max duration.
Project layout
src/
auth/ application authentication
authorization/ authorizeClient via client_members
oauth/ Google OAuth + token manager
mcp-oauth/ MCP OAuth 2.1 authorization server
connectors/ga4/ Google Analytics APIs
mcp/ga4/ MCP tools
repositories/ Supabase data access
app/mcp/ Streamable HTTP transportFuture connectors (DV360, Google Ads) should add src/connectors/<name> and src/mcp/<name> and reuse the shared core. Do not create a generic Google API dumping ground.
This server cannot be deployed
Maintenance
Related MCP Connectors
Connect Google Analytics to ChatGPT. Query GA4 data in plain English and get instant insights.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
GA4, Google Ads and Search Console in Claude. Read-only OAuth, multi-account for agencies.
Query OneLens cloud-cost data in natural language: breakdowns, trends, cost centers. Read-only.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables managing Google Analytics 4 properties, data streams, conversions, and running reports using natural language through the Admin and Data APIs.23MIT
- AlicenseAqualityDmaintenanceEnables querying Google Analytics 4 properties using natural language through MCP clients. Supports customizable reports with any dimensions and metrics, listing properties, and real-time data.4MIT
- AlicenseNot gradedqualityDmaintenanceEnables querying Google Analytics data and configuration through natural language using the Data and Admin APIs.Apache 2.0
- AlicenseNot gradedqualityAmaintenanceEnables natural language querying of Google Analytics 4, including reports, realtime data, custom dimensions, and property management.93 npmMIT