Skip to main content
Glama
ruchernchong

mcp-server-google-analytics

by ruchernchong

Google Analytics MCP Server

An MCP server implementation for accessing Google Analytics 4 (GA4) data, built using the Model Context Protocol TypeScript SDK.

Features

  • Get page view metrics with customizable dimensions

  • Track active and new users over time

  • Analyze specific events and their metrics

  • Monitor user behavior metrics (session duration, bounce rate)

  • Flexible date range selection for all queries

Related MCP server: MCP Search Analytics Server

Prerequisites

  • Node.js 20 or higher

  • A Google Analytics 4 property.

  • A Google Cloud project with the Analytics Data API enabled.

  • A service account with credentials to access the API.

Setup and Configuration

To use this server, you need to configure authentication with Google Analytics. This is done using a service account.

1. Enable the Google Analytics Data API

  1. Go to the Google Cloud Console.

  2. Select the project you want to use.

  3. In the navigation menu, go to APIs & Services > Library.

  4. Search for "Google Analytics Data API" and enable it.

2. Create a Service Account

  1. In the Google Cloud Console, navigate to IAM & Admin > Service Accounts.

  2. Click "Create Service Account".

  3. Give the service account a name (e.g., "GA4 MCP Server").

  4. Click "Create and Continue".

  5. You can skip granting the service account access to the project.

  6. Click "Done".

  7. Find the service account you just created and click on the three dots under "Actions".

  8. Select "Manage keys", then "Add Key" > "Create new key".

  9. Choose JSON as the key type and click "Create". A JSON file with the credentials will be downloaded.

3. Grant Service Account Access to Google Analytics

  1. Open Google Analytics.

  2. Navigate to the Admin section of your GA4 property.

  3. Under the Property column, click on Property Access Management.

  4. Click the "+" button to add a new user.

  5. In the "Email address" field, paste the client_email from the JSON credentials file you downloaded.

  6. Assign the "Viewer" role. You do not need to notify the user.

  7. Click "Add".

4. Set Environment Variables

The server requires the following environment variables:

  • GOOGLE_CLIENT_EMAIL: The client_email from your service account JSON file.

  • GOOGLE_PRIVATE_KEY: The private_key from your service account JSON file.

  • GA_PROPERTY_ID: Your Google Analytics 4 property ID.

You can set them in your environment or use a .env file.

export GOOGLE_CLIENT_EMAIL="your-service-account@your-project.iam.gserviceaccount.com"
export GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END PRIVATE KEY-----\n"
export GA_PROPERTY_ID="your_property_id"

Installation

Installing via Smithery

To install Google Analytics Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install mcp-server-google-analytics --client claude

Manual Installation

npm install -g mcp-server-google-analytics

Or use with npx directly:

npx mcp-server-google-analytics

Usage

Starting the Server

pnpm start

Configuration in Claude Desktop

Add this to your Claude Desktop configuration:

{
  "mcpServers": {
    "google-analytics": {
      "command": "npx",
      "args": ["-y", "mcp-server-google-analytics"],
      "env": {
        "GOOGLE_CLIENT_EMAIL": "your-service-account@project.iam.gserviceaccount.com",
        "GOOGLE_PRIVATE_KEY": "your-private-key",
        "GA_PROPERTY_ID": "your-ga4-property-id"
      }
    }
  }
}

Available Functions

runReport

Run a flexible report to get analytics data.

Input:

{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "dimensions": [{ "name": "country" }, { "name": "city" }],
  "metrics": [{ "name": "activeUsers" }, { "name": "newUsers" }],
  "dimensionFilter": {
    "filter": {
      "fieldName": "country",
      "stringFilter": {
        "value": "United States"
      }
    }
  }
}

getPageViews

Get page view metrics for a specific date range:

{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "dimensions": ["page", "country"] // Optional
}

getActiveUsers

Get active users metrics:

{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31"
}

getEvents

Get event metrics:

{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "eventName": "purchase" // Optional
}

getUserBehavior

Get user behavior metrics:

{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31"
}

Security Considerations

  • Least Privilege: Only grant the service account the "Viewer" role in Google Analytics.

  • Key Management: Keep your service account key file secure and do not expose it in client-side code.

  • Environment Variables: Use environment variables to store sensitive information like the client email, private key, and property ID.

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Available Tools

5 tools
getActiveUsersC

Get active users metrics for a specific date range

