Skip to content

Forward API key env vars to the nanobanana MCP server - #72

Open
ABDI-HILL wants to merge 1 commit into
gemini-cli-extensions:mainfrom
ABDI-HILL:fix/mcp-env-passthrough
Open

Forward API key env vars to the nanobanana MCP server#72
ABDI-HILL wants to merge 1 commit into
gemini-cli-extensions:mainfrom
ABDI-HILL:fix/mcp-env-passthrough

Conversation

@ABDI-HILL

Copy link
Copy Markdown

What

Add explicit env-var forwarding to the nanobanana MCP server spec in gemini-extension.json:

"env": {
  "NANOBANANA_API_KEY": "${NANOBANANA_API_KEY}",
  "GEMINI_API_KEY": "${GEMINI_API_KEY}"
}

Why

The MCP server reads its API key only from process.env — see mcp-server/src/imageGenerator.ts validateAuthentication(), which checks NANOBANANA_API_KEY then falls back to NANOBANANA_GEMINI_API_KEY / NANOBANANA_GOOGLE_API_KEY / GEMINI_API_KEY / GOOGLE_API_KEY.

But the server spec declared "env": {}, so the Gemini CLI did not forward those variables into the spawned MCP subprocess. Following the documented setup in README.md ("Set the NANOBANANA_API_KEY environment variable") then fails with:

ERROR: No valid API key found. Please set NANOBANANA_API_KEY environment variable.

because the variable is present in the parent shell but never reaches the child process.

Forwarding the two primary variables via ${VAR} expansion makes the documented env-var workflow actually work. The expansion is a no-op when the variables are unset, so it is safe.

Testing

Reproduced on Windows 11 (gemini-cli, nanobanana 1.0.12): with NANOBANANA_API_KEY exported, /generate failed with "No valid API key found" until this change was applied; after the change, /generate produced an image successfully.

The MCP server reads its API key exclusively from process.env
(NANOBANANA_API_KEY, with GEMINI_API_KEY/GOOGLE_API_KEY fallbacks), but
the server spec declared `"env": {}`, so the gemini CLI did not forward
those variables to the spawned MCP subprocess. As a result, following the
documented setup ("set the NANOBANANA_API_KEY environment variable") fails
with "No valid API key found" because the variable never reaches the child
process.

Forward NANOBANANA_API_KEY and GEMINI_API_KEY via ${VAR} expansion so the
documented env-var workflow works.
@google-cla

google-cla Bot commented Jun 3, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant