Skip to main content
Glama
gsc-mcp
by afiqiqmal
README.md
# gsc-mcp

MCP server for [Google Search Console](https://search.google.com/search-console). Lets Claude (or any MCP client) query search performance, inspect URLs and manage sitemaps.

## Tools

| Tool | What it does |
| --- | --- |
| `list_sites` | Properties the account can access |
| `search_analytics` | Clicks, impressions, CTR, position by query/page/country/device/date (~16 months, ~2-3 day lag). Options: `dateGrain` week/month; `pageGroup` host, pathPrefix or regex (e.g. all of `/moe-school/` as one row); `top` N plus an (others) row; `brandRegex` for a brand vs non-brand split; `compact` output; `exportFormat` csv/json writes every row to a file; `dataState: "all"` for fresh data. With the query dimension it also returns the share of hidden (anonymized) queries |
| `inspect_url` | Index status, coverage, canonical, mobile usability, rich results (2,000/day per property) |
| `compare_periods` | Two date ranges (MoM, YoY; previous period defaults to the same length right before) with totals, deltas and per-query/page changes, marking new and lost rows. Supports `pageGroup` |
| `batch_inspect_urls` | Inspect up to 10 URLs at once: verdict, coverage, last crawl, canonical mismatch |
| `quick_wins` | Queries (or query+page) at position 4–20 with many impressions, optional max CTR |
| `cannibalization` | Queries where 2+ of your pages compete, with each page's impression share (top 5 pages per query by default) |
| `ctr_anomalies` | Pages or queries whose CTR is far below the site's own CTR for that position, sorted by missed clicks |
| `lost_pages` | Pages that lost their impressions since the previous period, fetched live and flagged when now 4xx, 5xx, redirecting or unreachable |
| `list_sitemaps` | Submitted sitemaps with errors, warnings and submitted counts. Google no longer fills the indexed count, so it is left out |
| `unsubmitted_sitemaps` | Sitemaps declared in robots.txt (and their children) that aren't submitted in Search Console |
| `sitemap_urls` | Read sitemap XML (Search Console and robots.txt sitemaps, following indexes): list or filter URLs, check if URLs are listed |
| `sitemap_index_audit` | Estimate indexing at scale: inspect a random sample of sitemap URLs (or pages with impressions) and total by coverage state, with a 95% range |
| `check_pages_live` | Fetch live pages (optionally as Googlebot): status, redirects, X-Robots-Tag, meta robots, canonical, title, meta description and length, H1 count, word count, internal links, JSON-LD types and validity, lang, hreflang (optionally checks return links), robots.txt verdict |
| `crawl_site` | Crawl internal links with page and depth limits: status codes, broken links and a page linking to them, fewest incoming links, noindex/canonicalized pages, sitemap URLs the crawl never reached (likely orphans) |
| `page_speed` | Core Web Vitals from PageSpeed Insights: real-user (CrUX) LCP, INP, CLS, FCP, TTFB for the URL and origin, plus the Lighthouse score |
| `submit_sitemap` | Submit or resubmit a sitemap (hidden when `GSC_READONLY=true`) |
| `delete_sitemap` | Remove a sitemap from Search Console (hidden when `GSC_READONLY=true`) |

Results over 100,000 characters are written to a JSON file (in `GSC_EXPORT_DIR`, default the system temp folder `gsc-mcp-exports`) and the reply gives its path.

Tools that fetch pages or sitemaps only fetch URLs inside the property (its domain and subdomains, or its URL prefix's origin).

Requesting indexing is not available: Google offers no API for it.

## Setup

About 10 minutes, once. You need a Google account with access to the Search Console properties.

### 1. Create a Google Cloud project

1. Open [console.cloud.google.com](https://console.cloud.google.com/).
2. Click the project picker at the top → **New project** → name it (e.g. `gsc-mcp`) → **Create**. Make sure it is selected.

### 2. Enable the Search Console API

1. Go to **APIs & Services → Library**.
2. Search **Google Search Console API** → open it → **Enable**.
3. Optional, for `page_speed`: also enable **PageSpeed Insights API**.

### 3. Create a service account and key

1. Go to **IAM & Admin → Service Accounts** → **Create service account**.
2. Name it (e.g. `gsc-mcp`) → **Create and continue** → skip the optional role and user steps → **Done**.
3. Click the new service account → **Keys** tab → **Add key → Create new key** → **JSON** → **Create**. A `.json` file downloads.
4. Copy the service account's email (`gsc-mcp@<project>.iam.gserviceaccount.com`); you need it in step 5.

If key creation is blocked, your Google Workspace has the `iam.disableServiceAccountKeyCreation` policy; use a personal Google Cloud project or ask your admin.

### 4. Move the key to the default location

```bash
mkdir -p ~/.config/gsc-mcp
mv ~/Downloads/<downloaded-file>.json ~/.config/gsc-mcp/key.json
chmod 600 ~/.config/gsc-mcp/key.json
```

Keep it out of any git repo. Anyone with this file can read the properties you grant it.

### 5. Give the service account access in Search Console

For **each** property:

1. Open [Search Console](https://search.google.com/search-console) → pick the property.
2. **Settings → Users and permissions → Add user**.
3. Paste the service account email. Permission: **Full** to submit/delete sitemaps, **Restricted** for read-only.

### 6. Add to Claude Code

```bash
claude mcp add gsc -- npx -y --allow-git=all github:afiqiqmal/gsc-mcp
```

npm 12+ blocks git installs by default, hence `--allow-git=all`. Pin a release with `github:afiqiqmal/gsc-mcp#v0.4.0`.

### 7. Check it works

Start Claude Code, run `/mcp` and confirm `gsc` is connected, then ask *"list my Search Console sites"*. An empty list means step 5 was missed for that property.

### Other MCP clients

```json
{
  "mcpServers": {
    "gsc": {
      "command": "npx",
      "args": ["-y", "--allow-git=all", "github:afiqiqmal/gsc-mcp"]
    }
  }
}
```

## Environment

All optional.

| Variable | Description |
| --- | --- |
| `GSC_KEY_FILE` | Key path, if not at `~/.config/gsc-mcp/key.json` |
| `GOOGLE_APPLICATION_CREDENTIALS` | Used when neither `GSC_KEY_FILE` nor the default file exists |
| `GSC_READONLY` | `true` uses the read-only scope and hides write tools |
| `GSC_EXPORT_DIR` | Folder for exported files (default: system temp folder `gsc-mcp-exports`) |
| `PAGESPEED_API_KEY` | API key for `page_speed`. Without it, `page_speed` uses the service account's project: enable the **PageSpeed Insights API** there |

Key lookup order: `GSC_KEY_FILE` → `~/.config/gsc-mcp/key.json` (or `$XDG_CONFIG_HOME/gsc-mcp/key.json`) → `GOOGLE_APPLICATION_CREDENTIALS`.

## Development

```bash
npm install
npm run build   # commit dist/ — npx installs from GitHub use it directly
npm test
```

## License

MIT