ParametersJSON Schema
NameRequiredDescriptionDefault
startDateYesStart date in YYYY-MM-DD format
endDateYesEnd date in YYYY-MM-DD format

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves metrics but doesn't describe what 'active users' entails (e.g., definition of 'active', data format, potential rate limits, or authentication needs). For a tool with no annotation coverage, this leaves significant gaps in understanding its behavior and constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded with the core action and resource, making it easy to parse. Every part of the sentence earns its place by specifying the metrics and date range context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete for a tool that likely returns complex metrics data. It doesn't explain what 'active users metrics' includes (e.g., counts, trends, or breakdowns), how results are structured, or any limitations. For a metrics retrieval tool with no structured output information, this leaves the agent guessing about return values and usage context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with clear descriptions for both parameters ('startDate' and 'endDate') in the input schema. The description adds no additional meaning beyond implying a date range is required, which is already covered by the schema. This meets the baseline of 3 since the schema does the heavy lifting, but the description doesn't enhance parameter understanding further.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('active users metrics'), specifying the action and target. It distinguishes itself from siblings like 'getEvents' or 'getPageViews' by focusing on user metrics rather than events or views. However, it doesn't explicitly differentiate from 'getUserBehavior' or 'runReport', which might also involve user-related data, leaving some ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'getUserBehavior' or 'runReport'. It mentions a date range but doesn't clarify if this is the only way to retrieve user metrics or if there are specific use cases (e.g., monitoring daily activity vs. detailed analysis). Without explicit when/when-not instructions, the agent must infer usage from context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

getEventsC

Get event metrics for a specific date range

ParametersJSON Schema
NameRequiredDescriptionDefault
startDateYesStart date in YYYY-MM-DD format
endDateYesEnd date in YYYY-MM-DD format
eventNameNoSpecific event name to filter by (optional)

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states 'Get event metrics' but doesn't disclose behavioral traits such as whether this is a read-only operation, if it requires authentication, rate limits, pagination, or what the output format looks like (e.g., aggregated metrics vs. raw events). This leaves significant gaps for an agent to understand how to use it effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Get event metrics') and specifies the key constraint ('for a specific date range'). There is no wasted wording, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a metrics tool with no annotations and no output schema, the description is incomplete. It doesn't explain what 'event metrics' entail (e.g., counts, averages, trends), how results are returned, or any behavioral context. This leaves the agent with insufficient information to handle the tool robustly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents the parameters (startDate, endDate, eventName) with their types, formats, and optionality. The description adds no additional meaning beyond implying date-range filtering, which is already covered in the schema. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('event metrics') with scope ('for a specific date range'), making the purpose understandable. It doesn't explicitly distinguish from siblings like 'getActiveUsers' or 'getPageViews', but the focus on 'event metrics' provides some implicit differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'getActiveUsers', 'getPageViews', 'getUserBehavior', or 'runReport'. It mentions a date range but doesn't specify if this is the primary tool for event metrics or if other tools might overlap in functionality.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

getPageViewsB

Get page view metrics for a specific date range

ParametersJSON Schema
NameRequiredDescriptionDefault
startDateYesStart date in YYYY-MM-DD format
endDateYesEnd date in YYYY-MM-DD format
dimensionsNoDimensions to group by (e.g., page, country)

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'Get[s] page view metrics,' implying a read-only operation, but doesn't cover aspects like authentication needs, rate limits, error handling, or what the metrics include (e.g., counts, trends). This is a significant gap for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary details. It avoids redundancy and wastes no words, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on behavioral traits, usage context, and output format, which are needed for full completeness. Without annotations or output schema, more guidance would be beneficial.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for all parameters (e.g., date formats, dimensions grouping). The description adds no additional parameter semantics beyond implying date-range filtering, which is already covered in the schema. This meets the baseline score of 3 when the schema handles most documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as retrieving 'page view metrics for a specific date range,' which includes a specific verb ('Get') and resource ('page view metrics'). However, it doesn't distinguish this from sibling tools like 'getActiveUsers' or 'getEvents,' which likely retrieve different types of metrics, so it doesn't achieve full differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'getActiveUsers' or 'runReport.' It mentions a 'specific date range' but doesn't specify prerequisites, exclusions, or comparative contexts, leaving the agent to infer usage based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

getUserBehaviorB

Get user behavior metrics like session duration and bounce rate

