Ad space · Your tool here
PluginStack
Setup guide

How to add an MCP server to Gemini CLI

Checked against the official docs:

Gemini CLI is Google's open-source coding agent for the terminal. MCP (Model Context Protocol) servers give it extra tools, such as driving a browser or looking up current library docs. You can add one with a single gemini mcp add command or by editing settings.json. This guide covers both, how to check the server really connected, and the folder trust setting that blocks MCP servers for a lot of people. It was checked against Google's Gemini CLI docs on 2 December 2026, and the commands were run on Gemini CLI 0.72.0.

Get new guides by email

New MCP servers and agent tools, checked by hand. Free, unsubscribe anytime.

The newsletter hasn't started sending yet. Join the list now and we'll email you when the first issue goes out. From PluginStack (pluginstackai@gmail.com). Privacy policy.

Paid prompt and rules packs are on the packs page.

Quick answer

  1. Open a terminal in your project folder.
  2. For a server you run on your computer: gemini mcp add playwright npx @playwright/mcp@latest. For a hosted server with a URL: gemini mcp add --transport http context7 https://mcp.context7.com/mcp.
  3. Add -s user if you want the server in every folder. Without it, the server is saved for this project only.
  4. Start gemini and type /mcp. The server should be listed as connected, with its tools.
  5. If it says the servers are disabled because the folder is untrusted, run /permissions and trust the folder.

Free: MCP Starter Checklist

One page: Inspector smoke-test, Claude Code + Cursor connect steps, and the stdout gotcha. Join the list and download it free.

Markdown download + occasional PluginStack updates. No spam. Privacy policy.

Before you start

You need Gemini CLI installed (it needs Node.js 20 or newer). Google lists npm and Homebrew among the install options:

bash
# npm
npm install -g @google/gemini-cli

# Homebrew (macOS / Linux)
brew install gemini-cli

Local servers started with npx need Node.js too, and servers started with uvx need uv. Check what the server you want asks for before adding it.

Option 1: gemini mcp add

The gemini mcp add command writes the entry into your settings file for you. The pattern is gemini mcp add [options] <name> <command-or-url> [args...].

A local server (runs on your computer)

This adds Playwright MCP, which lets Gemini open and control a browser:

bash
gemini mcp add playwright npx @playwright/mcp@latest

If the server needs its own flags, put -- before them so Gemini CLI doesn't read them as its own. Google's example: gemini mcp add python-server python server.py -- --server-arg my-value.

A hosted server (a URL)

Use --transport http for servers that give you a normal MCP URL (Streamable HTTP), or --transport sse for older SSE URLs. This adds Context7, which looks up current library docs:

bash
gemini mcp add --transport http context7 https://mcp.context7.com/mcp

To send an API key in a header, add -H, for example -H "Authorization: Bearer YOUR_KEY". That saves the key in the settings file as plain text, so for anything shared, use an environment variable in settings.json instead (shown below).

Project or user scope

  • Project (the default): saved in .gemini/settings.json in the current folder. Good for a server only one project needs, or one your team shares through git.
  • User (-s user): saved in ~/.gemini/settings.json and used in every folder.

If you run gemini mcp add in your home folder without -s user, it stops with "Please use --scope user to edit settings in the home directory."

Other useful flags

  • -e KEY=value: set an environment variable for a local server.
  • --timeout 60000: timeout in milliseconds.
  • --include-tools a,b or --exclude-tools c: only allow some of the server's tools.
  • --trust: skip the confirmation prompt for every tool from this server. Only use it for servers you fully control.

Option 2: edit settings.json

Gemini CLI reads servers from an mcpServers object in settings.json. The two files you'll normally use are ~/.gemini/settings.json (just you, every folder) and .gemini/settings.json in a project (that project only; project settings override user settings). There are also system-wide files for admins.

~/.gemini/settings.json or .gemini/settings.json
json
{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    },
    "context7": {
      "httpUrl": "https://mcp.context7.com/mcp"
    }
  }
}

The fields that matter most:

  • command, args, env, cwd: for a local server.
  • httpUrl: a hosted server that uses Streamable HTTP (most current servers).
  • url: a hosted server that uses SSE. If an entry has more than one of these, Gemini CLI uses httpUrl first, then url, then command.
  • headers: extra HTTP headers, such as an API key, for httpUrl or url.
  • timeout: request timeout in milliseconds. The default is 600,000 (10 minutes).
  • trust, includeTools, excludeTools: the same as the flags above.

Entries written by gemini mcp add --transport http look slightly different: a url plus "type": "http". Both forms connected in our test, so you don't need to change one into the other.

Google warns against underscores in server names (use my-server, not my_server). Gemini CLI names each tool mcp_<server>_<tool>, and an underscore in the server name can make permission rules silently fail.

Coming from Cursor or Claude Desktop? Local server entries use the same command and args shape, so you can usually copy them across. For hosted servers, Gemini CLI uses httpUrl where Cursor uses url. See how to add an MCP server to Cursor for Cursor's version.

