Guide coding-agents/
Gemini CLI MCP config: settings.json servers and trust
How Gemini CLI finds MCP servers in settings.json, adds them with gemini mcp add, signs in with OAuth, and decides when an MCP tool call needs your approval.
Short answer
Gemini CLI reads MCP servers from the mcpServers object in settings.json: ~/.gemini/settings.json for your user, or .gemini/settings.json in a project. Each entry sets command for a stdio server, httpUrl for Streamable HTTP or url for SSE. gemini mcp add <name> <commandOrUrl> writes the entry for you and defaults to project scope. MCP tool calls ask for confirmation unless the server has trust: true, and servers don't connect in an untrusted folder.
Checked against: Google’s Gemini CLI docs at geminicli.com, MCP servers with Gemini CLI, Configuration, Trusted Folders, Gemini CLI for the enterprise and Policy engine, and their source in the google-gemini/gemini-cli repo, December 6, 2026.
Run by us: no. Commands are copied from Google’s Gemini CLI docs.
Where does Gemini CLI look for MCP servers?
Gemini CLI reads the mcpServers object from each settings.json layer and merges them; the user and project files are the ones you normally edit.
| Layer | Path (as of December 6, 2026) |
|---|---|
| System defaults (lowest) | /etc/gemini-cli/system-defaults.json (Linux), C:\ProgramData\gemini-cli\system-defaults.json (Windows), /Library/Application Support/GeminiCli/system-defaults.json (macOS) |
| User | ~/.gemini/settings.json |
| Project | .gemini/settings.json in the project root |
| System settings (highest file) | /etc/gemini-cli/settings.json (Linux), C:\ProgramData\gemini-cli\settings.json (Windows), /Library/Application Support/GeminiCli/settings.json (macOS) |
Server lists from the system, workspace and user files are combined. If two layers define the same server name, Google’s enterprise guide gives the order as System > Workspace > User, so a user can add servers but can’t redefine one set in system settings. GEMINI_CLI_SYSTEM_SETTINGS_PATH and GEMINI_CLI_SYSTEM_DEFAULTS_PATH override the two system paths.
How do I add a server with gemini mcp add?
Run gemini mcp add [options] <name> <commandOrUrl> [args...]; it writes to the project’s .gemini/settings.json unless you pass --scope user.
gemini mcp add -e API_KEY=123 -e DEBUG=true my-stdio-server /path/to/server arg1 arg2 arg3
gemini mcp add python-server python server.py -- --server-arg my-value
gemini mcp add --transport http http-server https://api.example.com/mcp/
gemini mcp add --transport http --header "Authorization: Bearer abc123" secure-http https://api.example.com/mcp/
gemini mcp add --transport sse sse-server https://api.example.com/sse/
gemini mcp add db node db-server.js --scope user
| Flag | Meaning |
|---|---|
-s, --scope |
user or project; default project |
-t, --transport |
stdio, sse or http; default stdio |
-e, --env |
Environment variable, e.g. -e KEY=value |
-H, --header |
HTTP header for SSE and HTTP transports |
--timeout |
Connection timeout in milliseconds |
--trust |
Bypass all tool call confirmation prompts |
--description |
Server description |
--include-tools, --exclude-tools |
Comma-separated tool lists |
Without --scope user, the entry lands in the project’s .gemini/settings.json, not your user file. Arguments meant for the server go after --, as in the python-server example.
What fields does an mcpServers entry take?
Each entry needs one of command, url or httpUrl, and that choice sets the transport.
{
"mcpServers": {
"pythonTools": {
"command": "python",
"args": ["-m", "my_mcp_server", "--port", "8080"],
"cwd": "./mcp-servers/python",
"env": {
"DATABASE_URL": "$DB_CONNECTION_STRING",
"API_KEY": "${EXTERNAL_API_KEY}"
},
"timeout": 15000
},
"httpServer": {
"httpUrl": "http://localhost:3000/mcp",
"timeout": 5000
}
}
}
| Key | Purpose |
|---|---|
command, args, cwd |
Start a stdio server |
httpUrl |
Streamable HTTP endpoint |
url |
SSE endpoint |
headers |
HTTP headers for url or httpUrl |
env |
Variables for the server process |
timeout |
Request timeout in ms; default 600,000 (10 minutes) |
trust |
true skips all tool call confirmations; default false |
includeTools / excludeTools |
Tool allowlist / denylist; excludeTools wins |
If several transport keys are set, httpUrl takes precedence, then url, then command. In env, Gemini CLI expands $VAR_NAME and ${VAR_NAME} on all platforms and %VAR_NAME% on Windows; an undefined variable becomes an empty string.
When it spawns a server, Gemini CLI redacts sensitive variables inherited from your shell, including GEMINI_API_KEY, GOOGLE_API_KEY and names matching *TOKEN*, *SECRET*, *PASSWORD*, *KEY*, *AUTH* and *CREDENTIAL*. To pass one through, name it in the server’s env, for example "MY_KEY": "$MY_KEY".
Avoid underscores in server names. Tools are registered as mcp_{serverName}_{toolName}, and Google warns that the policy parser splits on the first underscore after mcp_, so my_server can make policies “fail silently.” Use my-server.
How do I sign in to an OAuth-protected server?
Use /mcp auth <server-name> in a session; for servers that support discovery, Gemini CLI finds the OAuth endpoints after a 401 and performs dynamic client registration if the server supports it.
/mcp auth
/mcp auth serverName
The first form lists servers that need sign-in; the second starts the browser flow. The callback goes to http://localhost:<random-port>/oauth/callback unless you set redirectUri. Google says this flow won’t work in headless environments, SSH sessions without X11 forwarding, or containers without a browser. Tokens are stored in ~/.gemini/mcp-oauth-tokens.json and refreshed when a refresh token is available.
To configure OAuth by hand, add an oauth object with keys such as enabled, clientId, clientSecret, authorizationUrl, tokenUrl, issuer, scopes and redirectUri. Gemini CLI checks the iss parameter per RFC 9207: a mismatch fails with Issuer mismatch, and a required but absent iss fails with Missing issuer parameter in response. authProviderType can also be google_credentials (Application Default Credentials) or service_account_impersonation for IAP-protected services. See MCP authorization step by step.
When does Gemini CLI ask before running an MCP tool?
An MCP tool call shows a confirmation unless the server has trust: true, you already chose an “always allow” option, or a policy rule or approval mode allows it.
| Prompt choice | Effect |
|---|---|
| Proceed once | Runs this call only |
| Always allow this tool | Adds serverName.toolName to the tool-level allow-list |
| Always allow this server | Adds serverName to the server-level allow-list |
| Cancel | Aborts the call |
Google’s docs say the trust option “bypasses all confirmation dialogs” and should be used only for servers you completely control. For finer control, write policy-engine rules in TOML with the mcpName field, which Google recommends over matching tool names:
# Denies all tools from the `untrusted-server` MCP
[[rule]]
mcpName = "untrusted-server"
decision = "deny"
priority = 500
denyMessage = "This server is not trusted by the admin."
User policies live in ~/.gemini/policies/*.toml; workspace policy files are currently disabled. Admin policies go in /etc/gemini-cli/policies (Linux), /Library/Application Support/GeminiCli/policies (macOS) or C:\ProgramData\gemini-cli\policies (Windows). The --approval-mode flag accepts default, auto_edit, yolo and plan; in yolo mode a high-priority rule allows all tools. The admin.secureModeEnabled setting disallows YOLO mode and the “Always allow” options. How coding agents ask permission compares this with other agents.
How does folder trust affect MCP servers?
In an untrusted folder, Gemini CLI ignores the project’s .gemini/settings.json and doesn’t connect to any MCP server.
{
"security": {
"folderTrust": {
"enabled": true
}
}
}
Google’s docs disagree on the default: the Trusted Folders page says the feature is “disabled by default,” while the configuration reference lists security.folderTrust.enabled with a default of true. Set it explicitly in your user settings so you know which behavior you get.
When trust is on, the first run in a folder opens a dialog that lists what the project would load, including its MCP servers, before you choose. Choices are saved in ~/.gemini/trustedFolders.json (moved with GEMINI_CLI_TRUSTED_FOLDERS_PATH); /permissions changes the current folder’s setting. In CI, an untrusted folder raises FatalUntrustedWorkspaceError; --skip-trust or GEMINI_CLI_TRUST_WORKSPACE=true trusts the workspace for that session. gemini mcp list shows stdio servers as Connected only when the current folder is trusted.
How do admins lock down MCP servers?
Define each approved server in the system settings.json and list its name in mcp.allowed; without the allowlist, Gemini CLI also runs any server a user defines.
{
"mcp": {
"allowed": ["corp-data-api", "source-code-analyzer"]
},
"mcpServers": {
"corp-data-api": {
"command": "/usr/local/bin/start-corp-api.sh",
"timeout": 5000
},
"source-code-analyzer": {
"command": "/usr/local/bin/start-analyzer.sh"
}
}
}
mcp.allowed matches server names, so the system-level definition matters: it overrides any user server with the same name. Google also requires locking down every executable these entries run, owned by root (or SYSTEM or Administrators on Windows) and not writable by other users. Other documented controls are mcp.excluded, admin.mcp.enabled (false disallows MCP), admin.mcp.requiredConfig for servers that are always injected, and --allowed-mcp-server-names per session. Because users can override GEMINI_CLI_SYSTEM_SETTINGS_PATH, Google suggests a wrapper script that pins it.
How do I check status and fix a server that won’t connect?
Run gemini mcp list from the shell or /mcp in a session to see each server’s state.
gemini mcp list
gemini mcp remove my-server
gemini mcp disable <name> [--session]
gemini mcp enable <name> [--session]
Statuses are CONNECTED, CONNECTING and DISCONNECTED. Startup errors are quiet by default; you’ll see “MCP issues detected. Run /mcp list for status.” In a session, /mcp desc and /mcp schema add descriptions and schemas, and /mcp reload re-discovers tools. Enable and disable state is kept in ~/.gemini/mcp-server-enablement.json.
| Symptom | Check |
|---|---|
DISCONNECTED |
command, args and cwd; run the command by hand |
Stdio server shows Disconnected in gemini mcp list |
Folder trust |
| Connects but no tools | Servers with no usable tools are disconnected after discovery; check the server’s tool listing |
| Tool calls time out | Raise timeout |
| Fails only in the sandbox | Make the executable, network and variables available in the sandbox |
Start Gemini CLI with --debug for verbose output.
What to read next
Sources
Changelog
- First published.
Cite this page
Agents for Devs. "Gemini CLI MCP config: settings.json servers and trust." Published Dec 6, 2026. https://agentsfordevs.com/guides/gemini-cli-mcp - Page: https://agentsfordevs.com/guides/gemini-cli-mcp
- Markdown version: https://agentsfordevs.com/guides/gemini-cli-mcp.md
- Reuse: quote or summarize with a link to this page. Reuse terms
Cite one section
- Where does Gemini CLI look for MCP servers?
- How do I add a server with gemini mcp add?
- What fields does an mcpServers entry take?
- How do I sign in to an OAuth-protected server?
- When does Gemini CLI ask before running an MCP tool?
- How does folder trust affect MCP servers?
- How do admins lock down MCP servers?
- How do I check status and fix a server that won’t connect?
- What to read next