SEO MCP server
README.md
# SEO MCP server
**Want this set up for your business?** [AI WORKLABS](https://aiworklabs.co.uk/) can host this server, connect your Google accounts, and send you [monthly SEO reports](https://aiworklabs.co.uk/seo-ai-visibility/).
Remote [Model Context Protocol](https://modelcontextprotocol.io) server that exposes **Google Search Console**, **GA4**, **PageSpeed Insights**, **sitemap crawl**, **404 discovery**, and **markdown SEO reports** as MCP tools for Claude, Cursor, and other MCP clients.
## What it does
- Pull Search Console queries, pages, period-over-period movers, URL inspection, and UK local/location visibility.
- Pull GA4 landing pages and conversion-style events (configurable event names).
- Run PageSpeed (mobile/desktop) and crawl your sitemap for on-page SEO signals.
- Reconstruct likely 404 URLs from GSC + sitemap data, live-check them, and suggest redirects.
- Generate a single markdown report (optionally commit to a GitHub repo branch).
Auth is a long random secret in the URL path (`https://<host>/{MCP_SECRET}/mcp`). Health check: `GET /health` → `{ ok, version, commit }`.
## MCP tools
| Tool | Description |
| --- | --- |
| `list_sites` | Configured sites, integration flags (GSC / GA4 / local), and Google service account email |
| `gsc_top_queries` | Top queries (clicks, impressions, CTR, position) |
| `gsc_page_performance` | Top pages in Search Console |
| `gsc_compare_periods` | Query movers vs previous period |
| `gsc_local_visibility` | GSC by town/area (GB): summary, queries, `/locations/*` pages, flags (markdown) |
| `gsc_inspect_url` | URL indexing / coverage inspection |
| `ga4_landing_pages` | Sessions, engagement, key events by landing page |
| `ga4_conversions` | Phone + form events by page |
| `pagespeed` | Core Web Vitals + Lighthouse performance score |
| `crawl_site` | Sitemap crawl: links, titles, meta, H1, alt, schema, redirects |
| `find_404s` | GSC + sitemap URL reconstruction, live 404 checks, redirect suggestions |
| `generate_seo_report` | Runs the suite and returns markdown (optional GitHub commit) |
Most tools accept an optional `site` argument (see `list_sites` for ids). Phase 2 stubs (off by default): `gbp_performance`, `bing_backlinks` when `ENABLE_GBP_PERFORMANCE` / `ENABLE_BING_BACKLINKS` are `true`.
## Quick start (local)
```bash
git clone https://github.com/hyperwebpages/seo-mcp.git
cd seo-mcp
cp .env.example .env
# Edit .env — at minimum MCP_SECRET, GSC_SITE_URL, GOOGLE_SERVICE_ACCOUNT_JSON
npm install
npm run dev
curl -s http://127.0.0.1:3100/health
```
Run tests (Google APIs mocked):
```bash
npm test
npm run build
```
## Google API setup
1. Create a [Google Cloud project](https://console.cloud.google.com/).
2. Enable APIs: **Google Search Console API**, **Google Analytics Data API**, **PageSpeed Insights API** (recommended).
3. **IAM → Service accounts → Create** and download a JSON key. Minify to one line: `jq -c . key.json`.
4. Set `GOOGLE_SERVICE_ACCOUNT_JSON=` in `.env` (never commit this).
5. In [Search Console](https://search.google.com/search-console), add the service account email (`client_email` in the JSON) as a user on each property you query.
6. In GA4 **Admin → Property access management**, add the same email as **Viewer** (or Analyst). Set each property id in `GA4_PROPERTY_ID` / site config.
7. Optional: create a PageSpeed API key and set `PAGESPEED_API_KEY`.
On startup the server logs the service account email. `list_sites` returns it as `googleServiceAccountEmail`.
## Site configuration
**Option A — single site (env vars):** `GSC_SITE_URL`, `SITE_ORIGIN`, `GA4_PROPERTY_ID`, `SITE_DISPLAY_NAME`, `SITE_LOCATION`, etc. Default site id is `default` unless you set `DEFAULT_SITE_ID`. See `.env.example`.
**Option B — multiple sites (JSON):** set `SEO_SITES_JSON` to an array of site objects, or point `SEO_SITES_FILE` at a file (for example `config/seo-sites.json` copied from `config/seo-sites.example.json`). Optional `DEFAULT_SITE_ID` must match an entry id.
When `SEO_SITES_JSON` or `SEO_SITES_FILE` is set, it replaces the single-site env block.
## Connect Claude or Cursor
Use **Streamable HTTP** transport with your public URL:
```text
https://<SEO_MCP_HOST>/<MCP_SECRET>/mcp
```
Replace placeholders with your hostname and secret. Do not share the secret in screenshots or issue reports.
## HTTP endpoints
| Method | Path | Purpose |
| --- | --- | --- |
| `GET` | `/health` | Liveness |
| `POST/GET/DELETE` | `/{MCP_SECRET}/mcp` | MCP Streamable HTTP |
| `POST` | `/{MCP_SECRET}/run-report` | Batch report trigger (`days`, optional `site`, `commitToGithub`) |
## Docker / self-hosted deploy
1. Copy `.env.example` → `.env` on the server and fill in production values.
2. Build and run:
```bash
docker compose up -d --build
curl -s "https://${SEO_MCP_HOST}/health"
```
`docker-compose.yml` includes Traefik labels; set `SEO_MCP_HOST` in `.env`. Adjust labels if you use another reverse proxy.
Optional: configure `SEO_MCP_DEPLOY_DIR` and SSH credentials, then use `./scripts/deploy.sh` to pull `main` and rebuild on a VPS. See `AGENTS.md` for agent-oriented notes.
GitHub Actions: **CI** runs `npm test` and `npm run build` on every push. An optional **Deploy to VPS** workflow is `workflow_dispatch` only when you configure repository secrets.
## Environment variables
See `.env.example` for the full list. Never commit `.env`, service account JSON files, or tokens.
## Report output
`generate_seo_report` (and `/run-report`) produce markdown with summary metrics, query movers, and actionable tasks (page URL, suggested Next.js path, priority). With `GITHUB_TOKEN` and `WEBSITE_REPO`, reports can commit to `WEBSITE_REPORT_BRANCH` (default `seo-reports`).
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md). MIT licensed — Copyright © 2026 AI WORKLABS Ltd.This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues