gsc-ga4-mcp
Enables Claude Code to read Google Search Console and GA4 data locally with read-only access, and provides combined SEO analysis tools for comparing datasets and identifying opportunities.
README
gsc-ga4-mcp
A small local MCP server that gives Claude Code read-only access to Google Search Console and GA4, plus a few tools that cross the two datasets.
The problem
SEO work in an AI assistant usually means exporting CSVs from Search Console, exporting more CSVs from GA4, pasting both into a chat, and repeating that every time you want a fresh number. The two datasets also never line up on their own: Search Console knows impressions, clicks and CTR; GA4 knows sessions, engagement and conversions. Answering "which pages get traffic but waste it" means joining them by URL by hand.
Google publishes an official MCP server for Analytics, but it does not cover Search Console. Community Search Console servers exist, but if the data belongs to clients, running a small wrapper you can read end to end beats trusting someone else's.
This server calls the official Google APIs directly, with read-only scopes, from your own machine.
What it does
Twenty MCP tools over stdio.
Search Console
| Tool | Purpose |
|---|---|
gsc_list_sites |
Sites visible to the current credentials |
gsc_search_analytics |
Raw searchAnalytics.query with your own dimensions and filters |
gsc_top_queries |
Top queries for a date range |
gsc_top_pages |
Top pages for a date range |
gsc_query_page_matrix |
Query × page breakdown |
gsc_url_inspection |
Index status of a single URL |
GA4
| Tool | Purpose |
|---|---|
ga4_list_properties |
Accounts and property summaries |
ga4_run_report |
Raw runReport with your own dimensions and metrics |
ga4_top_pages |
Pages by sessions/views |
ga4_traffic_sources |
Sessions by source/medium |
ga4_landing_pages |
Landing pages with engagement metrics |
ga4_events |
Event counts |
ga4_realtime |
Last 30 minutes of activity |
Combined analysis
| Tool | Purpose |
|---|---|
seo_opportunity_report |
One pass over both APIs, grouped into quick wins and rewrites |
compare_gsc_ga4_pages |
Joins GSC pages to GA4 pages by URL path |
find_high_impression_low_ctr_pages |
Ranking but not earning the click |
find_pages_with_clicks_but_low_engagement |
Earning the click, losing the visitor |
content_refresh_candidates |
Pages whose performance has decayed |
Config
project_mappings and project_lookup read a local file that maps a project or client name to its GSC property and GA4 property, so you can say "cross GSC and GA4 for example.com" instead of remembering properties/123456789.
Stack
Node.js + TypeScript. @modelcontextprotocol/sdk for the server, google-auth-library for auth, zod for tool schemas. No database, no hosted backend, no telemetry — the process runs locally and Claude Code launches it over stdio.
Scopes are read-only and that is the whole permission surface:
https://www.googleapis.com/auth/webmasters.readonlyhttps://www.googleapis.com/auth/analytics.readonly
Credentials live outside the repo, by default in ~/.config/gsc-ga4-mcp/.
Setup
1. Install
git clone https://github.com/YOUR_USER/gsc-ga4-mcp.git
cd gsc-ga4-mcp
npm install
npm run build
mkdir -p ~/.config/gsc-ga4-mcp
2. Enable the APIs
In Google Cloud Console, create or pick a project, then enable:
- Google Search Console API
- Google Analytics Data API
- Google Analytics Admin API
3. Create OAuth credentials
Under APIs & Services → OAuth consent screen, configure the consent screen. Use External if the properties you manage are not all in one Google Workspace, and add your own email as a test user while the app is in testing.
Under APIs & Services → Credentials, create an OAuth client ID of type Desktop app, download the JSON, and save it as ~/.config/gsc-ga4-mcp/oauth-client.json.
For client work where you want permissions isolated per account, use a service account instead and add its email to each GSC and GA4 property with read access. Set GOOGLE_AUTH_MODE=service_account and point GOOGLE_SERVICE_ACCOUNT_KEY_FILE at the key.
4. Configure
cp .env.example .env
cp projects.example.json ~/.config/gsc-ga4-mcp/projects.json
Paths in .env must be absolute — ~ is not expanded.
GOOGLE_AUTH_MODE=oauth
GOOGLE_OAUTH_CREDENTIALS_FILE=/Users/YOUR_USER/.config/gsc-ga4-mcp/oauth-client.json
GOOGLE_TOKEN_PATH=/Users/YOUR_USER/.config/gsc-ga4-mcp/token.json
GOOGLE_OAUTH_REDIRECT_URI=http://127.0.0.1:3000/oauth2callback
PROJECTS_CONFIG=/Users/YOUR_USER/.config/gsc-ga4-mcp/projects.json
MCP_DEFAULT_GSC_SITE=sc-domain:example.com
MCP_DEFAULT_GA4_PROPERTY=properties/123456789
MAX_ROWS=25000
Project mappings (projects.json):
{
"projects": [
{
"name": "My Site",
"client": "Internal",
"domain": "example.com",
"gscSiteUrl": "sc-domain:example.com",
"ga4Property": "properties/123456789",
"notes": "Replace with the real GA4 property ID."
}
]
}
5. Authorise
npm run auth
The script starts a loopback listener on 127.0.0.1:3000 and prints a Google URL. Open it, approve the read-only scopes, and the token is written to GOOGLE_TOKEN_PATH.
6. Register with Claude Code
claude mcp add google-seo -- node /ABSOLUTE/PATH/TO/gsc-ga4-mcp/dist/index.js
claude mcp list
Or check a .mcp.json into the project where you want the tools (see .mcp.example.json):
{
"mcpServers": {
"google-seo": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/gsc-ga4-mcp/dist/index.js"],
"env": {
"GOOGLE_AUTH_MODE": "oauth",
"GOOGLE_OAUTH_CREDENTIALS_FILE": "/Users/YOUR_USER/.config/gsc-ga4-mcp/oauth-client.json",
"GOOGLE_TOKEN_PATH": "/Users/YOUR_USER/.config/gsc-ga4-mcp/token.json",
"PROJECTS_CONFIG": "/Users/YOUR_USER/.config/gsc-ga4-mcp/projects.json",
"MCP_DEFAULT_GSC_SITE": "sc-domain:example.com",
"MCP_DEFAULT_GA4_PROPERTY": "properties/123456789"
}
}
}
}
Use the CLI registration when you would rather keep paths and property defaults out of a repo.
Usage with Claude Code
Ask in plain language; Claude picks the tools.
Use gsc_list_sites and ga4_list_properties. Give me a table of the GSC sites
and GA4 properties I can reach.
Analyse organic traffic for sc-domain:example.com over the last 90 days using
gsc_top_queries and gsc_top_pages.
Cross GSC and GA4 for example.com over the last 90 days. Find pages with high
impressions and low CTR, and rank the opportunities by likely impact.
Run seo_opportunity_report and group the output into quick wins, pages that
need a rewrite, and pages that miss search intent.
Inspect https://www.example.com/page/ with gsc_url_inspection and tell me
whether Google has it indexed.
Operating notes
- Keep
.env,token.json,projects.jsonand any service-account key out of version control. The shipped.gitignorealready covers them. - Client analytics data is confidential. Do not paste full outputs into tools the client has not approved.
- Revoke the token or the service account when an engagement ends.
MAX_ROWScaps response size. Lower it if replies get unwieldy.
Troubleshooting
- Claude Code does not see the tools. Run
claude mcp list, then/mcpinside Claude Code. - OAuth token errors. Re-run
npm run authand confirmGOOGLE_TOKEN_PATHis an absolute path. access_denied. Add your email as a test user on the OAuth consent screen while the app is in testing.- A domain is missing from GSC. The credentials need access to that exact property —
sc-domain:example.comandhttps://www.example.com/are different properties. - A GA4 property is missing. The user or service account needs at least Viewer on the account or property.
gsc_url_inspectionfails.inspectionUrlmust sit insidesiteUrl, and URL-prefix properties must end with/.- Invalid GA4 metrics. Use the official GA4 dimension and metric names;
runReportrejects anything else.
References
- Claude Code MCP documentation
- Model Context Protocol
- Search Console API
- GA4 Data API
- Google Analytics Admin API
- Google OAuth scopes
Licence
MIT. See LICENSE.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。