GA4 SEO MCP

io.github.GermaniU由 GitHub 账号 GermaniU 发布v0.1.2更新于 Nov 7, 2026

Set up and audit site measurement: GA4, Search Console and PageSpeed. Read-only unless enabled.

概览

AI 生成的概览

本地 MCP 服务器,连接 GA4、Search Console 与 PageSpeed Insights:读取报表、审计 SEO 数据,并可选地完成站点测量配置。

可以做什么
  • 列出 GA4 账户、资源、数据流、关键事件、自定义维度和 Ads 关联
  • 运行 GA4 报表、实时报表、热门页面、事件、流量来源、转化以及多资源组合审计
  • 查询 Search Console 站点、热门查询、页面表现、单页查询明细和站点地图
  • 对公开网址运行 PageSpeed Insights 审计与 CrUX 实测数据检查
  • 用 bootstrap_site_measurement 规划或执行整套站点测量配置,并可选通过 DataForSEO 和 Google Ads 关键词规划师做关键词研究
适用场景
适合需要处理 Google Analytics 4、Search Console 或 Core Web Vitals 数据时使用:让助手拉取报表、审计站点埋点,或在一次对话中规划并执行新站点的测量配置。
运行要求
通过 uvx(需 uv 0.13.4 及以上)或 Docker 以 stdio 在本地运行。需要 Google 凭据:通过 GOOGLE_APPLICATION_CREDENTIALS 指定服务账号密钥文件,或使用 gcloud 的 Application Default Credentials,通常还需自建 OAuth 客户端。可选:PAGESPEED_API_KEY、DATAFORSEO_LOGIN 与 DATAFORSEO_PASSWORD、GOOGLE_ADS_DEVELOPER_TOKEN、GOOGLE_ADS_LOGIN_CUSTOMER_ID。用 GA4SEO_TOOLSETS 选择工具集。
安装前请注意
创建、更新、删除、提交或验证类写入工具仅在设置 GA4SEO_ENABLE_WRITES=1 或 --enable-writes 时才会注册;执行 bootstrap 计划会真实改动 GA4 与 Search Console 配置,应先审阅计划。凭据与密钥(服务账号密钥、DATAFORSEO_PASSWORD、GOOGLE_ADS_DEVELOPER_TOKEN、PAGESPEED_API_KEY)从环境变量或受限权限文件读取。DataForSEO 关键词数据为付费服务。HTTP 模式应设置 MCP_AUTH_TOKEN。

安装

在 SourceWeft 中

  1. 打开 控制台中的 GA4 SEO MCP,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

English · Español

ga4-seo-mcp — site measurement for AI agents, end to end

Get a site's measurement ready end to end: GA4 + Search Console + PageSpeed, with optional, guarded writes. An open source Model Context Protocol server for Google Analytics 4 & Search Console. Most MCP servers for Google read your data; this one can also set it up: property, web stream, key events, custom dimensions, Search Console DNS verification, sitemap and a PageSpeed baseline — read-only until you say otherwise.

[License: MIT] [MCP] [Python] [CI] [PRs Welcome]

[GA4 SEO MCP server]

Tags: mcp-server · ga4 · google-analytics · search-console · seo · pagespeed · core-web-vitals · keyword-research · claude-code · cursor

[An agent audits a public site with PageSpeed and plans the GA4 + Search Console setup of a new site]

Real run: psi_audit on a public site and bootstrap_site_measurement(apply=False) planning a new site. The demo script redacts the account ID.


💡 Why this one?

Launching a site means the same chores every time: create the GA4 property and its web stream, mark the key events, register custom dimensions, add the domain to Search Console, publish a DNS TXT record, verify it, submit the sitemap, and record a PageSpeed baseline. ga4-seo-mcp turns that into one plan your agent shows you, and one confirmation.

ga4-seo-mcpGoogle's official GA4 MCPsearch-console-mcpgoogle-seo-mcp
GA4 reports (Data API)✅✅✅✅
Search Console✅—✅ (+ Bing)✅
PageSpeed Insights / CrUX✅—✅✅
Create GA4 property + web stream✅———
Create key events / custom dimensions✅——✅
Search Console DNS verification✅———
One-call site plan → apply (idempotent)✅ bootstrap_site_measurement———
Read-only by default✅ write tools are not even registeredread-only onlysee its docs✅ read-only mode
Toolsets✅——✅
LanguagePythonPythonTypeScriptTypeScript

