image-router-mcp 0.1.5 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,12 +21,24 @@ Run it directly from npm with `npx`. You only need an API key for the provider y
21
21
 
22
22
  | Tool | Provider | Built-in default model | Supports |
23
23
  | --- | --- | --- | --- |
24
- | `openai_generate_image` | OpenAI | `gpt-image-2` | Text-to-image and local reference/edit images |
24
+ | `openai_generate_image` | OpenAI | `gpt-image-2.5-sunburst` | Text-to-image and local reference/edit images, including `xhigh`/`max` quality |
25
25
  | `google_generate_image` | Google Gemini/Nano Banana | `gemini-3.1-flash-image` | Text-to-image and local reference/edit images through the Interactions API |
26
- | `xai_generate_image` | xAI/Grok | `grok-imagine-image-quality` | Text-to-image and edits with up to 3 local input images |
26
+ | `xai_generate_image` | xAI/Grok | `grok-imagine-image-2.0` | Text-to-image and edits with up to 5 local input images |
27
27
 
28
28
  Model IDs are examples and defaults, not an allowlist. Other compatible model IDs can be supplied through the `model` argument.
29
29
 
30
+ ### Model update notes (checked 2026-10-05)
31
+
32
+ - OpenAI: Sunburst is the default for editing precision. Choose `gpt-image-2.5-flare` for everyday generation, or explicitly set `gpt-image-2` to retain the previous model. `xhigh` and `max` require GPT Image 2.5 or a compatible newer model. [Official guide](https://developers.openai.com/api/docs/guides/image-generation)
33
+ - Google: `gemini-3.1-flash-lite-image` (Nano Banana 2 Lite) is an optional faster, lower-cost model, limited to `1K` output. The default remains `gemini-3.1-flash-image`. [Official guide](https://ai.google.dev/gemini-api/docs/image-generation)
34
+ - xAI: Imagine Image 2.0 replaces the previous built-in default. The old `grok-imagine-image-quality` slug is scheduled to redirect to 2.0 at `low` quality on November 2, 2026. With 2.0, omitted `quality` uses provider `auto`, currently `low` for generation and `medium` for edits. Pin `quality` to control this cost/quality choice. Environment model pins still take precedence. [Migration guide](https://docs.x.ai/developers/migration/imagine-image-quality-nov-2)
35
+
36
+ Model access depends on your provider account. No automatic fallback to another paid model is performed.
37
+
38
+ Version 0.2.1 keeps these defaults and Node.js 20 support. It fixes `moderation` forwarding for GPT Image edits, validates legacy xAI dated aliases, and updates MCP SDK 1.32.0 plus two vulnerable transitive dependencies. See the [October audit](https://github.com/JiaDians/image-router-mcp/blob/main/docs/provider-audits/2026-10-05.md) for sources, deferred changes and verification limits.
39
+
40
+ If you pin an older OpenAI model, review its retirement date: `gpt-image-1` on October 23, 2026, and `gpt-image-1-mini`, `gpt-image-1.5`, `chatgpt-image-latest` on December 1, 2026. Explicit pins are not silently migrated. [Official deprecations](https://developers.openai.com/api/docs/deprecations)
41
+
30
42
  ## Prerequisites
31
43
 
32
44
  - Node.js 20 or later, including `npm` and `npx`.
@@ -121,7 +133,7 @@ Use absolute paths in prompts and tool calls. Relative paths depend on the worki
121
133
  - When `output_path` is omitted, files are saved under `DEFAULT_OUTPUT_DIR`, or `./generated-images` relative to the MCP server working directory.
122
134
  - Use absolute input and output paths for predictable behavior across clients.
123
135
  - For portable local-image use across providers, use PNG, JPG/JPEG, or WebP files. The Google and xAI loaders accept these extensions.
124
- - xAI accepts at most 3 `input_images`.
136
+ - xAI Imagine Image 2.0 accepts at most 5 `input_images`. Older model IDs retain the 3-image limit.
125
137
 
126
138
  ### Return modes
127
139
 
@@ -153,10 +165,11 @@ Use `file` for large images. Use `inline` or `both` only when the MCP client can
153
165
  | Parameter | Values or examples | Default |
154
166
  | --- | --- | --- |
155
167
  | `size` | `auto`, `1024x1024`, `1536x1024`, or another supported `WIDTHxHEIGHT` | Provider default |
156
- | `quality` | `auto`, `low`, `medium`, `high`, `standard`, `hd` | Provider default |
168
+ | `quality` | `auto`, `low`, `medium`, `high`, `xhigh`, `max`, `standard`, `hd` (model-dependent) | Provider default |
157
169
  | `background` | `transparent`, `opaque`, `auto` | Provider default |
158
170
  | `output_format` | `png`, `jpeg`, `webp` | `png` |
159
- | `moderation` | `low`, `auto` | Provider default |
171
+ | `output_compression` | Integer `0`–`100`, GPT Image JPEG/WebP output only | Provider default |
172
+ | `moderation` | `low`, `auto`, for GPT Image generation and editing (not sent to DALL-E) | Provider default |
160
173
  | `style` | `vivid`, `natural`; used with DALL-E 3 | Provider default |
161
174
 
162
175
  ### Google parameters
@@ -165,15 +178,25 @@ Use `file` for large images. Use `inline` or `both` only when the MCP client can
165
178
  | --- | --- | --- |
166
179
  | `aspect_ratio` | For example `1:1`, `16:9`, `9:16`, `4:3`, or `3:2` | Provider default |
167
180
  | `image_size` | `512`, `0.5K`, `1K`, `2K`, `4K`; availability depends on the model | Provider default |
181
+ | `output_format` | `png`, `jpeg` | Provider default |
182
+ | `thinking_level` | `minimal`, `high`, for Gemini 3.1 Flash Image / Flash Lite Image | Provider default |
183
+ | `previous_interaction_id` | `metadata.interactionId` from a previous Google result | None |
168
184
 
169
185
  `0.5K` is accepted as a legacy alias and normalized to `512`.
170
186
 
187
+ For a follow-up edit, pass the previous result's `metadata.interactionId` as `previous_interaction_id` with the new prompt. The previous interaction must still be available in the same Google account. This uses provider-stored conversation context and follows Google's retention policy. A stale or unavailable ID returns an error without silently starting a new generation. Lite is not optimized for sequential editing. Higher thinking levels can increase cost and latency.
188
+
171
189
  ### xAI parameters
172
190
 
173
191
  | Parameter | Values or examples | Default |
174
192
  | --- | --- | --- |
175
193
  | `aspect_ratio` | For example `1:1`, `16:9`, `9:16`, `3:2`, or `auto` | Provider default |
176
194
  | `resolution` | `1k`, `2k` | Provider default |
195
+ | `quality` | `low`, `medium`, `auto`, for Imagine Image 2.0 or compatible newer models | Provider `auto` |
196
+
197
+ Aspect ratios also accept `21:9` and `5:2`. When xAI returns its serving model ID, it is included as `metadata.servedModel`. The top-level `model` continues to identify the requested model.
198
+
199
+ Legacy dated aliases such as `grok-imagine-image-2026-03-02` retain the three-reference limit and reject the 2.0-only `quality` parameter, including when selected through `DEFAULT_XAI_IMAGE_MODEL`.
177
200
 
178
201
  ## Configuration
179
202
 
@@ -198,7 +221,7 @@ Most users can ask their MCP client in natural language. If your client supports
198
221
  "tool": "openai_generate_image",
199
222
  "arguments": {
200
223
  "prompt": "A cinematic product photo of a transparent mechanical keyboard on a marble desk",
201
- "model": "gpt-image-2",
224
+ "model": "gpt-image-2.5-sunburst",
202
225
  "size": "1024x1024",
203
226
  "return_mode": "file",
204
227
  "output_path": "/absolute/path/to/generated-images"
package/README.zh-TW.md CHANGED
@@ -21,12 +21,24 @@
21
21
 
22
22
  | 工具 | 供應商 | 內建預設模型 | 支援內容 |
23
23
  | --- | --- | --- | --- |
24
- | `openai_generate_image` | OpenAI | `gpt-image-2` | 文字生成圖片及本機參考圖/編輯圖 |
24
+ | `openai_generate_image` | OpenAI | `gpt-image-2.5-sunburst` | 文字生成圖片及本機參考圖/編輯圖,支援 `xhigh`/`max` 品質 |
25
25
  | `google_generate_image` | Google Gemini/Nano Banana | `gemini-3.1-flash-image` | 透過 Interactions API 進行文字生成圖片及本機參考圖/編輯圖 |
26
- | `xai_generate_image` | xAI/Grok | `grok-imagine-image-quality` | 文字生成圖片,以及最多 3 張本機輸入圖的編輯 |
26
+ | `xai_generate_image` | xAI/Grok | `grok-imagine-image-2.0` | 文字生成圖片,以及最多 5 張本機輸入圖的編輯 |
27
27
 
28
28
  以上模型是範例與預設值,不是允許清單。可透過 `model` 參數傳入其他相容的模型 ID。
29
29
 
30
+ ### 模型更新說明(2026-10-05 查核)
31
+
32
+ - OpenAI:預設使用偏重精準編輯的 Sunburst,日常生成可選 `gpt-image-2.5-flare`。若要維持先前模型,可明確指定 `gpt-image-2`。`xhigh`、`max` 需使用 GPT Image 2.5 或相容的新模型。[官方指南](https://developers.openai.com/api/docs/guides/image-generation)
33
+ - Google:可選速度更快、成本較低的 `gemini-3.1-flash-lite-image`(Nano Banana 2 Lite),僅支援 `1K` 輸出。預設仍為 `gemini-3.1-flash-image`。[官方指南](https://ai.google.dev/gemini-api/docs/image-generation)
34
+ - xAI:內建預設改為 Imagine Image 2.0。舊 `grok-imagine-image-quality` 預計於 2026 年 11 月 2 日轉向 2.0 的 `low` 品質。2.0 未指定 `quality` 時採供應商的 `auto`,目前生成使用 `low`、編輯使用 `medium`,費用隨實際品質而異。可明確指定品質,環境變數固定模型的行為仍保留。[遷移指南](https://docs.x.ai/developers/migration/imagine-image-quality-nov-2)
35
+
36
+ 模型存取權依供應商帳戶而定。無法使用時,不會自動改呼叫其他付費模型。
37
+
38
+ 0.2.1 維持以上預設值及 Node.js 20 支援,修正 GPT Image 編輯時的 `moderation` 傳遞與 xAI 舊日期版模型的限制檢查,更新 MCP SDK 至 1.32.0 並修補兩項間接依賴漏洞。官方來源、暫緩項目及驗證範圍見[十月查核紀錄](https://github.com/JiaDians/image-router-mcp/blob/main/docs/provider-audits/2026-10-05.md)。
39
+
40
+ 若固定使用舊 OpenAI 模型,請留意停用日期:`gpt-image-1` 為 2026 年 10 月 23 日,`gpt-image-1-mini`、`gpt-image-1.5`、`chatgpt-image-latest` 為 2026 年 12 月 1 日。本工具不會暗中替換指定模型。[官方棄用公告](https://developers.openai.com/api/docs/deprecations)
41
+
30
42
  ## 前置需求
31
43
 
32
44
  - Node.js 20 以上版本,並包含 `npm` 與 `npx`。
@@ -39,7 +51,7 @@
39
51
  呼叫供應商 API 可能產生費用。只需設定實際要使用的供應商 Key。
40
52
 
41
53
  > [!WARNING]
42
- > 請勿將真實 API Key 提交到版本控制。含有密鑰的設定建議放在使用者層級;若 MCP 客戶端支援,也可從既有環境變數轉送 Key。
54
+ > 請勿將真實 API Key 提交到版本控制。含有密鑰的設定建議放在使用者層級,若 MCP 客戶端支援,也可從既有環境變數轉送 Key。
43
55
 
44
56
  ## 快速開始
45
57
 
@@ -117,18 +129,18 @@ OPENAI_API_KEY = "your_openai_key"
117
129
  - `input_images` 路徑會從 MCP server process 的工作目錄開始解析。
118
130
  - `output_path` 可以是檔案路徑或資料夾。
119
131
  - 已存在的資料夾,或沒有副檔名的新路徑,會被視為資料夾。
120
- - 帶有副檔名的路徑會被視為指定輸出檔名;若有多張結果,檔名會加入編號。
121
- - 未傳入 `output_path` 時,圖片會儲存在 `DEFAULT_OUTPUT_DIR`;若未設定該變數,則使用 MCP server 工作目錄下的 `./generated-images`。
132
+ - 帶有副檔名的路徑會被視為指定輸出檔名,若有多張結果,檔名會加入編號。
133
+ - 未傳入 `output_path` 時,圖片會儲存在 `DEFAULT_OUTPUT_DIR`,若未設定該變數,則使用 MCP server 工作目錄下的 `./generated-images`。
122
134
  - 建議輸入與輸出都使用絕對路徑,確保不同客戶端有一致結果。
123
135
  - 若要跨供應商使用本機圖片,建議採用 PNG、JPG/JPEG 或 WebP。Google 與 xAI 的載入器接受這些副檔名。
124
- - xAI 最多接受 3 張 `input_images`。
136
+ - xAI Imagine Image 2.0 最多接受 5 張 `input_images`,舊模型維持 3 張限制。
125
137
 
126
138
  ### 回傳模式
127
139
 
128
140
  | 模式 | 行為 |
129
141
  | --- | --- |
130
142
  | `file` | 預設。將圖片儲存到磁碟並回傳路徑。 |
131
- | `inline` | 不儲存檔案,直接回傳 MCP `image` content;每張圖片受 `inline_max_bytes` 限制。 |
143
+ | `inline` | 不儲存檔案,直接回傳 MCP `image` content,每張圖片受 `inline_max_bytes` 限制。 |
132
144
  | `both` | 同時儲存圖片並回傳 inline MCP 圖片內容。 |
133
145
 
134
146
  大型圖片建議使用 `file`。只有在 MCP 客戶端可以顯示圖片、且結果符合 payload 限制時,才使用 `inline` 或 `both`。
@@ -145,7 +157,7 @@ OPENAI_API_KEY = "your_openai_key"
145
157
  | `output_path` | 否 | `DEFAULT_OUTPUT_DIR` 或 `./generated-images` | 儲存結果的檔案或資料夾。 |
146
158
  | `return_mode` | 否 | `file` | `file`、`inline` 或 `both`。 |
147
159
  | `inline_max_bytes` | 否 | `4194304`(4 MiB) | 每張 inline 圖片允許的最大大小。 |
148
- | `n` | 否 | 供應商預設值 | 供應商支援時的結果數量,範圍為 1 到 10;Google 目前回傳一張。 |
160
+ | `n` | 否 | 供應商預設值 | 供應商支援時的結果數量,範圍為 1 到 10,Google 目前回傳一張。 |
149
161
  | `user` | 否 | — | 選用的終端使用者識別碼,供供應商進行濫用監控。 |
150
162
 
151
163
  ### OpenAI 參數
@@ -153,27 +165,38 @@ OPENAI_API_KEY = "your_openai_key"
153
165
  | 參數 | 值或範例 | 預設值 |
154
166
  | --- | --- | --- |
155
167
  | `size` | `auto`、`1024x1024`、`1536x1024` 或其他支援的 `WIDTHxHEIGHT` | 供應商預設值 |
156
- | `quality` | `auto`、`low`、`medium`、`high`、`standard`、`hd` | 供應商預設值 |
168
+ | `quality` | `auto`、`low`、`medium`、`high`、`xhigh`、`max`、`standard`、`hd`,依模型支援 | 供應商預設值 |
157
169
  | `background` | `transparent`、`opaque`、`auto` | 供應商預設值 |
158
170
  | `output_format` | `png`、`jpeg`、`webp` | `png` |
159
- | `moderation` | `low`、`auto` | 供應商預設值 |
160
- | `style` | `vivid`、`natural`;供 DALL-E 3 使用 | 供應商預設值 |
171
+ | `output_compression` | 整數 `0`–`100`,僅供 GPT Image 的 JPEG/WebP 輸出使用 | 供應商預設值 |
172
+ | `moderation` | `low`、`auto`,適用 GPT Image 生成與編輯,不傳給 DALL-E | 供應商預設值 |
173
+ | `style` | `vivid`、`natural`,供 DALL-E 3 使用 | 供應商預設值 |
161
174
 
162
175
  ### Google 參數
163
176
 
164
177
  | 參數 | 值或範例 | 預設值 |
165
178
  | --- | --- | --- |
166
179
  | `aspect_ratio` | 例如 `1:1`、`16:9`、`9:16`、`4:3` 或 `3:2` | 供應商預設值 |
167
- | `image_size` | `512`、`0.5K`、`1K`、`2K`、`4K`;實際可用值依模型而定 | 供應商預設值 |
180
+ | `image_size` | `512`、`0.5K`、`1K`、`2K`、`4K`,實際可用值依模型而定 | 供應商預設值 |
181
+ | `output_format` | `png`、`jpeg` | 供應商預設值 |
182
+ | `thinking_level` | `minimal`、`high`,供 Gemini 3.1 Flash Image/Flash Lite Image 使用 | 供應商預設值 |
183
+ | `previous_interaction_id` | 前次 Google 結果的 `metadata.interactionId` | 無 |
168
184
 
169
185
  `0.5K` 是相容舊版的別名,送出前會正規化為 `512`。
170
186
 
187
+ 連續編輯時,將前次結果的 `metadata.interactionId` 放入 `previous_interaction_id`,並提供新的提示詞。前次互動必須仍可由同一 Google 帳戶存取。此功能使用供應商儲存的對話脈絡,適用 Google 的資料保留政策。ID 過期或無法使用時會回報錯誤,不會悄悄重新生成。Lite 不以連續編輯為主要用途,提高思考等級可能增加費用與等待時間。
188
+
171
189
  ### xAI 參數
172
190
 
173
191
  | 參數 | 值或範例 | 預設值 |
174
192
  | --- | --- | --- |
175
193
  | `aspect_ratio` | 例如 `1:1`、`16:9`、`9:16`、`3:2` 或 `auto` | 供應商預設值 |
176
194
  | `resolution` | `1k`、`2k` | 供應商預設值 |
195
+ | `quality` | `low`、`medium`、`auto`,供 Imagine Image 2.0 或相容新模型使用 | 供應商 `auto` |
196
+
197
+ 長寬比亦可指定 `21:9`、`5:2`。xAI 回傳實際服務模型時,會記錄於 `metadata.servedModel`。最外層的 `model` 仍表示請求指定的模型。
198
+
199
+ `grok-imagine-image-2026-03-02` 等舊日期版別名維持三張參考圖限制,不接受 2.0 才支援的 `quality` 參數。透過 `DEFAULT_XAI_IMAGE_MODEL` 固定模型時亦會檢查。
177
200
 
178
201
  ## 環境設定
179
202
 
@@ -182,10 +205,10 @@ OPENAI_API_KEY = "your_openai_key"
182
205
  | `OPENAI_API_KEY` | 使用 OpenAI 工具時需要 | OpenAI API Key。 |
183
206
  | `GOOGLE_API_KEY` 或 `GEMINI_API_KEY` | 使用 Google 工具時需要 | Google Gemini API Key。 |
184
207
  | `XAI_API_KEY` | 使用 xAI 工具時需要 | xAI API Key。 |
185
- | `DEFAULT_OPENAI_IMAGE_MODEL` | 否 | 未傳入 `model` 時使用的 OpenAI 預設模型;明確傳入的 `model` 可以覆寫。 |
208
+ | `DEFAULT_OPENAI_IMAGE_MODEL` | 否 | 未傳入 `model` 時使用的 OpenAI 預設模型,明確傳入的 `model` 可以覆寫。 |
186
209
  | `DEFAULT_GOOGLE_IMAGE_MODEL` | 否 | 將 Google 請求固定到此模型,優先於每次呼叫的 `model` 參數。 |
187
210
  | `DEFAULT_XAI_IMAGE_MODEL` | 否 | 將 xAI 請求固定到此模型,優先於每次呼叫的 `model` 參數。 |
188
- | `DEFAULT_OUTPUT_DIR` | 否 | 預設圖片儲存資料夾;預設為 MCP server 工作目錄下的 `./generated-images`。 |
211
+ | `DEFAULT_OUTPUT_DIR` | 否 | 預設圖片儲存資料夾,預設為 MCP server 工作目錄下的 `./generated-images`。 |
189
212
 
190
213
  Key 只會在呼叫對應工具時檢查,因此只設定一個供應商 Key 即可開始使用。
191
214
 
@@ -198,7 +221,7 @@ Key 只會在呼叫對應工具時檢查,因此只設定一個供應商 Key
198
221
  "tool": "openai_generate_image",
199
222
  "arguments": {
200
223
  "prompt": "A cinematic product photo of a transparent mechanical keyboard on a marble desk",
201
- "model": "gpt-image-2",
224
+ "model": "gpt-image-2.5-sunburst",
202
225
  "size": "1024x1024",
203
226
  "return_mode": "file",
204
227
  "output_path": "/absolute/path/to/generated-images"
@@ -233,7 +256,7 @@ Google 參考圖範例:
233
256
 
234
257
  - 檢查 JSON 或 TOML 語法,以及設定檔位置。
235
258
  - 編輯設定後,完整重新啟動 MCP 客戶端。
236
- - Codex 使用 `/mcp` 檢查;Cursor 前往 **Settings > Tools & MCP**。
259
+ - Codex 使用 `/mcp` 檢查,Cursor 前往 **Settings > Tools & MCP**。
237
260
 
238
261
  ### API 驗證或帳務錯誤
239
262
 
@@ -245,7 +268,7 @@ Google 參考圖範例:
245
268
 
246
269
  ### Inline 圖片超過 4 MiB
247
270
 
248
- 改用 `return_mode: "file"`;只有在客戶端能接受較大 payload 時,才提高 `inline_max_bytes`。
271
+ 改用 `return_mode: "file"`,只有在客戶端能接受較大 payload 時,才提高 `inline_max_bytes`。
249
272
 
250
273
  ## 開發
251
274
 
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { pathToFileURL } from "node:url";
3
+ import { readFileSync } from "node:fs";
3
4
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
5
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
6
  import { formatError } from "./errors.js";
@@ -30,11 +31,11 @@ function errorResult(error) {
30
31
  export function createServer() {
31
32
  const server = new McpServer({
32
33
  name: "image-router-mcp",
33
- version: "0.1.0",
34
+ version: JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version,
34
35
  });
35
36
  server.registerTool("openai_generate_image", {
36
37
  title: "OpenAI image generation and editing",
37
- description: "Generate or edit images with OpenAI image models. Model is a flexible string so newly released image models are not blocked.",
38
+ description: "Generate or edit images with OpenAI GPT Image 2.5 Sunburst and Flare, including xhigh/max quality, JPEG/WebP compression and optional moderation on both endpoints. Compatible model IDs remain flexible.",
38
39
  inputSchema: openAIInputShape,
39
40
  }, async (rawParams) => {
40
41
  try {
@@ -48,7 +49,7 @@ export function createServer() {
48
49
  });
49
50
  server.registerTool("google_generate_image", {
50
51
  title: "Google Gemini/Nano Banana image generation and editing",
51
- description: "Generate or edit images with Google Gemini image models, including Nano Banana, Nano Banana 2, and Nano Banana Pro model IDs.",
52
+ description: "Generate or edit images with Google Gemini image models, including Nano Banana 2, Nano Banana 2 Lite, and Nano Banana Pro. Continue edits with previous_interaction_id and choose PNG/JPEG output.",
52
53
  inputSchema: googleInputShape,
53
54
  }, async (rawParams) => {
54
55
  try {
@@ -62,7 +63,7 @@ export function createServer() {
62
63
  });
63
64
  server.registerTool("xai_generate_image", {
64
65
  title: "xAI/Grok image generation and editing",
65
- description: "Generate or edit images with xAI Grok Imagine models. Local input_images are sent as data URIs for the xAI JSON image edit endpoint.",
66
+ description: "Generate or edit images with xAI Imagine Image 2.0, with low/medium/auto quality and up to five local reference images sent as data URIs. Older model IDs remain available.",
66
67
  inputSchema: xaiInputShape,
67
68
  }, async (rawParams) => {
68
69
  try {
@@ -1,6 +1,6 @@
1
1
  import { GoogleGenAI } from "@google/genai";
2
2
  import { base64FromUrl, bytesFromBase64, loadInputImages } from "../files.js";
3
- import { requireEnv } from "../errors.js";
3
+ import { requireEnv, UserInputError } from "../errors.js";
4
4
  let googleClient;
5
5
  function getGoogleClient() {
6
6
  if (!googleClient) {
@@ -13,6 +13,9 @@ export function setGoogleClientForTests(client) {
13
13
  }
14
14
  export async function generateGoogleImage(params, client = getGoogleClient()) {
15
15
  const model = process.env.DEFAULT_GOOGLE_IMAGE_MODEL ?? params.model;
16
+ if (/^gemini-3\.1-flash-lite-image(?:-|$)/.test(model) && params.image_size && params.image_size !== "1K") {
17
+ throw new UserInputError("Gemini 3.1 Flash Lite Image supports only image_size 1K.");
18
+ }
16
19
  const inputImages = await loadInputImages(params.input_images);
17
20
  const input = [
18
21
  ...inputImages.map((image) => ({
@@ -25,9 +28,12 @@ export async function generateGoogleImage(params, client = getGoogleClient()) {
25
28
  const response = await client.interactions.create({
26
29
  model,
27
30
  input,
31
+ ...(params.previous_interaction_id ? { previous_interaction_id: params.previous_interaction_id } : {}),
32
+ ...(params.thinking_level ? { generation_config: { thinking_level: params.thinking_level } } : {}),
28
33
  response_format: {
29
34
  type: "image",
30
35
  delivery: "inline",
36
+ ...(params.output_format ? { mime_type: `image/${params.output_format}` } : {}),
31
37
  ...(params.aspect_ratio ? { aspect_ratio: params.aspect_ratio } : {}),
32
38
  ...(params.image_size ? { image_size: params.image_size === "0.5K" ? "512" : params.image_size } : {}),
33
39
  },
@@ -37,7 +43,7 @@ export async function generateGoogleImage(params, client = getGoogleClient()) {
37
43
  if (outputImage?.data) {
38
44
  image = {
39
45
  data: outputImage.data,
40
- mimeType: outputImage.mime_type ?? "image/png",
46
+ mimeType: outputImage.mime_type ?? `image/${params.output_format ?? "png"}`,
41
47
  bytes: bytesFromBase64(outputImage.data),
42
48
  };
43
49
  }
@@ -30,10 +30,20 @@ async function imageFromOpenAIItem(item, mimeType) {
30
30
  throw new Error("OpenAI response did not include b64_json or url image data.");
31
31
  }
32
32
  export async function generateOpenAIImage(params, client = getOpenAIClient()) {
33
- const model = params.model ?? process.env.DEFAULT_OPENAI_IMAGE_MODEL ?? "gpt-image-2";
33
+ const model = params.model ?? process.env.DEFAULT_OPENAI_IMAGE_MODEL ?? "gpt-image-2.5-sunburst";
34
34
  const outputFormat = params.output_format ?? "png";
35
35
  const inputImages = params.input_images ?? [];
36
36
  const dallEModel = isDallEModel(model);
37
+ if (params.output_compression !== undefined && (dallEModel || outputFormat === "png")) {
38
+ throw new UserInputError("output_compression requires a GPT Image model with output_format jpeg or webp.");
39
+ }
40
+ if ((params.quality === "xhigh" || params.quality === "max") &&
41
+ (dallEModel || /^gpt-image-(?:1(?:[.-]|$)|2(?:-|$))/.test(model))) {
42
+ throw new UserInputError("Quality xhigh and max require GPT Image 2.5 or a compatible newer model.");
43
+ }
44
+ // SDK 6 keeps Node.js 20 support. It forwards the API's new quality values unchanged,
45
+ // but its type declarations predate GPT Image 2.5. Wire-format tests cover both endpoints.
46
+ const quality = params.quality;
37
47
  const common = {
38
48
  model,
39
49
  prompt: params.prompt,
@@ -45,6 +55,8 @@ export async function generateOpenAIImage(params, client = getOpenAIClient()) {
45
55
  : {
46
56
  background: params.background,
47
57
  output_format: outputFormat,
58
+ output_compression: params.output_compression,
59
+ moderation: params.moderation,
48
60
  }),
49
61
  };
50
62
  const response = inputImages.length > 0
@@ -54,7 +66,7 @@ export async function generateOpenAIImage(params, client = getOpenAIClient()) {
54
66
  }
55
67
  return client.images.edit({
56
68
  ...common,
57
- quality: params.quality,
69
+ quality: quality,
58
70
  image: inputImages.length === 1
59
71
  ? createReadStream(inputImages[0])
60
72
  : inputImages.map((imagePath) => createReadStream(imagePath)),
@@ -62,8 +74,8 @@ export async function generateOpenAIImage(params, client = getOpenAIClient()) {
62
74
  })()
63
75
  : await client.images.generate({
64
76
  ...common,
65
- quality: params.quality,
66
- ...(dallEModel ? { style: params.style } : { moderation: params.moderation }),
77
+ quality,
78
+ ...(dallEModel ? { style: params.style } : {}),
67
79
  });
68
80
  const data = "data" in response ? response.data ?? [] : [];
69
81
  if (data.length === 0) {
@@ -1,5 +1,5 @@
1
1
  import { base64FromUrl, bytesFromBase64, loadInputImages, toDataUri } from "../files.js";
2
- import { requireEnv } from "../errors.js";
2
+ import { requireEnv, UserInputError } from "../errors.js";
3
3
  const XAI_BASE_URL = "https://api.x.ai/v1";
4
4
  async function imageFromXAIItem(item) {
5
5
  if (item.b64_json) {
@@ -17,6 +17,13 @@ async function imageFromXAIItem(item) {
17
17
  }
18
18
  export async function generateXAIImage(params, fetchImpl = fetch) {
19
19
  const model = process.env.DEFAULT_XAI_IMAGE_MODEL ?? params.model;
20
+ const legacyModel = /^grok-imagine-image(?:-quality|-pro)?(?:-latest|-\d{8}|-\d{4}-\d{2}-\d{2})?$/.test(model);
21
+ if (legacyModel && (params.input_images?.length ?? 0) > 3) {
22
+ throw new UserInputError("This older xAI model supports up to 3 input images. Use grok-imagine-image-2.0 for up to 5.");
23
+ }
24
+ if (legacyModel && params.quality !== undefined) {
25
+ throw new UserInputError("The quality parameter requires grok-imagine-image-2.0 or a compatible newer model.");
26
+ }
20
27
  const inputImages = await loadInputImages(params.input_images);
21
28
  const isEdit = inputImages.length > 0;
22
29
  const body = {
@@ -25,6 +32,7 @@ export async function generateXAIImage(params, fetchImpl = fetch) {
25
32
  n: params.n,
26
33
  aspect_ratio: params.aspect_ratio,
27
34
  resolution: params.resolution,
35
+ quality: params.quality,
28
36
  response_format: "b64_json",
29
37
  user: params.user,
30
38
  };
@@ -58,6 +66,7 @@ export async function generateXAIImage(params, fetchImpl = fetch) {
58
66
  images: await Promise.all(data.map(imageFromXAIItem)),
59
67
  metadata: {
60
68
  usage: "usage" in responseBody ? responseBody.usage : undefined,
69
+ servedModel: "model" in responseBody ? responseBody.model : undefined,
61
70
  },
62
71
  };
63
72
  }
package/dist/schemas.d.ts CHANGED
@@ -13,6 +13,8 @@ export declare const openAIInputShape: {
13
13
  low: "low";
14
14
  medium: "medium";
15
15
  high: "high";
16
+ xhigh: "xhigh";
17
+ max: "max";
16
18
  standard: "standard";
17
19
  hd: "hd";
18
20
  }>>;
@@ -26,6 +28,7 @@ export declare const openAIInputShape: {
26
28
  jpeg: "jpeg";
27
29
  webp: "webp";
28
30
  }>>;
31
+ readonly output_compression: z.ZodOptional<z.ZodNumber>;
29
32
  readonly moderation: z.ZodOptional<z.ZodEnum<{
30
33
  auto: "auto";
31
34
  low: "low";
@@ -48,6 +51,15 @@ export declare const openAIInputShape: {
48
51
  };
49
52
  export declare const googleInputShape: {
50
53
  readonly model: z.ZodDefault<z.ZodString>;
54
+ readonly output_format: z.ZodOptional<z.ZodEnum<{
55
+ png: "png";
56
+ jpeg: "jpeg";
57
+ }>>;
58
+ readonly previous_interaction_id: z.ZodOptional<z.ZodString>;
59
+ readonly thinking_level: z.ZodOptional<z.ZodEnum<{
60
+ high: "high";
61
+ minimal: "minimal";
62
+ }>>;
51
63
  readonly aspect_ratio: z.ZodOptional<z.ZodString>;
52
64
  readonly image_size: z.ZodOptional<z.ZodEnum<{
53
65
  512: "512";
@@ -71,6 +83,11 @@ export declare const googleInputShape: {
71
83
  export declare const xaiInputShape: {
72
84
  readonly input_images: z.ZodOptional<z.ZodArray<z.ZodString>>;
73
85
  readonly model: z.ZodDefault<z.ZodString>;
86
+ readonly quality: z.ZodOptional<z.ZodEnum<{
87
+ auto: "auto";
88
+ low: "low";
89
+ medium: "medium";
90
+ }>>;
74
91
  readonly aspect_ratio: z.ZodOptional<z.ZodString>;
75
92
  readonly resolution: z.ZodOptional<z.ZodEnum<{
76
93
  "1k": "1k";
@@ -95,6 +112,8 @@ export declare const openAIParamsSchema: z.ZodObject<{
95
112
  low: "low";
96
113
  medium: "medium";
97
114
  high: "high";
115
+ xhigh: "xhigh";
116
+ max: "max";
98
117
  standard: "standard";
99
118
  hd: "hd";
100
119
  }>>;
@@ -108,6 +127,7 @@ export declare const openAIParamsSchema: z.ZodObject<{
108
127
  jpeg: "jpeg";
109
128
  webp: "webp";
110
129
  }>>;
130
+ output_compression: z.ZodOptional<z.ZodNumber>;
111
131
  moderation: z.ZodOptional<z.ZodEnum<{
112
132
  auto: "auto";
113
133
  low: "low";
@@ -130,6 +150,15 @@ export declare const openAIParamsSchema: z.ZodObject<{
130
150
  }, z.core.$strict>;
131
151
  export declare const googleParamsSchema: z.ZodObject<{
132
152
  model: z.ZodDefault<z.ZodString>;
153
+ output_format: z.ZodOptional<z.ZodEnum<{
154
+ png: "png";
155
+ jpeg: "jpeg";
156
+ }>>;
157
+ previous_interaction_id: z.ZodOptional<z.ZodString>;
158
+ thinking_level: z.ZodOptional<z.ZodEnum<{
159
+ high: "high";
160
+ minimal: "minimal";
161
+ }>>;
133
162
  aspect_ratio: z.ZodOptional<z.ZodString>;
134
163
  image_size: z.ZodOptional<z.ZodEnum<{
135
164
  512: "512";
@@ -153,6 +182,11 @@ export declare const googleParamsSchema: z.ZodObject<{
153
182
  export declare const xaiParamsSchema: z.ZodObject<{
154
183
  input_images: z.ZodOptional<z.ZodArray<z.ZodString>>;
155
184
  model: z.ZodDefault<z.ZodString>;
185
+ quality: z.ZodOptional<z.ZodEnum<{
186
+ auto: "auto";
187
+ low: "low";
188
+ medium: "medium";
189
+ }>>;
156
190
  aspect_ratio: z.ZodOptional<z.ZodString>;
157
191
  resolution: z.ZodOptional<z.ZodEnum<{
158
192
  "1k": "1k";
package/dist/schemas.js CHANGED
@@ -5,7 +5,7 @@ export const returnModeSchema = z
5
5
  .default("file")
6
6
  .describe("How generated images are returned. Use file for large images; inline embeds base64 image content in the MCP response.");
7
7
  const nonEmptyString = z.string().trim().min(1);
8
- const defaultOpenAIImageModel = process.env.DEFAULT_OPENAI_IMAGE_MODEL ?? "gpt-image-2";
8
+ const defaultOpenAIImageModel = process.env.DEFAULT_OPENAI_IMAGE_MODEL ?? "gpt-image-2.5-sunburst";
9
9
  const commonImageShape = {
10
10
  prompt: nonEmptyString.describe("Image generation or editing instructions."),
11
11
  model: nonEmptyString.optional().describe("Provider model ID. Any string is allowed so newly released models are not blocked."),
@@ -23,17 +23,21 @@ const commonImageShape = {
23
23
  };
24
24
  export const openAIInputShape = {
25
25
  ...commonImageShape,
26
- model: nonEmptyString.default(defaultOpenAIImageModel).describe("OpenAI image model ID. Defaults to DEFAULT_OPENAI_IMAGE_MODEL or gpt-image-2."),
26
+ model: nonEmptyString.default(defaultOpenAIImageModel).describe("OpenAI image model ID. Defaults to DEFAULT_OPENAI_IMAGE_MODEL or gpt-image-2.5-sunburst. Use gpt-image-2.5-flare for everyday generation."),
27
27
  size: nonEmptyString.optional().describe("OpenAI size, such as auto, 1024x1024, 1536x1024, or any supported WIDTHxHEIGHT."),
28
- quality: z.enum(["auto", "low", "medium", "high", "standard", "hd"]).optional().describe("OpenAI quality."),
28
+ quality: z.enum(["auto", "low", "medium", "high", "xhigh", "max", "standard", "hd"]).optional().describe("OpenAI quality. xhigh and max require GPT Image 2.5 or a compatible newer model. Higher quality can increase cost and latency."),
29
29
  background: z.enum(["transparent", "opaque", "auto"]).optional().describe("OpenAI background option."),
30
30
  output_format: z.enum(["png", "jpeg", "webp"]).default("png").describe("Output image format."),
31
- moderation: z.enum(["low", "auto"]).optional().describe("OpenAI moderation setting for supported models."),
31
+ output_compression: z.number().int().min(0).max(100).optional().describe("Output compression from 0 to 100 for JPEG or WebP GPT Image output."),
32
+ moderation: z.enum(["low", "auto"]).optional().describe("Moderation for GPT Image generation and editing. Omit to use the provider default. Not sent to DALL-E models."),
32
33
  style: z.enum(["vivid", "natural"]).optional().describe("DALL-E 3 style option."),
33
34
  };
34
35
  export const googleInputShape = {
35
36
  ...commonImageShape,
36
37
  model: nonEmptyString.default("gemini-3.1-flash-image").describe("Google image model ID. Defaults to Nano Banana 2."),
38
+ output_format: z.enum(["png", "jpeg"]).optional().describe("Requested Google image output format. Omit to use the provider default."),
39
+ previous_interaction_id: nonEmptyString.optional().describe("Continue a Google image editing conversation using metadata.interactionId from a previous result. Requires that interaction to remain available in the same provider account."),
40
+ thinking_level: z.enum(["minimal", "high"]).optional().describe("Thinking level for Gemini 3.1 Flash Image and Flash Lite Image. Higher thinking can increase cost and latency."),
37
41
  aspect_ratio: nonEmptyString.optional().describe("Aspect ratio, for example 1:1, 16:9, 9:16, 4:3, or 3:2."),
38
42
  image_size: z
39
43
  .enum(["512", "0.5K", "1K", "2K", "4K"])
@@ -42,8 +46,9 @@ export const googleInputShape = {
42
46
  };
43
47
  export const xaiInputShape = {
44
48
  ...commonImageShape,
45
- input_images: z.array(nonEmptyString).max(3).optional().describe("Local image paths used as edit/reference inputs. xAI supports up to 3 input images."),
46
- model: nonEmptyString.default("grok-imagine-image-quality").describe("xAI/Grok image model ID."),
49
+ input_images: z.array(nonEmptyString).max(5).optional().describe("Local image paths used as edit/reference inputs. Imagine Image 2.0 supports up to 5 input images, older models up to 3."),
50
+ model: nonEmptyString.default("grok-imagine-image-2.0").describe("xAI/Grok image model ID. Defaults to Imagine Image 2.0."),
51
+ quality: z.enum(["low", "medium", "auto"]).optional().describe("Imagine Image 2.0 quality. Provider auto currently uses low for generation and medium for editing, with different costs. Set low or medium to pin quality."),
47
52
  aspect_ratio: nonEmptyString.optional().describe("Aspect ratio, for example 1:1, 16:9, 9:16, 3:2, or auto."),
48
53
  resolution: z.enum(["1k", "2k"]).optional().describe("xAI image resolution."),
49
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "image-router-mcp",
3
- "version": "0.1.5",
3
+ "version": "0.2.1",
4
4
  "description": "MCP server for routing image generation and editing across xAI, Google Gemini/Nano Banana, and OpenAI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -37,8 +37,8 @@
37
37
  "author": "",
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "@google/genai": "2.13.0",
41
- "@modelcontextprotocol/sdk": "1.29.0",
40
+ "@google/genai": "2.21.0",
41
+ "@modelcontextprotocol/sdk": "1.32.0",
42
42
  "openai": "6.49.0",
43
43
  "zod": "4.4.3"
44
44
  },
@@ -46,7 +46,7 @@
46
46
  "@types/node": "25.9.1",
47
47
  "tsx": "4.23.1",
48
48
  "typescript": "6.0.3",
49
- "vitest": "4.1.10"
49
+ "vitest": "4.1.11"
50
50
  },
51
51
  "repository": {
52
52
  "type": "git",