diff options
| author | jerop <[email protected]> | 2025-06-06 13:54:59 +0000 |
|---|---|---|
| committer | Jerop Kipruto <[email protected]> | 2025-06-06 11:47:37 -0400 |
| commit | 4e9d365407564e0f440bf4645607aa47a1d16bca (patch) | |
| tree | 257684bdade5e42fe7a07bd304321a990ea4ede7 /docs/cli/configuration.md | |
| parent | 9ad615c2a486675c4ad75c986a0a5dbd8f8b030e (diff) | |
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.
Diffstat (limited to 'docs/cli/configuration.md')
| -rw-r--r-- | docs/cli/configuration.md | 11 |
1 files changed, 10 insertions, 1 deletions
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**): |
