Is your GA4 data actually right? Get a fixed-price GA4 & GTM audit. Request an audit
noxtag
AI + analytics

Google Analytics MCP server: setup guide for Claude, Gemini and Cursor

Google publishes an official Model Context Protocol (MCP) server for Google Analytics. Once it's connected, an AI assistant like Claude, Gemini CLI or Cursor can list your GA4 properties, run reports and check your property configuration from a chat window. You don't have to export CSVs or click through Explorations.

This guide walks through the setup end to end, shows the config for each client, and covers the four mistakes behind almost every "it doesn't work" thread.

What the Google Analytics MCP server actually does

The server runs locally on your machine and talks to two Google APIs on your behalf:

  • Google Analytics Admin API: account and property details, Google Ads links, custom dimensions and metrics, annotations.
  • Google Analytics Data API: standard reports, funnel reports and realtime reports.

The tools it exposes to your AI client are:

Group Tools
Account and property info get_account_summaries, get_property_details, list_google_ads_links, list_property_annotations, create_property_annotation
Reports run_report, run_funnel_report, get_custom_dimensions_and_metrics
Realtime run_realtime_report

Two things to know before you start:

  1. It's read-only by default. The only write tool (creating annotations) stays off unless you start the server with --allow-write and your credentials include the edit scope.
  2. Google labels it experimental. It works well, but tool names and flags can change between releases, so check the GitHub repo if something in this guide stops matching.
How the Google Analytics MCP server connects your AI client to GA4
How the Google Analytics MCP server connects your AI client to GA4

Prerequisites

  • Python 3.10 or newer
  • pipx (or uv), which runs the server in its own isolated environment
  • The Google Cloud CLI (gcloud), used to create credentials
  • A Google Cloud project where you can enable APIs
  • Viewer access (or higher) on the GA4 properties you want to query
The four setup steps at a glance
The four setup steps at a glance

Is your GA4 & GTM setup collecting the right data?

Get a senior review of your tags, triggers, data layer and consent setup, with a prioritized fix list your developers can act on.

Fixed price · Read-only access · Reply within 1 business day

Step 1: Enable the two APIs

In the Google Cloud console, open your project and enable:

  • Google Analytics Admin API
  • Google Analytics Data API

If you skip this step, the server starts fine but every tool call fails with a 403 ... API has not been used in project error. That's the most common setup failure.

Step 2: Create credentials

The server uses Application Default Credentials (ADC) with the read-only Analytics scope: https://www.googleapis.com/auth/analytics.readonly. There are two ways to get them.

Option A: sign in as yourself (best for one person)

Create an OAuth client of type Desktop app in your Cloud project and download its JSON file. Then run:

gcloud auth application-default login \
  --scopes https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform \
  --client-id-file=YOUR_CLIENT_JSON_FILE

Option B: impersonate a service account (best for teams and agencies)

Create a service account, add its email as a Viewer in GA4 (Admin → Property access management), then run:

gcloud auth application-default login \
  --impersonate-service-account=SERVICE_ACCOUNT_EMAIL \
  --scopes=https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform

Either way, gcloud prints a line like Credentials saved to file: [/Users/you/.config/gcloud/application_default_credentials.json]. Copy that path. You need it in the next step.

Agency tip: use the service-account route. You add one email to each client's GA4 property, you don't share personal logins, and removing access is one click when an engagement ends.

Step 3: Add the server to your AI client

Claude Code

claude mcp add analytics-mcp \
  --scope user \
  -e "GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_CREDENTIALS_JSON" \
  -e "GOOGLE_PROJECT_ID=YOUR_PROJECT_ID" \
  -- pipx run analytics-mcp

Claude Desktop, Cursor and other JSON-configured clients

Add this inside the mcpServers block of the client's config file:

{
  "mcpServers": {
    "analytics-mcp": {
      "command": "pipx",
      "args": ["run", "analytics-mcp"],
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "PATH_TO_CREDENTIALS_JSON",
        "GOOGLE_PROJECT_ID": "YOUR_PROJECT_ID"
      }
    }
  }
}

