Agents and MCP

How to connect Google Analytics to Gemini CLI, step by step.

Short answer: connect your GA4 property to LopeBase with a Google sign-in, run npx lopebase login to sign this computer in, then run gemini mcp add lopebase npx -y lopebase mcp in your project folder. Start gemini, type /mcp to see LopeBase connected, and ask about your traffic. No Google Cloud project, no API key, and no token in settings.json.

Read only. Works on macOS, Linux, and Windows.

Connect Google Analytics to Gemini CLI: the steps

Six steps, about five minutes. Step 2 is the same for every app; the rest is specific to Gemini CLI.

1. Install Gemini CLI

Skip this if gemini --version already prints a version. Gemini CLI needs Node 20 or later (node -v to check). Install it with npm, or with Homebrew on macOS and Linux:

$ npm install -g @google/gemini-cli
$ brew install gemini-cli

Run gemini once and finish its own sign-in before you go on.

2. Connect GA4 to LopeBase

Start free and add your site. Open Connections, choose Google Analytics, and press Connect with Google. Pick the Google account that can see the GA4 property, allow the one read-only permission Google asks for, then pick the property and press Use this property. There is no Google Cloud project, enabled API, or credentials file. The full walkthrough is in Connect Google.

3. Sign this computer in to LopeBase

$ npx lopebase login

It opens LopeBase in your browser and shows a short code. Check that the code matches the one in your terminal and press Connect. The sign-in is saved in ~/.config/lopebase/auth.json, readable only by you, and lasts 30 days. You can revoke it any time under Settings, Agent access.

4. Add LopeBase to Gemini CLI

From your project folder, add LopeBase as an MCP server:

$ gemini mcp add lopebase npx -y lopebase mcp

This writes the server to .gemini/settings.json in the current folder, Gemini CLI's default project scope. To have LopeBase in every folder instead, add --scope user and it goes in ~/.gemini/settings.json:

$ gemini mcp add --scope user lopebase npx -y lopebase mcp

Either way the entry looks like this, and you can paste it under mcpServers by hand if you prefer. It holds no token: npx lopebase mcp reads the sign-in from step 3 each time it starts.

{
  "mcpServers": {
    "lopebase": {
      "command": "npx",
      "args": ["-y", "lopebase", "mcp"]
    }
  }
}

5. Start Gemini CLI and check with /mcp

Run gemini in the same folder and type /mcp. LopeBase should be listed as connected, with its tools under it (get_digest, read_source, and the rest). From your shell, gemini mcp list shows the same status. If Gemini CLI asks whether to trust the folder, trust it: in an untrusted folder it does not connect MCP servers.

6. Ask a test question

Paste a prompt that needs your GA4 numbers. Gemini CLI asks before it runs a tool; allow it.

Use LopeBase to compare this week's traffic with last week's for each of my sites.

Shortcut: npx lopebase on its own runs steps 3 and 4 for you, then starts Gemini CLI with a prompt to finish setting up the project. The same npx -y lopebase mcp command works in Claude, Codex, and Cursor.

Troubleshooting Google Analytics in Gemini CLI

The messages you are most likely to see, and what to do about each.

  • "Please use --scope user to edit settings in the home directory."You ran gemini mcp add in your home folder, which has no project settings. Change to your project folder, or add --scope user.
  • LopeBase shows as disconnected in /mcpFirst check the folder is trusted: run /permissions in Gemini CLI to change it. Then run npx -y lopebase mcp in a terminal yourself to see its error, or start gemini --debug for more detail.
  • "Not signed in. Run: npx lopebase login"This computer has no LopeBase sign-in yet. Run npx lopebase login, then restart Gemini CLI.
  • "LopeBase rejected the saved agent token"The sign-in expired after 30 days or was revoked. Run npx lopebase login again; nothing in settings.json needs to change.
  • Connected, but no GA4 numbersThe GA4 property is not connected in LopeBase yet, or it was connected with a Google account that cannot see it. See Connect Google for "no properties listed" and wrong-account fixes.
  • "MCP server "lopebase" is already configured"It is already in that settings file. To start over, run gemini mcp remove lopebase and add it again.
  • Disconnected on WindowsSome setups cannot start npx directly. Use "command": "cmd" with "args": ["/c", "npx", "-y", "lopebase", "mcp"], which is what npx lopebase registers on Windows.

What it looks like in Gemini CLI

One question, one tool call, and an answer built on your own GA4 numbers.

gemini · lopebase

How did traffic change this week compared with last week, for all my sites?

get_digest

propertythis weeklast weekchange
acme.com18,42016,990+8%
acme.shop6,2107,480−17%
acme.dev3,1053,020+3%

