
ga4-gsc-mcp
com.kkvlabs/ga4-gsc-mcp
Google Analytics 4 (GA4), Google Search Console (GSC) and Bing Webmaster Tools. Local, read only.
Documentation
GA4 + Google Search Console + Bing MCP server (Google Analytics 4, GSC and Bing Webmaster Tools for Claude, Cursor, Claude Code)
Hosted version: don't want to set up Google Cloud, or need it in claude.ai or ChatGPT on the web? Site Insights by KKV Labs is the same idea as a hosted connector: one Google sign-in, many sites, free for 1 site and 20 lookups a day. This repo stays free, MIT and fully usable on its own.
An open-source Model Context Protocol server that lets Claude Desktop, Claude Code, Cursor and any other MCP client answer questions from Google Analytics 4 (GA4), Google Search Console (GSC) and Bing Webmaster Tools in one place. It runs on your machine with your own credentials, asks only for read-only scopes, and joins the sources so you can ask "why did my traffic drop?" or "which platform sent fewer visitors?" in plain English.
- 36 read-only tools, three sources. GA4 sessions, key events and revenue next to GSC clicks, impressions, CTR and position, plus Bing clicks, crawl issues, backlinks and keyword data.
- Answers, not raw dumps. Why traffic dropped (with Google ranking updates in the window), keyword cannibalization, content decay, top movers, unusual days, AI Overview suspects, quick wins with a CTR benchmark, which platform dropped, attribution and funnels are calculated for you.
- Honest dates. Search Console data lags 2 to 3 days, so default ranges end on the last settled day. Every result carries a receipt with the property, dates and source.
- Local and read-only.
analytics.readonlyandwebmasters.readonlyonly. Calls go only to Google's APIs and Bing's API, over HTTPS, from your machine. No telemetry. - Raw access when you need it.
run_ga4_report, batch, pivot and realtime reports, andsearch_console_queryexpose the full GA4 Data API and Search Analytics API. Tables can come back as CSV.
Contents
- Quick start
- First 5 questions to ask
- Credentials
- Example questions
- Tools
- Bing Webmaster Tools
- Configuration
- Security
- Troubleshooting
- How it compares
- Need many sites, no Google Cloud setup, claude.ai or ChatGPT on the web?
- Development
Quick start
You need Node.js 20 or newer and Google credentials (3 options below). Try it first with built-in fake data, no credentials needed:
GA4_GSC_MCP_DEMO=1 npx -y ga4-gsc-mcp check
Then let the setup wizard do the rest. It opens each Google Cloud page in order, signs you in once, checks what your credentials can see, and (if you say yes) adds the server to Claude Desktop and Cursor, keeping a backup of each config file:
npx -y ga4-gsc-mcp setup
Already have credentials? Check them:
npx -y ga4-gsc-mcp check
One-click installs: the Cursor and VS Code buttons at the top add the server to those editors. For Claude Desktop, download ga4-gsc-mcp.mcpb and open it (Settings > Extensions). The buttons only add the server; you still sign in once with setup or auth (or pick a service account key in the extension settings).
Claude Code
- Set up credentials.
- Add the server:
With a service account, pass the key path:claude mcp add ga4-gsc --scope user -- npx -y ga4-gsc-mcpclaude mcp add ga4-gsc --scope user -e GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json -- npx -y ga4-gsc-mcp - Run
/mcpin Claude Code to confirmga4-gscis connected, then ask "How is example.com doing this month?"
Claude Desktop
- Set up credentials.
- Open Settings > Developer > Edit Config (
~/Library/Application Support/Claude/claude_desktop_config.jsonon macOS,%APPDATA%\Claude\claude_desktop_config.jsonon Windows) and add:
Leave out the{ "mcpServers": { "ga4-gsc": { "command": "npx", "args": ["-y", "ga4-gsc-mcp"], "env": { "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/key.json" } } } }envblock if you use gcloud orga4-gsc-mcp authcredentials. - Restart Claude Desktop. The tools appear under the tools icon in a new chat.
Cursor
- Set up credentials.
- Add this to
~/.cursor/mcp.json(all projects) or.cursor/mcp.json(one project):{ "mcpServers": { "ga4-gsc": { "command": "npx", "args": ["-y", "ga4-gsc-mcp"] } } } - Open Cursor Settings > MCP, check that
ga4-gscshows a green dot, then ask in Agent mode.
Any other MCP client (Windsurf, VS Code, Cline, Zed, Goose) works the same way: the command is npx -y ga4-gsc-mcp over stdio.
First 5 questions to ask
- "How is example.com doing compared with last month?"
- "Why did my Google traffic drop last month? Was there a Google update?"
- "Give me 10 SEO quick wins with the page to fix for each."
- "Which platform sent fewer visitors this month: Google, Bing, ChatGPT, social or email?"
- "How many visits came from ChatGPT, Perplexity and Claude in the last 90 days, and where did they land?"
More in Example questions.
Credentials
The server looks for credentials in this order and uses the first it finds:
GOOGLE_APPLICATION_CREDENTIALSpointing to a service account key (or any ADC JSON file)- A login saved by
npx ga4-gsc-mcp auth - gcloud Application Default Credentials
Whichever you pick, first enable three APIs in a Google Cloud project you own (console, or with gcloud):
gcloud services enable analyticsadmin.googleapis.com analyticsdata.googleapis.com searchconsole.googleapis.com --project=YOUR_PROJECT_ID
These are the Google Analytics Admin API (lists properties), the Google Analytics Data API (reports) and the Google Search Console API (search analytics and URL inspection).
Option A: one-time browser login (recommended)
This is the only option where the saved token holds nothing but the two read-only scopes.
- In Google Cloud > Google Auth Platform (APIs & Services > OAuth consent screen), configure the consent screen as External and add your Google account under Test users (or Internal on Google Workspace).
- Go to Clients (APIs & Services > Credentials) > Create client > Desktop app, then download the JSON.
- Sign in once:
Your browser opens, you approve read-only access, and a refresh token is saved tonpx -y ga4-gsc-mcp auth --client-secret ~/Downloads/client_secret_XXXX.json~/.config/ga4-gsc-mcp/oauth-token.json(%APPDATA%\ga4-gsc-mcpon Windows) with file mode 600.
While the consent screen is in Testing, Google expires refresh tokens after 7 days. Switch the publishing status to In production to keep the login (unverified apps for your own use show a warning screen you can click through), or run auth again.
Option B: gcloud Application Default Credentials
gcloud's built-in OAuth client is meant for Google Cloud APIs. For other Google APIs such as Analytics and Search Console, Google's gcloud docs say to create your own OAuth client and pass it with --client-id-file (steps 1 and 2 of Option A):
gcloud auth application-default login \
--scopes=https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/webmasters.readonly,https://www.googleapis.com/auth/cloud-platform \
--client-id-file=/path/to/client_secret_XXXX.json
With --client-id-file, the project that owns the OAuth client is used for quota. No environment variables are needed afterwards.
Be aware: gcloud requires the cloud-platform scope in this command, so the Application Default Credentials token it saves also has full access to your Google Cloud projects, and any other tool on your machine that uses ADC gets that access too. This server only calls the read-only Analytics and Search Console APIs with it, but if you do not already use ADC, prefer Option A.
Option C: service account (servers, CI, shared machines)
gcloud iam service-accounts create ga4-gsc-mcp --project=YOUR_PROJECT_ID
gcloud iam service-accounts keys create ~/ga4-gsc-mcp-key.json \
--iam-account=ga4-gsc-mcp@YOUR_PROJECT_ID.iam.gserviceaccount.com
Then give the service account's email (client_email in the key file) access to your data:
- GA4: Admin > Property access management > add the email with the Viewer role.
- Search Console: Settings > Users and permissions > Add user > the email with Restricted permission (enough for the reports this server reads; do not give it Owner). If URL inspection or sitemaps answer with a permission error, raise it to Full, which is still read-only through this server.
Lock the key file down so only your user can read it, then set GOOGLE_APPLICATION_CREDENTIALS=/path/to/ga4-gsc-mcp-key.json in your MCP client config:
chmod 600 ~/ga4-gsc-mcp-key.json
Keep the key file out of git and backups you share. Some organizations block key creation with the iam.disableServiceAccountKeyCreation policy; use Option A or B there.
Example questions
- "How is example.com doing compared with last month?"
- "What are my top 20 Google searches this quarter, and which ones lost clicks?"
- "Which pages get search clicks but few key events in GA4?"
- "Give me 10 SEO quick wins for example.com with the page to fix."
- "What pages lost the most traffic compared with the same period last year?"
- "How many visits came from ChatGPT, Perplexity, Claude, Gemini and Copilot in the last 90 days, and where did they land?"
- "Sessions by country and device for October." (uses
run_ga4_report) - "Search Console clicks by day for /pricing in the last 28 days." (uses
search_console_query) - "Is https://example.com/blog/new-post indexed?"
- "Why did my Google traffic drop last month? Was there a Google update?"
- "Which of my pages compete for the same keywords?"
- "Which pages have been slowly losing clicks for three months?"
- "Which platform sent fewer visitors this month: Google, Bing, ChatGPT, social or email?"
- "Which channels bring the most conversions and revenue, first touch?"
- "Where do visitors drop off between the pricing page and the sign-up event?"
- "How fast is my home page on mobile? What are the Core Web Vitals?"
- "Top Bing searches and crawl errors for example.com." (needs a Bing key)
Tools
All tools are read-only (readOnlyHint: true) and return JSON that starts with a receipt: the GA4 property, the Search Console site, the exact dates, the comparison range and any caveats.
Overview and search (GSC)
| Tool | Answers | Sources |
|---|---|---|
list_properties | Which GA4 properties and Search Console sites can these credentials see? | GA4 Admin, GSC |
site_overview | How is my site doing? Sessions, users, key events, engagement, clicks, impressions, CTR, position, each with change, plus bot or spam flags | GA4 + GSC |
top_queries | Which Google searches bring clicks? Filter by page, text, or brand vs non-brand. JSON or CSV | GSC |
top_pages | Which pages get the most search clicks and visits? GSC pages joined with GA4 landing pages. JSON or CSV | GSC + GA4 |
quick_wins | What should I improve first? Positions 4 to 20 with real impressions, ranked by extra clicks, plus your CTR by position against a benchmark | GSC |
traffic_drops | What lost traffic? Every page or query with the biggest click (or GA4 session) losses | GSC or GA4 |
why_did_it_drop | Why did Google traffic drop? Change split into impressions and CTR, start date, cause per page and query, index status, Google ranking updates in the window | GSC + GA4 + Search Status Dashboard |
find_cannibalization | Which queries are split between two or more of my pages, and which page to keep? | GSC |
content_decay | Which pages are slowly losing clicks over 3 months? | GSC |
top_movers | What gained or lost most, week on week, month on month or year on year? | GSC + GA4 |
find_anomalies | Which days were unusual spikes or dips, and when did a lasting drop start? | GSC + GA4 |
ai_overview_suspects | Which searches might an AI Overview be taking clicks from? | GSC |
inspect_url | Is this URL indexed? Verdict, coverage, last crawl, canonical, robots.txt | GSC URL Inspection |
inspect_urls | Up to 20 URLs or paths at once, not indexed first, canonical mismatches flagged | GSC URL Inspection |
sitemaps | Which sitemaps has Google got, with errors and warnings? | GSC |
page_speed | Core Web Vitals from real visitors (LCP, INP, CLS), Lighthouse score and top fixes | PageSpeed Insights |
search_console_query | Any Search Console query: by query, page, country, device, date or search appearance, any search type, filters, paging | GSC |
Visitors and conversions (GA4)
| Tool | Answers | Sources |
|---|---|---|
traffic_sources | Where do visitors come from? By channel, source / medium, source, campaign, country, device or landing page, with bot or spam flags | GA4 |
channel_changes | Which platform sent fewer visitors? Google, Bing, each AI assistant, social, email, direct, paid, cross-checked with GSC and Bing clicks | GA4 (+ GSC, Bing) |
attribution | Which channels bring key events and revenue? Session or first-user scope | GA4 |
ai_traffic | How many visits come from ChatGPT, Perplexity, Claude, Gemini, Copilot and others? | GA4 |
ga4_funnel | Where do visitors drop off before a goal? 2 to 10 steps by event or page (beta, Data API v1alpha) | GA4 |
run_ga4_report | Any GA4 report: your own dimensions, metrics, filters, order and paging. JSON or CSV | GA4 |
run_ga4_batch_reports | Up to 5 GA4 reports in one call | GA4 |
run_ga4_pivot_report | A GA4 pivot table | GA4 |
run_ga4_realtime_report | Who is on the site right now? | GA4 realtime |
ga4_metadata | Which dimensions and metrics (including custom ones) can I use? | GA4 |
Bing Webmaster Tools (only when BING_WEBMASTER_API_KEY is set, see below)
| Tool | Answers |
|---|---|
bing_sites | Which sites are in my Bing account? |
bing_overview | Bing clicks, impressions and CTR with change, and the daily numbers |
bing_top_queries / bing_top_pages | Top Bing searches and pages with clicks, impressions, CTR and position |
bing_crawl_issues | 4xx, 5xx, redirects, robots.txt blocks, DNS and timeout errors, and crawl stats |
bing_backlinks | Which pages have inbound links, and who links to one page (with anchor text). Bing's API often returns no link list even when the Backlinks report on the Bing website shows links; the tool then gives Bing's inbound anchor counts and a link to that report |
bing_sitemaps | Submitted sitemaps and feeds with status and URL counts |
bing_url_info | Bing's index details for one URL, or that Bing has no record of it yet |
bing_keyword_research | Weekly Bing search impressions for a keyword and related keywords |
Common inputs: site (a domain such as example.com, a URL, or sc-domain:example.com), ga4_property (optional; found automatically from the GA4 web stream that matches the site), period (last_7_days, last_28_days, last_90_days, last_3_months, last_6_months, last_12_months, last_month) or start_date / end_date, and compare (previous_period, previous_year, none).
Brand vs non-brand: top_queries and quick_wins take brand: "brand" | "non_brand". Terms come from brand_terms, else the BRAND_TERMS environment variable, else the domain name (my-brand.com gives "mybrand" and "my brand").
Large sites: analysis tools page through Search Console up to 100,000 rows per request.
Dates: Search Console data settles about 2 to 3 days late and GA4 about 1 day late, so named periods end 3 days ago for Search Console and combined tools, and 1 day ago for GA4-only tools. Explicit end dates inside the lag window are allowed and flagged in the receipt.
Bing Webmaster Tools
- Sign in to Bing Webmaster Tools and open Settings > API Access.
- Generate an API key. The key belongs to your user, not one site, and is read here only for the read-only methods listed in
src/bing.ts. - Add it to the server's environment, for example in Claude Code:
or in Claude Desktop and Cursor, underclaude mcp add ga4-gsc --scope user -e BING_WEBMASTER_API_KEY=your-key -- npx -y ga4-gsc-mcp"env": { "BING_WEBMASTER_API_KEY": "your-key" }. - Run
npx -y ga4-gsc-mcp checkto see your Bing sites.
Bing keeps about 6 months of history and reports query and page stats by week. Bing sites are matched to your Google sites by domain.
Configuration
| Variable | Purpose |
|---|---|
GOOGLE_APPLICATION_CREDENTIALS | Path to a service account key or other ADC JSON file |
GA4_PROPERTY_ID | Default GA4 property, so you can leave ga4_property out |
GSC_SITE_URL | Default Search Console site, e.g. sc-domain:example.com |
GA4_GSC_MCP_CONFIG_DIR | Where auth saves the refresh token (default ~/.config/ga4-gsc-mcp) |
BING_WEBMASTER_API_KEY | Bing Webmaster Tools API key. Adds the nine bing_ tools |
PAGESPEED_API_KEY | Google API key with the PageSpeed Insights API enabled, for a higher page_speed quota (works without one at low volume) |
BRAND_TERMS | Comma-separated brand terms, e.g. acme,acme widgets,acmee |
GA4_GSC_MCP_DEMO=1 | Use built-in fake data for example.com; no network calls at all |
GA4_GSC_MCP_NO_HINTS=1 | Hide the one-line pointer to the hosted version that auth, check and setup print on stderr (or pass --no-hints). Never shown in tool results |
Commands: ga4-gsc-mcp (start the server on stdio), ga4-gsc-mcp setup (guided, interactive), ga4-gsc-mcp auth --client-secret FILE, ga4-gsc-mcp check, ga4-gsc-mcp --help.
Security
This server reads analytics data you own, so it is built to do as little as possible with it:
- Read-only access. With Option A (
auth) the token holds onlyanalytics.readonlyandwebmasters.readonly. A service account (Option C) gets only the access you grant it in GA4 and Search Console (Viewer and Restricted). gcloud ADC (Option B) also carriescloud-platform, because gcloud requires it; this server still calls only read-only Analytics and Search Console endpoints, but the token itself is broader, so prefer Option A. Bing calls are limited to a fixed list of read (GET) methods; write methods such as URL submission are refused in code before any request. - Fixed destinations. Every request goes through one guard (
src/net.ts): HTTPS only, a fixed allow list of hosts (Google's Analytics and Search Console APIs,www.googleapis.comfor PageSpeed,status.search.google.comfor ranking updates,ssl.bing.com), no redirects, a timeout and a response size cap. Google credentials are sent only to Google API hosts; the Bing key only tossl.bing.com. - No telemetry. Nothing is sent anywhere else, and nothing is stored except the refresh token you create with
auth. - Secrets stay secret. The saved login is written atomically with file mode 600 in a 700 directory, and tightened to 600 if it was loosened. Tokens, API keys and private keys are redacted from every error message and log line.
- Safe sign-in.
authuses a loopback redirect on 127.0.0.1 with PKCE and a random state, ignores any request without that state, and times out after 5 minutes. The browser is opened without a shell (on Windows throughrundll32, so the URL is never parsed bycmd.exe). - Strict inputs. Property IDs must be numeric, sites must be domains, URLs or
sc-domain:properties, dates must beYYYY-MM-DD, GA4 field names must be API names, JSON filters are size capped and row limits are capped.inspect_urlsonly inspects URLs inside the property. - No outbound side channel.
page_speedis the one tool that sends a URL to a Google service outside your account, so it only tests pages on a Search Console (or Bing) site these credentials can see, and it strips the query string and fragment before sending. - Tool output is untrusted text. Answers include text other people control: search queries, backlink anchor text, referrer hostnames, page paths and titles. A query or anchor could contain instructions aimed at your AI assistant. Keep your client's confirmation prompts on for tools that reach other hosts (web fetch, email, file writes), especially in sessions that use this server.
- Safe CSV. Cells that a spreadsheet would run as a formula (
=,+,-,@) are prefixed with a quote. - Pinned dependencies, GitHub Actions pinned by commit SHA,
npm auditin CI, and npm releases published from CI with provenance.
Found a security issue? Please email support@kkvlabs.com rather than opening a public issue.
Troubleshooting
Run npx -y ga4-gsc-mcp check first. It prints which credentials were used and every property and site they can see.
| Error or symptom | Fix |
|---|---|
... API has not been used in project ... or it is disabled | Enable the Google Analytics Admin API, Google Analytics Data API and Google Search Console API in the project your credentials belong to. Wait a minute and retry. |
Request had insufficient authentication scopes / ACCESS_TOKEN_SCOPE_INSUFFICIENT | Your login lacks a scope. Re-run Option A or the Option B command with both analytics.readonly and webmasters.readonly. |
"This app is blocked" during gcloud auth application-default login | gcloud's own client cannot request these scopes. Add --client-id-file with your Desktop OAuth client (Option B). |
Access blocked: ... has not completed the Google verification process | Add your account under Test users on the OAuth consent screen. |
invalid_grant after about a week | The consent screen is in Testing, so the token expired. Publish it to In production or run auth again. |
User does not have sufficient permissions (403) | The account or service account is not a user on that GA4 property or Search Console site. Add client_email as described in Option C. |
No Search Console site matches "..." | Use the exact site from list_properties. Domain properties look like sc-domain:example.com, URL-prefix properties like https://www.example.com/. |
No GA4 property's web stream matches ... | Pass ga4_property (the numeric ID from GA4 Admin > Property details) or set GA4_PROPERTY_ID. |
Claude Desktop shows "Server disconnected" or spawn npx ENOENT | Claude Desktop does not always see your shell's PATH. Use the full path to npx (which npx) as command, and check the log in ~/Library/Logs/Claude/mcp-server-ga4-gsc.log. |
Could not load the default credentials | No credentials were found. Pick Option A, B or C above. |
| Numbers differ from the Search Console UI | The UI includes the last 2 to 3 unsettled days; this server ends on settled days by default. Pass end_date to match the UI exactly. Query and page tables also omit anonymized queries, so they do not sum to the site total. |
quota / 429 errors | GA4 and Search Console have per-project quotas. Use shorter ranges or fewer rows, and retry after a few minutes. URL Inspection allows about 2,000 a day and 600 a minute per site. |
No bing_ tools | Set BING_WEBMASTER_API_KEY and restart your client. check says whether Bing is on. |
Bing refused the API key or this site | Check the key in Bing Webmaster Tools > Settings > API Access and that the site is verified in that account. |
ga4_funnel errors | It uses Google's v1alpha funnel API, which can change. Check step event names with ga4_metadata or run_ga4_report on eventName. |
PageSpeed Insights quota is used up | Set PAGESPEED_API_KEY (a Google Cloud API key with the PageSpeed Insights API enabled). |
How it compares
| ga4-gsc-mcp (this repo) | Google analytics-mcp | mcp-gsc | Site Insights by KKV Labs (hosted) | |
|---|---|---|---|---|
| Google Analytics 4 (GA4) | Yes | Yes | No | Yes |
| Google Search Console (GSC) | Yes | No | Yes | Yes |
| GA4 and GSC joined (pages, overview) | Yes | No | No | Yes |
| Bing Webmaster Tools | Yes (API key) | No | No | Yes |
| Why it dropped, cannibalization, content decay, movers | Yes | No (raw reports) | Some (GSC only) | Yes |
| Attribution, funnels, which platform dropped | Yes | No (raw reports) | No | Yes |
| Core Web Vitals (PageSpeed Insights) | Yes | No | No | Yes |
| Client reports (white-label page) | No | No | No | Yes |
| Many sites in one account | Yes, any your credentials see | Yes | Yes | Yes |
| Runtime | Node.js, npx | Python, pipx | Python | Nothing to install |
| Google Cloud project and credentials | You set up | You set up | You set up | Not needed: sign in with Google |
| Works in Claude.ai and ChatGPT on the web | No (local stdio) | No (local stdio) | No (local stdio) | Yes |
| Access | Read-only | Read-only | Read and write (sitemaps) | Read-only |
| Price | Free, MIT | Free, Apache-2.0 | Free, MIT | Free plan: 1 site, 20 lookups a day; paid plans for more |
Corrections welcome: open an issue if a row is out of date.
Need many sites, no Google Cloud setup, claude.ai or ChatGPT on the web?
This repo is the free local edition. Site Insights by KKV Labs is the hosted version, built by the same team:
- No Google Cloud project, no Node process. Add one link as a connector and sign in with Google.
- Works where local servers cannot: claude.ai and ChatGPT on the web, and on phones.
- Many sites and Google accounts in one place, with labels, plus client reports with your own logo, a weekly email and drop alerts.
- Free plan: 1 site and 20 lookups a day. Paid plans add more sites.
Both are read-only. Pick whichever fits; this repo will stay MIT and fully usable on its own.
Development
git clone https://github.com/kkvlabs/ga4-gsc-mcp.git
cd ga4-gsc-mcp
npm install
npm run check # lint, typecheck, unit tests, then build and a stdio smoke test
npm testruns the vitest suite against mocked Google APIs (no network).npm run smokebuilds, starts the server over stdio in demo mode with the MCP SDK client, lists the tools and calls all 36.GA4_GSC_MCP_DEMO=1 npx @modelcontextprotocol/inspector node dist/index.jsopens the MCP Inspector against demo data.
See CONTRIBUTING.md for guidelines and CHANGELOG.md for releases.
Feedback or a feature request? Email support@kkvlabs.com or open an issue.
License
MIT © KKV Labs LLC. Google Analytics, Google Search Console and Google Cloud are trademarks of Google LLC. This project is not affiliated with or endorsed by Google.
ga4-gsc-mcpnpm install ga4-gsc-mcp