Based on each project's README on 2026-10-19; "—" means we did not find it documented. Corrections welcome. Those projects go wider than this one (Bing, AdSense, WordPress, GEO audits…); this one goes deeper on setting up measurement.

🤝 Need this done for you?

This server is built and maintained by Germani Uicab. If you'd rather not run it yourself, ServerStack Solutions can get your GA4 + Search Console measurement ready: a written plan, property and key events configured, the DNS verification and sitemap in place, and a PageSpeed baseline — with a QA pass before handover.


Extras: optional keyword research with DataForSEO (exact long-tail volumes) and Google Ads Keyword Planner (free, bucketed volumes), with es-MX defaults that you can override.


⚡ Quick start

1. Install uv 0.13.4 or newer — the client launches the server with uvx; nothing else to install.

2. Log in with the minimum scopes. The CLI prints the exact gcloud command for the toolsets you enable:

bash
uvx ga4-seo-mcp auth-command --client-id-file=oauth-client.json# gcloud auth application-default login --client-id-file=oauth-client.json --scopes=https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/webmasters.readonly

Run the printed command. Google blocks Analytics and Search Console scopes on gcloud's built-in OAuth client, so you need your own (a one-time, few-minute setup) or a service account — both are explained in docs/AUTH.md.

3. Check everything before connecting a client (read-only, changes nothing):

bash
uvx ga4-seo-mcp doctor# [ok] credentials found: Credentials via Application Default Credentials# [ok] access token refreshed# [ok] token has the 2 scope(s) these toolsets need# [ok] admin: <n> account(s) visible on the first page# [ok] data: responded (<n> metrics in the schema)# [ok] gsc: <n> site(s) visible# [ok] psi: no Google login needed; PAGESPEED_API_KEY set# all checks passed

4. Add it to your client (Claude Code shown; others below):

bash
claude mcp add ga4-seo -- uvx ga4-seo-mcp

Ask: "List my GA4 properties and show last week's sessions for the first one."


🧰 Toolsets, scopes and tools

Enable only what you need with --toolsets (or GA4SEO_TOOLSETS). Default: admin,data,gsc,psi. Only the tools of active toolsets are registered, and the OAuth scopes follow.

ToolsetWhatScopes (read-only)Extra scopes with --enable-writesTools (read + write)
adminGA4 Admin API: accounts, properties, streams, key events, custom dimensions, Ads links, bootstrap_site_measurementanalytics.readonlyanalytics.edit9 + 10
dataGA4 Data API: reports, realtime, top pages, events, traffic sources, portfolioanalytics.readonly—8 + 0
gscSearch Console: queries, pages, sitemaps, domain add + DNS verificationwebmasters.readonlywebmasters, siteverification5 + 3
psiPageSpeed Insights: Lighthouse lab + CrUX field datanone (PAGESPEED_API_KEY recommended)—2 + 0
dataforseoDataForSEO keyword ideas and exact volumes (paid)none (DATAFORSEO_LOGIN / DATAFORSEO_PASSWORD)—2 + 0
adsGoogle Ads Keyword Planner (needs pip install 'ga4-seo-mcp[ads]')adwords—2 + 0

Tool counts from the real registry: 24 with the defaults, 37 with --enable-writes, 8 with --toolsets data, 41 with every toolset and writes. The full list with descriptions is in docs/TOOLS.md (generated from the registry and checked in CI).

Prompts: audit_ga4_setup, seo_360_audit, portfolio_performance_digest and launch_site_measurement (the guided flow: plan → your confirmation → apply → DNS verification → sitemap → PageSpeed baseline).

bootstrap_site_measurement

text
bootstrap_site_measurement(site_url="https://example.com", account_id="123456789",                           property_display_name="Example", time_zone="America/Mexico_City",                           currency_code="USD", key_events=["generate_lead"],                           custom_dimensions=[{"parameter_name": "plan_type", "display_name": "Plan type"}])
  • apply=False (default): a plan. Read-only and always registered. It finds the existing property and web stream by the site's domain, the key events and custom dimensions already declared, and the Search Console domain property, and lists what would be created.
  • apply=True: executes the plan. Only works when the server runs with --enable-writes; otherwise it fails before touching anything. Idempotent: it skips what exists, so you can re-run it. Returns a step-by-step report with the measurement ID (G-…) and the DNS TXT token.
  • DNS verification (sc_verify_site_dns) and the sitemap (sc_submit_sitemap) stay explicit follow-up steps: you have to publish the TXT record first.

🔒 Security model