Two sites are steady or up. acme.shop fell 17%. Want me to read its traffic sources and see which channel dropped?

No Google Cloud console

No project, no enabled APIs, no credentials file. Connect with Google in LopeBase covers it.

Every property, one sign in

Compare all your GA4 properties in one answer, with the digest or per property.

Check it with /mcp

Type /mcp in Gemini CLI to see LopeBase and its tools listed.

GA4 prompts that work well in Gemini CLI

Quick checks that fit in a terminal between other work.

Week over week

Compare this week's traffic with last week's for every site.

One table across properties.

get_digestweb_analytics

Find the dropped channel

acme.shop traffic fell. Which channel lost the most visitors?

Narrow a drop to its source.

traffic_sources

Today's top pages

What were the ten most viewed pages in the last 7 days?

A quick look before you write or ship.

top_paths

Goal check

List the goal events and how many people triggered each in the last 7 days.

Make sure tracking still works after a deploy.

goal_events

What Gemini CLI can read from GA4

Seven datasets per GA4 property. Breakdowns cover the last 28 days and the trend up to 90. Pass any event as a goal to count conversions.

  • web_analyticsPageviews for 7 and 28 days, plus weekly and monthly users.pageviews_7d · pageviews_28d · wau · mau
  • daily_pageviewsPageviews and visitors per day.day · pageviews · visitors
  • top_pathsThe most viewed pages over the last 7 days.url · views · visitors
  • goal_eventsEvents that may count as a conversion, now and before.event · people_28d · people_prev_28d · people_7d
  • traffic_sourcesVisitors and sessions per channel. Add a goal for conversions.source · visitors · sessions · converters
  • landing_pagesVisitors and bounce rate per landing page.path · visitors · converters · bounce_rate
  • devicesVisitors per device. Add a goal for conversions.device · visitors · converters

More on each dataset: Google Analytics MCP. Connecting in the console: the GA4 connector. Running several sites: Google Analytics for multiple websites. The same setup in other assistants: ChatGPT, Claude, Codex, and Cursor.

Other ways to get GA4 into Gemini CLI

LopeBase is not the only route. Here is how it compares with the usual one.

TopicGoogle's Analytics MCP serverLopeBase
SetupPython and pipx, a Google Cloud project, two Analytics APIs, local credentials, and an entry in settings.json.npx lopebase and Connect with Google.
CredentialsA credentials path and project ID in your settings.Kept by LopeBase, encrypted.
FlexibilityAny GA4 report you describe, including custom dimensions.Seven shaped datasets, with goals built in.
Other dataGA4 only.Search Console, Bing, PostHog, Stripe, and uptime too.
Best whenYou already work in Google Cloud and need custom reports.You want GA4 in Gemini CLI in a few minutes.

Looking at Google's own Google Analytics MCP server? See how it compares with LopeBase. New to all of this? Ask AI about your website traffic covers the basics.

Google's server is described from its own README, checked October 2026. It is labeled experimental there, and its README covers Gemini CLI setup.

GA4 and Gemini CLI questions

Something else? Contact us.

How do I connect Google Analytics to Gemini CLI?

Connect your GA4 property to LopeBase with Connect with Google, run npx lopebase login to sign this computer in, then run gemini mcp add lopebase npx -y lopebase mcp in your project folder. Start gemini and type /mcp to check that LopeBase is connected.

Where is Gemini CLI's settings.json?

Project settings are in .gemini/settings.json inside the project folder, and user settings are in ~/.gemini/settings.json in your home folder. gemini mcp add writes to the project file unless you add --scope user.

Do I need a Google Cloud project or a GA4 API key?

No. LopeBase connects to GA4 with a Google sign-in and read-only access. You do not enable the Analytics APIs, create a service account, or download a credentials file.

Do I need my GA4 property ID?

No. You pick the property when you connect with Google, and Gemini CLI asks by name.

Does it work in every folder?

Only in the folder where you ran gemini mcp add, unless you added it with --scope user. The folder also has to be trusted, since Gemini CLI does not connect MCP servers in an untrusted folder.

How long does the sign-in last?

30 days. When it runs out, Gemini CLI's tool calls return a message asking you to run npx lopebase login again. You can revoke it sooner under Settings, Agent access.

Can I run Google's server and LopeBase together?

Yes. They are separate MCP servers with different names in settings.json. Use Google's for custom reports and LopeBase for the everyday questions and your other sources.

Does it work with the Gemini app?

This page is about Gemini CLI. LopeBase works in any client that can add a remote MCP server with sign in.

Can Gemini CLI see individual visitors?

No. It gets counts and rates, never a visitor, an IP address, or a user ID.

Ask Gemini CLI about your traffic.

Free for one property. No card. Agent access is on every plan.