Skip to main content
Glama
gsc-mcp-server

gsc-mcp-server

by SoloDevAbu
README.md
# gsc-mcp-server

**Give your AI coding agent all of your Google Search Console data, then let it fix your site.**

`gsc-mcp-server` is a local [Model Context Protocol](https://modelcontextprotocol.io) server for Claude Code, Cursor, Claude Desktop, Windsurf, Antigravity, Codex and any other MCP client. It gives the agent:

- **All your Search Console data, correctly counted.** Paginated past the 25k-row limit, including fresh data, with property totals, the share of anonymized queries, and a brand / non-brand split.
- **The reports Google's API doesn't have, rebuilt.** A Page Indexing report built from URL Inspection of every URL, canonical-mismatch and duplicate-URL detection, cannibalization, section rollups, and period comparisons.
- **The data Search Console doesn't have at all.** Core Web Vitals (PageSpeed and CrUX), GA4 conversions, Bing Webmaster stats and backlinks, IndexNow submission, and an on-page and internal-link crawler.
- **No data loss.** A local SQLite history that outlives GSC's 16-month window, plus a daily job that snapshots data and writes a full audit.

Then ask your agent things like *"run a full site audit and fix the top issues in this codebase"*.

---

## Contents
- [How it works](#how-it-works)
- [Requirements](#requirements)
- [Setup](#setup)
- [Connect your MCP client](#connect-your-mcp-client)
- [Tools](#tools)
- [Configuration](#configuration)
- [Daily collection (no data loss)](#daily-collection-no-data-loss)
- [Quotas and limits](#quotas-and-limits)
- [Troubleshooting](#troubleshooting)
- [Development](#development)

---

## How it works

```
 MCP client (Claude Code, Cursor, ...)
        │  stdio
        ▼
 gsc-mcp-server ──► Search Console API (analytics, URL Inspection, sitemaps)
        │       ──► PageSpeed Insights · GA4 Data API · Bing Webmaster · IndexNow  (optional)
        │       ──► your site's sitemap + pages (crawler)
        ▼
 ~/.gsc-mcp/gsc.db   local SQLite: inspections, quota counter, history, crawl results
```

- **Auth:** a Google Cloud **service account** that you add as a user on your Search Console property. Nothing leaves your machine except calls to these APIs.
- **Caching:** URL Inspection is limited to about 2,000 calls per day. Every result is cached, so audits are **resumable**: run one again and it only inspects new or stale URLs.
- **Optional integrations** only register their tools when their env vars are set, so the tool list stays clean.

## Requirements
- **Node.js 22.5+** (uses the built-in `node:sqlite`, so no native modules)
- A Google Cloud project and a verified Search Console property

## Setup

### 1. Install and build
```bash
git clone https://github.com/SoloDevAbu/gsc-mcp-server.git
cd gsc-mcp-server
pnpm install        # or: npm install
pnpm build          # or: npm run build
```

### 2. Create a service account
1. In [Google Cloud Console](https://console.cloud.google.com/), create or select a project.
2. **APIs & Services → Library** → enable **Google Search Console API**.
3. **IAM & Admin → Service Accounts → Create service account** (no roles needed) → **Keys → Add key → JSON**. Store the file somewhere safe, outside the repo.

### 3. Give it access to your property
[Search Console](https://search.google.com/search-console) → your property → **Settings → Users and permissions → Add user** → paste the service account's `client_email` from the JSON → permission **Full**.

> **Restricted** permission can read data, but submitting or deleting sitemaps needs **Full**.

### 4. Configure
```bash
cp .env.example .env
```
```dotenv
GOOGLE_APPLICATION_CREDENTIALS="/absolute/path/to/service-account.json"
GSC_DEFAULT_SITE_URL="sc-domain:example.com"   # or "https://www.example.com/" for URL-prefix properties
```
The server reads this `.env` on startup. Values set in your MCP client config take precedence.

### 5. Check it works
```bash
node dist/index.js     # prints "GSC MCP Server running on stdio" on stderr; Ctrl+C to quit
```

## Connect your MCP client

**Claude Code**
```bash
claude mcp add gsc -- node /absolute/path/to/gsc-mcp-server/dist/index.js
```

**Cursor** (`.cursor/mcp.json`), **Claude Desktop** (`claude_desktop_config.json`), **Windsurf / Antigravity** (`mcp_config.json`):
```json
{
  "mcpServers": {
    "gsc": {
      "command": "node",
      "args": ["/absolute/path/to/gsc-mcp-server/dist/index.js"]
    }
  }
}
```
If you'd rather not use `.env`, add `"env": { "GOOGLE_APPLICATION_CREDENTIALS": "...", "GSC_DEFAULT_SITE_URL": "..." }` to that entry. Restart the client after changing keys.

## Tools

### Search Console
| Tool | What it returns |
|---|---|
| `gsc_list_sites` | Properties the service account can access, with permission level |
| `gsc_search_analytics` | Every row (auto-paginated), fresh data, **totals**, **anonymized-query share**, brand split. Dimensions: `query`, `page`, `country`, `device`, `searchAppearance`, `date`, `hour`. Types: `web`, `image`, `video`, `news`, `discover`, `googleNews` |
| `gsc_find_low_ctr_opportunities` | Top-10 rankings whose CTR is below the **expected CTR for their position**, ranked by missed clicks |
| `gsc_find_striking_distance_keywords` | Queries at positions 4–20 with their landing page, clicks they'd gain in the top 3, and other queries on the same page |
| `gsc_inspect_url` | Full URL Inspection: coverage, Google vs declared canonical, sitemaps, crawl info, rich-result items and issues, plus **warnings** |
| `gsc_manage_sitemaps` | List, submit or delete sitemaps |

### Rebuilt reports
| Tool | What it returns |
|---|---|
| `gsc_audit_index_coverage` | **Page Indexing report**: inspects every sitemap URL and page with impressions (cached, resumable, quota-aware). URLs by coverage state, not-indexed, canonical mismatches, rich-result issues, sitemap URLs without impressions, pages missing from the sitemap |
| `gsc_get_coverage_report` | The same report from cache, using no quota |
| `gsc_find_duplicate_urls` | One page under several URLs (http/https, www/apex, `?query`, trailing slash), with fixes |
| `gsc_compare_periods` | Period over period: totals delta, gainers/losers, position movers, new and lost queries or pages |
| `gsc_find_cannibalization` | Queries split across pages, separating URL-variant duplicates from real cannibalization |
| `gsc_section_report` | Performance per section or subdomain (or custom regex groups); sections with zero clicks |
| `gsc_snapshot` | Saves daily `date × query × page` rows and totals to SQLite (first run backfills 16 months) |
| `gsc_history_query` | Reads stored history by date, week, month, query or page |
| `gsc_full_site_audit` | Runs everything and returns **one prioritized action list** |

### Beyond the Search Console API
| Tool | Needs |
|---|---|
| `psi_audit_url`, `cwv_audit_top_pages`: Lighthouse lab plus real-user Core Web Vitals | `PSI_API_KEY` (recommended; the keyless quota is tiny) |
| `site_crawl_audit`: status codes, noindex, canonicals, titles, meta descriptions, H1s, thin content, JSON-LD, orphan and weakly linked pages, links to non-preferred URL variants | nothing |
| `ga4_landing_pages`: sessions, engagement and key events per landing page, joined with GSC clicks | `GA4_PROPERTY_ID` |
| `bing_query_stats`, `bing_page_stats`, `bing_backlinks`, `bing_crawl_issues` | `BING_WEBMASTER_API_KEY`, `BING_SITE_URL` |
| `indexnow_submit`: push URLs to Bing and Yandex (`fromCoverage: true` sends every not-indexed URL) | `INDEXNOW_KEY` |

**No public API offers these:** manual actions, security issues, crawl stats (use your server logs), Google's Links report (use `bing_backlinks`), and an AI Overviews traffic split.

### Example prompts
- *"Run `gsc_audit_index_coverage`, then tell me why pages aren't indexed and fix what's in this repo."*
- *"Use `gsc_find_low_ctr_opportunities` and rewrite the titles and meta descriptions for the top 10 pages."*
- *"Compare the last 28 days to the previous 28 by page. What dropped and why?"*
- *"Run `gsc_full_site_audit` with `includeCrawl: true` and work through the critical actions."*

## Configuration

All variables can go in `.env` or your MCP client's `env` block.

| Variable | Required | Description |
|---|---|---|
| `GOOGLE_APPLICATION_CREDENTIALS` | ✅ | Absolute path to the service account JSON key |
| `GSC_DEFAULT_SITE_URL` | recommended | Default property, e.g. `sc-domain:example.com` |
| `GSC_BRAND_REGEX` | | Brand-query regex. Default: derived from the property domain |
| `GSC_PREFERRED_ORIGIN` | | Canonical origin, e.g. `https://www.example.com`. Default: the https origin with the most impressions |
| `GSC_DATA_DIR` | | Where the SQLite cache lives. Default `~/.gsc-mcp` |
| `GSC_INSPECTION_DAILY_LIMIT` | | Stop inspecting at this many per day. Default `1900` |
| `GSC_INSPECTION_PER_MINUTE` | | Inspection rate. Default `550` |
| `GSC_CTR_CURVE` | | Expected CTR % for positions 1..N, comma-separated |
| `CRAWL_USER_AGENT` | | User-Agent for `site_crawl_audit` |
| `PSI_API_KEY` | | PageSpeed Insights API key |
| `GA4_PROPERTY_ID` | | Numeric GA4 property ID |
| `BING_WEBMASTER_API_KEY`, `BING_SITE_URL` | | Bing Webmaster Tools API |
| `INDEXNOW_KEY`, `INDEXNOW_HOST`, `INDEXNOW_KEY_LOCATION` | | IndexNow |

<details>
<summary><b>How to get the optional keys</b></summary>

- **PageSpeed Insights:** Cloud Console → enable **PageSpeed Insights API** → **Credentials → Create API key** → restrict it to that API.
- **GA4:** Cloud Console → enable **Google Analytics Data API**. In GA4, **Admin → Property access management** → add the service account email as **Viewer**. The property ID is under **Admin → Property details**.
- **Bing:** [Bing Webmaster Tools](https://www.bing.com/webmasters) → *Import from Google Search Console* → **Settings → API access** → generate a key.
- **IndexNow:** generate any 32-character hex key and serve it as plain text at `https://<your-host>/<key>.txt`. On Cloudflare you can instead just turn on **Caching → Crawler Hints**.
</details>

## Daily collection (no data loss)

`dist/daily.js` does three things:
1. Snapshots analytics (web and image) into SQLite.
2. Re-inspects URLs whose cached result is older than 7 days.
3. Writes the full audit to `~/.gsc-mcp/reports/YYYY-MM-DD.json`, adding a crawl on Mondays.

It logs to `~/.gsc-mcp/daily.log`.

**Windows**
```powershell
schtasks /Create /TN "GSC daily" /SC DAILY /ST 09:00 /TR "node C:\path\to\gsc-mcp-server\dist\daily.js" /F
```
**macOS / Linux** (`crontab -e`)
```
0 9 * * * /usr/bin/env node /path/to/gsc-mcp-server/dist/daily.js
```

For a permanent, unlimited copy straight from Google, also turn on **Search Console → Settings → Bulk data export** to BigQuery. Back up `~/.gsc-mcp` (or point `GSC_DATA_DIR` at a synced folder).

## Quotas and limits
- **URL Inspection:** about 2,000 calls per day and 600 per minute per property. Audits stop at `GSC_INSPECTION_DAILY_LIMIT` and continue on the next run. One URL takes about 1 s at concurrency 8.
- **Search Analytics:** 25k rows per request, paginated automatically. Google hides rare queries; responses report that share as `anonymizedImpressionShare`.
- **Data freshness:** `dataState: "all"` (the default) includes the latest, still-provisional days. Use `"final"` for finalized data only.
- **Crawler:** keep concurrency low (default 2). CDNs like Cloudflare rate-limit fast crawlers; those pages are reported separately as `rateLimitedByCdn`.

## Troubleshooting
| Symptom | Fix |
|---|---|
| `has no access to "sc-domain:…"` | Add the service account email to the property (Setup step 3). The error lists the properties it can access. |
| `Permission denied … needs Full` | Change the service account to **Full** in GSC → Users and permissions |
| `User does not have sufficient permission` on GA4 | Add the service account as Viewer in GA4 and enable the Analytics Data API |
| `PageSpeed quota exceeded` | Set `PSI_API_KEY` |
| A tool isn't listed | Its env var isn't set, or the client wasn't restarted |
| Audit stops partway | You hit the daily inspection quota. Run it again tomorrow; nothing is lost. |

## Development
```bash
pnpm dev          # run from source with tsx (watch)
pnpm typecheck
pnpm build
```
Layout: `src/index.ts` (server), `src/tools.ts` (tool registration), `src/schemas.ts` (zod inputs), `src/gsc-client.ts` (auth and raw API), `src/lib/*` (analytics, inspection, coverage, opportunities, history, store, sitemap, URL helpers), `src/lib/external/*` (PageSpeed, GA4, Bing, IndexNow, crawler), `src/daily.ts` (scheduled job).

Issues and PRs are welcome.

## License
[MIT](LICENSE)