Google MCP Server

Google MCP Server

A unified MCP server that gives AI assistants direct access to Google Analytics 4, Google Search Console, Google Ads and Google Merchant Center data using OAuth2 user credentials.

Category
访问服务器

README

Google MCP Server

A unified Model Context Protocol (MCP) server that gives AI assistants direct access to Google Analytics 4, Google Search Console, Google Ads and Google Merchant Center data.

Built with FastMCP and Google REST APIs. Uses OAuth2 user credentials -- no service account needed. You authenticate once, and the server sees every property your Google account has access to.

Tools (21)

Google Analytics 4

Tool Description
ga4_list_properties List all accessible GA4 properties
ga4_run_report Run standard reports (dimensions, metrics, filters, sorting, date ranges, up to 10k rows)
ga4_realtime_report Realtime active users report
ga4_get_metadata List available dimensions and metrics for a property

Google Search Console

Tool Description
gsc_list_sites List all verified sites
gsc_search_analytics Search performance data (queries, pages, countries, devices, dates) with filters and pagination (up to 25k rows)
gsc_inspect_url Inspect URL indexing status (verdict, coverage, crawl state, robots.txt)
gsc_list_sitemaps List submitted sitemaps
gsc_submit_url Submit a URL for indexing

Google Ads

Tool Description
ads_list_customers List all accessible Google Ads accounts
ads_campaign_report Campaign performance (impressions, clicks, cost, conversions, CPC, CTR)
ads_adgroup_report Ad group performance
ads_keyword_report Keyword performance (with quality score)
ads_keyword_ideas Keyword Planner: search volume, CPC, competition

Google Merchant Center

Tool Description
merchant_list_accounts List all accessible Merchant Center accounts
merchant_list_products List products from catalog (title, offer ID, language, feed)
merchant_product_status Product approval statuses (approved, disapproved, pending, issues)
merchant_account_status Account information (name, language, timezone)
merchant_list_product_issues Product issues aggregated by type (with examples)

Batch

Tool Description
ga4_batch_report Run the same GA4 report across multiple properties at once
gsc_batch_analytics Run the same Search Analytics query across multiple sites at once

Setup

1. Prerequisites

  • Python 3.10+
  • A Google Cloud project with these APIs enabled:
    • Google Analytics Data API
    • Google Analytics Admin API
    • Google Search Console API
    • Google Ads API (for Ads tools)
    • Merchant API (for Merchant Center tools)

2. Create OAuth credentials

  1. Go to Google Cloud Console > Credentials
  2. Click Create Credentials > OAuth client ID > Desktop application
  3. Download the JSON file
  4. Save it as ~/.config/google-mcp/credentials.json

3. Configure OAuth consent screen scopes

In Google Cloud Console > Google Auth Platform > Data Access, add these scopes:

  • https://www.googleapis.com/auth/analytics.readonly
  • https://www.googleapis.com/auth/webmasters.readonly
  • https://www.googleapis.com/auth/adwords (sensitive)
  • https://www.googleapis.com/auth/content (sensitive)

4. Install dependencies

pip install -r requirements.txt

5. Authorize

python3 authorize.py --extra-scopes https://www.googleapis.com/auth/adwords https://www.googleapis.com/auth/content

This opens a browser for Google OAuth consent. The resulting token is saved to ~/.config/google-mcp/token.json.

Without --extra-scopes, only GA4 and GSC tools will work.

6. Google Ads: developer token

Google Ads requires a developer token. Create ~/.config/google-mcp/config.json:

{
  "google_ads": {
    "developer_token": "YOUR_DEVELOPER_TOKEN"
  }
}

This file is optional. Without it, GA4, GSC and Merchant Center tools still work. Google Ads tools require it.

You can also add default IDs to avoid passing them on every call:

{
  "google_ads": {
    "developer_token": "YOUR_DEVELOPER_TOKEN",
    "customer_id": "1234567890",
    "login_customer_id": "1234567890"
  },
  "merchant_center": {
    "merchant_id": "123456789"
  }
}

7. Google Merchant Center: GCP project registration

Merchant API v1 requires registering your GCP project with each Merchant Center account. This is a one-time step per account. See Register as a developer.

8. Configure Claude Code

Add to your ~/.claude.json:

{
  "mcpServers": {
    "google-mcp": {
      "type": "stdio",
      "command": "python3",
      "args": ["/path/to/google-mcp/server.py"],
      "env": {
        "GOOGLE_MCP_CONFIG_DIR": "/path/to/.config/google-mcp"
      }
    }
  }
}

Restart Claude Code. The 21 tools will be available immediately.

Configuration

All paths are configurable via environment variables:

Variable Default Description
GOOGLE_MCP_CONFIG_DIR ~/.config/google-mcp Directory for credentials, token and config files
GOOGLE_MCP_CREDENTIALS_FILE {config_dir}/credentials.json OAuth client credentials file
GOOGLE_MCP_TOKEN_FILE {config_dir}/token.json OAuth token file
GOOGLE_MCP_CONFIG_FILE {config_dir}/config.json Extended config (Ads developer token, default IDs)

Architecture

server.py           FastMCP entry point, 21 @mcp.tool() wrappers
auth.py             OAuth2 centralized (get_credentials, get_ads_client)
config.py           Optional config.json loader (developer token, default IDs)
tools_ga4.py        GA4 via google-api-python-client (REST)
tools_gsc.py        GSC via google-api-python-client (REST)
tools_batch.py      Batch orchestration over GA4/GSC tools
tools_ads.py        Google Ads via subprocess isolation (gRPC in child process)
_ads_impl.py        Google Ads gRPC implementation (runs in subprocess)
tools_merchant.py   Merchant Center via REST (requests HTTP)
authorize.py        One-time OAuth2 flow with --extra-scopes

Why subprocess for Google Ads? The google-ads SDK uses gRPC, which conflicts with FastMCP's asyncio event loop over stdio transport. Running Ads calls in a subprocess isolates gRPC from the MCP server process. All other APIs use REST and run in-process.

Usage examples

Once configured, you can ask Claude Code things like:

  • "List my GA4 properties"
  • "Show me the top 20 pages by sessions on property 123456789 for the last 7 days"
  • "What queries drive traffic to example.com?"
  • "Is this URL indexed? https://example.com/page"
  • "Show realtime active users on my site"
  • "List my Google Ads accounts"
  • "Show campaign performance for customer 9006396761 last month"
  • "Generate keyword ideas for 'chaussures running' in France"
  • "List my Merchant Center accounts"
  • "Show product issues for merchant 5300442232"
  • "Run a traffic report on all my GA4 properties at once"

Why this exists

The official Google MCP servers for GA4 and GSC require service account credentials (google.auth.default()), which means creating a service account, granting it access to each property, and managing key files. This is cumbersome for individual users.

This server uses OAuth2 user credentials (the same flow as signing in with your Google account), which means it works with whatever properties you already have access to -- no extra setup per property. One authentication, all your Google data.

License

MIT -- see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选