Codex CLI · ~/.codex/config.toml · TOML

Image generation in Codex: MCP server setup

Add an [mcp_servers.imagemcp] table for the Image MCP Server to ~/.codex/config.toml with url and http_headers, or run codex mcp add — Codex is the one client here configured in TOML rather than JSON. Codex is comfortable rewriting a component and leaving the image import pointing at a file that was never generated. Giving it the image tools closes that gap inside the same run.

By the Image MCP Server teamPublished Updated Codex docs verified November 2026

Add the server

Where the config lives
~/.codex/config.toml (user) · .codex/config.toml (trusted projects)
The key it nests under
[mcp_servers.<name>]
  1. 1

    Create an API key. Create a key in the Image MCP Server dashboard.

  2. 2

    Open config.toml. Edit ~/.codex/config.toml, or use codex mcp add to have Codex write the entry.

  3. 3

    Add the mcp_servers table. Set url to the endpoint and pass the key via http_headers or env_http_headers.

  4. 4

    Verify with /mcp. Start a Codex session and run /mcp to confirm the server connected and see its tools.

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.

codex · recommendeduse this
# ~/.codex/config.toml
[mcp_servers.imagemcp]
url = "https://mcp.imagemcpserver.com/mcp"
http_headers = { "x-api-key" = "sk-img-gen-…" }
startup_timeout_sec = 30
Keep the key in the environment
# env_http_headers maps a header name to an env var name,
# so the key never lands in the file.
[mcp_servers.imagemcp]
url = "https://mcp.imagemcpserver.com/mcp"
env_http_headers = { "x-api-key" = "IMAGEMCP_API_KEY" }

# Or add it from the shell instead of editing TOML:
#   codex mcp add imagemcp --url https://mcp.imagemcpserver.com/mcp

TOML, and three ways to send the key

Codex is the odd one out: every other client on this list takes JSON or YAML, Codex takes TOML. It also gives you three header mechanisms — http_headers for a static value, env_http_headers to read one from the environment, and bearer_token_env_var if you would rather send an Authorization bearer token. This server accepts all three, so pick on taste rather than necessity.

Check it connected in Codex

In the codex TUI, run /mcp: imagemcp should be listed among the active servers with its tools. From the shell, codex mcp list shows the configured entry before a session starts. 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 Codex

Generate the image a component already imports

  1. 1

    Keep the key in the environment

    Use env_http_headers, so config.toml names IMAGEMCP_API_KEY instead of holding the key.

  2. 2

    Confirm the server

    Run codex mcp list before the session, or /mcp inside it, and check imagemcp is there.

  3. 3

    Close the gap in the same run

    Ask Codex to generate the file the import points at and compress it before writing it. generate_image is 15 credits on the default model; compress_image is 1.

When Codex will not connect

Codex MCP symptoms, their usual cause and the fix
SymptomUsual causeFix
/mcp does not list imagemcpThe table is in a project .codex/config.toml, and Codex only reads that file for trusted projects.Trust the project, or move the table to ~/.codex/config.toml.
Listed, but every call failsenv_http_headers names a variable that is not set in the environment Codex started from.Export IMAGEMCP_API_KEY before launching codex, or use http_headers in your user config.
Codex reports a config parse errorA JSON-style block was pasted into TOML.Keys take =, inline tables look like { "x-api-key" = "…" }, and the header is [mcp_servers.imagemcp].

Once Codex is connected

Codex 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, Transparent PNG generator API and Image compression 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 Codex finds these tools and calls them.

Setting up another client too? The ChatGPT MCP connector setup and Gemini CLI MCP setup guides use the same endpoint and key in a different config shape.

Codex questions

Where is the Codex MCP config file?

MCP servers live in the same file as the rest of your Codex configuration: ~/.codex/config.toml by default. You can also scope a server to one project with .codex/config.toml, which Codex only reads for trusted projects.

Can Codex send a custom header rather than a bearer token?

Yes. http_headers takes a map of header names to static values, and env_http_headers takes a map of header names to environment variable names. bearer_token_env_var exists too if you prefer an Authorization bearer token — this server accepts that form as well.

How do I add an MCP server to Codex from the command line?

codex mcp add <name> --url <endpoint>. It edits config.toml for you, which avoids a hand-written TOML table with a typo in it.

Why do I not see the image tools in my session?

Run /mcp first — it reports each configured server and whether it actually connected. If it is not listed at all, Codex never read the table, which usually means it went into the wrong file or an untrusted project.

Does this work in the Codex IDE extension and the ChatGPT app too?

Codex documents config.toml as shared by the CLI, the IDE extension and the ChatGPT desktop app, so a server added here shows up in all three. ChatGPT on the web adds MCP servers as connectors instead; the ChatGPT guide covers that route.