prism-context-imagegen
v0.2.0
Published
Context-aware image generation and editing for Codex through a configurable local MCP server.
Maintainers
Readme
prism-context-imagegen
Context-aware image generation and editing for Codex IDE and Codex CLI. The package installs a user-level Skill and runs a local STDIO MCP server, so it works in any project without copying Prism AI Studio.
Requirements
- Node.js 18+
- Codex IDE extension or Codex CLI
- A sub2api or OpenAI-compatible synchronous image generation/editing endpoint
Install
Run the generated prompt from Prism AI Studio, or install directly:
npx -y [email protected] setup --yes \
--base-url "https://fastrouter.cloud" \
--model "gpt-image-2" \
--generations-path "/v1/images/generations" \
--edits-path "/v1/images/edits"setup only writes user-level files:
~/.agents/skills/context-imagegen/SKILL.md
~/.codex/config.toml
~/.config/prism-context-imagegen/config.jsonIt does not modify the current project. Restart Codex IDE or open a new Codex session after setup. If data[].url points to a different CDN hostname, explicitly trust it during setup with --download-hosts "cdn.example.com"; the API hostname is trusted automatically.
Configure the API key
Do not paste API keys into a Codex chat or pass them as command-line arguments. Run this yourself in a local terminal:
npx -y [email protected] authThe prompt hides the key. It is stored in the user config file with mode 0600. IMAGE_API_KEY remains supported and takes precedence over the stored key. These environment variables also override stored settings:
IMAGE_API_BASE_URL
IMAGE_API_KEY
IMAGE_API_MODEL
IMAGE_GENERATIONS_PATH
IMAGE_EDITS_PATH
IMAGE_DOWNLOAD_HOSTSVerify
npx -y [email protected] doctor
codex mcp listThe MCP server exposes generate_image and edit_image. It uses MCP roots/list when available and accepts an explicit absolute workspaceRoot for multi-root clients. Roots errors fail closed; clients without roots are restricted to the MCP process working directory. Project inputs and all outputs stay inside the trusted workspace; the only external input exception is Codex session images under CODEX_HOME/generated_images. Existing outputs are rejected unless the user explicitly requested overwrite: true. URL downloads are restricted to the API hostname plus IMAGE_DOWNLOAD_HOSTS, including every redirect.
Commands
prism-imagegen setup --yes [options] Install/update Skill and MCP config
--edits-path PATH Configure sub2api/OpenAI image edits endpoint
--download-hosts HOST1,HOST2 Trust cross-origin image CDN hosts
prism-imagegen auth Save API key from a hidden local prompt
prism-imagegen doctor Check local installation without generating
prism-imagegen serve Run the STDIO MCP serverTools
generate_image
Creates a new image from a context-derived text prompt.
edit_image
Edits one primary workspace image and optionally uses up to two additional references:
prompt Required edit instruction
imagePaths 1-3 workspace-relative images, or absolute Codex generated_images paths
images 1-3 inline { dataUrl, fileName? } images when caller has image bytes
maskPath Optional workspace-relative PNG mask or Codex generated_images path
maskDataUrl Optional inline PNG mask data URL
outputPath Workspace-relative output file
inputFidelity low or high (Skill defaults to high)
size Optional output size
outputFormat png, jpeg, or webpEach source image is limited to 19 MiB to stay below sub2api's 20 MiB multipart-part limit. A mask is limited to 4 MiB and must be PNG. The first image is the primary source. Sources can be workspace paths, Codex session paths under CODEX_HOME/generated_images, or inline base64 data URLs for clients that can provide the original bytes. Arbitrary absolute paths and symlinks are rejected. Outputs remain inside the active workspace. The tool sends repeated image parts, an optional mask, n=1, and response_format=b64_json to IMAGE_EDITS_PATH.
Output path and overwrite checks run before the paid API request. If the path has no extension, the result extension follows the returned image MIME type.
Codex's standard MCP tool call carries JSON arguments and does not automatically attach the visual content of a chat message. Inline data URLs work when a caller actually has the original bytes; if a Codex session exposes only visual context and neither bytes nor a local path, the MCP cannot recover the original image data.
The bundled Skill selects edit_image whenever the request depends on an existing image and never silently downgrades an edit to text-only generation.
Supported responses
The configured image endpoint must return one synchronous result:
{ "data": [{ "url": "https://example.com/image.png" }] }or:
{ "data": [{ "b64_json": "..." }] }Asynchronous taskId responses are not supported yet. Calls default to one image, and the bundled Skill avoids generating extra variants unless the user requests them.
Development
From the Prism AI Studio repository root:
npm install
npm run build:mcp
npm run test:mcp
npm pack --workspace prism-context-imagegen --dry-runBefore public publishing, confirm the package name, repository metadata, and license, then run:
npm publish --workspace prism-context-imagegen