mcp-google-marketing
v1.0.2
Published
Model Context Protocol (MCP) server for Google Analytics 4, Search Console, and AdSense
Downloads
318
Maintainers
Readme
MCP Google Marketing
A Model Context Protocol (MCP) server that provides unified access to Google Analytics 4, Google Search Console, and Google AdSense APIs. Designed to work with Claude Desktop, Claude Code, and other MCP-compatible clients.
Features
- Google Analytics 4 (GA4) - 22 tools for property management, data streams, conversions, reporting, and custom dimensions/metrics
- Google Search Console - 6 tools for site management, search analytics, and sitemaps
- Google AdSense - 6 tools for account management, ad units, payments, and revenue reports
- OAuth 2.0 - Secure browser-based authentication with automatic token refresh
Quick Start for Claude Code
1. Set up OAuth credentials
First, create OAuth credentials in Google Cloud Console:
- Create a new project or select existing one
- Enable APIs: Google Analytics Admin API, Google Analytics Data API, Google Search Console API, AdSense Management API
- Create OAuth client ID (Desktop app type)
- Copy your Client ID and Client Secret
2. Authenticate (one-time setup)
# Set your credentials
export GOOGLE_CLIENT_ID="your-client-id.apps.googleusercontent.com"
export GOOGLE_CLIENT_SECRET="your-client-secret"
# Run authentication (opens browser)
npx mcp-google-marketing auth3. Add to Claude Code
claude mcp add google-marketing npx mcp-google-marketing \
--env GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com \
--env GOOGLE_CLIENT_SECRET=your-client-secretThat's it! The server is now available in Claude Code.
Prerequisites
- Node.js 20+ - Required runtime
- Google Cloud Project - With enabled APIs
- OAuth 2.0 Credentials - Desktop app type
Installation
Via npx (Recommended)
No installation required:
npx mcp-google-marketing auth # Authenticate first
npx mcp-google-marketing # Start serverVia npm (Global)
npm install -g mcp-google-marketing
mcp-google-marketing auth # Authenticate first
mcp-google-marketing # Start serverFrom Source (Development)
git clone https://github.com/freema/mcp-google-marketing.git
cd mcp-google-marketing
npm install
npm run buildCLI Commands
# Authenticate with Google (opens browser)
npx mcp-google-marketing auth
# Check authentication status
npx mcp-google-marketing auth --status
# Remove stored tokens (logout)
npx mcp-google-marketing auth --logout
# Start MCP server (for Claude Code/Desktop)
npx mcp-google-marketing
# Show help
npx mcp-google-marketing --helpConfiguration
Step 1: Create Google Cloud Project
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the following APIs:
- Google Analytics Admin API
- Google Analytics Data API
- Google Search Console API
- AdSense Management API
Step 2: Create OAuth 2.0 Credentials
- Go to Credentials → Create Credentials → OAuth client ID
- Select Desktop app as the application type
- Name it (e.g., "MCP Google Marketing")
- Copy your Client ID and Client Secret
Step 3: Configure OAuth Consent Screen
- Go to OAuth consent screen
- Choose External user type
- Fill in required fields (app name, support email)
- Add scopes:
https://www.googleapis.com/auth/analytics.edithttps://www.googleapis.com/auth/analytics.readonlyhttps://www.googleapis.com/auth/webmastershttps://www.googleapis.com/auth/adsense.readonly
- Add your email to Test users (or publish the app)
Step 4: Set Environment Variables
export GOOGLE_CLIENT_ID="your-client-id.apps.googleusercontent.com"
export GOOGLE_CLIENT_SECRET="your-client-secret"Or create a .env file:
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secretStep 5: Authenticate
Run the authentication command to complete OAuth setup:
npx mcp-google-marketing authThis will:
- Open your browser for Google OAuth authorization
- Ask you to sign in and grant permissions
- Save tokens to
.credentials/tokens.json
Usage
Claude Code
# 1. Authenticate first (if not done already)
npx mcp-google-marketing auth
# 2. Add the MCP server
claude mcp add google-marketing npx mcp-google-marketing \
--env GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com \
--env GOOGLE_CLIENT_SECRET=your-client-secretClaude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"google-marketing": {
"command": "npx",
"args": ["-y", "mcp-google-marketing"],
"env": {
"GOOGLE_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
"GOOGLE_CLIENT_SECRET": "your-client-secret"
}
}
}
}Important: Run npx mcp-google-marketing auth in your terminal first to authenticate before using with Claude Desktop.
Available Tools
Utility (1 tool)
| Tool | Description |
|------|-------------|
| auth_status | Check OAuth authentication status |
Google Analytics 4 (22 tools)
Account & Property Management
| Tool | Description |
|------|-------------|
| ga4_list_accounts | List all GA4 accounts |
| ga4_list_properties | List properties for an account |
| ga4_create_property | Create a new GA4 property |
| ga4_get_property | Get property details |
| ga4_update_property | Update property settings |
| ga4_delete_property | Delete a property |
Data Streams
| Tool | Description |
|------|-------------|
| ga4_list_data_streams | List data streams for a property |
| ga4_create_web_stream | Create a web data stream |
| ga4_create_app_stream | Create an app data stream |
| ga4_update_data_stream | Update data stream settings |
| ga4_get_measurement_id | Get measurement ID for a stream |
Conversion Events
| Tool | Description |
|------|-------------|
| ga4_list_conversion_events | List conversion events |
| ga4_create_conversion_event | Create a conversion event |
| ga4_delete_conversion_event | Delete a conversion event |
Reporting
| Tool | Description |
|------|-------------|
| ga4_get_realtime | Get real-time visitor data |
| ga4_run_report | Run a custom report |
| ga4_run_pivot_report | Run a pivot table report |
| ga4_batch_run_reports | Run multiple reports at once |
Custom Dimensions & Metrics
| Tool | Description |
|------|-------------|
| ga4_list_custom_dimensions | List custom dimensions |
| ga4_create_custom_dimension | Create a custom dimension |
| ga4_list_custom_metrics | List custom metrics |
| ga4_create_custom_metric | Create a custom metric |
Google Search Console (6 tools)
| Tool | Description |
|------|-------------|
| gsc_list_sites | List all verified sites |
| gsc_get_site | Get site details |
| gsc_search_analytics | Query search performance data |
| gsc_list_sitemaps | List submitted sitemaps |
| gsc_submit_sitemap | Submit a new sitemap |
| gsc_delete_sitemap | Delete a sitemap |
Google AdSense (6 tools)
| Tool | Description |
|------|-------------|
| adsense_list_accounts | List all AdSense accounts |
| adsense_get_account | Get account details |
| adsense_list_ad_clients | List ad clients |
| adsense_list_ad_units | List ad units |
| adsense_list_payments | List payments history |
| adsense_generate_report | Generate earnings report |
Examples
GA4: Run a Report
{
"tool": "ga4_run_report",
"arguments": {
"propertyId": "properties/123456789",
"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
"dimensions": ["date", "country"],
"metrics": ["sessions", "totalUsers", "screenPageViews"]
}
}Search Console: Query Analytics
{
"tool": "gsc_search_analytics",
"arguments": {
"siteUrl": "https://example.com",
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["query", "page"],
"rowLimit": 100
}
}AdSense: Generate Report
{
"tool": "adsense_generate_report",
"arguments": {
"accountId": "accounts/pub-1234567890123456",
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"metrics": ["ESTIMATED_EARNINGS", "PAGE_VIEWS", "CLICKS"],
"dimensions": ["DATE"]
}
}Development
Commands
# Install dependencies
npm install
# Development with hot-reload
npm run dev
# Build for production
npm run build
# Run type checking
npm run typecheck
# Run linter
npm run lint
# Run tests
npm test
# Run all checks (typecheck + lint + test + build)
npm run check:allMCP Inspector
Debug and test your tools:
# First authenticate
npm run build
node -r dotenv/config dist/index.js auth
# Then run inspector
npm run inspectorProject Structure
src/
├── index.ts # Server entry point + CLI
├── config/
│ └── constants.ts # Configuration constants
├── tools/
│ ├── analytics/ # GA4 tools (22 tools)
│ ├── search-console/ # Search Console tools (6 tools)
│ └── adsense/ # AdSense tools (6 tools)
├── types/
│ ├── analytics.ts # GA4 schemas
│ ├── search-console.ts # Search Console schemas
│ ├── adsense.ts # AdSense schemas
│ └── common.ts # Shared types
└── utils/
├── google-auth.ts # OAuth authentication
├── oauth-flow.ts # OAuth browser flow
├── token-storage.ts # Token persistence
└── error-messages.ts # Error formattingTroubleshooting
"Authentication required" error in Claude Code
You need to authenticate before using the server:
npx mcp-google-marketing authThen restart Claude Code to reconnect the MCP server.
"Access blocked: app has not completed Google verification"
Your OAuth app is in testing mode:
- Go to OAuth consent screen → click PUBLISH APP
- Or add your email to Test users
"No refresh token received"
Revoke app access and re-authorize:
- Go to Google Account Permissions
- Find and remove the app
- Delete tokens:
npx mcp-google-marketing auth --logout - Re-authenticate:
npx mcp-google-marketing auth
Port 8085 already in use
The OAuth callback server uses port 8085:
- Stop other services using that port:
lsof -i :8085 - Or modify
OAUTH_CONFIG.portinsrc/config/constants.ts
Check authentication status
npx mcp-google-marketing auth --statusContributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT - see LICENSE for details.
