GSC Data Get
Fetch Google Search Console data for any verified property and export formatted
Excel reports (e.g. blog EN/CN comparison tables). Fully agent-agnostic: every
capability is exposed as a plain CLI (scripts/gsc.py), so it runs the same in
WorkBuddy, Codex, or a bare terminal — no MCP client needed.
Core promise: the user only creates a Google OAuth credential and clicks
"Allow" in the browser. Everything else — uv/Python dependency auto-install,
renaming/replacing the file, wiring the environment, authorizing, verifying,
even GA4 setup — is automated. On a fresh machine just run bootstrap and
confirm the browser prompts.
Read AGENTS.md for the agent-agnostic command reference, and
references/gotchas.md before producing any report (anchor variants,
cn-page detection, CTR anomaly checks).
Step 1 — User hands over a credential JSON
The user sends client_secret_xxx.apps.googleusercontent.com.json (any name).
Run one command:
python <skill_dir>/scripts/gsc.py bootstrap "<path-to-json>" # GSC only
python <skill_dir>/scripts/gsc.py bootstrap "<path-to-json>" --with-ga4 # GSC + GA4
That single command: auto-installs uv if missing → creates the work dir →
installs the proxy launcher → writes the host MCP config (only when a WorkBuddy
host is present) → validates and installs the credential as client_secrets.json
(auto-backup of any previous file) → triggers browser OAuth → prints the visible
properties → with --with-ga4: GA4 authorization (one more "Allow" click) →
property auto-selection (or prints a pick list) → merges the ga4Server config.
Success marker: [login] OK — authorized, N properties visible;
with --with-ga4 also GA4 就绪(属性 <ID>) or a property pick list (exit 10).
Variants:
- JSON pasted as text →
gsc.py import-secrets --text '<json>'thengsc.py login - Credential already installed on this machine → just
gsc.py login - User has no credential yet → give them
references/manual-guide.md(the only manual part: Google Cloud Console → enable Search Console API → create a 桌面应用 / Desktop app OAuth client → download JSON)
Reject web-type clients with guidance: the OAuth flow only works with desktop
clients. Service-account JSON is accepted, but the service account email must be
added as a user on each GSC property.
Step 2 — Fetch data
python <skill_dir>/scripts/gsc.py doctor # optional: env + proxy diagnosis
python <skill_dir>/scripts/gsc.py sites # exact site_url strings + permission
python <skill_dir>/scripts/gsc.py pages \
--site https://example.com/ --start 2025-07-10 --end 2026-10-31 \
--prefix en/blog/ --out pages.json
pagesreturns de-anchored URLs merged across#fragmentvariants (impressions/clicks summed, position impression-weighted) — never reimplement this naively.--prefixwithout a leading slash (en/blog/): Git Bash rewrites leading-slash args into install paths and silently returns 0 rows.- Default range for "总数据/全历史": earliest GSC-allowed date → today; always state the actual range in the report.
- Other dimensions (query / country / device) or indexing/sitemap checks:
gsc.py query <tool_name> '<json args>', list tools withgsc.py tools.
Step 3 — Build the Excel report
Compose a spec JSON, then gsc.py xlsx spec.json.
Column conventions (established with the user):
- Blog EN/CN: 标题 / EN(曝光、点击、CTR、平均排名) / CN(路径+同四项) / EN+CN 合计
- Identify cn pages by parsing each EN page's
hreflangalternates over the user's proxy (GET, not HEAD) — never guess/cn/paths, never trust a manually annotated list. - Add 上线天数 / 日均曝光 when publish dates matter (from JSON-LD datePublished).
- Include a 说明 sheet: date range, merge rules, caveats.
- Deliver the file to the user.
Design notes (why it is built this way)
- Proxy shim: hosts rewrite proxy env vars, and google-api-python-client's
httplib2 only reads env at construction → every call times out.
proxy_launcher.pyreplaceshttplib2.Httpwith a requests-backed shim and pins the route, auto-detecting the local proxy port (GSC_PROXYoverrides). - Dependency bootstrap: every script re-runs itself through
uv run --with mcp-search-console --with openpyxl --with requestswhen libs are missing, sopython gsc.py ...works on a fresh machine. A child process is used instead ofos.execvpe(process replacement segfaults on Windows). - Token reuse:
fetch_pages.pyandgsc.py loginboth go throughgsc_server.get_gsc_service(), so the CLI and the MCP share one cached token inuser_config_dir("mcp-gsc")/token.json— the user authorizes once. - Portable paths: work dir =
$GSC_HOME→~/.workbuddy/gsc(existing WorkBuddy installs) →~/.gsc-data-get(other hosts). - GA4 without gcloud:
ga4_login.pyruns the same browser OAuth with the existing client_secrets.json and writes an ADC-formatga4_adc.json(GOOGLE_APPLICATION_CREDENTIALS) — the officialgoogle-analytics-mcponly needs that file.setup_env.pyinstallsga4_launcher.py(same proxy shim, entryga4_mcp.server:main) and merges aga4ServerMCP entry once the ADC exists; property comes fromga4_property_id.txtor$GA4_PROPERTY_ID.
Resources
scripts/
gsc.py— unified CLI (bootstrap / doctor / setup / import-secrets / login / ga4-login / sites / pages / query / tools / xlsx)gsc_paths.py— path resolution, uvx discovery, dependency bootstrapimport_secrets.py— validate + install a credential file under the right namecheck_env.py— environment probe (JSON output, exit codes 0/1/2)setup_env.py— dirs, launcher install, MCP config merge (WorkBuddy only)proxy_patch.py— shared proxy shim (requests-backed httplib2 + Session pin)proxy_launcher.py— GSC server bootstrap via proxy_patchga4_launcher.py— GA4 server bootstrap via proxy_patchga4_login.py— gcloud-free GA4 ADC credential generation + verifygsc_query.py— call any GSC MCP tool over stdiofetch_pages.py— page-level analytics with anchor-variant mergingbuild_xlsx.py— spec-driven Excel writer
references/
manual-guide.md— the single manual step (credential creation) + migrationgotchas.md— data pitfalls; read before any report

微信扫一扫