How to Generate Images with Codex Using MCP Tools

Codex CLI handles code-centric tasks well, but projects often need more than code. Asset generation, visual documentation, placeholder images for UI work — these come up regularly. With AgentPatch connected, Codex can generate images directly instead of you stepping outside your workflow to do it.

Why This Matters

AgentPatch includes a Recraft-powered image generation tool. Recraft is capable of generating realistic photos, digital illustrations, and vector-style graphics from text descriptions. Access it through AgentPatch and Codex gains that capability without you setting up a Recraft account or handling API keys.

The agent uses the tool when the task calls for it. You don’t write the API call. You ask Codex to produce an image as part of whatever you’re working on, and it does.

Setup

Add AgentPatch to ~/.codex/config.toml:

[mcp_servers.agentpatch]
url = "https://agentpatch.ai/mcp"
bearer_token_env_var = "AGENTPATCH_API_KEY"

Then set your API key:

export AGENTPATCH_API_KEY=your_api_key

Replace your_api_key with your actual key from the AgentPatch dashboard. Codex discovers all AgentPatch tools automatically on next start.

Example

You’re scaffolding a new web app and need a placeholder logo. You ask Codex:

“Generate a simple, modern logo mark for a developer tool called ‘Stackr’. Use a geometric shape, dark background, and a bright accent color.”

Codex calls the Recraft image generation tool through AgentPatch and returns the image. You can ask it to save the output to public/images/logo.png directly, since Codex can also handle file writes.

Or you’re building a component library and want visual reference images:

“Generate a clean illustration of a card component UI with a header, body text, and a button. Make it look like a design spec screenshot.”

Codex generates the image through AgentPatch. Your design-to-code workflow gets a bit more self-contained.

You can iterate in the same session:

“Try again but use a light theme with more spacing around the elements.”

Codex calls the tool again with the updated description.

Wrapping Up

Image generation is part of a broader set of tools available through AgentPatch. The same connection also gives Codex access to web search, news, email, Google Maps, and more. One setup, full marketplace access. Visit agentpatch.ai to get started.