Google Analytics MCP Server
Enables interaction with Google Analytics APIs to fetch reports, manage properties, data streams, conversion events, and custom dimensions/metrics through OAuth2 authentication.
README
Google Analytics MCP Server
GA-MCP (Google Analytics Management Control Panel) is a lightweight Node.js package that provides developers with a structured interface to interact with Google Analytics APIs. It simplifies common GA tasks like querying analytics reports, managing properties, audiences, and more—making it ideal for data analysts, developers, and marketing teams looking to automate reporting and analytics workflows. MCP standard.
Features
- Fetch and analyze GA performance data (sessions, users, pageviews, conversions)
- Manage properties, data streams, and conversion events
- Query custom dimensions and metrics
- Access account hierarchies and property configurations
- Export data for dashboards or further analysis
- OAuth2 authentication with access and refresh tokens
- Lightweight, secure, and highly configurable
MCP Tools
get_reports: Get analytics reports data for specified metrics and dimensionslist_accounts: List all Google Analytics accountslist_properties: List properties for a Google Analytics accountlist_data_streams: List data streams for a propertylist_custom_dimensions: List custom dimensions for a propertylist_custom_metrics: List custom metrics for a propertylist_conversion_events: List conversion events for a property
Getting Started
Prerequisites
- Node.js v18 or later
- Google OAuth2 credentials (Client ID and Client Secret)
- Valid Google Analytics access and refresh tokens
Authentication Setup
-
Create OAuth2 Credentials:
-
Go to the Google Cloud Console
-
Create or select a project
-
Enable the Google Analytics API
-
Go to "Credentials" → "Create Credentials" → "OAuth 2.0 Client IDs"
-
Configure the consent screen and choose the appropriate application type:
Option A: Web Application (Recommended)
- Select "Web application"
- Add
http://localhost:3000/auth/callbackto "Authorized redirect URIs"
Option B: Desktop Application
- Select "Desktop application"
- No redirect URI configuration needed (uses out-of-band flow)
-
-
Generate Access and Refresh Tokens:
- Use the included helper script:
npm run oauth-helper - Or use Google OAuth2 Playground with your client credentials
- Or implement your own OAuth2 flow
- Use the included helper script:
Quick Setup Workflow
# 1. Set up environment file
npm run setup-env
# 2. Edit .env with your OAuth2 Client ID and Secret (from step 1 above)
# 3. Generate tokens
npm run oauth-helper
# 4. Copy the generated tokens to your .env file
# 5. Build and start
npm run build
node dist/index.js
Installation
Clone this repository and install dependencies:
pnpm install
# or
npm install
Build
pnpm build
# or
npm run build
Configuration Environment Variables
Option 1: Using .env file (Recommended)
Set up your environment file:
npm run setup-env
# This creates .env from the template
# Edit .env file with your actual credentials
Option 2: Using export commands
Set the following environment variables:
export GOOGLE_CLIENT_ID=your_oauth2_client_id
export GOOGLE_CLIENT_SECRET=your_oauth2_client_secret
export GOOGLE_ACCESS_TOKEN=your_access_token
export GOOGLE_REFRESH_TOKEN=your_refresh_token
Start
Start the MCP server:
node dist/index.js
Integrate with Cursor
To use this MCP server with Cursor, add a .cursor/mcp.json file to your project root:
{
"mcpServers": {
"ga-mcp": {
"command": "npx",
"args": ["-y", "ga-mcp"],
"env": {
"GOOGLE_CLIENT_ID": "your_oauth2_client_id",
"GOOGLE_CLIENT_SECRET": "your_oauth2_client_secret",
"GOOGLE_ACCESS_TOKEN": "your_access_token",
"GOOGLE_REFRESH_TOKEN": "your_refresh_token"
}
}
}
}
Integrate with VSCode
To use this MCP server with VSCode, add a .vscode/mcp.json file to your project root:
{
"servers": {
"ga-mcp": {
"command": "npx",
"args": ["-y", "ga-mcp"],
"env": {
"GOOGLE_CLIENT_ID": "your_oauth2_client_id",
"GOOGLE_CLIENT_SECRET": "your_oauth2_client_secret",
"GOOGLE_ACCESS_TOKEN": "your_access_token",
"GOOGLE_REFRESH_TOKEN": "your_refresh_token"
}
}
}
}
This configuration enables VSCode to recognize and manage the Google Analytics MCP server automatically.
This configuration enables Cursor to recognize and manage the Google Analytics MCP server automatically.
Token Refresh
The MCP server automatically handles token refresh using the provided refresh token. If the access token expires, it will be automatically refreshed during API calls.
Troubleshooting
"The redirect URI... can only be used by a Client ID for native application"
This error occurs when you have a Web application OAuth client but are using the out-of-band redirect URI. Solutions:
Solution 1: Use Web Application (Recommended)
- In Google Cloud Console, edit your OAuth client
- Add
http://localhost:3000/auth/callbackto "Authorized redirect URIs" - Keep
GOOGLE_REDIRECT_URI=http://localhost:3000/auth/callbackin your.envfile
Solution 2: Switch to Desktop Application
- Create a new OAuth client and select "Desktop application"
- Set
GOOGLE_REDIRECT_URI=urn:ietf:wg:oauth:2.0:oobin your.envfile
About AST Consulting
AST Consulting is a premier digital consulting firm specializing in FinOps, cloud optimization, AI/ML solutions, digital transformation, and performance marketing. With over 100 years of combined leadership experience and a portfolio impacting 50M+ businesses and 500M+ users, AST delivers measurable outcomes by blending strategic vision with deep technical expertise.
We developed ga-mcp as part of our commitment to empower marketers, analysts, and digital teams with tools that drive efficiency, transparency, and actionable insights. Whether optimizing cloud spend or automating analytics intelligence pipelines, AST builds solutions that scale.
👉 Visit us at www.astconsulting.in
ga-mcp
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。