mcp-server-google-analytics
Servidor MCP de Google Analytics
Una implementación de servidor MCP para acceder a los datos de Google Analytics 4 (GA4), creada utilizando el SDK de TypeScript de Model Context Protocol.
Características
Obtenga métricas de visitas a la página con dimensiones personalizables
Seguimiento de usuarios activos y nuevos a lo largo del tiempo
Analizar eventos específicos y sus métricas
Monitorear las métricas del comportamiento del usuario (duración de la sesión, tasa de rebote)
Selección de rango de fechas flexible para todas las consultas
Related MCP server: MCP Search Analytics Server
Prerrequisitos
Node.js 20 o superior
Propiedad de Google Analytics 4
Proyecto de Google Cloud con la API de datos de Analytics habilitada
Credenciales de cuenta de servicio con permisos adecuados
Configuración
Cree un proyecto de Google Cloud y habilite la API de datos de Analytics
Cree una cuenta de servicio y descargue el archivo JSON de credenciales
Otorgue a la cuenta de servicio el acceso adecuado a su propiedad GA4
Configurar variables de entorno:
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"Instalación
Instalación mediante herrería
Para instalar Google Analytics Server para Claude Desktop automáticamente a través de Smithery :
npx -y @smithery/cli install mcp-server-google-analytics --client claudeInstalación manual
pnpm install mcp-server-google-analyticsUso
Iniciando el servidor
pnpm startConfiguración en Claude Desktop
Añade esto a tu configuración de 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"
}
}
}
}Funciones disponibles
obtener vistas de página
Obtener métricas de visitas a la página para un rango de fechas específico:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["page", "country"] // Optional
}obtener usuarios activos
Obtenga métricas de usuarios activos:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31"
}obtenerEventos
Obtener métricas de eventos:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"eventName": "purchase" // Optional
}obtenerComportamientoUsuario
Obtener métricas de comportamiento del usuario:
{
"startDate": "2024-01-01",
"endDate": "2024-01-31"
}Consideraciones de seguridad
Utilice siempre variables de entorno para credenciales confidenciales
Implementar configuraciones CORS apropiadas
Siga el principio del mínimo privilegio al configurar los permisos de la cuenta de servicio
Rotar periódicamente las credenciales de la cuenta de servicio
Supervisar el uso de la API e implementar una limitación de velocidad si es necesario
Contribuyendo
¡Agradecemos sus contribuciones! Lea nuestra Guía de Contribución para obtener más información sobre nuestro código de conducta y el proceso para enviar solicitudes de incorporación de cambios.
Licencia
Este proyecto está licenciado bajo la licencia MIT: consulte el archivo de LICENCIA para obtener más detalles.
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-