google-analytics-mcp
A powerful Model Context Protocol (MCP) server that provides comprehensive Google Analytics 4 (GA4), Google Search Console (GSC), and Google Merchant Center (GMC) integration for Claude Desktop and other MCP clients.
README
Google Analytics MCP Server
A powerful Model Context Protocol (MCP) server that provides comprehensive Google Analytics 4 (GA4), Google Search Console (GSC), and Google Merchant Center (GMC) integration for Claude Desktop and other MCP clients.
Key Features
49 Specialized Tools Across Google Platforms
- GA4: 20+ tools for reporting, admin, and discovery
- GSC: 10+ tools for search analytics and site management
- GMC: 11+ tools for merchant center and product management
- Resolver: 4 tools for human-friendly ID resolution
- Whoami: 1 unified summary tool
Smart Resolver Layer
- Human-friendly queries: Use domains like "gatedepot.com" instead of cryptic IDs
- Auto-resolution: Automatically finds the right property/site/account
- Fuzzy matching: Handles typos and variations intelligently
- Multi-platform: Works across GA4, GSC, and GMC
Performance Optimizations
- TTL Caching: 10-minute cache for discovery calls (instant repeat lookups)
- Auto-retry: Handles Google API rate limits with exponential backoff
- Configurable: Environment variables for cache and retry settings
Enterprise Security
- OAuth Integration: User-based authentication via Application Default Credentials
- Secret Management: Credentials stored securely in Google Secret Manager
- Read-only Access: Limited scopes for data protection
Available Tools
GA4 Tools (20 tools)
Core Reporting:
run_report- Custom GA4 reports with dimensions, metrics, filtersrun_realtime_report- Real-time analytics dataget_custom_dimensions_and_metrics- Property metadata
Admin Management:
get_account_summaries- List all GA4 accounts and propertiesget_property_details- Detailed property informationlist_conversion_events- Conversion event managementlist_data_streams- Data stream configurationlist_custom_dimensions- Custom dimension managementlist_custom_metrics- Custom metric managementlist_google_ads_links- Google Ads integration
Enhanced Discovery:
properties_list_accounts- Flattened account/property listproperties_find- Search properties by name/URLdatastreams_find- Find streams by URL/measurement IDreport_top_pages- Top pages preset reportreport_revenue_by_channel- Revenue analysis presetreport_events_over_time- Event tracking over timereport_landing_pages_vs_conversions- Landing page analysis
GSC Tools (10 tools)
Basic Operations:
gsc_sites_list- List Search Console sitesgsc_sitemaps_list- Manage sitemapsgsc_search_analytics_query- Search performance data
Enhanced Analytics:
sites_find- Find sites by domain/URLpermissions_get- Site permission detailstop_queries- Top search queries presettop_pages- Top performing pages presetqueries_for_page- Queries driving specific pagescountry_device_matrix- Geographic and device analysissa_build_filters- Advanced filter builder
GMC Tools (11 tools)
Account Management:
gmc_accounts_list- List Merchant Center accountsgmc_accounts_get- Account detailsgmc_accounts_issues_list- Account issuesaccounts_list- Enhanced account listingaccount_status- Account status and summary
Product Management:
gmc_products_list- List productsgmc_products_get- Product detailsproducts_find- Search products by queryproduct_status- Individual product statusproduct_status_aggregate- Bulk product status
Reporting:
report_issues_last_30d- Recent issues report
Resolver Tools (4 tools)
find_ga4_property- Resolve domain/URL to GA4 propertyfind_gsc_site- Resolve domain/URL to GSC sitefind_gmc_account- Resolve domain/brand to GMC accountfind_google_ads_link- Find Google Ads links for properties
Whoami Tool (1 tool)
summary- Unified overview of all accessible accounts and resources
š ļø Quick Start
1. Clone and Setup
git clone https://github.com/pkidwell22/google-analytics-mcp.git
cd google-analytics-mcp
pip install -e .
2. Authentication Setup
# Run the OAuth setup script
./setup-oauth.sh
This will:
- Enable required Google APIs (GA4, GSC, GMC, Cloud Run, Secret Manager)
- Set up Application Default Credentials
- Configure OAuth scopes for all platforms
3. Local Testing
# Build and run with Docker
./test-local.sh
# Or run directly
python3 -m analytics_mcp.server --transport http --port 8080
4. Cloud Run Deployment
# Deploy to Google Cloud Run
./deploy.sh
š§ Configuration
Claude Desktop Integration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"ga4-mcp": {
"transport": {
"type": "http",
"url": "https://ga4-mcp-syiiroz2la-uc.a.run.app"
},
"env": {
"GOOGLE_PROJECT_ID": "your-project-id"
}
}
}
}
Environment Variables
GOOGLE_PROJECT_ID: Your Google Cloud Project IDMCP_CACHE_TTL_SEC: Cache TTL in seconds (default: 600)MCP_CACHE_MAXSIZE: Maximum cache entries (default: 2048)MCP_GOOGLE_RETRIES: API retry attempts (default: 5)
Example Usage
With Claude Desktop
Natural Language Queries:
- "Show me revenue by channel for gatedepot.com"
- "What are the top pages for my site?"
- "Find conversion issues in my Merchant Center"
- "List all my Google properties and accounts"
- "Show me search performance for my landing pages"
Advanced Analytics:
- "Get top queries driving traffic to /products page"
- "Show me country and device breakdown for last month"
- "Find products with issues in my Merchant Center"
- "Analyze events over time for purchase events"
Direct API Usage
# Health check
curl https://ga4-mcp-syiiroz2la-uc.a.run.app/health
# Test cache functionality
bash scripts/smoke_cache.sh
Architecture
analytics_mcp/
āāā coordinator.py # MCP server configuration
āāā server.py # Entry point and transport handling
āāā tools/
ā āāā utils.py # Common utilities and auth
ā āāā reporting/ # GA4 Data API tools
ā āāā admin/ # GA4 Admin API tools
ā āāā gsc.py # Google Search Console tools
ā āāā gsc_enhanced.py # Enhanced GSC tools
ā āāā gmc.py # Google Merchant Center tools
ā āāā gmc_enhanced.py # Enhanced GMC tools
ā āāā ga4_enhanced.py # Enhanced GA4 tools
ā āāā resolver.py # Human-friendly ID resolution
ā āāā whoami.py # Unified account summary
āāā utils/
ā āāā cache.py # TTL caching system
ā āāā google_retry.py # API retry logic
āāā scripts/
āāā smoke_cache.sh # Cache validation script
Security
- OAuth Integration: User-based authentication via Application Default Credentials
- Secret Management: Credentials stored securely in Google Secret Manager
- Read-only Access: Limited scopes for data protection
- No Hardcoded Keys: All sensitive data externalized
- Environment-based Config: Secure configuration via environment variables
Performance Features
Smart Caching
- TTL-based: Configurable cache expiration (default: 10 minutes)
- Memory efficient: LRU eviction with configurable max size
- Transparent: Cache status visible in
meta.cachedfield - Selective: Only caches discovery/resolver calls, not real-time data
Resilient API Calls
- Auto-retry: Handles 429/5xx errors automatically
- Exponential backoff: Prevents API hammering
- Random jitter: Avoids thundering herd problems
- Configurable: Adjustable retry attempts and timing
Testing
Local Testing
# Run server locally
python3 -m analytics_mcp.server --transport http --port 8080
# Test specific tools
python3 -c "
import asyncio
from analytics_mcp.tools.resolver import find_ga4_property
# Test your tool here
"
Cache Testing
# Test cache functionality
bash scripts/smoke_cache.sh
# Test with custom URL
URL=https://your-service-url.run.app bash scripts/smoke_cache.sh
Real-World Impact
Before MCP:
- Copy/paste property IDs like
properties/341922028 - Switch between multiple Google tools
- Remember different interfaces and APIs
- Manual ID lookups and context switching
After MCP:
- Natural language: "Show me revenue for gatedepot.com"
- Unified interface through Claude
- Instant cached lookups
- Automatic error handling and retries
Deployment Scripts
setup-oauth.sh- Initial OAuth setup and API enablementtest-local.sh- Local Docker testingdeploy.sh- Cloud Run deployment with environment variablestest-mcp.sh- MCP server testingscripts/smoke_cache.sh- Cache validation testing
Prerequisites
- Python 3.10+
- Google Cloud Project with billing enabled
- Google Analytics 4 property
- Google Search Console access (optional)
- Google Merchant Center access (optional)
- Docker (for local testing)
gcloudCLI configured
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
Apache 2.0 - See LICENSE file for details
Support
- Issues: GitHub Issues
- Documentation: See
README_mcp_claude.mdfor Claude Desktop setup - Deployment: See
DEPLOYMENT_STEPS.mdfor detailed deployment guide
Roadmap
- [x] Resolver Layer - Human-friendly ID resolution
- [x] TTL Caching - Performance optimization
- [x] Auto-retry - Resilient API calls
- [x] GMC Integration - Merchant Center tools
- [x] Enhanced Tools - Discovery and preset reports
- [ ] URL Inspection API - GSC URL inspection
- [ ] Batch Operations - Bulk data operations
- [ ] Custom Dashboards - Visualization tools
- [ ] Export Functionality - Data export capabilities
- [ ] Advanced Filtering - More sophisticated query options
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.