Repository avatar
Monitoring
v0.3.0
active

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)

npm version CI License: MIT Node 20+ MCP Read-only

Install in Cursor Install in VS Code Claude Desktop extension

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.readonly and webmasters.readonly only. 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, and search_console_query expose the full GA4 Data API and Search Analytics API. Tables can come back as CSV.

Contents

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

  1. Set up credentials.
  2. Add the server:
    claude mcp add ga4-gsc --scope user -- npx -y ga4-gsc-mcp
    
    With a service account, pass the key path: claude mcp add ga4-gsc --scope user -e GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json -- npx -y ga4-gsc-mcp
  3. Run /mcp in Claude Code to confirm ga4-gsc is connected, then ask "How is example.com doing this month?"

Claude Desktop

  1. Set up credentials.
  2. Open Settings > Developer > Edit Config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS, %APPDATA%\Claude\claude_desktop_config.json on Windows) and add:
    {
      "mcpServers": {
        "ga4-gsc": {
          "command": "npx",
          "args": ["-y", "ga4-gsc-mcp"],
          "env": {
            "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/key.json"
          }
        }
      }
    }
    
    Leave out the env block if you use gcloud or ga4-gsc-mcp auth credentials.
  3. Restart Claude Desktop. The tools appear under the tools icon in a new chat.

Cursor

  1. Set up credentials.
  2. Add this to ~/.cursor/mcp.json (all projects) or .cursor/mcp.json (one project):
    {
      "mcpServers": {
        "ga4-gsc": {
          "command": "npx",
          "args": ["-y", "ga4-gsc-mcp"]
        }
      }
    }
    
  3. Open Cursor Settings > MCP, check that ga4-gsc shows 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

  1. "How is example.com doing compared with last month?"
  2. "Why did my Google traffic drop last month? Was there a Google update?"
  3. "Give me 10 SEO quick wins with the page to fix for each."
  4. "Which platform sent fewer visitors this month: Google, Bing, ChatGPT, social or email?"
  5. "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:

  1. GOOGLE_APPLICATION_CREDENTIALS pointing to a service account key (or any ADC JSON file)
  2. A login saved by npx ga4-gsc-mcp auth
  3. 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.

  1. 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).
  2. Go to Clients (APIs & Services > Credentials) > Create client > Desktop app, then download the JSON.
  3. Sign in once:
    npx -y ga4-gsc-mcp auth --client-secret ~/Downloads/client_secret_XXXX.json
    
    Your browser opens, you approve read-only access, and a refresh token is saved to ~/.config/ga4-gsc-mcp/oauth-token.json (%APPDATA%\ga4-gsc-mcp on 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)

ToolAnswersSources
list_propertiesWhich GA4 properties and Search Console sites can these credentials see?GA4 Admin, GSC
site_overviewHow is my site doing? Sessions, users, key events, engagement, clicks, impressions, CTR, position, each with change, plus bot or spam flagsGA4 + GSC
top_queriesWhich Google searches bring clicks? Filter by page, text, or brand vs non-brand. JSON or CSVGSC
top_pagesWhich pages get the most search clicks and visits? GSC pages joined with GA4 landing pages. JSON or CSVGSC + GA4
quick_winsWhat should I improve first? Positions 4 to 20 with real impressions, ranked by extra clicks, plus your CTR by position against a benchmarkGSC
traffic_dropsWhat lost traffic? Every page or query with the biggest click (or GA4 session) lossesGSC or GA4
why_did_it_dropWhy did Google traffic drop? Change split into impressions and CTR, start date, cause per page and query, index status, Google ranking updates in the windowGSC + GA4 + Search Status Dashboard
find_cannibalizationWhich queries are split between two or more of my pages, and which page to keep?GSC
content_decayWhich pages are slowly losing clicks over 3 months?GSC
top_moversWhat gained or lost most, week on week, month on month or year on year?GSC + GA4
find_anomaliesWhich days were unusual spikes or dips, and when did a lasting drop start?GSC + GA4
ai_overview_suspectsWhich searches might an AI Overview be taking clicks from?GSC
inspect_urlIs this URL indexed? Verdict, coverage, last crawl, canonical, robots.txtGSC URL Inspection
inspect_urlsUp to 20 URLs or paths at once, not indexed first, canonical mismatches flaggedGSC URL Inspection
sitemapsWhich sitemaps has Google got, with errors and warnings?GSC
page_speedCore Web Vitals from real visitors (LCP, INP, CLS), Lighthouse score and top fixesPageSpeed Insights
search_console_queryAny Search Console query: by query, page, country, device, date or search appearance, any search type, filters, pagingGSC

Visitors and conversions (GA4)

ToolAnswersSources
traffic_sourcesWhere do visitors come from? By channel, source / medium, source, campaign, country, device or landing page, with bot or spam flagsGA4
channel_changesWhich platform sent fewer visitors? Google, Bing, each AI assistant, social, email, direct, paid, cross-checked with GSC and Bing clicksGA4 (+ GSC, Bing)
attributionWhich channels bring key events and revenue? Session or first-user scopeGA4
ai_trafficHow many visits come from ChatGPT, Perplexity, Claude, Gemini, Copilot and others?GA4
ga4_funnelWhere do visitors drop off before a goal? 2 to 10 steps by event or page (beta, Data API v1alpha)GA4
run_ga4_reportAny GA4 report: your own dimensions, metrics, filters, order and paging. JSON or CSVGA4
run_ga4_batch_reportsUp to 5 GA4 reports in one callGA4
run_ga4_pivot_reportA GA4 pivot tableGA4
run_ga4_realtime_reportWho is on the site right now?GA4 realtime
ga4_metadataWhich dimensions and metrics (including custom ones) can I use?GA4

Bing Webmaster Tools (only when BING_WEBMASTER_API_KEY is set, see below)

ToolAnswers
bing_sitesWhich sites are in my Bing account?
bing_overviewBing clicks, impressions and CTR with change, and the daily numbers
bing_top_queries / bing_top_pagesTop Bing searches and pages with clicks, impressions, CTR and position
bing_crawl_issues4xx, 5xx, redirects, robots.txt blocks, DNS and timeout errors, and crawl stats
bing_backlinksWhich 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_sitemapsSubmitted sitemaps and feeds with status and URL counts
bing_url_infoBing's index details for one URL, or that Bing has no record of it yet
bing_keyword_researchWeekly 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

  1. Sign in to Bing Webmaster Tools and open Settings > API Access.
  2. 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.
  3. Add it to the server's environment, for example in Claude Code:
    claude mcp add ga4-gsc --scope user -e BING_WEBMASTER_API_KEY=your-key -- npx -y ga4-gsc-mcp
    
    or in Claude Desktop and Cursor, under "env": { "BING_WEBMASTER_API_KEY": "your-key" }.
  4. Run npx -y ga4-gsc-mcp check to 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

VariablePurpose
GOOGLE_APPLICATION_CREDENTIALSPath to a service account key or other ADC JSON file
GA4_PROPERTY_IDDefault GA4 property, so you can leave ga4_property out
GSC_SITE_URLDefault Search Console site, e.g. sc-domain:example.com
GA4_GSC_MCP_CONFIG_DIRWhere auth saves the refresh token (default ~/.config/ga4-gsc-mcp)
BING_WEBMASTER_API_KEYBing Webmaster Tools API key. Adds the nine bing_ tools
PAGESPEED_API_KEYGoogle API key with the PageSpeed Insights API enabled, for a higher page_speed quota (works without one at low volume)
BRAND_TERMSComma-separated brand terms, e.g. acme,acme widgets,acmee
GA4_GSC_MCP_DEMO=1Use built-in fake data for example.com; no network calls at all
GA4_GSC_MCP_NO_HINTS=1Hide 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 only analytics.readonly and webmasters.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 carries cloud-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.com for PageSpeed, status.search.google.com for 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 to ssl.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. auth uses 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 through rundll32, so the URL is never parsed by cmd.exe).
  • Strict inputs. Property IDs must be numeric, sites must be domains, URLs or sc-domain: properties, dates must be YYYY-MM-DD, GA4 field names must be API names, JSON filters are size capped and row limits are capped. inspect_urls only inspects URLs inside the property.
  • No outbound side channel. page_speed is 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 audit in 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 symptomFix
... API has not been used in project ... or it is disabledEnable 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_INSUFFICIENTYour 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 logingcloud'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 processAdd your account under Test users on the OAuth consent screen.
invalid_grant after about a weekThe 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 ENOENTClaude 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 credentialsNo credentials were found. Pick Option A, B or C above.
Numbers differ from the Search Console UIThe 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 errorsGA4 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_ toolsSet BING_WEBMASTER_API_KEY and restart your client. check says whether Bing is on.
Bing refused the API key or this siteCheck the key in Bing Webmaster Tools > Settings > API Access and that the site is verified in that account.
ga4_funnel errorsIt 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 upSet PAGESPEED_API_KEY (a Google Cloud API key with the PageSpeed Insights API enabled).

How it compares

ga4-gsc-mcp (this repo)Google analytics-mcpmcp-gscSite Insights by KKV Labs (hosted)
Google Analytics 4 (GA4)YesYesNoYes
Google Search Console (GSC)YesNoYesYes
GA4 and GSC joined (pages, overview)YesNoNoYes
Bing Webmaster ToolsYes (API key)NoNoYes
Why it dropped, cannibalization, content decay, moversYesNo (raw reports)Some (GSC only)Yes
Attribution, funnels, which platform droppedYesNo (raw reports)NoYes
Core Web Vitals (PageSpeed Insights)YesNoNoYes
Client reports (white-label page)NoNoNoYes
Many sites in one accountYes, any your credentials seeYesYesYes
RuntimeNode.js, npxPython, pipxPythonNothing to install
Google Cloud project and credentialsYou set upYou set upYou set upNot needed: sign in with Google
Works in Claude.ai and ChatGPT on the webNo (local stdio)No (local stdio)No (local stdio)Yes
AccessRead-onlyRead-onlyRead and write (sitemaps)Read-only
PriceFree, MITFree, Apache-2.0Free, MITFree 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 test runs the vitest suite against mocked Google APIs (no network).
  • npm run smoke builds, 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.js opens 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.

NPM
ga4-gsc-mcp
Install Command
npm install ga4-gsc-mcp
Runtime: npx