Defaults are safe for a single user on a laptop. Details and threat model: SECURITY.md.

  • Read-only by default. Without --enable-writes (or GA4SEO_ENABLE_WRITES=1), tools that create, update, delete, submit or verify are not registered at all — the model cannot call what does not exist.
  • MCP annotations on every tool: readOnlyHint on reads, destructiveHint on deletes and updates, idempotentHint where repeating is harmless, openWorldHint everywhere. Clients that honor them can auto-approve reads and ask before writes.
  • Minimum scopes: each Google client requests only the scope of the call it makes; auth-command asks only for the scopes of your toolsets.
  • HTTP transport (--transport streamable-http): binds to 127.0.0.1, DNS-rebinding protection on, CORS off unless MCP_CORS_ORIGINS, and an optional bearer token MCP_AUTH_TOKEN (401 without it). Listening on 0.0.0.0 without a token prints a warning, and LAN clients need MCP_ALLOWED_HOSTS or the rebinding protection answers 421.
  • Secrets (DataForSEO, Ads developer token, PageSpeed key) come only from environment variables or a chmod 600 file, and are never logged or returned in errors.

⚙️ Configuration

VariableDefaultDescription
GOOGLE_APPLICATION_CREDENTIALS—Service account key file. Unset = Application Default Credentials from gcloud.
GA4SEO_TOOLSETSadmin,data,gsc,psiSame as --toolsets.
GA4SEO_ENABLE_WRITES01 = same as --enable-writes.
PAGESPEED_API_KEY—Recommended: the anonymous PageSpeed quota is shared and often exhausted (429).
DATAFORSEO_LOGIN, DATAFORSEO_PASSWORD—dataforseo toolset.
GOOGLE_ADS_DEVELOPER_TOKEN—ads toolset, or ~/.config/ga4-seo-mcp/dev-token with chmod 600.
GOOGLE_ADS_LOGIN_CUSTOMER_ID—Only when operating through a manager (MCC) account.
MCP_TRANSPORTstdiostdio, streamable-http or sse.
MCP_HOST / MCP_PORT127.0.0.1 / 8000HTTP bind address and port. A specific non-loopback address is added to the allowed Host headers; 0.0.0.0 is not, so set MCP_ALLOWED_HOSTS for LAN clients.
MCP_AUTH_TOKEN—Require Authorization: Bearer <token> on every HTTP request.
MCP_CORS_ORIGINS—Comma-separated exact origins for a browser client. Never *.
MCP_ALLOWED_HOSTS—Comma-separated host/IP values clients use (e.g. 192.168.1.10). Required when binding 0.0.0.0 and connecting over the LAN; DNS-rebinding protection rejects everything else with 421.

Copy .env.example as a starting point.


🔌 Connect your client

Every client launches the server over stdio. Add --enable-writes to args only for the session where you actually want to set up a site.

Claude Code

bash
claude mcp add ga4-seo -- uvx ga4-seo-mcp# with options:claude mcp add ga4-seo -e PAGESPEED_API_KEY=your-key -- uvx ga4-seo-mcp --toolsets admin,data,gsc,psi

Claude Desktop (claude_desktop_config.json) and Cursor (~/.cursor/mcp.json)

json
{  "mcpServers": {    "ga4-seo": {      "command": "uvx",      "args": ["ga4-seo-mcp"],      "env": { "PAGESPEED_API_KEY": "your-key" }    }  }}

VS Code (.vscode/mcp.json)

json
{  "servers": {    "ga4-seo": {      "type": "stdio",      "command": "uvx",      "args": ["ga4-seo-mcp"]    }  }}

Docker (stdio). Mount your credentials file read-only — the ADC file from gcloud or a service account key — and run as your own user so the container can read a 0600 file:

bash
docker run -i --rm --user "$(id -u):$(id -g)" \  -v ~/.config/gcloud/application_default_credentials.json:/creds/credentials.json:ro \  -e GOOGLE_APPLICATION_CREDENTIALS=/creds/credentials.json \  ghcr.io/germaniu/ga4-seo-mcp

HTTP (several clients sharing one server):

bash
MCP_AUTH_TOKEN=$(openssl rand -hex 32) uvx ga4-seo-mcp --transport streamable-http# endpoint: http://127.0.0.1:8000/mcp  (send Authorization: Bearer <token>)

🩹 Troubleshooting

SymptomCause and fix
This app is blocked / access_denied during gcloud ... logingcloud's built-in client cannot request Analytics or Search Console scopes. Use your own OAuth client (--client-id-file) and add yourself as a Test User of its consent screen — docs/AUTH.md.
cloud-platform scope is required but not requestedUse the command printed by ga4-seo-mcp auth-command: gcloud needs cloud-platform in the list. The server itself never requests it.
403 ... API has not been used in projectEnable the Google Analytics Admin API, Google Analytics Data API and Search Console API in your quota project, then gcloud auth application-default set-quota-project my-gcp-project.
403 ... does not have sufficient permissions for this propertyAdd your user (or the service account email) to the GA4 property or Search Console site.
ga4-seo-mcp doctor says the token is missing scopesYou logged in before enabling a toolset or writes. Re-run the auth-command output.
Write tools do not show upStart the server with --enable-writes. It is off by default on purpose.
PageSpeed Insights error 429The anonymous quota is shared by everyone. Create an API key and set PAGESPEED_API_KEY.
Keyword Planner volumes look rounded (10, 30, 170, 210…)Google Ads reports bucketed volume for accounts without active spend. Use the dataforseo toolset for exact numbers.
A deleted GA4 property still appearsdelete_property is a soft delete: Google keeps it in the trash for 35 days (list_properties(include_deleted=True)).
HTTP answers 421 Invalid Host headerDNS-rebinding protection. Connect with the host you bound (127.0.0.1/localhost, or the MCP_HOST address).
HTTP answers 401Send Authorization: Bearer $MCP_AUTH_TOKEN.

📚 Documentation

🧪 Development

bash
uv sync --all-extrasuv run ruff check . && uv run ruff format --check . && uv run pytestuv run python scripts/smoke_stdio.py --expect 24   # real stdio initialize + tools/list

📄 License

MIT. Not affiliated with or endorsed by Google. Google Analytics, Search Console and PageSpeed Insights are trademarks of Google LLC.

来源:README.md,提交 7c23c3c

工具

24

list_account_summaries

List every GA4 account you can access, with a summary of its properties. Start here to find the account_id and property_id the other tools need.

无需输入参数。

list_properties

List the GA4 properties under an account. Args: account_id: numeric account ID or 'accounts/123456789'. include_deleted: also return properties in the trash (soft-deleted, kept 35 days).

输入参数account_id必填include_deleted

get_property

Get the full settings of a GA4 property (time zone, currency, industry, type).

输入参数property_id必填

list_data_streams

List the data streams (web, iOS, Android) of a GA4 property. Web streams include their measurement ID (G-XXXXXXX) and default URI.

输入参数property_id必填

get_data_stream

Get one data stream, including the measurement ID of a web stream.

输入参数stream_id必填property_id必填

list_key_events

List the key events (formerly conversions) declared on a GA4 property.

输入参数property_id必填

list_custom_dimensions

List the custom dimensions declared on a GA4 property, with their scope.

输入参数property_id必填

bootstrap_site_measurement

Plan, and optionally apply, the full measurement setup of a website. With apply=False (default) nothing is changed: it detects what already exists for the site (GA4 property and web stream matched by the site's domain, key events, custom dimensions, Search Console domain property) and returns the steps that would run. Show this plan to the user and get explicit confirmation before calling apply=True. With apply=True (requires the server to run with --enable-writes) it creates only the missing pieces, skipping what exists, so it is safe to re-run. It returns a step-by-step report with the GA4 measurement ID (G-...) and the DNS TXT token for Search Console. DNS verification and sitemap submission stay manual follow-up steps (sc_verify_site_dns, sc_submit_sitemap) because the TXT record must be published first. Args: site_url: the site, e.g. 'https://example.com'. account_id: GA4 account that owns (or will own) the property; see list_account_summaries. property_display_name: name for a new property; also used to find an existing one. time_zone: IANA time zone for a new property, e.g. 'America/Mexico_City'. currency_code: ISO 4217 currency for a new property, e.g. 'USD'. key_events: event names to mark as key events, e.g. ['generate_lead']. custom_dimensions: parameters to register as custom dimensions. apply: False = plan only (default); True = execute the plan.

输入参数applysite_url必填time_zone必填account_id必填key_eventscurrency_code必填custom_dimensionsproperty_display_name必填

run_report

Run a flexible GA4 report. Args: property_id: numeric ID or 'properties/123456789'. metrics: e.g. ['sessions', 'activeUsers', 'keyEvents']. Catalog: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema#metrics dimensions: optional, e.g. ['date', 'sessionSource', 'pagePath']. Catalog: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema#dimensions date_start: 'YYYY-MM-DD', 'today', 'yesterday' or 'NdaysAgo' (e.g. '28daysAgo'). date_end: same formats as date_start. limit: maximum rows (default 25). order_by_metric: sort by this metric, e.g. 'sessions'. order_desc: sort descending (default True). Returns the dimension and metric names, the date range, row_count and the rows.

输入参数limitmetrics必填date_enddate_startdimensionsorder_descproperty_id必填order_by_metric

run_realtime_report

Realtime report for the last 30 minutes. Useful to confirm that a new event fires in production right after a deploy. Args: metrics: default ['activeUsers']; 'eventCount' also works. dimensions: default ['eventName']; also 'unifiedScreenName', 'country', 'deviceCategory'.

输入参数limitmetricsdimensionsproperty_id必填

top_pages

Top pages by sessions, with active users, bounce rate and average session duration.

输入参数limitdate_enddate_startproperty_id必填

events_summary

Count of every event that fired, to audit what is actually being measured. Compare it with list_key_events to find key events that never fire.

输入参数limitdate_enddate_startproperty_id必填

traffic_sources

Top traffic sources (source / medium) with sessions, active users and conversions.

输入参数limitdate_enddate_startproperty_id必填

conversions_summary

Conversions and total users per event name: a summary of the active key events.

输入参数date_enddate_startproperty_id必填

web_vitals_summary

Core Web Vitals reported by your own site as GA4 events. Requires the site to send web-vitals events with the parameters `web_vital_metric` and `web_vital_rating`, both registered as event-scoped custom dimensions. For Google's field data use psi_field_data_only instead.

输入参数date_enddate_startproperty_id必填

audit_portfolio

Summary metrics for several GA4 properties in one call. Returns sessions, active users, conversions, bounce rate and average session duration per property, plus the properties that failed and why. Args: property_ids: e.g. ['123456789', '987654321'].

输入参数date_enddate_startproperty_ids必填

sc_list_sites

List the Search Console sites you can access. Each entry has `siteUrl` ('sc-domain:example.com' for domain properties or a URL prefix like 'https://example.com/') and `permissionLevel` ('siteOwner', 'siteFullUser', 'siteRestrictedUser' or 'siteUnverifiedUser').

无需输入参数。

sc_top_queries

Top search queries with clicks, impressions, CTR (%) and average position. Args: site_url: 'sc-domain:example.com' or 'https://example.com/', exactly as in sc_list_sites. date_start: 'YYYY-MM-DD'. date_end: 'YYYY-MM-DD'. Search Console data lags 2-3 days. limit: rows to return (max 25000). country: optional ISO 3166-1 alpha-3 code to filter by, e.g. 'mex' or 'usa'.

输入参数limitcountrydate_end必填site_url必填date_start必填

sc_page_performance

Top pages in Google Search by clicks, with impressions, CTR (%) and average position.

输入参数limitdate_end必填site_url必填date_start必填

sc_query_breakdown_by_page

Which search queries bring traffic to one specific page. Useful to decide which keywords to strengthen in that page's content.

输入参数limitdate_end必填page_url必填site_url必填date_start必填

sc_list_sitemaps

List the sitemaps submitted for a Search Console site, with errors and warnings.

输入参数site_url必填

psi_audit

Run a PageSpeed Insights audit (Lighthouse lab test + CrUX field data) on a public URL. Takes 30-90 seconds. Without PAGESPEED_API_KEY the anonymous quota is small and Google may answer 429; set the key for regular use. Args: url: absolute public URL, e.g. 'https://example.com/'. strategy: 'mobile' (default) or 'desktop'. categories: subset of ['performance', 'accessibility', 'best-practices', 'seo']. Default: all four. Returns 0-100 category scores, lab Core Web Vitals (LCP, FCP, CLS, TBT, SI, TTFB) and, when Chrome has enough real-user traffic, CrUX p75 field data for the URL and its origin.

输入参数url必填strategycategories

psi_field_data_only

Only the CrUX field data (real Chrome users, p75 over 28 days) for a URL and its origin. PageSpeed Insights still runs a performance-only Lighthouse pass, so expect 15-40 seconds. `overall_category` is FAST, AVERAGE or SLOW; it is null when the page has too little traffic.

输入参数url必填strategy

版本历史

2
  1. v0.1.2最新Oct 24, 2026
  2. v0.1.0Oct 19, 2026

评分

已满足适用检查项的 90%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分
  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分