GA4 MCP Server
A Model Context Protocol (MCP) server that connects Claude Desktop (and other MCP clients) to the Google Analytics 4 Data API — run reports, view top pages, analyze traffic sources, check realtime users, and compare periods.
Features
7 Analytics Tools
| Tool | Description |
|---|---|
ga4_list_properties |
List all GA4 properties accessible by the service account |
ga4_get_report |
Run a custom report with any dimensions and metrics |
ga4_get_top_pages |
Top pages by sessions with bounce rate and duration |
ga4_get_traffic_sources |
Traffic breakdown by source/medium |
ga4_get_conversions |
Conversion events and their counts |
ga4_get_realtime |
Realtime active users and top pages |
ga4_compare_periods |
Compare current vs previous period with percentage changes |
Built-in Reliability
- Token-bucket rate limiter — respects GA4's 10 concurrent request limit
- Auto-retry on 429/5xx — exponential backoff (2s, 4s, 8s) up to 3 retries
- Lazy imports — defers heavy Google client libraries for fast MCP handshake
- Actionable error messages — guides users to fix permission, auth, and input errors
Quick Start
Prerequisites
- Python 3.11+
- A Google Cloud service account with GA4 access
- Claude Desktop (or any MCP-compatible client)
Set Up Google Analytics Access
- Create a Google Cloud service account
- Enable the Google Analytics Data API and Google Analytics Admin API in your project
- Download the service account JSON key file
- In GA4: go to Admin > Property Access Management and add the service account email as a Viewer
Installation
Run the published package without a global install:
uvx --from luminarylane-ga4-mcp luminarylane-ga4-mcp
The package is published on PyPI. Alternatively, install it with pip install luminarylane-ga4-mcp.
Configuration
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"ga4": {
"command": "uvx",
"args": ["--from", "luminarylane-ga4-mcp", "luminarylane-ga4-mcp"],
"env": {
"GA4_CREDENTIALS_PATH": "/path/to/service_account_credentials.json",
"GA4_PROPERTY_ID": "123456789"
}
}
}
}
Environment variables:
| Variable | Required | Description |
|---|---|---|
GA4_CREDENTIALS_PATH |
Yes | Path to service account JSON key file |
GA4_PROPERTY_ID |
No | Default property ID (can also pass per-tool) |
For local development only, credential files may be stored in paths excluded by .gitignore; never commit them. Prefer the explicit environment-variable path above.
Usage Examples
Once configured, ask Claude to:
- "What are my top pages this month?"
- "Show me traffic sources for the last 7 days"
- "How does this week compare to last week?"
- "Are there any active users on the site right now?"
- "Run a report on sessions by country for the last 90 days"
- "What conversion events fired this week?"
- "List all GA4 properties I have access to"
Rate Limits
GA4 Data API allows 10 concurrent requests per property. The server handles this with a client-side token bucket and exponential backoff retries.
Troubleshooting
Permission denied (403)
The service account doesn't have access to the GA4 property. Go to GA4 Admin > Property Access Management and add the service account email as a Viewer.
Property not found (404)
Property IDs are numeric (e.g., 123456789), not the measurement ID (G-XXXXXXX). Use ga4_list_properties to find valid IDs.
Authentication failed (401)
Check that GA4_CREDENTIALS_PATH points to a valid service account JSON key file.
Invalid dimension/metric (400)
Check the GA4 Dimensions & Metrics Explorer for valid names. Common mistakes: sessions not session, sessionSource not source, pagePath not page.
Contributing
See CONTRIBUTING.md. Never commit service-account credentials or OAuth tokens.
Security
Report vulnerabilities privately using GitHub's private vulnerability reporting; do not include credentials in public issues.
License
MIT License — see LICENSE for details.
Acknowledgments
- Anthropic for the MCP specification
- Google Analytics Data API for the reporting API
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file luminarylane_ga4_mcp-1.0.1.tar.gz.
File metadata
- Download URL: luminarylane_ga4_mcp-1.0.1.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3640f5f8ecc7c29f248eded063fac0864725a09703c326145c36707f29a86234
|
|
| MD5 |
5a28eb6e9a3a7b2d0650cff7eb12686d
|
|
| BLAKE2b-256 |
4f40e53a1a2e82a2de57ffea1cb173299aadd8743dd60f9e99027f6d10a399c3
|
Provenance
The following attestation bundles were made for luminarylane_ga4_mcp-1.0.1.tar.gz:
Publisher:
publish.yml on luminarylane/ga4-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
luminarylane_ga4_mcp-1.0.1.tar.gz -
Subject digest:
3640f5f8ecc7c29f248eded063fac0864725a09703c326145c36707f29a86234 - Sigstore transparency entry: 2357358169
- Sigstore integration time:
-
Permalink:
luminarylane/ga4-mcp@9375dbcda97c6606785c581562b8a8a9f35bc509 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/luminarylane
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9375dbcda97c6606785c581562b8a8a9f35bc509 -
Trigger Event:
push
-
Statement type:
File details
Details for the file luminarylane_ga4_mcp-1.0.1-py3-none-any.whl.
File metadata
- Download URL: luminarylane_ga4_mcp-1.0.1-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
738a7f32840c6f5c00c5e4b2d2effc439226ce0b8609d56e146ad7d32694b654
|
|
| MD5 |
1f93ab5c3be2416c7504316ffa551dea
|
|
| BLAKE2b-256 |
d23be0cdba9ceaa9656ffc39abc10ed7b702b54c537fd79babf468aea35e2820
|
Provenance
The following attestation bundles were made for luminarylane_ga4_mcp-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on luminarylane/ga4-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
luminarylane_ga4_mcp-1.0.1-py3-none-any.whl -
Subject digest:
738a7f32840c6f5c00c5e4b2d2effc439226ce0b8609d56e146ad7d32694b654 - Sigstore transparency entry: 2357358605
- Sigstore integration time:
-
Permalink:
luminarylane/ga4-mcp@9375dbcda97c6606785c581562b8a8a9f35bc509 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/luminarylane
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9375dbcda97c6606785c581562b8a8a9f35bc509 -
Trigger Event:
push
-
Statement type: