The Google Analytics MCP Server: Query GA4 From Claude And Other AI Tools

The Google Analytics MCP server is an open-source tool from Google that lets you query your GA4 data directly from AI assistants like Claude and Gemini. It uses the Model Context Protocol to bridge your analytics property with large language models, turning natural language questions into Data API calls. You run the server locally or as a cloud service, connect it to your LLM client, and start asking questions about your traffic, conversions, and custom dimensions without writing a single line of API code.

What The GA4 MCP Server Is

The GA4 MCP server is a Python application that implements the Model Context Protocol (MCP) for Google Analytics 4. It acts as a middle layer between an LLM (like Gemini, Claude, or any MCP-compatible client) and the GA4 Data API and Admin API. When you ask a question in natural language, the LLM decides which MCP tool to call, the server executes the corresponding API request, and the results flow back into your chat.

Google publishes the server on GitHub and on PyPI as analytics-mcp. It is designed for both single-user local setups and multi-tenant HTTP deployments. The server exposes a set of tools, functions the LLM can invoke, that cover account discovery, property configuration inspection, standard reporting, realtime reporting, funnel reports, and conversion reports. Because it uses the official APIs, you get the same data you would see in the GA4 interface, subject to the same quota limits.

For GA4 users, it eliminates the need to manually copy-paste report data into a prompt. Instead, you can have a conversation with your data, asking follow-up questions and getting answers from the same Data API that powers reports. Because the source code is public on GitHub, you can inspect it.

What It Can And Cannot Do (Read-Only Data API Access)

By default, the GA4 MCP server operates in read-only mode. It can retrieve account summaries, property details, Google Ads links, annotations, key events, custom dimensions and metrics, and run several report types. The exact tools available are:

  • get_account_summaries, lists your GA4 accounts and properties.
  • get_property_details, returns configuration info for a property.
  • list_google_ads_links, shows linked Google Ads accounts.
  • list_property_annotations, fetches annotations on a property.
  • list_key_events, returns key events (formerly conversions).
  • get_custom_dimensions_and_metrics, retrieves custom dimensions and metrics.
  • run_report, runs a standard report via the Data API.
  • run_realtime_report, runs a realtime report.
  • run_funnel_report, runs a funnel exploration report.
  • run_conversions_report, runs a conversions performance report with attribution.

These tools cover most reporting needs, but they cannot modify your GA4 property. The server does not create or change anything by default. However, the GitHub repository documents optional write tools, create_property_annotation, create_custom_dimension, and create_key_event, that you can enable by passing the --allow-write flag and adding the https://www.googleapis.com/auth/analytics.edit scope to your credentials. Google's documentation describes the server as currently for read-only requests that cannot modify your Google Analytics settings, so treat the write tools as optional and check the repository before relying on them.

Keep in mind that every tool call consumes API quota tokens, and the server respects the same rate limits as direct API requests. If you ask a question that would generate a very large report, the LLM may need to break it into multiple calls, each counting against your quota.

Short on time? Analytics Art can check this in your property for you.

How To Set It Up: Credentials, Property Access, Client Config

Setting up the GA4 MCP server involves four main stages: meeting prerequisites, enabling APIs, granting property access, and configuring your MCP client. Here is the exact sequence, drawn from Google’s official documentation.

Prerequisites

  • Python 3.10 or higher installed on your machine.
  • A package runner: pipx (recommended) or uv (for uvx). Install pipx and make sure it is in your PATH.
  • A Google Cloud project. You can create one at console.cloud.google.com.

Enable the required APIs

In your Google Cloud project, enable both the Google Analytics Admin API (analyticsadmin.googleapis.com) and the Google Analytics Data API (analyticsdata.googleapis.com). You can do this from the Cloud Console or with the gcloud command:

gcloud services enable analyticsadmin.googleapis.com \
  analyticsdata.googleapis.com \
  --project=YOUR_PROJECT_ID

Grant property access

In the GA4 admin interface, give your Google user account (or a service account) at least the Viewer role on the property you want to query. For a service account, add its email as a user with Viewer permissions. For the optional write tools, the repository lists the Editor role for custom dimensions and Marketer or Editor for key events. If you need to locate your GA4 property ID, see our guide on finding your Measurement ID.

Authenticate with Application Default Credentials

Run the following command to create ADC with the required read-only scope:

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

When the command finishes, note the path printed after “Credentials saved to file:”. You will use this absolute path as GOOGLE_APPLICATION_CREDENTIALS. If you need write tools, add the analytics.edit scope to the --scopes flag.

Configure your MCP client

The server runs as a subprocess that your AI client launches. The configuration differs slightly per client, but the examples all set two environment variables: GOOGLE_APPLICATION_CREDENTIALS (absolute path to your ADC or service account JSON file) and GOOGLE_CLOUD_PROJECT (the project ID where you enabled the APIs; Google recommends setting it). Below are the configuration snippets for the most common clients.

ClientConfiguration file / commandExample
Claude Desktopclaude_desktop_config.json
{
  "mcpServers": {
    "analytics-mcp": {
      "command": "pipx",
      "args": ["run", "analytics-mcp"],
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/creds.json",
        "GOOGLE_CLOUD_PROJECT": "your-project-id"
      }
    }
  }
}
Claude CodeCLI command
claude mcp add analytics-mcp \
  --scope user \
  -e GOOGLE_APPLICATION_CREDENTIALS="path/to/creds.json" \
  -e GOOGLE_CLOUD_PROJECT="your-project-id" \
  -- pipx run analytics-mcp
Cursor.cursor/mcp.json
{
  "mcpServers": {
    "google-analytics-mcp": {
      "command": "uvx",
      "args": ["--from", "analytics-mcp", "google-analytics-mcp"],
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/creds.json",
        "GOOGLE_CLOUD_PROJECT": "your-project-id"
      }
    }
  }
}
Antigravity (Gemini)~/.gemini/config/mcp_config.jsonSame JSON structure as Claude Desktop, using "command": "pipx" and "args": ["run", "analytics-mcp"].

After adding the configuration, restart your AI client and verify that analytics-mcp appears in the MCP server list (in Claude Code, run /mcp). If the server fails to launch, check that Python 3.10+ is installed, that pipx is in your PATH, and that you used an absolute path for the credentials file, as Google's troubleshooting notes advise.

For a multi-tenant HTTP setup or deployment on Cloud Run, refer to the GitHub repository for the full --transport http and OAuth instructions.

Example Questions To Ask Your GA4 Data

Once the MCP server is connected, you can ask your AI assistant questions about your GA4 property in plain English. The LLM translates your question into one or more tool calls, and the server returns the data. Here are prompts that Google’s documentation and the repository suggest as starting points:

  • “How many users did I have yesterday?”
  • “What were my top selling products yesterday?”
  • “What are the most popular events in my Google Analytics property in the last 180 days?”
  • “What custom dimensions and custom metrics are configured in my property?”
  • “Were most of my users in the last 6 months logged in?”
  • “Give me details about my Google Analytics property with ‘xyz’ in the name.”
  • “I have a marketing budget of $5,000/month and need to generate more revenue. Help me create a data-driven marketing plan.”

The first few questions map directly to a single run_report or get_custom_dimensions_and_metrics call. The last one is more open-ended: the LLM might run a conversions report, break down traffic by channel, and then synthesize a plan. Because the server exposes the report tools, you can ask follow-up questions that drill into specific dimensions or date ranges. For instance, after seeing top events, you could ask “Show me the event count by country for the purchase event.”

You can also inspect property configuration without opening the GA4 interface. Asking “List my key events” calls list_key_events, and “Show me my Google Ads links” calls list_google_ads_links. If you have enabled write tools with --allow-write, you can even say “Create an event-scoped custom dimension for the plan_tier parameter in property 12345,” and the server will create it, since that prompt needs the --allow-write flag.

Remember that the quality of the answer depends on the LLM’s ability to choose the right tool and parameters. If a question is ambiguous, the assistant may ask for clarification or make assumptions, just as it would with any other MCP tool.

Security And Access Limits To Know

The GA4 MCP server is designed to keep your credentials and data under your control. When you run it locally, authentication uses Application Default Credentials stored on your machine; the server runs on your machine and calls Google’s APIs with those credentials. In stateless HTTP mode, each request is handled independently without in-memory session state.

If you deploy the server as a multi-tenant HTTP service (using --transport http), each end user must sign in with their own Google account via OAuth 2.0. The server supports both agent-framework OAuth (where the chat UI shows a Sign-in button) and a built-in MCP OAuth 2.1 authorization server. In that mode, you must set GOOGLE_OAUTH_CLIENT_ID and GOOGLE_OAUTH_CLIENT_SECRET, and the built-in OAuth server keeps pending authorization state and refresh tokens in process memory, so run it as a single instance or with sticky sessions; restarts require re-authentication.

Every request the server makes to the Data API or Admin API consumes quota tokens against your GA4 property. The same quota limits apply as if you were calling the API directly. For a standard property, you have 200,000 core tokens per day, 40,000 per hour, and 10 concurrent requests. Analytics 360 properties get higher limits (2,000,000 tokens per day, 50 concurrent requests). Token consumption varies with report complexity, more rows, more dimensions, longer date ranges, and high-cardinality fields like pagePath all increase the cost. You can monitor your remaining quota by setting "returnPropertyQuota": true in a report request, though the MCP tools may not expose that option, so you may need to check via the API directly or watch for 429 errors.

The server’s source code is public on GitHub, so you can review it. The LLM you connect to (Claude, Gemini, etc.) will process the data returned by the server. If you are using a cloud-based LLM, consider the data privacy implications of sending your analytics data to that provider.

Frequently Asked Questions

Does Google Have An MCP Server?

Yes. Google publishes an official MCP server for Google Analytics 4 on GitHub and PyPI. It lets AI assistants like Gemini and Claude query your GA4 data using the Model Context Protocol. The source code is public on GitHub.

Is There A Google Analytics MCP For Claude?

Yes. Google's setup instructions include configuration for Claude Desktop and Claude Code. You add it to your Claude configuration, set your credentials, and then you can ask Claude questions about your GA4 property directly in the chat.

What Is MCP In Data Analytics?

MCP (Model Context Protocol) is an open standard that lets AI models interact with external tools and data sources. In data analytics, an MCP server like Google’s exposes API functions, such as running a report, so an LLM can fetch live data instead of relying solely on its training data.

How Do I Add Google MCP To My AI Tool?

You add the server to your MCP client’s configuration file (e.g., claude_desktop_config.json for Claude Desktop, .cursor/mcp.json for Cursor). The config specifies the command pipx run analytics-mcp and environment variables for your Google Cloud project and credentials. After restarting the client, the server appears as an available tool.

What Is The Google Analytics MCP Server URL?

The server is not accessed via a URL in local mode; it runs as a local subprocess. The Python package is analytics-mcp on PyPI. If you deploy it as an HTTP service, you would use the URL of your Cloud Run or server instance, but there is no single public URL provided by Google.

Can The GA4 MCP Server Write Data Or Change Settings?

By default, the server is read-only. You can optionally enable write tools (create_property_annotation, create_custom_dimension, create_key_event) by passing the --allow-write flag and adding the analytics.edit scope, but Google describes the server as read-only for now, so check the repository for current write support.

What Quotas Apply To GA4 MCP Requests?

Each MCP tool call that hits the Data API consumes tokens from your property’s quota: 200,000 core tokens per day for standard properties, 40,000 per hour, and 10 concurrent requests. The same limits apply as direct API calls, and you can monitor usage with the returnPropertyQuota parameter.