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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。