Page Summary
-
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:
- Install Python and a package runner:
- Install Python 3.10 or higher.
- Install
pipxoruv(uvx) to run the MCP server in an isolated Python environment.
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
Grant Google Analytics property access:
- In the Google Analytics UI, grant your user
account or service account at least the Viewer role
(
roles/analytics.viewer) on the target Google Analytics property. For instructions, see Manage access and data-restriction management.
- In the Google Analytics UI, grant your user
account or service account at least the Viewer role
(
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
- Install and initialize the gcloud CLI.
Run
gcloud auth application-default loginwith 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_FILEWhen the command finishes, copy the credentials path printed to the console (
Credentials saved to file: [PATH_TO_CREDENTIALS_JSON]). You use this path inGOOGLE_APPLICATION_CREDENTIALSwhen 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_CREDENTIALSin 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_JSONwith the absolute path to your ADC or service account JSON file.YOUR_PROJECT_IDwith the project ID where you enabled the Google Analytics APIs.
Antigravity CLI and Antigravity IDE
- Install Antigravity CLI or Antigravity IDE.
Add the
analytics-mcpserver to~/.gemini/config/mcp_config.json(or.agents/mcp_config.jsonin 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" } } } }Verify that
analytics-mcpis connected:- Antigravity CLI: Run
agy, then enter/mcpto view your configured MCP servers. - Antigravity IDE: Open Settings > Customizations > Installed MCP Servers and click Refresh.
- Antigravity CLI: Run
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):
get_account_summaries: Lists the Google Analytics accounts and properties accessible to the authenticated user (accountSummaries.list).get_property_details: Returns configuration details for a specific Google Analytics property (properties.get).list_google_ads_links: Lists links to Google Ads accounts for a property (properties.googleAdsLinks.list).list_property_annotations: Lists annotations configured for a property (properties.reportingDataAnnotations.list).
- 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 byGOOGLE_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-rungcloud auth application-default loginwith thehttps://www.googleapis.com/auth/analytics.readonlyandhttps://www.googleapis.com/auth/cloud-platformscopes.
- Confirm that both the Google Analytics Admin API
(
Missing quota project (
GOOGLE_CLOUD_PROJECT) or403 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'senvconfiguration, or set the quota project on your ADC file:gcloud auth application-default set-quota-project YOUR_PROJECT_ID
401 UNAUTHENTICATEDor credentials file not found:- Use an absolute path for
GOOGLE_APPLICATION_CREDENTIALS(for example,/Users/username/.config/gcloud/application_default_credentials.json). Avoid~or$HOMEvariables, as many MCP hosts don't expand shell variables inside JSON configuration files. - Re-run
gcloud auth application-default loginif your user credentials have expired.
- Use an absolute path for
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 bywhich pipxorwhich uvx(for example,/opt/homebrew/bin/pipxor/Users/username/.local/bin/pipx).
- Confirm that Python 3.10 or higher is installed (