mcp-duojie-image 0.5.2 → 0.5.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/dist/index.js CHANGED
@@ -23,7 +23,7 @@ const server = new McpServer({
23
23
  version: "0.1.0",
24
24
  });
25
25
  server.registerTool("generate_image", {
26
- description: "Generate image async. Ask user to choose model before calling.",
26
+ description: "Generate image async. If user didn't specify model and no model was chosen in this conversation, ask once. Reuse that model later unless user changes it. Return after tool call; don't wait/check.",
27
27
  inputSchema: z.object({
28
28
  prompt: z.string().min(1).describe("Prompt"),
29
29
  output_dir: z.string().describe("Absolute output dir"),
@@ -32,7 +32,7 @@ server.registerTool("generate_image", {
32
32
  size: z.enum(["512px", "1K", "2K", "4K"]).optional().describe("Default 1K"),
33
33
  aspect_ratio: z.string().optional().describe("e.g. 16:9"),
34
34
  format: z.string().optional().describe("Default png"),
35
- model: z.enum(["gemini-3.1-flash-image", "gpt-image-2"]).describe("Required"),
35
+ model: z.enum(["gemini-3.1-flash-image", "gpt-image-2"]).describe("Required; ask once per conversation if unknown"),
36
36
  overwrite: z.boolean().optional().describe("Default false"),
37
37
  negative_prompt: z.string().optional().describe("Avoid"),
38
38
  silent: z.boolean().optional().describe("No notification"),
@@ -92,8 +92,9 @@ server.registerTool("generate_image", {
92
92
  content: [{
93
93
  type: "text",
94
94
  text: JSON.stringify({
95
- status: "pending",
96
- message: `已开始:${args.output_filename}`,
95
+ success: true,
96
+ status: "submitted",
97
+ message: `已提交异步生成:${args.output_filename};无需等待或检查结果`,
97
98
  }),
98
99
  }],
99
100
  };
package/dist/provider.js CHANGED
@@ -46,18 +46,43 @@ function mapSize(size) {
46
46
  function isOpenAIImageModel(model) {
47
47
  return model === "gpt-image-2";
48
48
  }
49
+ function parseAspectRatio(aspectRatio) {
50
+ const match = aspectRatio?.match(/^(\d+):(\d+)$/);
51
+ if (!match)
52
+ return [1, 1];
53
+ return [Number(match[1]), Number(match[2])];
54
+ }
55
+ function mapOpenAI4KSize(aspectRatio) {
56
+ const [ratioWidth, ratioHeight] = parseAspectRatio(aspectRatio);
57
+ const maxPixels = 3840 * 2160;
58
+ const maxEdge = 3840;
59
+ let width = Math.floor(Math.sqrt((maxPixels * ratioWidth) / ratioHeight));
60
+ let height = Math.floor((width * ratioHeight) / ratioWidth);
61
+ if (width > maxEdge) {
62
+ width = maxEdge;
63
+ height = Math.floor((width * ratioHeight) / ratioWidth);
64
+ }
65
+ if (height > maxEdge) {
66
+ height = maxEdge;
67
+ width = Math.floor((height * ratioWidth) / ratioHeight);
68
+ }
69
+ width = Math.floor(width / 8) * 8;
70
+ height = Math.floor(height / 8) * 8;
71
+ return `${width}x${height}`;
72
+ }
49
73
  function mapOpenAISize(size, aspectRatio) {
50
74
  const squareBySize = {
51
75
  "512px": "512x512",
52
76
  "1K": "1024x1024",
53
77
  "2K": "2048x2048",
54
- "4K": "4096x4096",
55
78
  };
79
+ if (size === "4K")
80
+ return mapOpenAI4KSize(aspectRatio);
56
81
  if (aspectRatio === "16:9" || aspectRatio === "3:2" || aspectRatio === "4:3") {
57
- return size === "2K" ? "2048x1536" : size === "4K" ? "4096x3072" : "1536x1024";
82
+ return size === "2K" ? "2048x1536" : "1536x1024";
58
83
  }
59
84
  if (aspectRatio === "9:16" || aspectRatio === "2:3" || aspectRatio === "3:4") {
60
- return size === "2K" ? "1536x2048" : size === "4K" ? "3072x4096" : "1024x1536";
85
+ return size === "2K" ? "1536x2048" : "1024x1536";
61
86
  }
62
87
  return squareBySize[size] ?? "1024x1024";
63
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-duojie-image",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "MCP server for image generation via duojie.games",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",