ga4-mcp
A Google Analytics 4 MCP server with a one-command setup. It is a TypeScript rewrite of Google's google-analytics-mcp. You don't need gcloud, Python, OAuth clients or env vars: give it a service account key and pick your agents.
npx @saeedsakib/ga4-mcp setup
Setup does four things:
- Asks for the path to your service account JSON key and stores a copy in
~/.config/ga4-mcp/(owner-only permissions). - Checks access live. If an API isn't enabled or the service account can't see any property, it tells you exactly what to fix and waits while you do.
- Adds the MCP server to Claude Code, Cursor and/or Codex, and installs the bundled
ga4-mcpskill so the agent knows how to query GA4 well. - Prints a config snippet for any other MCP client or custom harness.
Restart your agent and ask something like "How did organic traffic change over the last 28 days?"
Before you start: get a service account key
- In Google Cloud Console, pick or create a project and enable the Google Analytics Admin API and the Google Analytics Data API.
- Go to IAM & Admin → Service Accounts → Create service account. It needs no Cloud roles.
- Open the service account, go to Keys → Add key → Create new key → JSON, and download it.
- In Google Analytics, go to Admin → Property access management → + → Add users. Paste the service account email
(
…@….iam.gserviceaccount.com), choose Viewer and save. Repeat for each property you want the agent to see.
Setup checks each of these steps and tells you which one is missing.
Commands
Custom harnesses
Any MCP client that can spawn a stdio server works. Run setup once to store the key, then point your client at:
{
"mcpServers": {
"ga4": { "command": "npx", "args": ["-y", "@saeedsakib/ga4-mcp"] }
}
}
Give your agent skills/ga4-mcp/SKILL.md as instructions if it supports skills or system prompts.
Tools
All tools are read-only and match upstream's tool names and arguments.
Where things are written
Setup only changes its own ga4 entry and leaves the rest of each config file as it was.
Development
bun install
bun test
bun run typecheck
bun run build
The published package runs on Node 20.11 or later.
License
Apache-2.0. See NOTICE for attribution to the original Google project.