From 4e9d365407564e0f440bf4645607aa47a1d16bca Mon Sep 17 00:00:00 2001 From: jerop Date: Fri, 6 Jun 2025 13:54:59 +0000 Subject: feat: Enable environment variable substitution in settings This commit introduces the ability to use system environment variables within the settings files (e.g., `settings.json`). Users can now reference environment variables using the `${VAR_NAME}` syntax. This enhancement improves security and flexibility, particularly for configurations like MCP server settings, which often require sensitive tokens. Previously, to configure an MCP server, a token might be directly embedded: ```json "mcpServers": { "github": { "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "pat_abc123" } // ... } } ``` With this change, the same configuration can securely reference an environment variable: ```json "mcpServers": { "github": { "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}" } // ... } } ``` This allows users to avoid storing secrets directly in configuration files. --- docs/cli/configuration.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'docs/cli') diff --git a/docs/cli/configuration.md b/docs/cli/configuration.md index 4503ed81..89efe21d 100644 --- a/docs/cli/configuration.md +++ b/docs/cli/configuration.md @@ -23,6 +23,8 @@ The Gemini CLI uses `settings.json` files for persistent configuration. There ar - **Location:** `.gemini/settings.json` within your project's root directory. - **Scope:** Applies only when running Gemini CLI from that specific project. Project settings override User settings. +**Note on Environment Variables in Settings:** String values within your `settings.json` files can reference environment variables using either `$VAR_NAME` or `${VAR_NAME}` syntax. These variables will be automatically resolved when the settings are loaded. For example, if you have an environment variable `MY_API_TOKEN`, you could use it in `settings.json` like this: `"apiKey": "$MY_API_TOKEN"`. + ### The `.gemini` Directory in Your Project When you create a `.gemini/settings.json` file for project-specific settings, or when the system needs to store project-specific information, this `.gemini` directory is used. @@ -145,7 +147,14 @@ When you create a `.gemini/settings.json` file for project-specific settings, or "command": "node", "args": ["mcp_server.js"], "cwd": "./mcp_tools/node" - } + }, + "myDockerServer": { + "command": "docker", + "args": ["run", "i", "--rm", "-e", "API_KEY", "ghcr.io/foo/bar"], + "env": { + "API_KEY": "$MY_API_TOKEN" + } + }, } ``` - **`mcpServerCommand`** (string, advanced, **deprecated**): -- cgit v1.2.3