Google Analytics MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add -e "GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS}" google-analytics-ca8b -- uv run google-analytics-mcp
Required:GOOGLE_APPLICATION_CREDENTIALS+ 2 optional
README.md

Provides AI agents with comprehensive access to Google Analytics 4 data

Google Analytics MCP Server

A FastMCP server that provides AI agents with comprehensive access to Google Analytics 4 data via the Model Context Protocol (MCP).

Features

  • 18 MCP tools covering all aspects of Google Analytics 4
  • HTTP streaming transport for scalable deployments
  • Service account authentication for automated server-to-server access
  • Dynamic property discovery across all accessible GA4 accounts
  • Historical reports with flexible dimensions, metrics, and date ranges
  • Realtime data for current user activity
  • Custom dimensions/metrics support

Installation

# Clone the repository
git clone <repo-url>
cd google-analytics-mcp

# Install dependencies with uv
uv sync

Configuration

Environment Variables

Variable Required Default Description
GOOGLE_APPLICATION_CREDENTIALS Yes* - Path to service account JSON file
MCP_HOST No 0.0.0.0 Host to bind the server
MCP_PORT No 8000 Port for the server

*Can also use Application Default Credentials (ADC) via gcloud auth application-default login

Google Cloud Setup

Step 1: Create a Google Cloud Project (if you don't have one)
  1. Go to the Google Cloud Console
  2. Click the project dropdown at the top of the page
  3. Click New Project
  4. Enter a project name (e.g., "GA MCP Server")
  5. Click Create
  6. Wait for the project to be created, then select it from the project dropdown
Step 2: Enable Required APIs
  1. In the Google Cloud Console, go to APIs & Services > Library

  2. Search for and enable these APIs:

    • Google Analytics Data API - for running reports
    • Google Analytics Admin API - for listing properties

    For each API:

    • Click on the API name
    • Click Enable
Step 3: Create a Service Account
  1. In the Google Cloud Console, go to IAM & Admin > Service Accounts
  2. Click + Create Service Account at the top
  3. Fill in the details:
    • Service account name: ga-mcp-server
    • Service account ID: (auto-filled based on name)
    • Description: "Service account for Google Analytics MCP Server"
  4. Click Create and Continue
  5. Skip the optional "Grant this service account access" step (click Continue)
  6. Skip the optional "Grant users access" step (click Done)
Step 4: Create and Download the Credentials JSON Key
  1. In the Service Accounts list, find your newly created service account
  2. Click on the service account email to open its details
  3. Go to the Keys tab
  4. Click Add Key > Create new key
  5. Select JSON as the key type
  6. Click Create
  7. The JSON key file will automatically download to your computer
  8. Important: Move this file to a secure location and note the path
    # Example: move to your project directory
    mv ~/Downloads/your-project-xxxxx.json ./credentials.json
    

Security Warning: This JSON file contains sensitive credentials. Never commit it to version control or share it publicly.

Step 5: Grant the Service Account Access to Google Analytics

The service account needs explicit access to your GA4 properties. Without this step, list_properties will return an empty list.

Find your service account email:

  1. Go to Google Cloud Console > IAM & Admin > Service Accounts
  2. Find your service account and copy the email address
    • It looks like: ga-mcp-server@your-project.iam.gserviceaccount.com

Grant access in Google Analytics:

  1. Go to Google Analytics

  2. Click the Admin gear icon (bottom left corner)

  3. Choose where to grant access:

    Option A: Account Level (recommended) - Grants access to ALL properties under the account:

    • In the Account column, click Account Access Management

    Option B: Property Level - Grants access to a specific property only:

    • First select the property from the Property dropdown
    • In the Property column, click Property Access Management
  4. Click the + button in the top right

  5. Select Add users

  6. In the "Email addresses" field, paste your service account email

  7. Under "Direct roles and data restrictions":

    • Select Viewer (sufficient for reading all analytics data)
    • Leave data restrictions unchecked for full access
  8. Click Add

Verify access was granted:

  • The service account email should now appear in the users list
  • You can test by calling list_properties - it should return your properties

Note: It may take a few minutes for permissions to propagate. If list_properties still returns empty, wait 2-3 minutes and try again.

Step 6: Set the Environment Variable
# Option 1: Set for current terminal session
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json

# Option

Tools (3)

list_propertiesLists all Google Analytics 4 properties accessible to the service account.
run_reportRuns a historical report for a specific GA4 property with custom dimensions, metrics, and date ranges.
get_realtime_dataRetrieves real-time user activity data for a specific GA4 property.

Environment Variables

GOOGLE_APPLICATION_CREDENTIALSrequiredPath to service account JSON file
MCP_HOSTHost to bind the server
MCP_PORTPort for the server

Configuration

claude_desktop_config.json
{"mcpServers": {"google-analytics": {"command": "uv", "args": ["run", "google-analytics-mcp"], "env": {"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/credentials.json"}}}}

Try it

List all the Google Analytics properties I have access to.
Run a report for my main website property showing sessions and active users for the last 30 days.
What is the current real-time user activity on my website?
Get a breakdown of user acquisition sources for the last week.

Frequently Asked Questions

What are the key features of Google Analytics?

18 MCP tools covering GA4 reporting and management. Service account authentication for secure server-to-server access. Dynamic property discovery across all accessible GA4 accounts. Support for historical reports and real-time user activity monitoring. Custom dimensions and metrics support.

What can I use Google Analytics for?

Automating weekly performance reporting for marketing teams. Quickly checking real-time traffic spikes during product launches. Integrating analytics data directly into AI-driven business intelligence workflows. Auditing property configurations across multiple client accounts.

How do I install Google Analytics?

Install Google Analytics by running: git clone https://github.com/reklis/google-analytics-mcp && cd google-analytics-mcp && uv sync

What MCP clients work with Google Analytics?

Google Analytics works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Google Analytics docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare