A self-hosted MCP server for Google Analytics · vanrossum.dev    

       vanrossum.dev 

 Article

A self-hosted MCP server for Google Analytics
=============================================

 ![](https://vanrossum.dev/images/jeffrey-portrait.webp) By Jeffrey van Rossum

  vanrossum.dev  

  [      vanrossum.dev ](https://vanrossum.dev)                      

  [ ← Writing ](https://vanrossum.dev/posts)   [ ← Writing ](https://vanrossum.dev/posts) [ What it can do ](#what-it-can-do) [ Deploy the Worker ](#deploy-the-worker) [ Set up Google Cloud ](#set-up-google-cloud) [ Connect Claude, Cursor or Grok Bot ](#connect-claude-cursor-or-grok-bot) [ A few things worth knowing ](#a-few-things-worth-knowing) [ Try it ](#try-it) 

I wanted my AI tools to answer questions about my own traffic and search performance. Not from a screenshot of the Google Analytics dashboard, and not through a shared service holding my Google tokens.

So I built a small self-hosted MCP server that runs on a Cloudflare Worker and talks to Google Analytics 4 and Search Console.

The repo is [google-analytics-mcp](https://github.com/jeffreyvr/google-analytics-mcp). You deploy your own Worker and your own Google OAuth client. There is no shared hosted service, and for personal use you don't need Google app verification.

What it can do
--------------

Once it's connected, you can ask how a property performed last week, which pages dropped, or how a site is doing in Search Console.

It gives you read-only tools for:

- GA4 accounts and properties
- Historical and realtime reports
- Available dimensions and metrics
- Search Console sites, performance, sitemaps, and URL inspection

Reports come back compact. When something goes wrong, the errors try to say the useful thing: API not enabled, no access to the property, a bad field name, or a dead refresh token.

Deploy the Worker
-----------------

The easiest path is the Deploy to Cloudflare button in the [README](https://github.com/jeffreyvr/google-analytics-mcp). It creates the KV namespace and asks for a Google client id and secret. You can leave those blank for a minute and fill them in once Google Cloud is ready.

Or do it with Wrangler:

```bash
npm install
npx wrangler login
npx wrangler kv namespace create OAUTH_KV

```

Put the new namespace id into `wrangler.jsonc`, then:

```bash
npx wrangler secret put GOOGLE_CLIENT_ID
npx wrangler secret put GOOGLE_CLIENT_SECRET
npx wrangler deploy

```

Open your Worker URL. The home page walks through the rest and shows the exact redirect URI to copy.

Set up Google Cloud
-------------------

You need one Google Cloud project for everything.

1. [Create a Web application OAuth client](https://console.cloud.google.com/auth/clients).
2. Paste the redirect URI from your Worker home page, for example `https://your-worker.workers.dev/callback`.
3. Add these scopes under Data access: `openid`, `https://www.googleapis.com/auth/userinfo.email`, `https://www.googleapis.com/auth/analytics.readonly`, and `https://www.googleapis.com/auth/webmasters.readonly`.
4. Enable the [Analytics Data API](https://console.cloud.google.com/apis/library/analyticsdata.googleapis.com), the [Analytics Admin API](https://console.cloud.google.com/apis/library/analyticsadmin.googleapis.com), and the [Search Console API](https://console.cloud.google.com/apis/library/searchconsole.googleapis.com).
5. Set the consent screen to **In production**. Testing mode expires refresh tokens after 7 days.

Google may show an "unverified app" warning for these scopes. That is normal for a private app. Choose Advanced and continue. If you are on Google Workspace, you can use Internal instead.

Then put the client id and secret on the Worker if you have not already, and reload `/`. Both secrets should say Set.

Connect Claude, Cursor or Grok Bot
----------------------------------

Copy the MCP URL from the setup page: `https://your-worker.workers.dev/mcp`.

- **Claude:** add a custom connector with that URL
- **Cursor:** add a remote MCP / HTTPS server with that URL
- **Grok Bot:** add a custom connector, choose Remote HTTPS, paste the URL, and leave the Client ID blank

The first connection opens the Worker's consent page, then Google. Sign in with an account that can view the GA4 property and the Search Console property.

A few things worth knowing
--------------------------

The MCP URL is public, but a caller still needs a bearer token from your Worker, issued only after the consent screen and Google sign-in. Google refresh tokens stay encrypted in KV. The MCP client never receives them.

Still, leave the Worker URL private if you don't want other people to start a connection. You can also set `HOSTED_DOMAIN` so only Google accounts on one Workspace domain are allowed.

It's unofficial, and not affiliated with Google.

Try it
------

The source, the deploy button and the full setup notes are on GitHub:

→ **[github.com/jeffreyvr/google-analytics-mcp](https://github.com/jeffreyvr/google-analytics-mcp)**

Self-hosted only for now. If you'd rather not host it yourself, [let me know](/contact).

Questions welcome on [X](https://x.com/jeffreyrossum).

  ![](https://vanrossum.dev/images/jeffrey-portrait.webp) Jeffrey van Rossum [@jeffreyrossum](https://x.com/jeffreyrossum) 

 share [𝕏](https://twitter.com/intent/tweet?url=https%3A%2F%2Fvanrossum.dev%2Fposts%2Fa-self-hosted-mcp-server-for-google-analytics&text=A+self-hosted+MCP+server+for+Google+Analytics) [WhatsApp](https://wa.me/?text=A+self-hosted+MCP+server+for+Google+Analytics+https%3A%2F%2Fvanrossum.dev%2Fposts%2Fa-self-hosted-mcp-server-for-google-analytics) [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fvanrossum.dev%2Fposts%2Fa-self-hosted-mcp-server-for-google-analytics) 

   © 2026 Jeffrey van Rossum 

  vanrossum.dev vanrossum.dev
