ga4-mcp-server
by spindle79·★ 0·Score 36
Google Analytics 4 MCP server exposing metrics to AI agents with daily/monthly breakdowns and dual MCP/REST endpoints.
Overview
This is a production-ready MCP server that provides access to Google Analytics 4 data through both Model Context Protocol and REST endpoints. It includes five useful tools: getUrlAnalytics, getUrlEngagement, getUrlSourceTraffic, getUrlConversions, and getUrlPageViews. The server features proper authentication using service accounts, structured response formats with time-based breakdowns, and comprehensive error handling. Built with TypeScript using the official @modelcontextprotocol/sdk, it demonstrates best practices with Jest tests, debug logging, and smoke scripts for both MCP and REST interfaces.
Try asking AI
After installing, here are 5 things you can ask your AI assistant:
When to choose this
Choose this when you need to integrate Google Analytics 4 data into AI systems and want both MCP and REST access options with proper time breakdowns.
When NOT to choose this
Avoid this if you need access to Universal Analytics data, require real-time analytics with sub-minute granularity, or need more than 5 concurrent API calls to Google.
Tools this server exposes
5 tools extracted from the READMEgetUrlAnalytics({ url: string, timeframe?: string, startDate?: string, endDate?: string, trafficSourceLimit?: number }) => AnalyticsResponseGet comprehensive analytics for a URL including engagement, traffic sources, and conversions
getUrlEngagement({ url: string, timeframe?: string, startDate?: string, endDate?: string }) => AnalyticsResponseGet engagement metrics for a URL such as average session duration and bounce rate
getUrlSourceTraffic({ url: string, timeframe?: string, startDate?: string, endDate?: string, limit?: number }) => AnalyticsResponseGet traffic source data for a URL showing how users are finding the page
getUrlConversions({ url: string, timeframe?: string, startDate?: string, endDate?: string }) => AnalyticsResponseGet conversion events and metrics for a URL
getUrlPageViews({ url: string, timeframe?: string, startDate?: string, endDate?: string }) => AnalyticsResponseGet page view statistics for a URL
Comparable tools
Installation
Installation
- Install dependencies:
pnpm install- Set up environment variables:
GA_PROPERTY_ID=your_ga4_property_id
GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credentials.json
PORT=3001 # optional, defaults to 3001- Start the server:
pnpm devFor Claude Desktop, add this to your claude_desktop_config.json:
{
"mcpServers": {
"ga4": {
"command": "node",
"args": ["dist/index.js"],
"env": {
"GA_PROPERTY_ID": "your_ga4_property_id",
"GOOGLE_APPLICATION_CREDENTIALS": "path/to/your/credentials.json"
}
}
}
}FAQ
- What authentication method is required for this server?
- The server requires Google service account authentication. You need to provide a service account JSON file and set the GOOGLE_APPLICATION_CREDENTIALS environment variable.
- Can I use this server with my existing Google Analytics 4 property?
- Yes, as long as your service account has appropriate permissions to access the GA4 property data. You'll need to configure it in the Google Cloud Console.
Compare ga4-mcp-server with
Last updated · Auto-generated from public README + GitHub signals.