ParametersJSON Schema
NameRequiredDescriptionDefault
startDateYesStart date in YYYY-MM-DD format
endDateYesEnd date in YYYY-MM-DD format

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It implies a read-only operation ('Get') but doesn't specify permissions, rate limits, data freshness, or what happens if date ranges are invalid. For a tool with zero annotation coverage, this is a significant gap in behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose with no wasted words. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 required parameters) and lack of annotations or output schema, the description is minimally adequate. It covers the basic purpose but lacks details on behavioral traits, usage guidelines, and return values, which are important for an agent to use it correctly without structured metadata.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with both parameters ('startDate' and 'endDate') documented in the schema. The description doesn't add any parameter-specific details beyond what the schema provides, such as format constraints or usage examples, so it meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Get') and resource ('user behavior metrics'), and provides examples of metrics like 'session duration and bounce rate'. However, it doesn't explicitly differentiate from sibling tools like 'getActiveUsers' or 'getEvents', which might also retrieve user-related data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'getActiveUsers', 'getEvents', or 'runReport'. It doesn't mention prerequisites, exclusions, or specific contexts for usage, leaving the agent to infer based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

runReportC

Run a report to get analytics data

ParametersJSON Schema
NameRequiredDescriptionDefault
startDateYesStart date in YYYY-MM-DD format
endDateYesEnd date in YYYY-MM-DD format
dimensionsYesDimensions to group by (e.g., page, country)
metricsYesMetrics to include in the report
dimensionFilterNoFilter for dimensions

TDQS

C2.7/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'run a report' which implies a read operation, but fails to disclose critical traits like whether it's safe (non-destructive), requires authentication, has rate limits, or what the output format looks like. This is a significant gap for a tool with multiple parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste: 'Run a report to get analytics data'. It's appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (5 parameters, nested objects, no output schema) and lack of annotations, the description is incomplete. It doesn't explain what the report returns, how results are structured, or behavioral aspects like safety and performance, leaving the agent with insufficient context for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the input schema already documents all 5 parameters (e.g., startDate, endDate, dimensions, metrics, dimensionFilter) with descriptions. The tool description adds no additional meaning beyond what the schema provides, resulting in a baseline score of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Run a report to get analytics data' states a vague purpose with the verb 'run' and resource 'report', but it lacks specificity about what kind of analytics or how it differs from sibling tools like getActiveUsers or getEvents. It doesn't clearly distinguish itself from alternatives, making it only adequate.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus the sibling tools (getActiveUsers, getEvents, etc.). There's no mention of context, prerequisites, or alternatives, leaving the agent without clear usage instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 5 tool updates
    • First observedgetActiveUsers
    • First observedgetEvents
    • First observedgetPageViews
    • First observedgetUserBehavior
    • First observedrunReport

TDQS

B3.2/5.0
Disambiguation3/5

The first four tools have clear distinctions by metric type (active users, events, page views, user behavior), but 'runReport' overlaps significantly with the others as a generic alternative, creating potential confusion for an agent about when to use it versus the specific tools.

Naming Consistency4/5

Four tools follow a consistent 'getNoun' pattern (e.g., getActiveUsers, getEvents), which is clear and predictable. However, 'runReport' deviates from this pattern with a different verb ('run'), slightly breaking the consistency.

Tool Count5/5

With 5 tools, the count is well-scoped for an analytics server, providing focused coverage without being overwhelming or too sparse. Each tool appears to serve a distinct purpose within the domain.

Completeness4/5

The tools cover key analytics metrics like users, events, page views, and behavior, which are core to the domain. However, there might be minor gaps, such as missing tools for configuration (e.g., listing properties) or more advanced analytics (e.g., cohort analysis), but agents can likely work around these with the existing tools.

Maintenance

ActivityInactive
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    Provides an interface to access Google Analytics Data API through Model Context Protocol (MCP), allowing users to retrieve reports and realtime data from Google Analytics 4 properties.
    1,209
    7
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    A Model Context Protocol server that provides unified access to Google Analytics 4 and Google Search Console data through real-time analytics queries.
    2
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    This project is a Google Analytics 4 (GA4) automation server implemented as a Model Context Protocol (MCP) tool. It lets AI agents query GA4 data (reports, traffic sources, demographics, etc.) and also includes a simple connection test script.
    7
    1
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    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.
    Apache 2.0

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ruchernchong/mcp-server-google-analytics'

If you have feedback or need assistance with the MCP directory API, please join our Discord server