image-router-mcp 0.1.0 → 0.1.2

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
@@ -1,5 +1,8 @@
1
1
  # image-router-mcp
2
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
+
3
6
  English | [繁體中文](#繁體中文)
4
7
 
5
8
  Open-source MCP server for routing image generation and editing across xAI/Grok, Google Gemini/Nano Banana, and OpenAI.
@@ -18,8 +21,8 @@ It keeps model IDs flexible instead of locking tools to a small allowlist, so ne
18
21
 
19
22
  | Tool | Provider | Supports |
20
23
  | --- | --- | --- |
21
- | `xai_generate_image` | xAI/Grok | Text-to-image and JSON image edits with local `input_images` |
22
- | `google_generate_image` | Google Gemini/Nano Banana | Text-to-image and local reference/edit images |
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 |
23
26
  | `openai_generate_image` | OpenAI | Text-to-image and local reference/edit images |
24
27
 
25
28
  ## Model examples
@@ -69,7 +72,7 @@ For MCP clients, run the published package with `npx`:
69
72
  | `OPENAI_API_KEY` | For OpenAI tool | OpenAI API key. |
70
73
  | `DEFAULT_XAI_IMAGE_MODEL` | No | Overrides the default xAI image model. |
71
74
  | `DEFAULT_GOOGLE_IMAGE_MODEL` | No | Overrides the default Google image model. |
72
- | `DEFAULT_OPENAI_IMAGE_MODEL` | No | Overrides the default OpenAI image model. |
75
+ | `DEFAULT_OPENAI_IMAGE_MODEL` | No | Sets the default OpenAI image model when `model` is omitted. |
73
76
  | `DEFAULT_OUTPUT_DIR` | No | Directory for saved images. Defaults to `./generated-images`. |
74
77
 
75
78
  ## How to use this MCP
@@ -99,6 +102,7 @@ To edit or reference existing local images, pass file paths with `input_images`:
99
102
  "model": "gemini-3.1-flash-image-preview",
100
103
  "input_images": ["./assets/sketch.png"],
101
104
  "aspect_ratio": "16:9",
105
+ "image_size": "512",
102
106
  "return_mode": "both"
103
107
  }
104
108
  }
@@ -142,8 +146,8 @@ npm run ci
142
146
 
143
147
  | 工具 | 供應商 | 支援內容 |
144
148
  | --- | --- | --- |
145
- | `xai_generate_image` | xAI/Grok | 文字生成圖片,以及使用本機 `input_images` 的 JSON 圖片編輯 |
146
- | `google_generate_image` | Google Gemini/Nano Banana | 文字生成圖片,以及本機參考圖/編輯圖 |
149
+ | `xai_generate_image` | xAI/Grok | 文字生成圖片,以及最多 3 張本機 `input_images` 的 JSON 圖片編輯 |
150
+ | `google_generate_image` | Google Gemini/Nano Banana | 文字生成圖片,以及本機參考圖/編輯圖;支援供應商允許的 `512`、`1K`、`2K`、`4K` 圖片尺寸 |
147
151
  | `openai_generate_image` | OpenAI | 文字生成圖片,以及本機參考圖/編輯圖 |
148
152
 
149
153
  ## 模型範例
@@ -193,7 +197,7 @@ npm run build
193
197
  | `OPENAI_API_KEY` | 使用 OpenAI 工具時需要 | OpenAI API Key。 |
194
198
  | `DEFAULT_XAI_IMAGE_MODEL` | 否 | 覆寫預設 xAI 圖片模型。 |
195
199
  | `DEFAULT_GOOGLE_IMAGE_MODEL` | 否 | 覆寫預設 Google 圖片模型。 |
196
- | `DEFAULT_OPENAI_IMAGE_MODEL` | 否 | 覆寫預設 OpenAI 圖片模型。 |
200
+ | `DEFAULT_OPENAI_IMAGE_MODEL` | 否 | 未傳入 `model` 時使用的預設 OpenAI 圖片模型。 |
197
201
  | `DEFAULT_OUTPUT_DIR` | 否 | 圖片輸出資料夾,預設為 `./generated-images`。 |
198
202
 
199
203
  ## 這個 MCP 怎麼用
@@ -223,6 +227,7 @@ npm run build
223
227
  "model": "gemini-3.1-flash-image-preview",
224
228
  "input_images": ["./assets/sketch.png"],
225
229
  "aspect_ratio": "16:9",
230
+ "image_size": "512",
226
231
  "return_mode": "both"
227
232
  }
228
233
  }
@@ -12,6 +12,9 @@ function getOpenAIClient() {
12
12
  export function setOpenAIClientForTests(client) {
13
13
  openAIClient = client;
14
14
  }
15
+ function isDallEModel(model) {
16
+ return model.startsWith("dall-e-");
17
+ }
15
18
  async function imageFromOpenAIItem(item, mimeType) {
16
19
  if (item.b64_json) {
17
20
  return {
@@ -27,18 +30,22 @@ async function imageFromOpenAIItem(item, mimeType) {
27
30
  throw new Error("OpenAI response did not include b64_json or url image data.");
28
31
  }
29
32
  export async function generateOpenAIImage(params, client = getOpenAIClient()) {
30
- const model = process.env.DEFAULT_OPENAI_IMAGE_MODEL ?? params.model;
31
- const outputFormat = params.output_format;
33
+ const model = params.model ?? process.env.DEFAULT_OPENAI_IMAGE_MODEL ?? "gpt-image-2";
34
+ const outputFormat = params.output_format ?? "png";
32
35
  const inputImages = params.input_images ?? [];
36
+ const dallEModel = isDallEModel(model);
33
37
  const common = {
34
38
  model,
35
39
  prompt: params.prompt,
36
40
  n: params.n,
37
41
  size: params.size,
38
- background: params.background,
39
- output_format: outputFormat,
40
- response_format: "b64_json",
41
42
  user: params.user,
43
+ ...(dallEModel
44
+ ? { response_format: "b64_json" }
45
+ : {
46
+ background: params.background,
47
+ output_format: outputFormat,
48
+ }),
42
49
  };
43
50
  const response = inputImages.length > 0
44
51
  ? await (async () => {
@@ -56,8 +63,7 @@ export async function generateOpenAIImage(params, client = getOpenAIClient()) {
56
63
  : await client.images.generate({
57
64
  ...common,
58
65
  quality: params.quality,
59
- moderation: params.moderation,
60
- style: params.style,
66
+ ...(dallEModel ? { style: params.style } : { moderation: params.moderation }),
61
67
  });
62
68
  const data = "data" in response ? response.data ?? [] : [];
63
69
  if (data.length === 0) {
package/dist/schemas.d.ts CHANGED
@@ -50,6 +50,7 @@ export declare const googleInputShape: {
50
50
  readonly model: z.ZodDefault<z.ZodString>;
51
51
  readonly aspect_ratio: z.ZodOptional<z.ZodString>;
52
52
  readonly image_size: z.ZodOptional<z.ZodEnum<{
53
+ 512: "512";
53
54
  "1K": "1K";
54
55
  "2K": "2K";
55
56
  "4K": "4K";
@@ -67,6 +68,7 @@ export declare const googleInputShape: {
67
68
  readonly user: z.ZodOptional<z.ZodString>;
68
69
  };
69
70
  export declare const xaiInputShape: {
71
+ readonly input_images: z.ZodOptional<z.ZodArray<z.ZodString>>;
70
72
  readonly model: z.ZodDefault<z.ZodString>;
71
73
  readonly aspect_ratio: z.ZodOptional<z.ZodString>;
72
74
  readonly resolution: z.ZodOptional<z.ZodEnum<{
@@ -75,7 +77,6 @@ export declare const xaiInputShape: {
75
77
  }>>;
76
78
  readonly prompt: z.ZodString;
77
79
  readonly output_path: z.ZodOptional<z.ZodString>;
78
- readonly input_images: z.ZodOptional<z.ZodArray<z.ZodString>>;
79
80
  readonly return_mode: z.ZodDefault<z.ZodEnum<{
80
81
  file: "file";
81
82
  inline: "inline";
@@ -130,6 +131,7 @@ export declare const googleParamsSchema: z.ZodObject<{
130
131
  model: z.ZodDefault<z.ZodString>;
131
132
  aspect_ratio: z.ZodOptional<z.ZodString>;
132
133
  image_size: z.ZodOptional<z.ZodEnum<{
134
+ 512: "512";
133
135
  "1K": "1K";
134
136
  "2K": "2K";
135
137
  "4K": "4K";
@@ -147,6 +149,7 @@ export declare const googleParamsSchema: z.ZodObject<{
147
149
  user: z.ZodOptional<z.ZodString>;
148
150
  }, z.core.$strict>;
149
151
  export declare const xaiParamsSchema: z.ZodObject<{
152
+ input_images: z.ZodOptional<z.ZodArray<z.ZodString>>;
150
153
  model: z.ZodDefault<z.ZodString>;
151
154
  aspect_ratio: z.ZodOptional<z.ZodString>;
152
155
  resolution: z.ZodOptional<z.ZodEnum<{
@@ -155,7 +158,6 @@ export declare const xaiParamsSchema: z.ZodObject<{
155
158
  }>>;
156
159
  prompt: z.ZodString;
157
160
  output_path: z.ZodOptional<z.ZodString>;
158
- input_images: z.ZodOptional<z.ZodArray<z.ZodString>>;
159
161
  return_mode: z.ZodDefault<z.ZodEnum<{
160
162
  file: "file";
161
163
  inline: "inline";
package/dist/schemas.js CHANGED
@@ -5,6 +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
9
  const commonImageShape = {
9
10
  prompt: nonEmptyString.describe("Image generation or editing instructions."),
10
11
  model: nonEmptyString.optional().describe("Provider model ID. Any string is allowed so newly released models are not blocked."),
@@ -22,7 +23,7 @@ const commonImageShape = {
22
23
  };
23
24
  export const openAIInputShape = {
24
25
  ...commonImageShape,
25
- model: nonEmptyString.default("gpt-image-2").describe("OpenAI image model ID. Defaults to gpt-image-2."),
26
+ model: nonEmptyString.default(defaultOpenAIImageModel).describe("OpenAI image model ID. Defaults to DEFAULT_OPENAI_IMAGE_MODEL or gpt-image-2."),
26
27
  size: nonEmptyString.optional().describe("OpenAI size, such as auto, 1024x1024, 1536x1024, or any supported WIDTHxHEIGHT."),
27
28
  quality: z.enum(["auto", "low", "medium", "high", "standard", "hd"]).optional().describe("OpenAI quality."),
28
29
  background: z.enum(["transparent", "opaque", "auto"]).optional().describe("OpenAI background option."),
@@ -34,10 +35,11 @@ export const googleInputShape = {
34
35
  ...commonImageShape,
35
36
  model: nonEmptyString.default("gemini-3.1-flash-image-preview").describe("Google image model ID. Defaults to Nano Banana 2."),
36
37
  aspect_ratio: nonEmptyString.optional().describe("Aspect ratio, for example 1:1, 16:9, 9:16, 4:3, or 3:2."),
37
- image_size: z.enum(["1K", "2K", "4K"]).optional().describe("Google image size where supported."),
38
+ image_size: z.enum(["512", "1K", "2K", "4K"]).optional().describe("Google image size where supported."),
38
39
  };
39
40
  export const xaiInputShape = {
40
41
  ...commonImageShape,
42
+ input_images: z.array(nonEmptyString).max(3).optional().describe("Local image paths used as edit/reference inputs. xAI supports up to 3 input images."),
41
43
  model: nonEmptyString.default("grok-imagine-image-quality").describe("xAI/Grok image model ID."),
42
44
  aspect_ratio: nonEmptyString.optional().describe("Aspect ratio, for example 1:1, 16:9, 9:16, 3:2, or auto."),
43
45
  resolution: z.enum(["1k", "2k"]).optional().describe("xAI image resolution."),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "image-router-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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,9 +33,9 @@
33
33
  "author": "",
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
- "@google/genai": "2.6.0",
36
+ "@google/genai": "2.7.0",
37
37
  "@modelcontextprotocol/sdk": "1.29.0",
38
- "openai": "6.39.0",
38
+ "openai": "6.39.1",
39
39
  "zod": "4.4.3"
40
40
  },
41
41
  "devDependencies": {