Try the Google Analytics MCP server

  • The Google Analytics Model Context Protocol (MCP) server connects your Analytics data to a Large Language Model (LLM) like Gemini.

  • The MCP server allows you to interact with your data through chat and build custom agents with data access.

  • The MCP server can answer questions about your data, including user counts and top-selling products, and help with data-driven marketing plans.

  • The MCP server is currently for read-only requests and cannot modify your Google Analytics settings.

The Google Analytics Model Context Protocol (MCP) server lets you connect your Google Analytics data to large language models (LLMs) and AI agents, such as Gemini. You can use the MCP server to query reports in natural language, inspect property configurations, and build custom analytics agents.

Set up the MCP server View on GitHub Watch the Setup Tutorial

Prerequisites

Before configuring the Google Analytics MCP server, complete the following requirements:

  1. Install Python and a package runner:
  2. Enable the Google Analytics APIs in :

    • Create or select a project.
    • Enable both the Google Analytics Admin API (analyticsadmin.googleapis.com) and the Google Analytics Data API (analyticsdata.googleapis.com) in your project:

      gcloud services enable analyticsadmin.googleapis.com \
        analyticsdata.googleapis.com \
        --project=YOUR_PROJECT_ID
      
  3. Grant Google Analytics property access:

Set up authentication

The Google Analytics MCP server authenticates using Application Default Credentials (ADC) with the read-only Google Analytics OAuth 2.0 scope:

https://www.googleapis.com/auth/analytics.readonly

You can configure ADC using either your Google user account or a service account.

Option 1: Authenticate with user credentials

  1. Install and initialize the gcloud CLI.
  2. Run gcloud auth application-default login with the required scopes:

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

    If you use a downloaded OAuth 2.0 desktop or web client configuration file (see Manage OAuth clients), pass --client-id-file:

    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
    
  3. When the command finishes, copy the credentials path printed to the console (Credentials saved to file: [PATH_TO_CREDENTIALS_JSON]). You use this path in GOOGLE_APPLICATION_CREDENTIALS when configuring your MCP client.

Option 2: Authenticate with a service account

To authenticate with a service account that has Viewer access to your Google Analytics property:

  • Service account JSON key file: Set GOOGLE_APPLICATION_CREDENTIALS in your MCP client configuration to the absolute path of your service account JSON file.
  • Service account impersonation: Generate ADC credentials by impersonating the service account with the gcloud CLI:

    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"
    

Configure your MCP client

The server is published on PyPI as analytics-mcp and exposes both the analytics-mcp and google-analytics-mcp console scripts.

In the following configurations, replace:

  • PATH_TO_CREDENTIALS_JSON with the absolute path to your ADC or service account JSON file.
  • YOUR_PROJECT_ID with the project ID where you enabled the Google Analytics APIs.

Antigravity CLI and Antigravity IDE

  1. Install Antigravity CLI or Antigravity IDE.
  2. Add the analytics-mcp server to ~/.gemini/config/mcp_config.json (or .agents/mcp_config.json in your workspace):

    {
      "mcpServers": {
        "analytics-mcp": {
          "command": "pipx",
          "args": ["run", "analytics-mcp"],
          "env": {
            "GOOGLE_APPLICATION_CREDENTIALS": "PATH_TO_CREDENTIALS_JSON",
            "GOOGLE_CLOUD_PROJECT": "YOUR_PROJECT_ID"
          }
        }
      }
    }
    
  3. Verify that analytics-mcp is connected:

    • Antigravity CLI: Run agy, then enter /mcp to view your configured MCP servers.
    • Antigravity IDE: Open Settings > Customizations > Installed MCP Servers and click Refresh.

Claude Desktop and Claude Code

For Claude Desktop, add the server to your claude_desktop_config.json file (~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows):

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

For Claude Code, register the server using the command-line tool:

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

Cursor

Add the server to .cursor/mcp.json in your project directory (or ~/.cursor/mcp.json for global configuration). You can invoke google-analytics-mcp using either uvx or pipx:

{
  "mcpServers": {
    "google-analytics-mcp": {
      "command": "uvx",
      "args": ["--from", "analytics-mcp", "google-analytics-mcp"],
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "PATH_TO_CREDENTIALS_JSON",
        "GOOGLE_CLOUD_PROJECT": "YOUR_PROJECT_ID"
      }
    }
  }
}

To run the latest development version directly from GitHub using uvx, update "args":

"args": [
  "--from",
  "git+https://github.com/googleanalytics/google-analytics-mcp.git",
  "google-analytics-mcp"
]

Alternatively, to use pipx, change "command" to "pipx" and set "args" to:

"command": "pipx",
"args": [
  "run",
  "--spec",
  "git+https://github.com/googleanalytics/google-analytics-mcp.git",
  "google-analytics-mcp"
]

Available MCP tools

The Google Analytics MCP server uses the Admin API and Data API v1 to expose read-only tools to your MCP client:

  • Account and property discovery (Admin API):
  • Reporting and schema inspection (Data API v1):
    • get_custom_dimensions_and_metrics: Retrieves custom dimensions and custom metrics defined for a property (getMetadata).
    • run_report: Runs a standard Google Analytics report (runReport).
    • run_realtime_report: Runs a Google Analytics realtime report (runRealtimeReport).
    • run_funnel_report: Runs a Google Analytics funnel exploration report (runFunnelReport).
    • run_conversions_report: Runs a conversions performance report (runConversionsReport).

Sample prompts

Once connected, try asking your AI assistant questions such as:

  • How many users did I have yesterday?
  • What were my top selling products yesterday?
  • I have a marketing budget of $5,000/month and need to generate more revenue. Help me create a data-driven marketing plan.
  • What custom dimensions and custom metrics are configured in my property?
  • What are the most popular events in my Google Analytics property over the last 90 days?

Troubleshooting

Use the following checklist to resolve common setup and runtime errors:

  • 403 PERMISSION_DENIED (API not enabled or insufficient property permissions):
    • Confirm that both the Google Analytics Admin API (analyticsadmin.googleapis.com) and the Google Analytics Data API (analyticsdata.googleapis.com) are enabled in the project specified by GOOGLE_CLOUD_PROJECT.
    • Verify that the authenticating user or service account has at least the Viewer role (roles/analytics.viewer) on the target Google Analytics property in the Google Analytics UI.
    • If the error states Request had insufficient authentication scopes, re-run gcloud auth application-default login with the https://www.googleapis.com/auth/analytics.readonly and https://www.googleapis.com/auth/cloud-platform scopes.
  • Missing quota project (GOOGLE_CLOUD_PROJECT) or 403 ACCESS_NOT_CONFIGURED:

    • Requests authenticated with user ADC credentials require a quota project with the Google Analytics APIs enabled. Set "GOOGLE_CLOUD_PROJECT": "YOUR_PROJECT_ID" in your MCP server's env configuration, or set the quota project on your ADC file:

      gcloud auth application-default set-quota-project YOUR_PROJECT_ID
      
  • 401 UNAUTHENTICATED or credentials file not found:

    • Use an absolute path for GOOGLE_APPLICATION_CREDENTIALS (for example, /Users/username/.config/gcloud/application_default_credentials.json). Avoid ~ or $HOME variables, as many MCP hosts don't expand shell variables inside JSON configuration files.
    • Re-run gcloud auth application-default login if your user credentials have expired.
  • Server fails to launch (spawn pipx ENOENT, uvx: command not found, or Python version errors):

    • Confirm that Python 3.10 or higher is installed (python3 --version).
    • Desktop GUI applications (such as Claude Desktop and Cursor) often don't inherit your interactive shell PATH. Replace "pipx" or "uvx" in "command" with the absolute binary path returned by which pipx or which uvx (for example, /opt/homebrew/bin/pipx or /Users/username/.local/bin/pipx).