Gemini CLI

Use the same block in ~/.gemini/settings.json, then run /mcp inside Gemini CLI. You should see analytics-mcp listed with its tools.

Project ID variable: Google's README mentions GOOGLE_CLOUD_PROJECT in its text but uses GOOGLE_PROJECT_ID in the config example. If the server complains about a missing project, set both to the same value.

Restart the client after editing its config. MCP servers load at startup.

Step 4: Test it with three prompts

Start simple and work up:

  1. "What GA4 accounts and properties can you see?" This calls get_account_summaries. If it returns your properties, credentials and APIs are working.
  2. "For property 123456789, show sessions, engaged sessions and key events by default channel group for the last 28 days." This exercises run_report.
  3. "What custom dimensions and metrics are defined on property 123456789?" This is the start of a quick configuration audit.

Prompts that are actually useful

The kind of questions that would take ten minutes of clicking in GA4
The kind of questions that would take ten minutes of clicking in GA4

The real value isn't "how many users yesterday". It's questions that would take ten minutes of clicking:

  • "Compare purchase revenue by device category this month vs. last month, and flag any category that dropped more than 20%."
  • "Build a funnel: view_item → add_to_cart → begin_checkout → purchase for the last 30 days, split by device. Where is the biggest drop?"
  • "List event names with fewer than 10 events in the last 90 days." Rare events are usually typos or broken tags. add_to_cart and add-to-cart firing side by side is a classic.
  • "Show me (not set) landing pages by session source for the last 14 days." A spike in (not set) landing pages usually means a session started without a page_view, often because of consent or tag sequencing problems.
  • "Which Google Ads accounts are linked to this property?" Handy when you inherit an account and nobody knows what's connected.

Troubleshooting

The five errors behind almost every failed setup
The five errors behind almost every failed setup

"API has not been used in project … or it is disabled." Enable both Analytics APIs (Step 1) in the same project as your credentials, then wait a minute or two.

"Request had insufficient authentication scopes." Your ADC file was created without the analytics scope, often by an earlier plain gcloud auth application-default login. Re-run the login command from Step 2 with --scopes.

The server shows up but has no tools, or times out on start. Run pipx run analytics-mcp in a terminal to see the real error. Usually it's a Python version below 3.10 or pipx missing from the PATH the client uses. On macOS, apps launched from the Dock don't inherit your shell's PATH, so use the full path to pipx in command.

"User does not have sufficient permissions for this property." The identity behind your credentials (you or the service account) needs at least Viewer access on that GA4 property. Account-level access works too.

Numbers don't match the GA4 interface. Check the date range and time zone first. Then look for thresholding: GA4 hides rows with small user counts when Google signals is on, and the API applies the same rules. Explorations and standard reports can also disagree because of sampling and different session definitions. That isn't the MCP server's fault.

Security notes before you roll this out

Four rules before you connect client properties
Four rules before you connect client properties
  • Keep it read-only unless you have a reason not to. The read-only scope can't change your property even if a prompt asks it to.
  • Treat the credentials file like a password. Anyone with it can read every property that identity can see.
  • Watch for data leaving your machine. Report rows go into the AI model's context. For most aggregate reporting that's fine. Check your company's AI policy before pulling anything user-level.
  • Use one service account per client if you're an agency, so access is easy to audit and revoke.

Where MCP fits in a measurement stack

An MCP server makes it fast to ask questions of GA4. It doesn't make the data any more correct. If your events are duplicated, your consent setup drops sessions, or your ecommerce data layer sends the wrong values, the AI will confidently summarize wrong numbers.

That's why we pair MCP-assisted analysis with a proper implementation check. Our GA4 & GTM audit covers tags, the data layer, consent mode and ecommerce events, so the answers your AI gives you are worth acting on.

noxtag is a small, senior tracking-implementation practice. We write these guides from real GA4 and GTM audits. More about us.