@@ -163,7 +163,8 @@ Each server configuration supports the following properties:
163163- ** ` args ` ** (string[ ] ): Command-line arguments for Stdio transport
164164- ** ` headers ` ** (object): Custom HTTP headers when using ` url ` or ` httpUrl `
165165- ** ` env ` ** (object): Environment variables for the server process. Values can
166- reference environment variables using ` $VAR_NAME ` or ` ${VAR_NAME} ` syntax
166+ reference environment variables using ` $VAR_NAME ` or ` ${VAR_NAME} ` syntax (all
167+ platforms), or ` %VAR_NAME% ` (Windows only).
167168- ** ` cwd ` ** (string): Working directory for Stdio transport
168169- ** ` timeout ` ** (number): Request timeout in milliseconds (default: 600,000ms =
169170 10 minutes)
@@ -184,6 +185,63 @@ Each server configuration supports the following properties:
184185 Service Account to impersonate. Used with
185186 ` authProviderType: 'service_account_impersonation' ` .
186187
188+ ### Environment variable expansion
189+
190+ Gemini CLI automatically expands environment variables in the ` env ` block of
191+ your MCP server configuration. This allows you to securely reference variables
192+ defined in your shell or environment without hardcoding sensitive information
193+ directly in your ` settings.json ` file.
194+
195+ The expansion utility supports:
196+
197+ - ** POSIX/Bash syntax:** ` $VARIABLE_NAME ` or ` ${VARIABLE_NAME} ` (supported on
198+ all platforms)
199+ - ** Windows syntax:** ` %VARIABLE_NAME% ` (supported only when running on Windows)
200+
201+ If a variable is not defined in the current environment, it resolves to an empty
202+ string.
203+
204+ ** Example:**
205+
206+ ``` json
207+ "env" : {
208+ "API_KEY" : " $MY_EXTERNAL_TOKEN" ,
209+ "LOG_LEVEL" : " $LOG_LEVEL" ,
210+ "TEMP_DIR" : " %TEMP%"
211+ }
212+ ```
213+
214+ ### Security and environment sanitization
215+
216+ To protect your credentials, Gemini CLI performs environment sanitization when
217+ spawning MCP server processes.
218+
219+ #### Automatic redaction
220+
221+ By default, the CLI redacts sensitive environment variables from the base
222+ environment (inherited from the host process) to prevent unintended exposure to
223+ third-party MCP servers. This includes:
224+
225+ - Core project keys: ` GEMINI_API_KEY ` , ` GOOGLE_API_KEY ` , etc.
226+ - Variables matching sensitive patterns: ` *TOKEN* ` , ` *SECRET* ` , ` *PASSWORD* ` ,
227+ ` *KEY* ` , ` *AUTH* ` , ` *CREDENTIAL* ` .
228+ - Certificates and private key patterns.
229+
230+ #### Explicit overrides
231+
232+ If an environment variable must be passed to an MCP server, you must explicitly
233+ state it in the ` env ` property of the server configuration in ` settings.json ` .
234+ Explicitly defined variables (including those from extensions) are trusted and
235+ are ** not** subjected to the automatic redaction process.
236+
237+ This follows the security principle that if a variable is explicitly configured
238+ by the user for a specific server, it constitutes informed consent to share that
239+ specific data with that server.
240+
241+ > ** Note:** Even when explicitly defined, you should avoid hardcoding secrets.
242+ > Instead, use environment variable expansion (e.g., ` "MY_KEY": "$MY_KEY" ` ) to
243+ > securely pull the value from your host environment at runtime.
244+
187245### OAuth support for remote MCP servers
188246
189247The Gemini CLI supports OAuth 2.0 authentication for remote MCP servers using
@@ -738,7 +796,9 @@ The MCP integration tracks several states:
738796- ** Trust settings:** The ` trust ` option bypasses all confirmation dialogs. Use
739797 cautiously and only for servers you completely control
740798- ** Access tokens:** Be security-aware when configuring environment variables
741- containing API keys or tokens
799+ containing API keys or tokens. See
800+ [ Security and environment sanitization] ( #security-and-environment-sanitization )
801+ for details on how Gemini CLI protects your credentials.
742802- ** Sandbox compatibility:** When using sandboxing, ensure MCP servers are
743803 available within the sandbox environment
744804- ** Private data:** Using broadly scoped personal access tokens can lead to
0 commit comments