Skip to main content
Glama
openai-image-mcp-secure

openai-image-mcp-secure

by leiting684

openai-image-mcp-secure

供 Google Antigravity、Amazon Quick Desktop 和 DeepSeek Harness 使用的本地 stdio 图像服务。它沿用 rogadev 的 OpenAI Images API 生成、编辑、模型发现、原尺寸保存、JPEG 预览和修订编号,在付费请求发送前增加文件授权与 SQLite 预算检查。各客户端分别启动进程,使用同一 Windows 用户和数据目录时可共享策略、凭据来源和账本。上游与许可证

在 Windows 上安装

在本仓库根目录运行以下命令。需要 uv。已在 Windows 的 Python 3.12、3.13 上验证。项目锁定 MCP 2.3.0、OpenAI Python 3.60.0 和 httpx2 2.16.0。项目保留可执行文件名 openai-image-mcp.exe,客户端应使用本仓库虚拟环境中的绝对路径。

uv sync --locked
.\.venv\Scripts\python.exe -m pytest -q
(Resolve-Path .\.venv\Scripts\openai-image-mcp.exe).Path

初次启动时付费预算为 0 USD。可以先接入客户端,用 get_budget_status 验证启动、工具发现和本地存储。

Related MCP server: imagegen-mcp

密钥与 Pro 赠金

使用已绑定 API Organization 下的项目 API Key。在交互式 PowerShell 中运行以下命令,按提示隐藏输入。它只写入 Windows Credential Manager 的独立项 openai-image-mcp-secure。命令行参数、仓库和客户端 JSON 都不需要填密钥。

.\.venv\Scripts\python.exe manage.py key --no-check

--no-check 跳过联网验钥。默认从凭据管理器读取。仅当凭据库正常且没有保存值,并且子进程显式设置 OPENAI_IMAGE_MCP_ALLOW_ENV_API_KEY=1 时,才读取 OPENAI_API_KEY。凭据库报错会终止请求。保存值始终优先。get_usage 的 key_source 字段记录实际来源。两个桌面模板都使用默认设置。需要指定归属时,官方 SDK 也识别 OPENAI_ORG_ID 和 OPENAI_PROJECT_ID。两个客户端应使用同一项目下的专用 Key。

OpenAI 确认,符合资格且已领取的 Pro API 赠金覆盖绑定组织的 Images API。用量可按公开价格产生费用,再由平台抵扣赠金。赠金用完后,组织若还有购买的额度,后续请求可以继续消费。实际余额、到期日和抵扣结果以该组织的 Billing → Credit grants 为准。官方赠金说明

启用预算和本地目录

策略位于 %LOCALAPPDATA%\openai-image-mcp-secure\policy.json。先审阅 示例策略,按自己愿意承担的金额调整。下面的命令供所有者启用示例时使用,已存在的策略会保留。

$stateDir = Join-Path $env:LOCALAPPDATA 'openai-image-mcp-secure'
New-Item -ItemType Directory -Force -Path $stateDir | Out-Null
$policyFile = Join-Path $stateDir 'policy.json'
if (!(Test-Path -LiteralPath $policyFile)) {
    Copy-Item -LiteralPath .\examples\policy.json -Destination $policyFile
}

示例授权单次 1 美元、每日 2 美元、每月 5 美元、每日 4 次、每次 1 张。每个获准请求独占完整单次预留,按响应 usage 结算后释放差额。日、月以 UTC 划分。客户端工具无法改变这些值。计费、精度与对账

新安装默认输出到数据目录下的 OpenAI Images。升级时若同一数据目录已存在 Claude Images,继续使用旧目录;两目录共存时也优先旧目录。切换目录请显式配置,已有图片保留原位置。可在策略中加入 "output_dir": "D:\\ImageStudio\\output",再通过 "read_dirs": ["D:\\ImageStudio\\input"] 授权额外的专用输入目录。输出目录也可供后续修图读取。策略中的输出目录优先于旧版 IMAGE_OUTPUT_DIR 和手动保存的目录设置。路径使用实际本机目录,JSON 的反斜杠写两次。

输入与输出目录均须使用本机磁盘,Windows 映射网络盘和 UNC 共享路径会被拒绝。

编辑时,参考图与蒙版的图像输入 token 在发送前通常未知。默认策略会拒绝这类编辑。所有者确认接受这项费用不确定性后,可手动设置 "allow_unpriced_inputs": true。此时仍需足额预留,输出与文本的可估部分仍受单次上限检查。配置每次调用重新读取。文件权限与信任范围

工具

工具

用途

联网行为

generate_image

从提示词生成 1 至 4 张图,返回本地路径与预览

付费;受更低的本地数量上限约束

edit_image

用授权目录内的参考图、可选 PNG 蒙版和提示词修图

付费;上传本次指定并校验过的图像

list_image_models

列出 Key 可见的图像模型,标记本地允许项,可按词过滤

查询官方模型目录

estimate_image_cost

输入具体模型、尺寸、质量、数量、可选提示词和参考图数量,查看估算、未知项与准入结果

本地

get_usage

按 UUID 或最近记录查看 usage、预留、结算和交付状态

本地

get_cost_summary

按模型和请求状态汇总费用与在途预留

本地

get_budget_status

查看有效配置、可读目录、当日/月可用额度

本地

manage.py model <模型 ID> 先检查本地能力表、已核验的定价和策略白名单,三项通过后再查询当前 Key 的模型可见性。检查失败时保留原默认模型。latest 会从符合本地条件的候选中选择。图像工具继续在本地拒绝未知参数和不兼容的编辑组合。逐模型能力表

