mcp-server-google-analytics
Google Analytics MCP 服务器
用于访问 Google Analytics 4 (GA4) 数据的 MCP 服务器实现,使用模型上下文协议 TypeScript SDK 构建。
特征
获取具有可自定义维度的页面浏览量指标
跟踪一段时间内的活跃用户和新用户
分析特定事件及其指标
监控用户行为指标(会话时长、跳出率)
所有查询均可灵活选择日期范围
Related MCP server: MCP Search Analytics Server
先决条件
Node.js 20 或更高版本
Google Analytics 4 媒体资源
已启用 Analytics Data API 的 Google Cloud 项目
具有适当权限的服务帐户凭据
设置
创建 Google Cloud 项目并启用 Analytics Data API
创建服务帐户并下载凭证 JSON 文件
授予服务帐号对您的 GA4 资源的适当访问权限
设置环境变量:
export GOOGLE_CLIENT_EMAIL="your-service-account@project.iam.gserviceaccount.com"
export GOOGLE_PRIVATE_KEY="your-private-key"
export GA_PROPERTY_ID="your-ga4-property-id"安装
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 Google Analytics Server:
npx -y @smithery/cli install mcp-server-google-analytics --client claude手动安装
pnpm install mcp-server-google-analytics用法
启动服务器
pnpm startClaude Desktop中的配置
将其添加到您的 Claude Desktop 配置中:
{
"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"
}
}
}
}可用函数
获取页面浏览量
获取特定日期范围内的页面浏览量指标:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["page", "country"] // Optional
}获取活跃用户
获取活跃用户指标:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31"
}获取事件
获取事件指标:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"eventName": "purchase" // Optional
}获取用户行为
获取用户行为指标:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31"
}安全注意事项
始终对敏感凭据使用环境变量
实施适当的 CORS 设置
设置服务帐户权限时遵循最小特权原则
定期轮换服务帐户凭据
监控 API 使用情况并根据需要实施速率限制
贡献
欢迎贡献代码!请阅读我们的贡献指南,详细了解我们的行为准则以及提交 Pull Request 的流程。
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。
Available Tools
5 toolsgetActiveUsersC
Get active users metrics for a specific date range
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | Yes | Start date in YYYY-MM-DD format | |
| endDate | Yes | End date in YYYY-MM-DD format |
TDQS
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.
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.
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.
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.
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.
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
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | Yes | Start date in YYYY-MM-DD format | |
| endDate | Yes | End date in YYYY-MM-DD format | |
| eventName | No | Specific event name to filter by (optional) |
TDQS
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.
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.
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.
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.
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.
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
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | Yes | Start date in YYYY-MM-DD format | |
| endDate | Yes | End date in YYYY-MM-DD format | |
| dimensions | No | Dimensions to group by (e.g., page, country) |
TDQS
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.
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.
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.
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.
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.
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
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | Yes | Start date in YYYY-MM-DD format | |
| endDate | Yes | End date in YYYY-MM-DD format |
TDQS
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.
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.
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.
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.
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.
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
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | Yes | Start date in YYYY-MM-DD format | |
| endDate | Yes | End date in YYYY-MM-DD format | |
| dimensions | Yes | Dimensions to group by (e.g., page, country) | |
| metrics | Yes | Metrics to include in the report | |
| dimensionFilter | No | Filter for dimensions |
TDQS
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.
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.
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.
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.
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.
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.
5 tool updates
- First observed
getActiveUsers - First observed
getEvents - First observed
getPageViews - First observed
getUserBehavior - First observed
runReport
TDQS
Scored across 5 tools
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.
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.
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.
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
Related MCP Connectors
Read-only Google Analytics 4 MCP server for AI assistants.
Hosted MCP server for GA4, Google Ads and Search Console. Google OAuth, nothing to install.
Read-only Google Search Console MCP server for AI assistants.
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides 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.763 npm7MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides unified access to Google Analytics 4 and Google Search Console data through real-time analytics queries.2MIT
- AlicenseNot gradedqualityDmaintenanceA 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
- FlicenseNot gradedqualityDmaintenanceExposes a semantic layer on GA4 event data in BigQuery via an MCP server for consistent querying.3-