google-analytics-mcp

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.

Category
访问服务器

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, filters
  • run_realtime_report - Real-time analytics data
  • get_custom_dimensions_and_metrics - Property metadata

Admin Management:

  • get_account_summaries - List all GA4 accounts and properties
  • get_property_details - Detailed property information
  • list_conversion_events - Conversion event management
  • list_data_streams - Data stream configuration
  • list_custom_dimensions - Custom dimension management
  • list_custom_metrics - Custom metric management
  • list_google_ads_links - Google Ads integration

Enhanced Discovery:

  • properties_list_accounts - Flattened account/property list
  • properties_find - Search properties by name/URL
  • datastreams_find - Find streams by URL/measurement ID
  • report_top_pages - Top pages preset report
  • report_revenue_by_channel - Revenue analysis preset
  • report_events_over_time - Event tracking over time
  • report_landing_pages_vs_conversions - Landing page analysis

GSC Tools (10 tools)

Basic Operations:

  • gsc_sites_list - List Search Console sites
  • gsc_sitemaps_list - Manage sitemaps
  • gsc_search_analytics_query - Search performance data

Enhanced Analytics:

  • sites_find - Find sites by domain/URL
  • permissions_get - Site permission details
  • top_queries - Top search queries preset
  • top_pages - Top performing pages preset
  • queries_for_page - Queries driving specific pages
  • country_device_matrix - Geographic and device analysis
  • sa_build_filters - Advanced filter builder

GMC Tools (11 tools)

Account Management:

  • gmc_accounts_list - List Merchant Center accounts
  • gmc_accounts_get - Account details
  • gmc_accounts_issues_list - Account issues
  • accounts_list - Enhanced account listing
  • account_status - Account status and summary

Product Management:

  • gmc_products_list - List products
  • gmc_products_get - Product details
  • products_find - Search products by query
  • product_status - Individual product status
  • product_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 property
  • find_gsc_site - Resolve domain/URL to GSC site
  • find_gmc_account - Resolve domain/brand to GMC account
  • find_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 ID
  • MCP_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.cached field
  • 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 enablement
  • test-local.sh - Local Docker testing
  • deploy.sh - Cloud Run deployment with environment variables
  • test-mcp.sh - MCP server testing
  • scripts/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)
  • gcloud CLI configured

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

Apache 2.0 - See LICENSE file for details

Support

  • Issues: GitHub Issues
  • Documentation: See README_mcp_claude.md for Claude Desktop setup
  • Deployment: See DEPLOYMENT_STEPS.md for 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

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选