image-router-mcp 0.1.4 → 0.1.5
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 +160 -150
- package/README.zh-TW.md +264 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -3,46 +3,72 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/image-router-mcp)
|
|
4
4
|
[](https://www.npmjs.com/package/image-router-mcp)
|
|
5
5
|
|
|
6
|
-
English | [繁體中文](
|
|
6
|
+
English | [繁體中文](./README.zh-TW.md)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
An open-source MCP server that routes image generation and editing to xAI/Grok, Google Gemini/Nano Banana, and OpenAI.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Run it directly from npm with `npx`. You only need an API key for the provider you want to use.
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
14
|
+
- Three focused MCP tools for xAI, Google, and OpenAI.
|
|
15
|
+
- Text-to-image plus local reference image and image-editing workflows.
|
|
16
|
+
- Flexible model IDs, so compatible new models are not blocked by a fixed allowlist.
|
|
17
|
+
- File output by default, avoiding large base64 payloads over stdio.
|
|
18
|
+
- Optional inline image content for MCP clients that can display it.
|
|
19
19
|
|
|
20
|
-
## Tools
|
|
20
|
+
## Tools and default models
|
|
21
21
|
|
|
22
|
-
| Tool | Provider | Supports |
|
|
23
|
-
| --- | --- | --- |
|
|
24
|
-
| `
|
|
25
|
-
| `google_generate_image` | Google Gemini/Nano Banana | Text-to-image and local reference/edit images through the Interactions API
|
|
26
|
-
| `
|
|
22
|
+
| Tool | Provider | Built-in default model | Supports |
|
|
23
|
+
| --- | --- | --- | --- |
|
|
24
|
+
| `openai_generate_image` | OpenAI | `gpt-image-2` | Text-to-image and local reference/edit images |
|
|
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 |
|
|
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
|
-
|
|
30
|
+
## Prerequisites
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
- Node.js 20 or later, including `npm` and `npx`.
|
|
33
|
+
- An MCP client that supports local stdio servers, such as Codex, Claude Desktop, or Cursor.
|
|
34
|
+
- At least one provider API key:
|
|
35
|
+
- `OPENAI_API_KEY` for OpenAI
|
|
36
|
+
- `GOOGLE_API_KEY` or `GEMINI_API_KEY` for Google
|
|
37
|
+
- `XAI_API_KEY` for xAI
|
|
38
|
+
|
|
39
|
+
Provider API usage may incur charges. Set only the keys for providers you intend to use.
|
|
40
|
+
|
|
41
|
+
> [!WARNING]
|
|
42
|
+
> Never commit real API keys. Prefer user-level config for settings that contain secrets, or forward keys from your existing environment when the MCP client supports it.
|
|
37
43
|
|
|
38
44
|
## Quick start
|
|
39
45
|
|
|
46
|
+
The examples below configure OpenAI only. Replace or add the environment variables listed in [Configuration](#configuration) to use Google or xAI.
|
|
47
|
+
|
|
48
|
+
### Codex
|
|
49
|
+
|
|
50
|
+
Add the server from the command line:
|
|
51
|
+
|
|
40
52
|
```bash
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
codex mcp add image-router-mcp --env OPENAI_API_KEY=your_openai_key -- npx -y image-router-mcp
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Or add it to `~/.codex/config.toml` for all projects, or `.codex/config.toml` for one trusted project:
|
|
57
|
+
|
|
58
|
+
```toml
|
|
59
|
+
[mcp_servers.image-router-mcp]
|
|
60
|
+
command = "npx"
|
|
61
|
+
args = ["-y", "image-router-mcp"]
|
|
62
|
+
|
|
63
|
+
[mcp_servers.image-router-mcp.env]
|
|
64
|
+
OPENAI_API_KEY = "your_openai_key"
|
|
43
65
|
```
|
|
44
66
|
|
|
45
|
-
|
|
67
|
+
Restart Codex after editing the file. Use `/mcp` to confirm that `image-router-mcp` and its three tools are available.
|
|
68
|
+
|
|
69
|
+
### Claude Desktop
|
|
70
|
+
|
|
71
|
+
Open **Settings > Developer > Edit Config** and add this server to `claude_desktop_config.json`:
|
|
46
72
|
|
|
47
73
|
```json
|
|
48
74
|
{
|
|
@@ -51,8 +77,6 @@ For MCP clients, run the published package with `npx`:
|
|
|
51
77
|
"command": "npx",
|
|
52
78
|
"args": ["-y", "image-router-mcp"],
|
|
53
79
|
"env": {
|
|
54
|
-
"XAI_API_KEY": "your_xai_key",
|
|
55
|
-
"GOOGLE_API_KEY": "your_google_key",
|
|
56
80
|
"OPENAI_API_KEY": "your_openai_key"
|
|
57
81
|
}
|
|
58
82
|
}
|
|
@@ -60,149 +84,114 @@ For MCP clients, run the published package with `npx`:
|
|
|
60
84
|
}
|
|
61
85
|
```
|
|
62
86
|
|
|
63
|
-
|
|
64
|
-
> Set only the API keys for the providers you use. Keys are checked lazily when each tool is called.
|
|
87
|
+
Default config locations:
|
|
65
88
|
|
|
66
|
-
|
|
89
|
+
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
90
|
+
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
67
91
|
|
|
68
|
-
|
|
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`. |
|
|
92
|
+
Completely quit and reopen Claude Desktop after saving the file.
|
|
77
93
|
|
|
78
|
-
|
|
94
|
+
### Cursor
|
|
79
95
|
|
|
80
|
-
|
|
96
|
+
Add the same JSON configuration shown above to one of these locations:
|
|
81
97
|
|
|
82
|
-
|
|
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`:
|
|
98
|
+
- Global: `~/.cursor/mcp.json`
|
|
99
|
+
- Project only: `.cursor/mcp.json`
|
|
96
100
|
|
|
97
|
-
|
|
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
|
-
```
|
|
101
|
+
Open **Cursor Settings > Tools & MCP** to confirm that the server and tools are enabled.
|
|
110
102
|
|
|
111
|
-
|
|
103
|
+
## Generate your first image
|
|
112
104
|
|
|
113
|
-
|
|
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. |
|
|
105
|
+
After the server is connected, ask your MCP client:
|
|
118
106
|
|
|
119
|
-
Use `
|
|
107
|
+
> Use `openai_generate_image` to create a 1024x1024 cinematic product photo of a transparent mechanical keyboard on a marble desk. Save it to `/absolute/path/to/generated-images` and return the saved file path.
|
|
120
108
|
|
|
121
|
-
|
|
109
|
+
To edit an existing image:
|
|
122
110
|
|
|
123
|
-
|
|
124
|
-
npm install
|
|
125
|
-
npm run dev
|
|
126
|
-
npm run ci
|
|
127
|
-
```
|
|
111
|
+
> Use `google_generate_image` with `/absolute/path/to/sketch.png` as the input image. Turn it into a polished 16:9 mobile app hero illustration and save the result to `/absolute/path/to/generated-images`.
|
|
128
112
|
|
|
129
|
-
|
|
113
|
+
Use absolute paths in prompts and tool calls. Relative paths depend on the working directory chosen by the MCP client.
|
|
130
114
|
|
|
131
|
-
##
|
|
115
|
+
## Paths and image output
|
|
132
116
|
|
|
133
|
-
|
|
117
|
+
- `input_images` paths are resolved from the MCP server process working directory.
|
|
118
|
+
- `output_path` can be either a file path or a directory.
|
|
119
|
+
- An existing directory, or a new path without a file extension, is treated as a directory.
|
|
120
|
+
- A path with a file extension is treated as the requested output filename. Multiple results receive numbered suffixes.
|
|
121
|
+
- When `output_path` is omitted, files are saved under `DEFAULT_OUTPUT_DIR`, or `./generated-images` relative to the MCP server working directory.
|
|
122
|
+
- Use absolute input and output paths for predictable behavior across clients.
|
|
123
|
+
- 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`.
|
|
134
125
|
|
|
135
|
-
|
|
126
|
+
### Return modes
|
|
136
127
|
|
|
137
|
-
|
|
128
|
+
| Mode | Behavior |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| `file` | Default. Saves images to disk and returns their paths. |
|
|
131
|
+
| `inline` | Returns MCP `image` content without saving it. Each image is limited by `inline_max_bytes`. |
|
|
132
|
+
| `both` | Saves images and also returns inline MCP image content. |
|
|
138
133
|
|
|
139
|
-
|
|
140
|
-
- 使用本機圖片作為參考圖或編輯輸入,透過 `input_images` 傳入。
|
|
141
|
-
- 預設將生成圖片儲存到磁碟,避免透過 stdio 傳送大型 base64 payload。
|
|
142
|
-
- 可選擇回傳 inline MCP 圖片內容,讓支援的客戶端直接顯示圖片。
|
|
143
|
-
- 可用環境變數或每次呼叫的 `model` 參數覆寫預設模型。
|
|
134
|
+
Use `file` for large images. Use `inline` or `both` only when the MCP client can display image content and the result fits its payload limits.
|
|
144
135
|
|
|
145
|
-
##
|
|
136
|
+
## Tool parameters
|
|
146
137
|
|
|
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 | 文字生成圖片,以及本機參考圖/編輯圖 |
|
|
138
|
+
### Common parameters
|
|
152
139
|
|
|
153
|
-
|
|
140
|
+
| Parameter | Required | Default | Description |
|
|
141
|
+
| --- | --- | --- | --- |
|
|
142
|
+
| `prompt` | Yes | — | Image generation or editing instructions. |
|
|
143
|
+
| `model` | No | Provider default | Compatible provider model ID. |
|
|
144
|
+
| `input_images` | No | `[]` | Local reference/edit image paths. |
|
|
145
|
+
| `output_path` | No | `DEFAULT_OUTPUT_DIR` or `./generated-images` | Saved output file or directory. |
|
|
146
|
+
| `return_mode` | No | `file` | `file`, `inline`, or `both`. |
|
|
147
|
+
| `inline_max_bytes` | No | `4194304` (4 MiB) | Maximum size of each inline image. |
|
|
148
|
+
| `n` | No | Provider default | Number of results, from 1 to 10, when supported. Google currently returns one image. |
|
|
149
|
+
| `user` | No | — | Optional end-user identifier for provider abuse monitoring. |
|
|
154
150
|
|
|
155
|
-
|
|
151
|
+
### OpenAI parameters
|
|
156
152
|
|
|
157
|
-
|
|
|
158
|
-
| --- | --- |
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
|
|
|
153
|
+
| Parameter | Values or examples | Default |
|
|
154
|
+
| --- | --- | --- |
|
|
155
|
+
| `size` | `auto`, `1024x1024`, `1536x1024`, or another supported `WIDTHxHEIGHT` | Provider default |
|
|
156
|
+
| `quality` | `auto`, `low`, `medium`, `high`, `standard`, `hd` | Provider default |
|
|
157
|
+
| `background` | `transparent`, `opaque`, `auto` | Provider default |
|
|
158
|
+
| `output_format` | `png`, `jpeg`, `webp` | `png` |
|
|
159
|
+
| `moderation` | `low`, `auto` | Provider default |
|
|
160
|
+
| `style` | `vivid`, `natural`; used with DALL-E 3 | Provider default |
|
|
162
161
|
|
|
163
|
-
|
|
162
|
+
### Google parameters
|
|
164
163
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
| Parameter | Values or examples | Default |
|
|
165
|
+
| --- | --- | --- |
|
|
166
|
+
| `aspect_ratio` | For example `1:1`, `16:9`, `9:16`, `4:3`, or `3:2` | Provider default |
|
|
167
|
+
| `image_size` | `512`, `0.5K`, `1K`, `2K`, `4K`; availability depends on the model | Provider default |
|
|
169
168
|
|
|
170
|
-
|
|
169
|
+
`0.5K` is accepted as a legacy alias and normalized to `512`.
|
|
171
170
|
|
|
172
|
-
|
|
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
|
-
```
|
|
171
|
+
### xAI parameters
|
|
187
172
|
|
|
188
|
-
|
|
189
|
-
|
|
173
|
+
| Parameter | Values or examples | Default |
|
|
174
|
+
| --- | --- | --- |
|
|
175
|
+
| `aspect_ratio` | For example `1:1`, `16:9`, `9:16`, `3:2`, or `auto` | Provider default |
|
|
176
|
+
| `resolution` | `1k`, `2k` | Provider default |
|
|
190
177
|
|
|
191
|
-
##
|
|
178
|
+
## Configuration
|
|
192
179
|
|
|
193
|
-
|
|
|
180
|
+
| Variable | Required | Behavior |
|
|
194
181
|
| --- | --- | --- |
|
|
195
|
-
| `
|
|
196
|
-
| `GOOGLE_API_KEY`
|
|
197
|
-
| `
|
|
198
|
-
| `
|
|
199
|
-
| `DEFAULT_GOOGLE_IMAGE_MODEL` |
|
|
200
|
-
| `
|
|
201
|
-
| `DEFAULT_OUTPUT_DIR` |
|
|
182
|
+
| `OPENAI_API_KEY` | For the OpenAI tool | OpenAI API key. |
|
|
183
|
+
| `GOOGLE_API_KEY` or `GEMINI_API_KEY` | For the Google tool | Google Gemini API key. |
|
|
184
|
+
| `XAI_API_KEY` | For the xAI tool | xAI API key. |
|
|
185
|
+
| `DEFAULT_OPENAI_IMAGE_MODEL` | No | Default OpenAI model when `model` is omitted. An explicit `model` argument can override it. |
|
|
186
|
+
| `DEFAULT_GOOGLE_IMAGE_MODEL` | No | Pins Google requests to this model and takes precedence over the per-call `model` argument. |
|
|
187
|
+
| `DEFAULT_XAI_IMAGE_MODEL` | No | Pins xAI requests to this model and takes precedence over the per-call `model` argument. |
|
|
188
|
+
| `DEFAULT_OUTPUT_DIR` | No | Default saved-image directory. Defaults to `./generated-images` from the MCP server working directory. |
|
|
202
189
|
|
|
203
|
-
|
|
190
|
+
Keys are checked only when their corresponding tool is called, so one provider key is enough to start.
|
|
204
191
|
|
|
205
|
-
|
|
192
|
+
## Advanced direct tool calls
|
|
193
|
+
|
|
194
|
+
Most users can ask their MCP client in natural language. If your client supports direct tool invocation, the equivalent OpenAI request is:
|
|
206
195
|
|
|
207
196
|
```json
|
|
208
197
|
{
|
|
@@ -212,12 +201,12 @@ npm run build
|
|
|
212
201
|
"model": "gpt-image-2",
|
|
213
202
|
"size": "1024x1024",
|
|
214
203
|
"return_mode": "file",
|
|
215
|
-
"output_path": "
|
|
204
|
+
"output_path": "/absolute/path/to/generated-images"
|
|
216
205
|
}
|
|
217
206
|
}
|
|
218
207
|
```
|
|
219
208
|
|
|
220
|
-
|
|
209
|
+
Google reference-image example:
|
|
221
210
|
|
|
222
211
|
```json
|
|
223
212
|
{
|
|
@@ -225,25 +214,42 @@ npm run build
|
|
|
225
214
|
"arguments": {
|
|
226
215
|
"prompt": "Turn this sketch into a polished mobile app hero illustration",
|
|
227
216
|
"model": "gemini-3.1-flash-image",
|
|
228
|
-
"input_images": ["
|
|
217
|
+
"input_images": ["/absolute/path/to/sketch.png"],
|
|
229
218
|
"aspect_ratio": "16:9",
|
|
230
219
|
"image_size": "512",
|
|
231
|
-
"return_mode": "
|
|
220
|
+
"return_mode": "file",
|
|
221
|
+
"output_path": "/absolute/path/to/generated-images"
|
|
232
222
|
}
|
|
233
223
|
}
|
|
234
224
|
```
|
|
235
225
|
|
|
236
|
-
|
|
226
|
+
## Troubleshooting
|
|
237
227
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
228
|
+
### `npx` is not found
|
|
229
|
+
|
|
230
|
+
Install Node.js 20 or later and confirm that both `node --version` and `npx --version` work in a new terminal.
|
|
231
|
+
|
|
232
|
+
### The MCP tools do not appear
|
|
243
233
|
|
|
244
|
-
|
|
234
|
+
- Check the JSON or TOML syntax and the config file location.
|
|
235
|
+
- Completely restart the MCP client after editing its configuration.
|
|
236
|
+
- In Codex, use `/mcp`; in Cursor, check **Settings > Tools & MCP**.
|
|
245
237
|
|
|
246
|
-
|
|
238
|
+
### Authentication or billing errors
|
|
239
|
+
|
|
240
|
+
Confirm that the key matches the selected tool and that the provider account has access, billing, or credits enabled. Only the provider whose tool is called checks its key.
|
|
241
|
+
|
|
242
|
+
### An input image cannot be found
|
|
243
|
+
|
|
244
|
+
Replace relative paths with absolute paths that are readable by the local MCP server process.
|
|
245
|
+
|
|
246
|
+
### An inline image exceeds 4 MiB
|
|
247
|
+
|
|
248
|
+
Use `return_mode: "file"`, or raise `inline_max_bytes` only if the client can accept the larger payload.
|
|
249
|
+
|
|
250
|
+
## Development
|
|
251
|
+
|
|
252
|
+
For contributors working from the source repository:
|
|
247
253
|
|
|
248
254
|
```bash
|
|
249
255
|
npm install
|
|
@@ -251,4 +257,8 @@ npm run dev
|
|
|
251
257
|
npm run ci
|
|
252
258
|
```
|
|
253
259
|
|
|
254
|
-
`npm run ci`
|
|
260
|
+
`npm run ci` runs type checking, tests, and a production build.
|
|
261
|
+
|
|
262
|
+
## License
|
|
263
|
+
|
|
264
|
+
[MIT](./LICENSE)
|
package/README.zh-TW.md
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# image-router-mcp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/image-router-mcp)
|
|
4
|
+
[](https://www.npmjs.com/package/image-router-mcp)
|
|
5
|
+
|
|
6
|
+
[English](./README.md) | 繁體中文
|
|
7
|
+
|
|
8
|
+
開源 MCP 伺服器,可將圖片生成與編輯請求路由到 xAI/Grok、Google Gemini/Nano Banana 與 OpenAI。
|
|
9
|
+
|
|
10
|
+
可直接透過 npm 的 `npx` 執行。只需準備實際要使用之供應商的 API Key。
|
|
11
|
+
|
|
12
|
+
## 功能
|
|
13
|
+
|
|
14
|
+
- 分別提供 xAI、Google 與 OpenAI 三個明確的 MCP 工具。
|
|
15
|
+
- 支援文字生成圖片、本機參考圖及圖片編輯流程。
|
|
16
|
+
- 接受彈性的模型 ID,不會因固定允許清單而阻擋相容的新模型。
|
|
17
|
+
- 預設將圖片儲存成檔案,避免透過 stdio 傳送大型 base64 payload。
|
|
18
|
+
- 可選擇回傳 inline 圖片內容,讓支援的 MCP 客戶端直接顯示。
|
|
19
|
+
|
|
20
|
+
## 工具與預設模型
|
|
21
|
+
|
|
22
|
+
| 工具 | 供應商 | 內建預設模型 | 支援內容 |
|
|
23
|
+
| --- | --- | --- | --- |
|
|
24
|
+
| `openai_generate_image` | OpenAI | `gpt-image-2` | 文字生成圖片及本機參考圖/編輯圖 |
|
|
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 張本機輸入圖的編輯 |
|
|
27
|
+
|
|
28
|
+
以上模型是範例與預設值,不是允許清單。可透過 `model` 參數傳入其他相容的模型 ID。
|
|
29
|
+
|
|
30
|
+
## 前置需求
|
|
31
|
+
|
|
32
|
+
- Node.js 20 以上版本,並包含 `npm` 與 `npx`。
|
|
33
|
+
- 支援本機 stdio server 的 MCP 客戶端,例如 Codex、Claude Desktop 或 Cursor。
|
|
34
|
+
- 至少一組供應商 API Key:
|
|
35
|
+
- OpenAI 使用 `OPENAI_API_KEY`
|
|
36
|
+
- Google 使用 `GOOGLE_API_KEY` 或 `GEMINI_API_KEY`
|
|
37
|
+
- xAI 使用 `XAI_API_KEY`
|
|
38
|
+
|
|
39
|
+
呼叫供應商 API 可能產生費用。只需設定實際要使用的供應商 Key。
|
|
40
|
+
|
|
41
|
+
> [!WARNING]
|
|
42
|
+
> 請勿將真實 API Key 提交到版本控制。含有密鑰的設定建議放在使用者層級;若 MCP 客戶端支援,也可從既有環境變數轉送 Key。
|
|
43
|
+
|
|
44
|
+
## 快速開始
|
|
45
|
+
|
|
46
|
+
以下範例只設定 OpenAI。若要使用 Google 或 xAI,請依照[環境設定](#環境設定)取代或加入對應的環境變數。
|
|
47
|
+
|
|
48
|
+
### Codex
|
|
49
|
+
|
|
50
|
+
透過命令列加入 server:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
codex mcp add image-router-mcp --env OPENAI_API_KEY=your_openai_key -- npx -y image-router-mcp
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
也可以加入所有專案共用的 `~/.codex/config.toml`,或單一受信任專案中的 `.codex/config.toml`:
|
|
57
|
+
|
|
58
|
+
```toml
|
|
59
|
+
[mcp_servers.image-router-mcp]
|
|
60
|
+
command = "npx"
|
|
61
|
+
args = ["-y", "image-router-mcp"]
|
|
62
|
+
|
|
63
|
+
[mcp_servers.image-router-mcp.env]
|
|
64
|
+
OPENAI_API_KEY = "your_openai_key"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
編輯檔案後重新啟動 Codex,再使用 `/mcp` 確認 `image-router-mcp` 與三個工具已出現。
|
|
68
|
+
|
|
69
|
+
### Claude Desktop
|
|
70
|
+
|
|
71
|
+
開啟 **Settings > Developer > Edit Config**,將以下 server 加入 `claude_desktop_config.json`:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"mcpServers": {
|
|
76
|
+
"image-router-mcp": {
|
|
77
|
+
"command": "npx",
|
|
78
|
+
"args": ["-y", "image-router-mcp"],
|
|
79
|
+
"env": {
|
|
80
|
+
"OPENAI_API_KEY": "your_openai_key"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
預設設定檔位置:
|
|
88
|
+
|
|
89
|
+
- macOS:`~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
90
|
+
- Windows:`%APPDATA%\Claude\claude_desktop_config.json`
|
|
91
|
+
|
|
92
|
+
儲存後請完整結束並重新開啟 Claude Desktop。
|
|
93
|
+
|
|
94
|
+
### Cursor
|
|
95
|
+
|
|
96
|
+
將上方相同的 JSON 設定加入下列其中一個位置:
|
|
97
|
+
|
|
98
|
+
- 全域:`~/.cursor/mcp.json`
|
|
99
|
+
- 僅限單一專案:`.cursor/mcp.json`
|
|
100
|
+
|
|
101
|
+
開啟 **Cursor Settings > Tools & MCP**,確認 server 與工具已啟用。
|
|
102
|
+
|
|
103
|
+
## 生成第一張圖片
|
|
104
|
+
|
|
105
|
+
連線完成後,直接向 MCP 客戶端提出:
|
|
106
|
+
|
|
107
|
+
> 使用 `openai_generate_image` 生成一張 1024x1024 的電影感產品照,內容是放在大理石桌面上的透明機械鍵盤。將圖片儲存到 `/absolute/path/to/generated-images`,並回傳儲存路徑。
|
|
108
|
+
|
|
109
|
+
若要編輯既有圖片:
|
|
110
|
+
|
|
111
|
+
> 使用 `google_generate_image`,以 `/absolute/path/to/sketch.png` 作為輸入圖片。將它轉換成精緻的 16:9 行動 App 主視覺插圖,並儲存到 `/absolute/path/to/generated-images`。
|
|
112
|
+
|
|
113
|
+
請在提示詞與工具呼叫中使用絕對路徑。相對路徑會受到 MCP 客戶端所選工作目錄影響。
|
|
114
|
+
|
|
115
|
+
## 路徑與圖片輸出
|
|
116
|
+
|
|
117
|
+
- `input_images` 路徑會從 MCP server process 的工作目錄開始解析。
|
|
118
|
+
- `output_path` 可以是檔案路徑或資料夾。
|
|
119
|
+
- 已存在的資料夾,或沒有副檔名的新路徑,會被視為資料夾。
|
|
120
|
+
- 帶有副檔名的路徑會被視為指定輸出檔名;若有多張結果,檔名會加入編號。
|
|
121
|
+
- 未傳入 `output_path` 時,圖片會儲存在 `DEFAULT_OUTPUT_DIR`;若未設定該變數,則使用 MCP server 工作目錄下的 `./generated-images`。
|
|
122
|
+
- 建議輸入與輸出都使用絕對路徑,確保不同客戶端有一致結果。
|
|
123
|
+
- 若要跨供應商使用本機圖片,建議採用 PNG、JPG/JPEG 或 WebP。Google 與 xAI 的載入器接受這些副檔名。
|
|
124
|
+
- xAI 最多接受 3 張 `input_images`。
|
|
125
|
+
|
|
126
|
+
### 回傳模式
|
|
127
|
+
|
|
128
|
+
| 模式 | 行為 |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| `file` | 預設。將圖片儲存到磁碟並回傳路徑。 |
|
|
131
|
+
| `inline` | 不儲存檔案,直接回傳 MCP `image` content;每張圖片受 `inline_max_bytes` 限制。 |
|
|
132
|
+
| `both` | 同時儲存圖片並回傳 inline MCP 圖片內容。 |
|
|
133
|
+
|
|
134
|
+
大型圖片建議使用 `file`。只有在 MCP 客戶端可以顯示圖片、且結果符合 payload 限制時,才使用 `inline` 或 `both`。
|
|
135
|
+
|
|
136
|
+
## 工具參數
|
|
137
|
+
|
|
138
|
+
### 共用參數
|
|
139
|
+
|
|
140
|
+
| 參數 | 必填 | 預設值 | 說明 |
|
|
141
|
+
| --- | --- | --- | --- |
|
|
142
|
+
| `prompt` | 是 | — | 圖片生成或編輯指示。 |
|
|
143
|
+
| `model` | 否 | 供應商預設值 | 相容的供應商模型 ID。 |
|
|
144
|
+
| `input_images` | 否 | `[]` | 本機參考圖/編輯圖路徑。 |
|
|
145
|
+
| `output_path` | 否 | `DEFAULT_OUTPUT_DIR` 或 `./generated-images` | 儲存結果的檔案或資料夾。 |
|
|
146
|
+
| `return_mode` | 否 | `file` | `file`、`inline` 或 `both`。 |
|
|
147
|
+
| `inline_max_bytes` | 否 | `4194304`(4 MiB) | 每張 inline 圖片允許的最大大小。 |
|
|
148
|
+
| `n` | 否 | 供應商預設值 | 供應商支援時的結果數量,範圍為 1 到 10;Google 目前回傳一張。 |
|
|
149
|
+
| `user` | 否 | — | 選用的終端使用者識別碼,供供應商進行濫用監控。 |
|
|
150
|
+
|
|
151
|
+
### OpenAI 參數
|
|
152
|
+
|
|
153
|
+
| 參數 | 值或範例 | 預設值 |
|
|
154
|
+
| --- | --- | --- |
|
|
155
|
+
| `size` | `auto`、`1024x1024`、`1536x1024` 或其他支援的 `WIDTHxHEIGHT` | 供應商預設值 |
|
|
156
|
+
| `quality` | `auto`、`low`、`medium`、`high`、`standard`、`hd` | 供應商預設值 |
|
|
157
|
+
| `background` | `transparent`、`opaque`、`auto` | 供應商預設值 |
|
|
158
|
+
| `output_format` | `png`、`jpeg`、`webp` | `png` |
|
|
159
|
+
| `moderation` | `low`、`auto` | 供應商預設值 |
|
|
160
|
+
| `style` | `vivid`、`natural`;供 DALL-E 3 使用 | 供應商預設值 |
|
|
161
|
+
|
|
162
|
+
### Google 參數
|
|
163
|
+
|
|
164
|
+
| 參數 | 值或範例 | 預設值 |
|
|
165
|
+
| --- | --- | --- |
|
|
166
|
+
| `aspect_ratio` | 例如 `1:1`、`16:9`、`9:16`、`4:3` 或 `3:2` | 供應商預設值 |
|
|
167
|
+
| `image_size` | `512`、`0.5K`、`1K`、`2K`、`4K`;實際可用值依模型而定 | 供應商預設值 |
|
|
168
|
+
|
|
169
|
+
`0.5K` 是相容舊版的別名,送出前會正規化為 `512`。
|
|
170
|
+
|
|
171
|
+
### xAI 參數
|
|
172
|
+
|
|
173
|
+
| 參數 | 值或範例 | 預設值 |
|
|
174
|
+
| --- | --- | --- |
|
|
175
|
+
| `aspect_ratio` | 例如 `1:1`、`16:9`、`9:16`、`3:2` 或 `auto` | 供應商預設值 |
|
|
176
|
+
| `resolution` | `1k`、`2k` | 供應商預設值 |
|
|
177
|
+
|
|
178
|
+
## 環境設定
|
|
179
|
+
|
|
180
|
+
| 變數 | 必要性 | 行為 |
|
|
181
|
+
| --- | --- | --- |
|
|
182
|
+
| `OPENAI_API_KEY` | 使用 OpenAI 工具時需要 | OpenAI API Key。 |
|
|
183
|
+
| `GOOGLE_API_KEY` 或 `GEMINI_API_KEY` | 使用 Google 工具時需要 | Google Gemini API Key。 |
|
|
184
|
+
| `XAI_API_KEY` | 使用 xAI 工具時需要 | xAI API Key。 |
|
|
185
|
+
| `DEFAULT_OPENAI_IMAGE_MODEL` | 否 | 未傳入 `model` 時使用的 OpenAI 預設模型;明確傳入的 `model` 可以覆寫。 |
|
|
186
|
+
| `DEFAULT_GOOGLE_IMAGE_MODEL` | 否 | 將 Google 請求固定到此模型,優先於每次呼叫的 `model` 參數。 |
|
|
187
|
+
| `DEFAULT_XAI_IMAGE_MODEL` | 否 | 將 xAI 請求固定到此模型,優先於每次呼叫的 `model` 參數。 |
|
|
188
|
+
| `DEFAULT_OUTPUT_DIR` | 否 | 預設圖片儲存資料夾;預設為 MCP server 工作目錄下的 `./generated-images`。 |
|
|
189
|
+
|
|
190
|
+
Key 只會在呼叫對應工具時檢查,因此只設定一個供應商 Key 即可開始使用。
|
|
191
|
+
|
|
192
|
+
## 進階直接工具呼叫
|
|
193
|
+
|
|
194
|
+
多數使用者直接用自然語言要求 MCP 客戶端即可。若客戶端支援直接呼叫工具,對等的 OpenAI 請求如下:
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
{
|
|
198
|
+
"tool": "openai_generate_image",
|
|
199
|
+
"arguments": {
|
|
200
|
+
"prompt": "A cinematic product photo of a transparent mechanical keyboard on a marble desk",
|
|
201
|
+
"model": "gpt-image-2",
|
|
202
|
+
"size": "1024x1024",
|
|
203
|
+
"return_mode": "file",
|
|
204
|
+
"output_path": "/absolute/path/to/generated-images"
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Google 參考圖範例:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"tool": "google_generate_image",
|
|
214
|
+
"arguments": {
|
|
215
|
+
"prompt": "Turn this sketch into a polished mobile app hero illustration",
|
|
216
|
+
"model": "gemini-3.1-flash-image",
|
|
217
|
+
"input_images": ["/absolute/path/to/sketch.png"],
|
|
218
|
+
"aspect_ratio": "16:9",
|
|
219
|
+
"image_size": "512",
|
|
220
|
+
"return_mode": "file",
|
|
221
|
+
"output_path": "/absolute/path/to/generated-images"
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## 疑難排解
|
|
227
|
+
|
|
228
|
+
### 找不到 `npx`
|
|
229
|
+
|
|
230
|
+
安裝 Node.js 20 以上版本,並在新的終端機中確認 `node --version` 與 `npx --version` 都能執行。
|
|
231
|
+
|
|
232
|
+
### MCP 工具沒有出現
|
|
233
|
+
|
|
234
|
+
- 檢查 JSON 或 TOML 語法,以及設定檔位置。
|
|
235
|
+
- 編輯設定後,完整重新啟動 MCP 客戶端。
|
|
236
|
+
- Codex 使用 `/mcp` 檢查;Cursor 前往 **Settings > Tools & MCP**。
|
|
237
|
+
|
|
238
|
+
### API 驗證或帳務錯誤
|
|
239
|
+
|
|
240
|
+
確認 Key 與選擇的工具相符,且供應商帳戶已取得存取權限並啟用帳務或額度。只有被呼叫工具所屬的供應商會檢查 Key。
|
|
241
|
+
|
|
242
|
+
### 找不到輸入圖片
|
|
243
|
+
|
|
244
|
+
將相對路徑改為本機 MCP server process 可以讀取的絕對路徑。
|
|
245
|
+
|
|
246
|
+
### Inline 圖片超過 4 MiB
|
|
247
|
+
|
|
248
|
+
改用 `return_mode: "file"`;只有在客戶端能接受較大 payload 時,才提高 `inline_max_bytes`。
|
|
249
|
+
|
|
250
|
+
## 開發
|
|
251
|
+
|
|
252
|
+
若要從原始碼進行開發:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
npm install
|
|
256
|
+
npm run dev
|
|
257
|
+
npm run ci
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
`npm run ci` 會執行型別檢查、測試與正式建置。
|
|
261
|
+
|
|
262
|
+
## 授權
|
|
263
|
+
|
|
264
|
+
[MIT](./LICENSE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "image-router-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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": {
|
|
@@ -11,8 +11,12 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
13
|
"README.md",
|
|
14
|
+
"README.zh-TW.md",
|
|
14
15
|
"LICENSE"
|
|
15
16
|
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20.0.0"
|
|
19
|
+
},
|
|
16
20
|
"scripts": {
|
|
17
21
|
"build": "tsc -p tsconfig.json",
|
|
18
22
|
"dev": "tsx src/index.ts",
|