API keys and environment variables

Don't paste keys straight into settings.json. Gemini CLI fills in $NAME or ${NAME} from your environment when it loads the file:

json
{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["-y", "some-mcp-server"],
      "env": {
        "API_KEY": "$MY_API_KEY"
      }
    }
  }
}

This matters more than in other apps. To protect your secrets, Gemini CLI removes sensitive variables from what a local server inherits, including names that contain TOKEN, SECRET, PASSWORD, KEY, AUTH or CREDENTIAL. A key that is set in your shell is not passed on unless you list it in that server's env. If a server says its API key is missing, this is the first thing to check.

A variable that isn't set becomes an empty string, so set it (for example export MY_API_KEY=... in your shell profile) and open a new terminal before starting gemini.

Servers that ask you to sign in

Many hosted servers use OAuth sign-in instead of a key. You only need the URL. When the server answers that sign-in is needed, Gemini CLI finds the sign-in details, opens your browser and saves the tokens. Inside Gemini CLI, /mcp auth lists servers that support sign-in, and /mcp auth <name> signs in again, for example when a token has expired.

The browser has to be able to reach localhost on the same computer. Sign-in doesn't work over a plain SSH session, in a container without a browser, or on a headless server.

Check that it works

  1. Start gemini in the folder and type /mcp. Each server shows as connected or disconnected, with its tools. /mcp desc adds tool descriptions.
  2. From a normal terminal, gemini mcp list shows the same status for every configured server.
  3. Ask for something only that server can do, for example "Use playwright to open https://example.com and tell me the page title". Gemini CLI asks you to confirm each tool call unless the server is trusted.

After editing settings.json while Gemini CLI is running, /mcp reload reconnects the servers. To turn a server off without deleting it, use gemini mcp disable <name> (add --session for this session only) and gemini mcp enable <name> to turn it back on. gemini mcp remove <name> deletes it; add -s user for a user-scope server.

Common errors and fixes

"MCP servers are configured but disabled because this folder is untrusted"

Gemini CLI's Trusted Folders setting is on by default in current versions (the settings reference lists it as on, and our test on 0.72.0 matched). The first time you start gemini in a new folder, it asks whether to trust it. In a folder you haven't trusted, it doesn't load the project's .gemini/settings.json and doesn't connect to MCP servers at all, including ones in your user settings. Start gemini in the folder, run /permissions and choose to trust it. Your choices are saved in ~/.gemini/trustedFolders.json.

For scripts and CI, where there is nobody to answer the prompt, setting GEMINI_CLI_TRUST_WORKSPACE=true trusts the current folder for that run.

"Cannot modify settings in an untrusted workspace"

This comes from gemini mcp add in a folder that isn't trusted. Trust the folder first (above), or add the server to your user settings with -s user.

The server shows as disconnected

  • Run the same command in a terminal (for example npx @playwright/mcp@latest). If it fails there, the error tells you what's missing. If it starts and waits quietly, the server is fine and the problem is in the settings.
  • Check the JSON. A missing comma or quote makes the whole file invalid.
  • Start Gemini CLI with gemini --debug for detailed output (press F12 for the debug console in interactive mode).
  • At startup, connection errors are quiet by default. If you only see "MCP issues detected. Run /mcp list for status.", run /mcp list to see the real error.

The server connects but has no tools

Check includeTools and excludeTools in the entry. If the server is your own, make sure it registers its tools. Gemini CLI also closes connections to servers that offer no tools.

Tool calls time out

Raise timeout (milliseconds) on that server. More on timeouts in every client: fix MCP error -32001: Request timed out.

Testing a server outside Gemini CLI

The official MCP Inspector connects to a server on its own and lists its tools, which tells you whether the problem is the server or the Gemini CLI settings. See how to use MCP Inspector.

FAQ

Where is the Gemini CLI MCP config file?

~/.gemini/settings.json for your user, or .gemini/settings.json in a project folder. Servers go under the top-level mcpServers key.

Does Gemini CLI support remote MCP servers?

Yes. Use httpUrl for Streamable HTTP or url for SSE, or gemini mcp add --transport http or --transport sse.

Can my team share the same servers?

Yes. Put them in .gemini/settings.json in the project and commit it, with keys coming from environment variables. Each person still has to trust the folder before the servers connect.

Can I stop Gemini CLI asking before every tool call?

Setting "trust": true on a server (or --trust when adding it) skips the prompts for that server. Google's docs say to use it only for servers you completely control.

Sources

Commands and config above come from these official docs. Tools change often, so check them for the latest steps.

PluginStack is independent and not affiliated with or endorsed by the companies mentioned. Spotted something out of date? Email pluginstackai@gmail.com.

Get new guides by email

New MCP servers and agent tools, checked by hand. Free, unsubscribe anytime.

The newsletter hasn't started sending yet. Join the list now and we'll email you when the first issue goes out. From PluginStack (pluginstackai@gmail.com). Privacy policy.

Paid prompt and rules packs are on the packs page.