📊 Google Analytics MCP Server

Server Running

Server Information

  • Version: 2.0.0
  • Implementation: McpAgent with Durable Objects
  • Authentication: Google OAuth 2.0
  • Transport: SSE + Streamable HTTP

Available Endpoints

SSE Transport: https://analytics-mcp.moonstream.xyz/sse
Streamable HTTP: https://analytics-mcp.moonstream.xyz/mcp
Health Check: https://analytics-mcp.moonstream.xyz/health
Google OAuth Enabled

Claude Desktop Set-Up


1. Install Node

# Download and install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

# in lieu of restarting the shell
\. "$HOME/.nvm/nvm.sh"

# Download and install Node.js:
nvm install 22

# Verify the Node.js version:
node -v # Should print "v22.18.0".
nvm current # Should print "v22.18.0".

# Verify npm version:
npm -v # Should print "10.9.3".

2. Set up MCP Configuration in Claude Desktop

{
   "mcpServers": {
     "analytics": {
       "command": "npx",
       "args": ["mcp-remote", "https://analytics-mcp.moonstream.xyz/sse"]
     }
   }
 }

3. Property Configuration Template

Replace all REPLACE_WITH_* placeholders with your actual values:

<property>
    <property-info>
        <project-name>REPLACE_WITH_PROJECT_NAME</project-name>
        <ga4-property-id>REPLACE_WITH_GA4_PROPERTY_ID</ga4-property-id>
        <search-console-url>REPLACE_WITH_SEARCH_CONSOLE_URL</search-console-url>
    </property-info>
    <service-key type="analytics">
{
  "type": "service_account",
  "project_id": "REPLACE_WITH_GCP_PROJECT_ID",
  "private_key_id": "REPLACE_WITH_PRIVATE_KEY_ID",
  "private_key": "-----BEGIN PRIVATE KEY-----\nREPLACE_WITH_PRIVATE_KEY_CONTENT\n-----END PRIVATE KEY-----\n",
  "client_email": "REPLACE_WITH_SERVICE_ACCOUNT_EMAIL",
  "client_id": "REPLACE_WITH_CLIENT_ID",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "REPLACE_WITH_CLIENT_CERT_URL",
  "universe_domain": "googleapis.com"
}
    </service-key>
    <service-key type="search-console">
{
  "type": "service_account",
  "project_id": "REPLACE_WITH_GCP_PROJECT_ID",
  "private_key_id": "REPLACE_WITH_PRIVATE_KEY_ID",
  "private_key": "-----BEGIN PRIVATE KEY-----\nREPLACE_WITH_PRIVATE_KEY_CONTENT\n-----END PRIVATE KEY-----\n",
  "client_email": "REPLACE_WITH_SERVICE_ACCOUNT_EMAIL",
  "client_id": "REPLACE_WITH_CLIENT_ID",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "REPLACE_WITH_CLIENT_CERT_URL",
  "universe_domain": "googleapis.com"
}
    </service-key>
</property>

Before using this template, ensure you have completed these steps:

  1. Google Cloud Project Setup:
    Created a Google Cloud Project (or using existing one)
    Enabled Google Analytics Data API (for GA4)
    Enabled Search Console API (for Search Console)
  2. Service Account Creation:
    Created service account(s) in Google Cloud Console
    Downloaded JSON key file(s) for the service account(s)
    Note: You can use the same service account for both if it has access to both services
  3. Google Analytics 4 (GA4) Setup:
    Located your GA4 Property ID (Admin > Property Settings)
    Added service account email to GA4 property (Admin > Property Access Management)
    Granted at least "Viewer" permissions to the service account
  4. Search Console Setup:
    Verified ownership of your domain/website in Search Console
    Added service account email to Search Console property (Settings > Users and permissions)
    Granted "Full" or "Restricted" access to the service account
  5. Template Configuration:
    Replaced all REPLACE_WITH_* placeholders with actual values
    Ensured private key maintains proper formatting (keep \n characters)
    Verified all JSON is properly formatted (use a JSON validator if needed)

4. Property Set-Up & Initial Testing

Explore Available Capabilities

First, have Claude show you what tools and features are available for Google Analytics and Search Console integration. This helps you understand what data you can access and what operations are supported.

Example Prompt:

Can you please explore your available Google Search Console and Analytics tools? I would like to get a sense of their capabilities.

Configure Your Properties

Provide Claude with completed XML templates containing your service account credentials and property information. You can configure multiple properties at once by providing multiple <property> blocks.

Example Prompt:

Please configure the following properties for me:

<property>
    <property-info>
        <project-name>My Website Name</project-name>
        <ga4-property-id>123456789</ga4-property-id>
        <search-console-url>sc-domain:mywebsite.com</search-console-url>
    </property-info>
    <service-key type="analytics">
    {
        [Paste your GA4 service account JSON here]
    }
    </service-key>
    <service-key type="search-console">
    {
        [Paste your Search Console service account JSON here]
    }
    </service-key>
</property>

Verify Configuration Success

After configuration, Claude should report which properties were successfully added and which (if any) failed. Address any permission or setup issues before proceeding.

Example Prompt (if needed):

Can you check which properties were successfully configured and list any that failed with their error messages?

Explore Available Data

Once properties are configured, have Claude demonstrate the available data by running test queries. This verifies the integration is working and shows you what metrics and dimensions are accessible.

Example Prompt:

Please explore the available Analytics and Search Console data sources for [Your Property Name]. Can you show me some sample data from the last 30 days to verify everything is working?

5. Run Custom Queries (Optional)

After setup verification, you can request specific data analyses, comparisons, or custom date ranges.

Example Prompts:

Show me the top 20 search queries driving traffic to my site in the last 7 days.
What are my top performing pages by sessions this month, and what's their average engagement time?
Compare organic search performance between this month and last month.

Quick Setup Checklist

Before starting, ensure you have:

  • Google Cloud Project with APIs enabled (GA4 Data API and/or Search Console API)
  • Service Account(s) created with JSON key files downloaded
  • GA4 Property ID (found in GA4 Admin > Property Settings)
  • Search Console Property verified (domain or URL prefix)
  • Permissions Granted to service accounts in both GA4 and Search Console
  • XML Template filled out with your credentials and property information

Troubleshooting Tips

  • Failed Configuration? Check that your service account email is added as a user in both GA4 and Search Console
  • No Data Returned? Verify the property IDs are correct and the date range contains data
  • Permission Errors? Ensure service accounts have at least "Viewer" access in GA4 and "Full" or "Restricted" access in Search Console

Common Issues & Solutions:

  1. "Resource not found" error:
    • Verify the property exists and service account is added as a user
    • Check that APIs are enabled in Google Cloud Console
  2. "Access denied" error:
    • Ensure service account has proper permissions (Viewer for GA4, Full/Restricted for Search Console)
    • Verify the property ID/URL is correct
  3. JSON parsing errors:
    • Ensure private key line breaks are preserved as \n
    • Validate JSON structure using a JSON validator
    • Check for missing commas or quotes
  4. Multiple properties:
    • Create separate <property> blocks for each website/domain
    • You can reuse the same service account if it has access to multiple properties

Available Tools

This server provides the following MCP tools for Google Analytics integration:

list_properties
List all configured GA4 properties with their details and service accounts
add_property
Add a new GA4 property with service account credentials for data access
remove_property
Remove a property and optionally delete its stored credentials
list_stored_credentials
View all stored service accounts and their associated properties
get_ga4_data
Query GA4 analytics data with custom dimensions, metrics, and date ranges
list_dimensions
Show all available GA4 dimensions for data queries
list_metrics
Show all available GA4 metrics for data queries

Quick Setup

  1. Install Node.js (version 22+)
  2. Configure Claude Desktop with this server URL: https://analytics-mcp.moonstream.xyz/sse
  3. Create Google Cloud Project and enable APIs
  4. Create Service Account and download JSON key
  5. Grant Permissions in Google Analytics/Search Console
  6. Configure Properties using Claude with your service account key

Claude Desktop Configuration

{
  "mcpServers": {
    "analytics": {
      "command": "npx",
      "args": ["mcp-remote", "https://analytics-mcp.moonstream.xyz/sse"]
    }
  }
}

Need Help?

  • View the complete setup guide in the Setup Guide tab above
  • Check the Available Tools tab to see what you can do
  • Use Claude to explore capabilities: "Show me your available tools"