Image generation in Gemini CLI: MCP server setup
Add the Image MCP Server to ~/.gemini/settings.json using httpUrl — not url — and its 8 image tools (11 MCP tools in all) appear in the next Gemini CLI session. Gemini CLI already reads and writes the files in your project. What it cannot do out of the box is produce the images those files reference, so a build ends with real markup pointing at placeholder art.
Add the server
- Where the config lives
- ~/.gemini/settings.json (user) · .gemini/settings.json (project)
- The key it nests under
- mcpServers
- 1
Create an API key. Create a key in the Image MCP Server dashboard.
- 2
Open settings.json. Edit ~/.gemini/settings.json, or .gemini/settings.json inside the project.
- 3
Add the entry under httpUrl. Use httpUrl for this streamable HTTP endpoint and pass the key as an x-api-key header.
- 4
Restart and check. Start a new session and run /mcp to see the server and its tools listed.
The server reads the key from an x-api-key header, an Authorization: Bearer header or a ?apikey= query parameter — see authentication. What each tool costs is on the credits page.
{
"mcpServers": {
"imagemcp": {
"httpUrl": "https://mcp.imagemcpserver.com/mcp",
"headers": { "x-api-key": "sk-img-gen-…" },
"timeout": 30000
}
}
}{
"mcpServers": {
"imagemcp": {
"httpUrl": "https://mcp.imagemcpserver.com/mcp",
"headers": { "x-api-key": "$IMAGEMCP_API_KEY" }
}
}
}httpUrl, not url
Gemini CLI treats url and httpUrl as two different transports: url is an SSE endpoint, httpUrl is streamable HTTP. Putting a streamable HTTP endpoint in url is the single most common reason a Gemini CLI config connects to nothing. This server is streamable HTTP, so it goes in httpUrl.
Check it connected in Gemini CLI
Start a new gemini session and run /mcp. imagemcp should be listed as connected with its 11 tools (8 image tools + 3 utility tools); a server Gemini CLI could not reach is marked disconnected instead. Then ask for your image credit balance: get_user_info is free, and it is the first call that actually checks the key, because the server lists its tools without one.
Example workflow in Gemini CLI
Fill the placeholders in a page Gemini CLI just built
- 1
Commit the project config
Put the entry in .gemini/settings.json with "$IMAGEMCP_API_KEY" in the header, so the repository carries the server but not the key.
- 2
Confirm, then check the balance
Run /mcp to see imagemcp connected, then ask for your credit balance; get_user_info is free.
- 3
Generate what the markup points at
Ask it to generate each image the page references and save it where the markup expects it. generate_image bills the model’s rate: 15 credits on the default model, 8–30 across the range.
When Gemini CLI will not connect
| Symptom | Usual cause | Fix |
|---|---|---|
| Listed, but disconnected | The endpoint is in url, which Gemini CLI opens as an SSE connection. | Move it to httpUrl, the field that selects streamable HTTP. |
| Every tool call fails | $IMAGEMCP_API_KEY was not set in the shell that started gemini, so the header went out empty. | Export the variable in your shell profile and start a new session; settings values resolve when the file loads. |
| The server is never contacted | An mcp.allowed list in settings.json does not name imagemcp, or mcp.excluded does. | Add imagemcp to mcp.allowed, or take it out of mcp.excluded. |
Once Gemini CLI is connected
Gemini CLI gets the server’s 8 image tools, plus 3 utility tools for the credit balance, the model list and batching: 11 MCP tools in all. The ones most setups reach for first are the AI image generation API, Background removal API and Transparent PNG generator API; each page covers what the tool does and what a call costs. If the protocol itself is new to you, what is MCP explains how a client like Gemini CLI finds these tools and calls them.
- generate_image · 8–30 creditsAI image generation APIText-to-image and image-to-image, any live model
- remove_background · 8 creditsBackground removal APICut the subject out in one call
- generate_transparent_image · 16–38 creditsTransparent PNG generator APIGenerate and cut out in one call
- Use caseAI images for landing pagesThe complete workflow, with the calls in order and what each one costs.
Setting up another client too? The Antigravity MCP setup (also under ~/.gemini) and Claude Code MCP setup guides use the same endpoint and key in a different config shape.
Gemini CLI questions
How do I add an MCP server to Gemini CLI?
Add an entry to the mcpServers object in ~/.gemini/settings.json for every project, or .gemini/settings.json inside one project. There is no separate install step — the CLI reads the file at startup and connects to whatever it finds there.
Why does my Gemini CLI MCP server never connect?
Almost always the transport field. url means SSE to Gemini CLI, and httpUrl means streamable HTTP. A streamable HTTP endpoint placed in url will not work, and the failure is quiet rather than loud.
Can I keep the API key out of settings.json?
Yes. String values in settings.json can reference environment variables as $VAR_NAME or ${VAR_NAME}, resolved when the settings load, so "$IMAGEMCP_API_KEY" inside the headers object keeps a project-scoped .gemini/settings.json safe to commit.
Does the free Gemini CLI tier work with this?
Yes. The MCP connection is between the CLI and this server; whatever model tier you use for the conversation is unrelated. Image credits are billed by this server, not by Google.
How do I confirm the tools loaded?
Run /mcp inside the session. It lists each connected server with its tool names, which is faster than guessing from a failed prompt.
Sources & references