两个付费工具保留原有参数,另接受可选 request_id。需要可靠重试的调用方应先生成 UUID,同一逻辑请求始终复用它。重复 UUID 会返回查询指引。省略 UUID 时由服务器生成。预览由客户端决定如何显示,原尺寸文件路径会随结果返回。

客户端接入与验收

将相应模板中的示例路径换成本机安装路径。DeepSeek Harness 的模板同时注册本地报价钩子和官方 MCP Client,用于生图和编辑的逐次审批。Antigravity 模板 · Amazon Quick 模板 · DeepSeek Harness 模板 · 客户端接入说明

本地测试使用合成图与内存 HTTP 响应,覆盖生成、蒙版编辑、两个独立 stdio 进程竞争同一预算、进程退出、超时重连及账本对账。三端生图已由使用者分别验证。独立零费用验收中,DeepSeek Harness 桌面读回了测试 UUID,Antigravity 和 Quick 对同一条测试记录的回执仍待补齐。Round 2 验收记录 · 第一轮记录

Available Tools

7 tools
edit_imageA

Revises an existing image, or combines several as references, and saves the result.

This is the tool for follow-up changes ("make it black", "add sunglasses", "remove the
background"): pass the saved path of the latest version from the previous result. The
result is saved as the next numbered version, so earlier versions stay available.

Args:
    request_id: Optional client-generated UUID. Reuse on retry to prevent a second paid request.
    prompt: The change to make, and what must stay the same, for example "Make the cat's
        fur black. Keep the pose, background, and lighting unchanged." For several
        references, describe the new image to build from them.
    image_paths: Full paths to one or more local PNG, JPEG, or WebP files. For a revision,
        the single most recent version.
    mask_path: Optional PNG whose transparent areas mark where to edit the first image.
    size: "auto" or WIDTHxHEIGHT, with the same rules as generate_image.
    quality: "low" for fast drafts up to "max".
    background: "transparent" needs output_format "png" or "webp".
    output_format: File format of the saved image.
    n: Number of results, 1 to 4. Each one is billed.
    model: A model ID for this request only. Leave empty to use the user's default.
    open_after: Open each saved image in the user's default image viewer. Set it when the
        user asks to see or open the result, when the client cannot display inline previews.
    input_fidelity: Use "auto" to omit the API parameter. GPT Image 1.5 accepts low or high,
        1 mini accepts low, and the verified 2.x models require auto here.

Inputs: prompt (required), image_paths (required), n, size, +8 more.

estimate_image_costB
Read-only

Offline USD quote. Include the intended prompt and reference count (including mask). An omitted prompt budgets the maximum possible UTF-8 prompt. No files are read.

Inputs: model (required), n, size, prompt, +2 more.

generate_imageA

Generates new images from a text prompt and saves them to the user's image folder.

For changes to an image that already exists, use edit_image on its saved path instead;
generating again produces a different image rather than a revision.

Args:
    request_id: Optional client-generated UUID. Reuse on retry to prevent a second paid request.
    prompt: What to draw. Be specific about subject, style, composition, and any text to render.
    size: "auto", or WIDTHxHEIGHT such as 1024x1024 (square), 1536x1024 (landscape), or
        1024x1536 (portrait). Only the verified 2.x models allow custom dimensions.
    quality: "low" for fast drafts up to "max". "auto" lets the model choose.
    background: "transparent" needs output_format "png" or "webp".
    output_format: File format of the saved image.
    n: Number of images, 1 to 4. Each one is billed.
    model: A model ID for this request only. Leave empty to use the user's default
        (the newest model unless they pinned one). See list_image_models.
    open_after: Open each saved image in the user's default image viewer. Set it when the
        user asks to see or open the result, when the client cannot display inline previews.

Inputs: prompt (required), n, size, model, +5 more.

get_budget_statusA
Read-only

Read local policy and remaining day/month capacity in UTC; excludes organization credits.

Inputs: no named parameters.

get_cost_summaryB
Read-only

Local lifetime costs grouped by exact model and status, in USD.

Inputs: no named parameters. Returns: result

get_usageB
Read-only

Read recent request statuses, numeric usage, reservations and delivery, optionally by UUID.

Inputs: limit, request_id. Returns: result

list_image_modelsA
Read-only

Lists the OpenAI image models the user's API key can use, newest first.

Shows which model is used by default and whether the user pinned one.

Args:
    query: Optional words to filter by, such as "2.5" or "flare".

Inputs: query. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 7 tools

    Disambiguation4/5

    generate_image and edit_image are clearly distinct (new vs. revision), and list_image_models is unambiguous. The four cost/usage tools overlap somewhat—get_budget_status, get_usage, get_cost_summary, and estimate_image_cost all relate to billing—but their descriptions distinguish current capacity, recent requests, lifetime totals, and pre-request quotes.

    Naming Consistency5/5

    All tools follow a consistent snake_case verb_noun pattern: generate_image, edit_image, list_image_models, get_budget_status, estimate_image_cost, get_usage, get_cost_summary. No mixing of conventions.

    Tool Count5/5

    Seven tools is well-scoped for an image generation server with cost and usage management. Each tool covers a distinct responsibility without excessive surface area.

    Completeness4/5

    Core image generation (generate, edit, list models) and cost/usage management are well covered. Minor gaps exist—no tool to list or delete saved images, or fetch metadata for a saved image—but these are not essential for the primary workflow.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers