image-router-mcp 0.1.2 → 0.1.4

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 image-router-mcp contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 image-router-mcp contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,254 +1,254 @@
1
- # image-router-mcp
2
-
3
- [![npm version](https://img.shields.io/npm/v/image-router-mcp.svg)](https://www.npmjs.com/package/image-router-mcp)
4
- [![npm downloads](https://img.shields.io/npm/dm/image-router-mcp.svg)](https://www.npmjs.com/package/image-router-mcp)
5
-
6
- English | [繁體中文](#繁體中文)
7
-
8
- Open-source MCP server for routing image generation and editing across xAI/Grok, Google Gemini/Nano Banana, and OpenAI.
9
-
10
- It keeps model IDs flexible instead of locking tools to a small allowlist, so newly released image models can work as soon as the provider API supports the same image endpoint and parameters.
11
-
12
- ## Features
13
-
14
- - Route image generation and editing through three MCP tools: xAI, Google, and OpenAI.
15
- - Use local images as references or edit inputs via `input_images`.
16
- - Save generated images to disk by default to avoid large base64 payloads over stdio.
17
- - Optionally return inline MCP image content for clients that can render images directly.
18
- - Override provider defaults with environment variables or per-call `model` arguments.
19
-
20
- ## Tools
21
-
22
- | Tool | Provider | Supports |
23
- | --- | --- | --- |
24
- | `xai_generate_image` | xAI/Grok | Text-to-image and JSON image edits with up to 3 local `input_images` |
25
- | `google_generate_image` | Google Gemini/Nano Banana | Text-to-image and local reference/edit images, including `512`, `1K`, `2K`, and `4K` image sizes where supported |
26
- | `openai_generate_image` | OpenAI | Text-to-image and local reference/edit images |
27
-
28
- ## Model examples
29
-
30
- These are examples, not allowlists.
31
-
32
- | Provider | Example models |
33
- | --- | --- |
34
- | xAI | `grok-imagine-image-quality`, `grok-imagine-image` |
35
- | Google | `gemini-3.1-flash-image-preview`, `gemini-3-pro-image-preview`, `gemini-2.5-flash-image` |
36
- | OpenAI | `gpt-image-2`, `gpt-image-1.5`, `gpt-image-1`, `chatgpt-image-latest`, `dall-e-3` |
37
-
38
- ## Quick start
39
-
40
- ```bash
41
- npm install
42
- npm run build
43
- ```
44
-
45
- For MCP clients, run the published package with `npx`:
46
-
47
- ```json
48
- {
49
- "mcpServers": {
50
- "image-router-mcp": {
51
- "command": "npx",
52
- "args": ["-y", "image-router-mcp"],
53
- "env": {
54
- "XAI_API_KEY": "your_xai_key",
55
- "GOOGLE_API_KEY": "your_google_key",
56
- "OPENAI_API_KEY": "your_openai_key"
57
- }
58
- }
59
- }
60
- }
61
- ```
62
-
63
- > [!TIP]
64
- > Set only the API keys for the providers you use. Keys are checked lazily when each tool is called.
65
-
66
- ## Configuration
67
-
68
- | Variable | Required | Description |
69
- | --- | --- | --- |
70
- | `XAI_API_KEY` | For xAI tool | xAI API key. |
71
- | `GOOGLE_API_KEY` or `GEMINI_API_KEY` | For Google tool | Google Gemini API key. |
72
- | `OPENAI_API_KEY` | For OpenAI tool | OpenAI API key. |
73
- | `DEFAULT_XAI_IMAGE_MODEL` | No | Overrides the default xAI image model. |
74
- | `DEFAULT_GOOGLE_IMAGE_MODEL` | No | Overrides the default Google image model. |
75
- | `DEFAULT_OPENAI_IMAGE_MODEL` | No | Sets the default OpenAI image model when `model` is omitted. |
76
- | `DEFAULT_OUTPUT_DIR` | No | Directory for saved images. Defaults to `./generated-images`. |
77
-
78
- ## How to use this MCP
79
-
80
- After adding the server to your MCP client, ask the client to use one of the image tools. For example:
81
-
82
- ```json
83
- {
84
- "tool": "openai_generate_image",
85
- "arguments": {
86
- "prompt": "A cinematic product photo of a transparent mechanical keyboard on a marble desk",
87
- "model": "gpt-image-2",
88
- "size": "1024x1024",
89
- "return_mode": "file",
90
- "output_path": "./generated-images"
91
- }
92
- }
93
- ```
94
-
95
- To edit or reference existing local images, pass file paths with `input_images`:
96
-
97
- ```json
98
- {
99
- "tool": "google_generate_image",
100
- "arguments": {
101
- "prompt": "Turn this sketch into a polished mobile app hero illustration",
102
- "model": "gemini-3.1-flash-image-preview",
103
- "input_images": ["./assets/sketch.png"],
104
- "aspect_ratio": "16:9",
105
- "image_size": "512",
106
- "return_mode": "both"
107
- }
108
- }
109
- ```
110
-
111
- ### Return modes
112
-
113
- | Mode | Behavior |
114
- | --- | --- |
115
- | `file` | Default. Saves images to disk and returns file paths. |
116
- | `inline` | Returns MCP `image` content blocks, capped by `inline_max_bytes`. |
117
- | `both` | Saves images to disk and also returns inline image content. |
118
-
119
- Use `file` for large generations. Use `inline` or `both` only when your MCP client can display image content and the images fit within your payload limits.
120
-
121
- ## Development
122
-
123
- ```bash
124
- npm install
125
- npm run dev
126
- npm run ci
127
- ```
128
-
129
- `npm run ci` runs type checking, tests, and a production build.
130
-
131
- ## 繁體中文
132
-
133
- 開源 MCP 伺服器,可將圖片生成與編輯請求路由到 xAI/Grok、Google Gemini/Nano Banana 與 OpenAI。
134
-
135
- 此專案刻意接受彈性的模型 ID,而不是把工具鎖在固定清單內;只要供應商 API 支援相同圖片端點與參數,新模型通常可以直接使用。
136
-
137
- ## 功能
138
-
139
- - 透過三個 MCP 工具路由圖片生成與編輯:xAI、Google、OpenAI。
140
- - 使用本機圖片作為參考圖或編輯輸入,透過 `input_images` 傳入。
141
- - 預設將生成圖片儲存到磁碟,避免透過 stdio 傳送大型 base64 payload。
142
- - 可選擇回傳 inline MCP 圖片內容,讓支援的客戶端直接顯示圖片。
143
- - 可用環境變數或每次呼叫的 `model` 參數覆寫預設模型。
144
-
145
- ## 工具
146
-
147
- | 工具 | 供應商 | 支援內容 |
148
- | --- | --- | --- |
149
- | `xai_generate_image` | xAI/Grok | 文字生成圖片,以及最多 3 張本機 `input_images` 的 JSON 圖片編輯 |
150
- | `google_generate_image` | Google Gemini/Nano Banana | 文字生成圖片,以及本機參考圖/編輯圖;支援供應商允許的 `512`、`1K`、`2K`、`4K` 圖片尺寸 |
151
- | `openai_generate_image` | OpenAI | 文字生成圖片,以及本機參考圖/編輯圖 |
152
-
153
- ## 模型範例
154
-
155
- 以下是範例,不是允許清單。
156
-
157
- | 供應商 | 模型範例 |
158
- | --- | --- |
159
- | xAI | `grok-imagine-image-quality`, `grok-imagine-image` |
160
- | Google | `gemini-3.1-flash-image-preview`, `gemini-3-pro-image-preview`, `gemini-2.5-flash-image` |
161
- | OpenAI | `gpt-image-2`, `gpt-image-1.5`, `gpt-image-1`, `chatgpt-image-latest`, `dall-e-3` |
162
-
163
- ## 快速開始
164
-
165
- ```bash
166
- npm install
167
- npm run build
168
- ```
169
-
170
- 在 MCP 客戶端中,可用 `npx` 執行已發布的套件:
171
-
172
- ```json
173
- {
174
- "mcpServers": {
175
- "image-router-mcp": {
176
- "command": "npx",
177
- "args": ["-y", "image-router-mcp"],
178
- "env": {
179
- "XAI_API_KEY": "your_xai_key",
180
- "GOOGLE_API_KEY": "your_google_key",
181
- "OPENAI_API_KEY": "your_openai_key"
182
- }
183
- }
184
- }
185
- }
186
- ```
187
-
188
- > [!TIP]
189
- > 只需要設定會用到的供應商 API Key。Key 會在呼叫對應工具時才檢查。
190
-
191
- ## 設定
192
-
193
- | 變數 | 必要性 | 說明 |
194
- | --- | --- | --- |
195
- | `XAI_API_KEY` | 使用 xAI 工具時需要 | xAI API Key。 |
196
- | `GOOGLE_API_KEY` 或 `GEMINI_API_KEY` | 使用 Google 工具時需要 | Google Gemini API Key。 |
197
- | `OPENAI_API_KEY` | 使用 OpenAI 工具時需要 | OpenAI API Key。 |
198
- | `DEFAULT_XAI_IMAGE_MODEL` | 否 | 覆寫預設 xAI 圖片模型。 |
199
- | `DEFAULT_GOOGLE_IMAGE_MODEL` | 否 | 覆寫預設 Google 圖片模型。 |
200
- | `DEFAULT_OPENAI_IMAGE_MODEL` | 否 | 未傳入 `model` 時使用的預設 OpenAI 圖片模型。 |
201
- | `DEFAULT_OUTPUT_DIR` | 否 | 圖片輸出資料夾,預設為 `./generated-images`。 |
202
-
203
- ## 這個 MCP 怎麼用
204
-
205
- 將 server 加到 MCP 客戶端後,請客戶端呼叫其中一個圖片工具。例如:
206
-
207
- ```json
208
- {
209
- "tool": "openai_generate_image",
210
- "arguments": {
211
- "prompt": "A cinematic product photo of a transparent mechanical keyboard on a marble desk",
212
- "model": "gpt-image-2",
213
- "size": "1024x1024",
214
- "return_mode": "file",
215
- "output_path": "./generated-images"
216
- }
217
- }
218
- ```
219
-
220
- 若要使用既有本機圖片作為編輯或參考輸入,傳入 `input_images`:
221
-
222
- ```json
223
- {
224
- "tool": "google_generate_image",
225
- "arguments": {
226
- "prompt": "Turn this sketch into a polished mobile app hero illustration",
227
- "model": "gemini-3.1-flash-image-preview",
228
- "input_images": ["./assets/sketch.png"],
229
- "aspect_ratio": "16:9",
230
- "image_size": "512",
231
- "return_mode": "both"
232
- }
233
- }
234
- ```
235
-
236
- ### 回傳模式
237
-
238
- | 模式 | 行為 |
239
- | --- | --- |
240
- | `file` | 預設。將圖片存到磁碟並回傳檔案路徑。 |
241
- | `inline` | 回傳 MCP `image` content block,大小受 `inline_max_bytes` 限制。 |
242
- | `both` | 同時儲存圖片到磁碟並回傳 inline 圖片內容。 |
243
-
244
- 大型生成結果建議使用 `file`。只有在 MCP 客戶端支援圖片顯示、且圖片大小符合 payload 限制時,才使用 `inline` 或 `both`。
245
-
246
- ## 開發
247
-
248
- ```bash
249
- npm install
250
- npm run dev
251
- npm run ci
252
- ```
253
-
254
- `npm run ci` 會執行型別檢查、測試與正式建置。
1
+ # image-router-mcp
2
+
3
+ [![npm version](https://img.shields.io/npm/v/image-router-mcp.svg)](https://www.npmjs.com/package/image-router-mcp)
4
+ [![npm downloads](https://img.shields.io/npm/dm/image-router-mcp.svg)](https://www.npmjs.com/package/image-router-mcp)
5
+
6
+ English | [繁體中文](#繁體中文)
7
+
8
+ Open-source MCP server for routing image generation and editing across xAI/Grok, Google Gemini/Nano Banana, and OpenAI.
9
+
10
+ It keeps model IDs flexible instead of locking tools to a small allowlist, so newly released image models can work as soon as the provider API supports the same image endpoint and parameters.
11
+
12
+ ## Features
13
+
14
+ - Route image generation and editing through three MCP tools: xAI, Google, and OpenAI.
15
+ - Use local images as references or edit inputs via `input_images`.
16
+ - Save generated images to disk by default to avoid large base64 payloads over stdio.
17
+ - Optionally return inline MCP image content for clients that can render images directly.
18
+ - Override provider defaults with environment variables or per-call `model` arguments.
19
+
20
+ ## Tools
21
+
22
+ | Tool | Provider | Supports |
23
+ | --- | --- | --- |
24
+ | `xai_generate_image` | xAI/Grok | Text-to-image and JSON image edits with up to 3 local `input_images` |
25
+ | `google_generate_image` | Google Gemini/Nano Banana | Text-to-image and local reference/edit images through the Interactions API, including `512`, `1K`, `2K`, and `4K` image sizes where supported |
26
+ | `openai_generate_image` | OpenAI | Text-to-image and local reference/edit images |
27
+
28
+ ## Model examples
29
+
30
+ These are examples, not allowlists.
31
+
32
+ | Provider | Example models |
33
+ | --- | --- |
34
+ | xAI | `grok-imagine-image-quality`, `grok-imagine-image` |
35
+ | Google | `gemini-3.1-flash-image`, `gemini-3.1-flash-lite-image`, `gemini-3-pro-image` |
36
+ | OpenAI | `gpt-image-2` |
37
+
38
+ ## Quick start
39
+
40
+ ```bash
41
+ npm install
42
+ npm run build
43
+ ```
44
+
45
+ For MCP clients, run the published package with `npx`:
46
+
47
+ ```json
48
+ {
49
+ "mcpServers": {
50
+ "image-router-mcp": {
51
+ "command": "npx",
52
+ "args": ["-y", "image-router-mcp"],
53
+ "env": {
54
+ "XAI_API_KEY": "your_xai_key",
55
+ "GOOGLE_API_KEY": "your_google_key",
56
+ "OPENAI_API_KEY": "your_openai_key"
57
+ }
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ > [!TIP]
64
+ > Set only the API keys for the providers you use. Keys are checked lazily when each tool is called.
65
+
66
+ ## Configuration
67
+
68
+ | Variable | Required | Description |
69
+ | --- | --- | --- |
70
+ | `XAI_API_KEY` | For xAI tool | xAI API key. |
71
+ | `GOOGLE_API_KEY` or `GEMINI_API_KEY` | For Google tool | Google Gemini API key. |
72
+ | `OPENAI_API_KEY` | For OpenAI tool | OpenAI API key. |
73
+ | `DEFAULT_XAI_IMAGE_MODEL` | No | Overrides the default xAI image model. |
74
+ | `DEFAULT_GOOGLE_IMAGE_MODEL` | No | Overrides the default Google image model. |
75
+ | `DEFAULT_OPENAI_IMAGE_MODEL` | No | Sets the default OpenAI image model when `model` is omitted. |
76
+ | `DEFAULT_OUTPUT_DIR` | No | Directory for saved images. Defaults to `./generated-images`. |
77
+
78
+ ## How to use this MCP
79
+
80
+ After adding the server to your MCP client, ask the client to use one of the image tools. For example:
81
+
82
+ ```json
83
+ {
84
+ "tool": "openai_generate_image",
85
+ "arguments": {
86
+ "prompt": "A cinematic product photo of a transparent mechanical keyboard on a marble desk",
87
+ "model": "gpt-image-2",
88
+ "size": "1024x1024",
89
+ "return_mode": "file",
90
+ "output_path": "./generated-images"
91
+ }
92
+ }
93
+ ```
94
+
95
+ To edit or reference existing local images, pass file paths with `input_images`:
96
+
97
+ ```json
98
+ {
99
+ "tool": "google_generate_image",
100
+ "arguments": {
101
+ "prompt": "Turn this sketch into a polished mobile app hero illustration",
102
+ "model": "gemini-3.1-flash-image",
103
+ "input_images": ["./assets/sketch.png"],
104
+ "aspect_ratio": "16:9",
105
+ "image_size": "512",
106
+ "return_mode": "both"
107
+ }
108
+ }
109
+ ```
110
+
111
+ ### Return modes
112
+
113
+ | Mode | Behavior |
114
+ | --- | --- |
115
+ | `file` | Default. Saves images to disk and returns file paths. |
116
+ | `inline` | Returns MCP `image` content blocks, capped by `inline_max_bytes`. |
117
+ | `both` | Saves images to disk and also returns inline image content. |
118
+
119
+ Use `file` for large generations. Use `inline` or `both` only when your MCP client can display image content and the images fit within your payload limits.
120
+
121
+ ## Development
122
+
123
+ ```bash
124
+ npm install
125
+ npm run dev
126
+ npm run ci
127
+ ```
128
+
129
+ `npm run ci` runs type checking, tests, and a production build.
130
+
131
+ ## 繁體中文
132
+
133
+ 開源 MCP 伺服器,可將圖片生成與編輯請求路由到 xAI/Grok、Google Gemini/Nano Banana 與 OpenAI。
134
+
135
+ 此專案刻意接受彈性的模型 ID,而不是把工具鎖在固定清單內;只要供應商 API 支援相同圖片端點與參數,新模型通常可以直接使用。
136
+
137
+ ## 功能
138
+
139
+ - 透過三個 MCP 工具路由圖片生成與編輯:xAI、Google、OpenAI。
140
+ - 使用本機圖片作為參考圖或編輯輸入,透過 `input_images` 傳入。
141
+ - 預設將生成圖片儲存到磁碟,避免透過 stdio 傳送大型 base64 payload。
142
+ - 可選擇回傳 inline MCP 圖片內容,讓支援的客戶端直接顯示圖片。
143
+ - 可用環境變數或每次呼叫的 `model` 參數覆寫預設模型。
144
+
145
+ ## 工具
146
+
147
+ | 工具 | 供應商 | 支援內容 |
148
+ | --- | --- | --- |
149
+ | `xai_generate_image` | xAI/Grok | 文字生成圖片,以及最多 3 張本機 `input_images` 的 JSON 圖片編輯 |
150
+ | `google_generate_image` | Google Gemini/Nano Banana | 透過 Interactions API 進行文字生成圖片與本機參考圖/編輯圖;支援供應商允許的 `512`、`1K`、`2K`、`4K` 圖片尺寸 |
151
+ | `openai_generate_image` | OpenAI | 文字生成圖片,以及本機參考圖/編輯圖 |
152
+
153
+ ## 模型範例
154
+
155
+ 以下是範例,不是允許清單。
156
+
157
+ | 供應商 | 模型範例 |
158
+ | --- | --- |
159
+ | xAI | `grok-imagine-image-quality`, `grok-imagine-image` |
160
+ | Google | `gemini-3.1-flash-image`, `gemini-3.1-flash-lite-image`, `gemini-3-pro-image` |
161
+ | OpenAI | `gpt-image-2` |
162
+
163
+ ## 快速開始
164
+
165
+ ```bash
166
+ npm install
167
+ npm run build
168
+ ```
169
+
170
+ 在 MCP 客戶端中,可用 `npx` 執行已發布的套件:
171
+
172
+ ```json
173
+ {
174
+ "mcpServers": {
175
+ "image-router-mcp": {
176
+ "command": "npx",
177
+ "args": ["-y", "image-router-mcp"],
178
+ "env": {
179
+ "XAI_API_KEY": "your_xai_key",
180
+ "GOOGLE_API_KEY": "your_google_key",
181
+ "OPENAI_API_KEY": "your_openai_key"
182
+ }
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+ > [!TIP]
189
+ > 只需要設定會用到的供應商 API Key。Key 會在呼叫對應工具時才檢查。
190
+
191
+ ## 設定
192
+
193
+ | 變數 | 必要性 | 說明 |
194
+ | --- | --- | --- |
195
+ | `XAI_API_KEY` | 使用 xAI 工具時需要 | xAI API Key。 |
196
+ | `GOOGLE_API_KEY` 或 `GEMINI_API_KEY` | 使用 Google 工具時需要 | Google Gemini API Key。 |
197
+ | `OPENAI_API_KEY` | 使用 OpenAI 工具時需要 | OpenAI API Key。 |
198
+ | `DEFAULT_XAI_IMAGE_MODEL` | 否 | 覆寫預設 xAI 圖片模型。 |
199
+ | `DEFAULT_GOOGLE_IMAGE_MODEL` | 否 | 覆寫預設 Google 圖片模型。 |
200
+ | `DEFAULT_OPENAI_IMAGE_MODEL` | 否 | 未傳入 `model` 時使用的預設 OpenAI 圖片模型。 |
201
+ | `DEFAULT_OUTPUT_DIR` | 否 | 圖片輸出資料夾,預設為 `./generated-images`。 |
202
+
203
+ ## 這個 MCP 怎麼用
204
+
205
+ 將 server 加到 MCP 客戶端後,請客戶端呼叫其中一個圖片工具。例如:
206
+
207
+ ```json
208
+ {
209
+ "tool": "openai_generate_image",
210
+ "arguments": {
211
+ "prompt": "A cinematic product photo of a transparent mechanical keyboard on a marble desk",
212
+ "model": "gpt-image-2",
213
+ "size": "1024x1024",
214
+ "return_mode": "file",
215
+ "output_path": "./generated-images"
216
+ }
217
+ }
218
+ ```
219
+
220
+ 若要使用既有本機圖片作為編輯或參考輸入,傳入 `input_images`:
221
+
222
+ ```json
223
+ {
224
+ "tool": "google_generate_image",
225
+ "arguments": {
226
+ "prompt": "Turn this sketch into a polished mobile app hero illustration",
227
+ "model": "gemini-3.1-flash-image",
228
+ "input_images": ["./assets/sketch.png"],
229
+ "aspect_ratio": "16:9",
230
+ "image_size": "512",
231
+ "return_mode": "both"
232
+ }
233
+ }
234
+ ```
235
+
236
+ ### 回傳模式
237
+
238
+ | 模式 | 行為 |
239
+ | --- | --- |
240
+ | `file` | 預設。將圖片存到磁碟並回傳檔案路徑。 |
241
+ | `inline` | 回傳 MCP `image` content block,大小受 `inline_max_bytes` 限制。 |
242
+ | `both` | 同時儲存圖片到磁碟並回傳 inline 圖片內容。 |
243
+
244
+ 大型生成結果建議使用 `file`。只有在 MCP 客戶端支援圖片顯示、且圖片大小符合 payload 限制時,才使用 `inline` 或 `both`。
245
+
246
+ ## 開發
247
+
248
+ ```bash
249
+ npm install
250
+ npm run dev
251
+ npm run ci
252
+ ```
253
+
254
+ `npm run ci` 會執行型別檢查、測試與正式建置。
@@ -2,8 +2,8 @@ import { GoogleGenAI } from "@google/genai";
2
2
  import type { GoogleParams } from "../schemas.js";
3
3
  import type { ProviderResult } from "../types.js";
4
4
  export type GoogleImageClient = {
5
- models: {
6
- generateContent: GoogleGenAI["models"]["generateContent"];
5
+ interactions: {
6
+ create: GoogleGenAI["interactions"]["create"];
7
7
  };
8
8
  };
9
9
  export declare function setGoogleClientForTests(client: GoogleImageClient | undefined): void;
@@ -1,5 +1,5 @@
1
- import { GoogleGenAI, Modality } from "@google/genai";
2
- import { bytesFromBase64, loadInputImages } from "../files.js";
1
+ import { GoogleGenAI } from "@google/genai";
2
+ import { base64FromUrl, bytesFromBase64, loadInputImages } from "../files.js";
3
3
  import { requireEnv } from "../errors.js";
4
4
  let googleClient;
5
5
  function getGoogleClient() {
@@ -14,54 +14,48 @@ export function setGoogleClientForTests(client) {
14
14
  export async function generateGoogleImage(params, client = getGoogleClient()) {
15
15
  const model = process.env.DEFAULT_GOOGLE_IMAGE_MODEL ?? params.model;
16
16
  const inputImages = await loadInputImages(params.input_images);
17
- const parts = [
18
- { text: params.prompt },
17
+ const input = [
19
18
  ...inputImages.map((image) => ({
20
- inlineData: {
21
- data: image.data,
22
- mimeType: image.mimeType,
23
- },
19
+ type: "image",
20
+ data: image.data,
21
+ mime_type: image.mimeType,
24
22
  })),
23
+ { type: "text", text: params.prompt },
25
24
  ];
26
- const response = await client.models.generateContent({
25
+ const response = await client.interactions.create({
27
26
  model,
28
- contents: [{ role: "user", parts }],
29
- config: {
30
- responseModalities: [Modality.IMAGE, Modality.TEXT],
31
- ...(params.aspect_ratio || params.image_size
32
- ? {
33
- imageConfig: {
34
- ...(params.aspect_ratio ? { aspectRatio: params.aspect_ratio } : {}),
35
- ...(params.image_size ? { imageSize: params.image_size } : {}),
36
- },
37
- }
38
- : {}),
27
+ input,
28
+ response_format: {
29
+ type: "image",
30
+ delivery: "inline",
31
+ ...(params.aspect_ratio ? { aspect_ratio: params.aspect_ratio } : {}),
32
+ ...(params.image_size ? { image_size: params.image_size === "0.5K" ? "512" : params.image_size } : {}),
39
33
  },
40
34
  });
41
- const responseParts = response.candidates?.[0]?.content?.parts ?? [];
42
- const images = responseParts
43
- .filter((part) => part.inlineData?.data)
44
- .map((part) => {
45
- const data = part.inlineData.data;
46
- const mimeType = part.inlineData.mimeType ?? "image/png";
47
- return { data, mimeType, bytes: bytesFromBase64(data) };
48
- });
49
- const text = responseParts
50
- .map((part) => part.text)
51
- .filter((value) => Boolean(value))
52
- .join("\n");
53
- if (images.length === 0) {
54
- throw new Error(text || response.promptFeedback?.blockReasonMessage || "Google response did not include generated image data.");
35
+ const outputImage = response.output_image;
36
+ let image;
37
+ if (outputImage?.data) {
38
+ image = {
39
+ data: outputImage.data,
40
+ mimeType: outputImage.mime_type ?? "image/png",
41
+ bytes: bytesFromBase64(outputImage.data),
42
+ };
43
+ }
44
+ else if (outputImage?.uri) {
45
+ image = { ...(await base64FromUrl(outputImage.uri)), url: outputImage.uri };
46
+ }
47
+ if (!image) {
48
+ throw new Error(response.output_text || `Google interaction ${response.status} did not include generated image data.`);
55
49
  }
56
50
  return {
57
51
  provider: "google",
58
52
  model,
59
- images,
60
- text: text || undefined,
53
+ images: [image],
54
+ text: response.output_text || undefined,
61
55
  metadata: {
62
- modelVersion: response.modelVersion,
63
- responseId: response.responseId,
64
- usageMetadata: response.usageMetadata,
56
+ interactionId: response.id,
57
+ status: response.status,
58
+ usage: response.usage,
65
59
  },
66
60
  };
67
61
  }
package/dist/schemas.d.ts CHANGED
@@ -51,6 +51,7 @@ export declare const googleInputShape: {
51
51
  readonly aspect_ratio: z.ZodOptional<z.ZodString>;
52
52
  readonly image_size: z.ZodOptional<z.ZodEnum<{
53
53
  512: "512";
54
+ "0.5K": "0.5K";
54
55
  "1K": "1K";
55
56
  "2K": "2K";
56
57
  "4K": "4K";
@@ -132,6 +133,7 @@ export declare const googleParamsSchema: z.ZodObject<{
132
133
  aspect_ratio: z.ZodOptional<z.ZodString>;
133
134
  image_size: z.ZodOptional<z.ZodEnum<{
134
135
  512: "512";
136
+ "0.5K": "0.5K";
135
137
  "1K": "1K";
136
138
  "2K": "2K";
137
139
  "4K": "4K";
package/dist/schemas.js CHANGED
@@ -33,9 +33,12 @@ export const openAIInputShape = {
33
33
  };
34
34
  export const googleInputShape = {
35
35
  ...commonImageShape,
36
- model: nonEmptyString.default("gemini-3.1-flash-image-preview").describe("Google image model ID. Defaults to Nano Banana 2."),
36
+ model: nonEmptyString.default("gemini-3.1-flash-image").describe("Google image model ID. Defaults to Nano Banana 2."),
37
37
  aspect_ratio: nonEmptyString.optional().describe("Aspect ratio, for example 1:1, 16:9, 9:16, 4:3, or 3:2."),
38
- image_size: z.enum(["512", "1K", "2K", "4K"]).optional().describe("Google image size where supported."),
38
+ image_size: z
39
+ .enum(["512", "0.5K", "1K", "2K", "4K"])
40
+ .optional()
41
+ .describe('Google image size where supported. Use "512" for 512px; legacy "0.5K" is accepted and normalized to "512".'),
39
42
  };
40
43
  export const xaiInputShape = {
41
44
  ...commonImageShape,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "image-router-mcp",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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": {
@@ -33,16 +33,16 @@
33
33
  "author": "",
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
- "@google/genai": "2.7.0",
36
+ "@google/genai": "2.13.0",
37
37
  "@modelcontextprotocol/sdk": "1.29.0",
38
- "openai": "6.39.1",
38
+ "openai": "6.49.0",
39
39
  "zod": "4.4.3"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "25.9.1",
43
- "tsx": "4.22.3",
43
+ "tsx": "4.23.1",
44
44
  "typescript": "6.0.3",
45
- "vitest": "4.1.7"
45
+ "vitest": "4.1.10"
46
46
  },
47
47
  "repository": {
48
48
  "type": "git",