-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Description
What happened?
Summary
I am using the github-mcp-server, the official one from Microsoft. I am seeing some confusing behavior with the way Gemini CLI treats environment variables. I think this is not relevant to the specific MCP Server.
Case 1: explicit secret in the settings file - WORKS
This configuration in settings.json , in which I explicitly specify the value for the personal access token, "works" The token is applied by the MCP server.:
{
"theme": "Default",
"selectedAuthType": "oauth-personal",
"mcpServers": {
"github-stdio": {
"command": "github-mcp-server",
"args": ["stdio"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_BISAMPLEKEYp"
},
"trust": true
}
},
...
}
Case 2: implicit reference to .env environment variables - WORKS
In this case, GITHUB_PERSONAL_ACCESS_TOKEN is defined in my ~/.gemini/.env
file with the correct value.
{
"theme": "Default",
"selectedAuthType": "oauth-personal",
"mcpServers": {
"github-stdio": {
"command": "github-mcp-server",
"args": ["stdio"],
"trust": true
}
},
...
}
Case 3: environment variable substitution - DOES NOT WORK
Here as above, GITHUB_PERSONAL_ACCESS_TOKEN is defined in my ~/.gemini/.env
file . But in this case the MCP server does not work; every call fails with 401 Bad Credentials. The reason I would want to do this, rather than relying on the magic/silent environment variables as in Case 2, is to "document" which env variables are needed by this particular server.
{
"theme": "Default",
"selectedAuthType": "oauth-personal",
"mcpServers": {
"github-stdio": {
"command": "github-mcp-server",
"args": ["stdio"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}"
},
"trust": true
}
},
...
}
Further details
Same is true if I use the docker/podman version of the MCP server.
Suggestion
Maybe the problem is that I am using the same name for the input and output of the environment variable.
I don't know, I grew weary of testing all these scenarios.
But it seems like something is not working correctly.
This may be related to #5282 . But note in the above - none of these are remote servers. I am not using HTTP headers.
What did you expect to happen?
I expect that substitution of env variables works for local MCP servers, even if the environment variable names are the same.
Client information
╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ About Gemini CLI │
│ │
│ CLI Version 0.1.17 │
│ Git Commit b3cfaeb6 │
│ Model gemini-2.5-pro │
│ Sandbox no sandbox │
│ OS linux │
│ Auth Method OAuth │
│ GCP Project my-gca-3201 │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯```
</details>
### Login information
Google Account
### Anything else we need to know?
_No response_