gpt-image-mcp
MCP server that exposes OpenAI image generation and editing as tools, focused on creating consistent character expressions by compositing edited regions onto a stable base image.
README
gpt-image-mcp
OpenAI の画像生成/編集を MCP ツールとして出すサーバ。 同じキャラクターの差分絵(口の形・目の開閉)を作る用途を主目的にしている。
なぜ単なるAPIラッパーではないか
/v1/images/edits は、マスクを渡しても画像全体を再生成する。
実測(2026-08-12・gpt-image-2・1024x1024):
| マスク内で変化 | マスク外で変化 | マスク外の最大差分 | |
|---|---|---|---|
| 口を「あ」に編集 | 7,184px (35.8%) | 9,425px (0.92%) | 220 |
| 口を「い」に編集 | 1,498px (7.5%) | 7,431px (0.72%) | 216 |
最大差分220は「ほぼ別の色」。編集結果をそのまま動画のコマに使うと、口が変わるたびに髪や輪郭も動く—— 30fps で切り替えると顔が揺れる。
このサーバは対処を同梱している。編集結果は「口の形の参考」として扱い、土台は1枚に固定して、
マスク領域だけをローカルで貼り直す(compose_region)。土台はビット単位で保たれる。
| マスク外の最大差分 | |
|---|---|
| 編集結果をそのまま使う | 220 |
| 単純にぼかして合成 | 55(ぼけがマスク外へ滲む) |
compose_region(内側だけぼかす) |
10(知覚不能) |
ツール
| ツール | 課金 | 何をするか |
|---|---|---|
list_image_models |
なし | このキーで使える画像モデルを列挙。キーが生きているかの確認にも使う |
generate_image |
あり | プロンプトから生成し、ファイルに保存してパスを返す |
edit_image |
あり | マスク指定で編集。そのままコマに使わないこと(上記) |
compose_region |
なし | 編集結果のマスク領域だけを土台へ貼る。土台の汚れを自動検証する |
make_mask |
なし | 楕円マスクを作る(比率指定) |
画像は base64 で返さずファイルに書いてパスを返す。会話の文脈を食い潰さないため。
APIキーの扱い
このサーバはキーを保持しない。 呼ぶたびに、次の順で解決する。
- 環境変数
OPENAI_API_KEY - macOS Keychain(
OPENAI_KEYCHAIN_SERVICEにサービス名を設定した場合)
エラー本文にキーが混ざった場合は [REDACTED] に置換してから返す。
Keychain へ入れる場合(コマンド履歴にキーを残さない形):
printf 'key: '; stty -echo; read -r K; stty echo; echo
security add-generic-password -a "$USER" -s openai-image -U -w "$K"; unset K
⚠
securityの対話入力(-wを引数なしで最後に置く形)は128文字で切り捨てる。sk-proj-形式のキーは164文字あるため、上の「値として渡す」形を使うこと。
設定
.mcp.json / Claude Code の MCP 設定に追加する。
{
"mcpServers": {
"gpt-image": {
"command": "node",
"args": ["/path/to/gpt-image-mcp/src/index.mjs"],
"env": { "OPENAI_KEYCHAIN_SERVICE": "openai-image" }
}
}
}
必要なもの
- Node.js 18+(
fetch/FormDataを使う) - Python 3 + Pillow(
compose_region/make_mask)。numpyがあれば土台の汚れを自動検証する
npm install
pip install Pillow numpy
アバターの作り方(この構成での標準手順)
generate_imageで土台を1枚作る。背景は単色、影とグラデーションを禁止、正面向き、口は閉じ目は開くmake_maskで口の領域(目安0.40 / 0.455 / 0.60 / 0.575)と目の領域(0.34 / 0.32 / 0.66 / 0.42)のマスクを作るedit_imageで口の形(あいうえお)と閉じた目を作るcompose_regionで全部を土台へ貼り直す ← ここを飛ばすと顔が揺れる- 口の形は母音ごとに1枚。日本語の口パクは
a i u e o+ 閉じ口の6枚で足りる
⚠ 「い」のように変化が小さい口の形は生成が弱い(実測でマスク内の変化が7.5%しか出ず、 マスク外のほうが動いた)。プロンプトを形で具体的に指示するか、その口だけ手で描くほうが早い。
生成物の権利
生成画像を販売物に使う場合、「動画に使ってよい」と「販売する教材に使ってよい」が 別条項のことがある。使う前に、使うキーのアカウントの利用規約を確認すること。 借りたキーで作った素材を自社商品に使わない。
ライセンス
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.