SuperAPIAI Directory

google-analytics-mcp

github.com · AI data analysis

Google Analytics MCP is a Model Context Protocol (MCP) server for Google Analytics 4 (GA4) that lets MCP-compatible AI clients such as Claude query GA4 properties directly in natural language. It supports listing accounts and properties, viewing page views, active users, events, traffic sources, and device metrics, running custom reports, performing funnel analysis (experimental), querying real-time active users over the last 30 minutes, and listing available dimensions and metrics. The project provides two modes: local STDIO mode (single-user, no server required, tokens stored locally) and remote HTTP server mode (acting as an OAuth 2.1 authorization server, supporting Claude Teams, claude.ai, and multiple users, with credentials stored in Firestore and deployable to Cloud Run). Before use, prepare a GA4 property and a Google Cloud project, enable the Google Analytics Data API and Admin API, and configure OAuth credentials.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)

About this tool

Google Analytics MCP is a Model Context Protocol (MCP) server for Google Analytics 4 (GA4). Its goal is to connect Claude or other MCP-compatible AI clients directly to GA4 properties and use natural language to perform operations such as traffic queries, user behavior analysis, event viewing, and funnel analysis.

Main capabilities

  • Property management: List all accessible GA4 accounts and their properties.
  • Reporting and analysis: Query page views, active users, events, traffic sources, and device metrics; run fully custom reports using any combination of GA4 metrics and dimensions.
  • Funnel analysis: Track user drop-off in multi-step processes (experimental feature).
  • Real-time and discovery: Query active users over the last 30 minutes through the Realtime API; list all valid dimensions and metrics for a property to help build custom reports.

Two operating modes Mode A: Local STDIO (single-user, no server required). Suitable for local use only. Run setup_local_auth.py once for the Google OAuth flow and save the token to ~/.config/google-analytics-mcp/token.json; Claude Desktop starts server.py as a subprocess. No Firestore, Cloud Run, or public URL is required. Mode B: Remote HTTP server (Claude Teams, claude.ai, multi-user). This MCP server is also an OAuth 2.1 authorization server: Claude discovers metadata through /.well-known/oauth-protected-resource and /.well-known/oauth-authorization-server, registers itself through dynamic client registration (POST /oauth/register), and redirects the user to /oauth/authorize, where Google OAuth performs identity verification; after login, the server issues its own opaque bearer token to Claude, and Google credentials never leave the server; each /mcp request carries that bearer, and the server maps it server-side to the correspondinguser-stored Google credentials and calls the GA4 API. The ?user=email query parameter in older versions has been removed, and copying per-user URLs is no longer necessary.

Prerequisites and configuration A GA4 property and a Google Cloud project are required. In the Google Cloud Console, create or select a project, enable the Google Analytics Data API and Google Analytics Admin API; create an OAuth 2.0 client (Web application type) and add an authorized redirect URI:http://localhost:8080/auth/callback(本地开发/setup_local_auth.py)以及 https://YOUR-CLOUD-RUN-URL/auth/callback(远程部署后添加);下载 Save the JSON as client_secret.json in the project root (already gitignored), or put the Client ID / Client Secret directly into environment variables. Configure the OAuth consent screen: for Google Workspace organizations, Internal is recommended; for personal use, External can be selected; add https://www.googleapis.com/auth/analytics and https://www.googleapis.com/auth/analytics.readonly Two scopes; if External is in Testing mode, each user email must be added to Test users. Mode B also requires enabling Firestore (Native mode) and granting the Cloud Datastore User role to the Cloud Run service account in IAM.

Usage Mode A: Run the setup and local authorization script, open the browser and sign in with Google, the script writes a local token file; then add the corresponding configuration to the Claude Desktop configuration file and restart Claude Desktop. Mode B: Deploy to Cloud Run (it is recommended to store GOOGLE_CLIENT_SECRET as a Cloud Run secret rather than a regular environment variable), and after deployment add the online callback URL in the OAuth client. Claude Teams requires the organization owner to add a custom connector once, with the URL being https://YOUR-SERVICE-URL.run.app/mcp,各成员点击 Connect and sign in with Google; claude.ai personal edition and Claude Desktop remote servers likewise complete the OAuth flow on first use.

Use cases and limitations Suitable for marketing teams, data analysts, and developers to query GA4 data, build custom reports, and perform funnel analysis using natural language. The project author notes that its read-only interfaces are relatively broad and write interfaces are deliberately narrowed, and it runs against a real GA4 account. Funnel analysis is marked as experimental. Usage requires preparing your own GA4 property, Google Cloud project, and completing API enablement and OAuth configuration; the remote multi-user mode depends on Firestore and Cloud Run. For the specific tool list, example prompts, environment variable details, and OAuth endpoint reference, please see the repository documentation.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools