imageforge-mcp 0.3.0 → 0.5.0
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 +459 -44
- package/dist/imageInput.d.ts +33 -3
- package/dist/imageInput.js +259 -54
- package/dist/imageInput.js.map +1 -1
- package/dist/index.d.ts +1 -29
- package/dist/index.js +46 -104
- package/dist/index.js.map +1 -1
- package/dist/providers.d.ts +53 -0
- package/dist/providers.js +385 -0
- package/dist/providers.js.map +1 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,141 +1,73 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
import { promises as fs } from "node:fs";
|
|
4
|
+
import { promises as fs, realpathSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
6
7
|
import { z } from "zod";
|
|
7
8
|
import { loadImages } from "./imageInput.js";
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
import { requestImage, resolveConfig, resolveProvider, } from "./providers.js";
|
|
10
|
+
const generateQualitySchema = z.enum(["auto", "low", "medium", "high", "standard", "hd"]);
|
|
11
|
+
const editQualitySchema = z.enum(["auto", "low", "medium", "high"]);
|
|
11
12
|
const outputFormatSchema = z.enum(["png", "jpeg", "webp"]);
|
|
12
|
-
function firstValue(...values) {
|
|
13
|
-
return values.map((value) => value?.trim()).find(Boolean);
|
|
14
|
-
}
|
|
15
|
-
export function resolveConfig(input) {
|
|
16
|
-
const apiKey = firstValue(input.apiKey, process.env.OPENAI_API_KEY);
|
|
17
|
-
if (!apiKey) {
|
|
18
|
-
throw new Error("Missing API key: pass api_key or set OPENAI_API_KEY.");
|
|
19
|
-
}
|
|
20
|
-
const model = firstValue(input.model, process.env.OPENAI_IMAGE_MODEL, DEFAULT_MODEL);
|
|
21
|
-
if (model !== DEFAULT_MODEL) {
|
|
22
|
-
throw new Error(`Unsupported model '${model}'. This MVP only supports ${DEFAULT_MODEL}.`);
|
|
23
|
-
}
|
|
24
|
-
const baseUrl = firstValue(input.baseUrl, process.env.OPENAI_BASE_URL, DEFAULT_BASE_URL);
|
|
25
|
-
let parsedUrl;
|
|
26
|
-
try {
|
|
27
|
-
parsedUrl = new URL(baseUrl);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
throw new Error("base_url must be a valid absolute HTTP(S) URL.");
|
|
31
|
-
}
|
|
32
|
-
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
|
33
|
-
throw new Error("base_url must use HTTP or HTTPS.");
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
apiKey,
|
|
37
|
-
model,
|
|
38
|
-
baseUrl: baseUrl.replace(/\/+$/, ""),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export async function requestImage(input) {
|
|
42
|
-
const fetchImpl = input.fetchImpl ?? fetch;
|
|
43
|
-
const commonFields = {
|
|
44
|
-
model: input.config.model,
|
|
45
|
-
prompt: input.prompt,
|
|
46
|
-
n: 1,
|
|
47
|
-
size: input.size,
|
|
48
|
-
quality: input.quality,
|
|
49
|
-
output_format: input.outputFormat,
|
|
50
|
-
};
|
|
51
|
-
const hasInputImages = Boolean(input.inputImages?.length);
|
|
52
|
-
let body;
|
|
53
|
-
let headers = { authorization: `Bearer ${input.config.apiKey}` };
|
|
54
|
-
if (hasInputImages) {
|
|
55
|
-
const form = new FormData();
|
|
56
|
-
for (const [name, value] of Object.entries(commonFields))
|
|
57
|
-
form.append(name, String(value));
|
|
58
|
-
for (const image of input.inputImages) {
|
|
59
|
-
form.append("image[]", new Blob([new Uint8Array(image.data)], { type: image.mimeType }), image.fileName);
|
|
60
|
-
}
|
|
61
|
-
body = form;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
headers = { ...headers, "content-type": "application/json" };
|
|
65
|
-
body = JSON.stringify(commonFields);
|
|
66
|
-
}
|
|
67
|
-
const endpoint = hasInputImages ? "edits" : "generations";
|
|
68
|
-
const response = await fetchImpl(`${input.config.baseUrl}/images/${endpoint}`, {
|
|
69
|
-
method: "POST",
|
|
70
|
-
headers,
|
|
71
|
-
body,
|
|
72
|
-
});
|
|
73
|
-
if (!response.ok) {
|
|
74
|
-
const detail = (await response.text()).slice(0, 500);
|
|
75
|
-
throw new Error(`OpenAI image request failed (${response.status}): ${detail || response.statusText}`);
|
|
76
|
-
}
|
|
77
|
-
const payload = (await response.json());
|
|
78
|
-
const encodedImage = payload.data?.[0]?.b64_json;
|
|
79
|
-
if (!encodedImage) {
|
|
80
|
-
throw new Error("OpenAI image response contained no base64 image data.");
|
|
81
|
-
}
|
|
82
|
-
const normalizedImage = encodedImage.replace(/\s+/g, "");
|
|
83
|
-
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(normalizedImage)) {
|
|
84
|
-
throw new Error("OpenAI image response contained invalid base64 image data.");
|
|
85
|
-
}
|
|
86
|
-
const image = Buffer.from(normalizedImage, "base64");
|
|
87
|
-
if (image.length === 0 || image.toString("base64").replace(/=+$/, "") !== normalizedImage.replace(/=+$/, "")) {
|
|
88
|
-
throw new Error("OpenAI image response contained invalid base64 image data.");
|
|
89
|
-
}
|
|
90
|
-
return image;
|
|
91
|
-
}
|
|
92
13
|
export async function saveImage(image, outputPath) {
|
|
93
14
|
const resolvedPath = path.resolve(outputPath);
|
|
94
15
|
await fs.mkdir(path.dirname(resolvedPath), { recursive: true });
|
|
95
16
|
await fs.writeFile(resolvedPath, image, { flag: "wx" });
|
|
96
17
|
return resolvedPath;
|
|
97
18
|
}
|
|
98
|
-
async function imageResult(image,
|
|
19
|
+
async function imageResult(image, outputPath) {
|
|
99
20
|
const content = [
|
|
100
21
|
{
|
|
101
22
|
type: "image",
|
|
102
|
-
data: image.toString("base64"),
|
|
103
|
-
mimeType:
|
|
23
|
+
data: image.data.toString("base64"),
|
|
24
|
+
mimeType: image.mimeType,
|
|
104
25
|
},
|
|
105
26
|
];
|
|
106
27
|
if (outputPath) {
|
|
107
|
-
const savedPath = await saveImage(image, outputPath);
|
|
28
|
+
const savedPath = await saveImage(image.data, outputPath);
|
|
108
29
|
content.push({ type: "text", text: `Image saved to ${savedPath}` });
|
|
109
30
|
}
|
|
110
31
|
return { content };
|
|
111
32
|
}
|
|
112
33
|
export function createServer() {
|
|
113
|
-
const server = new McpServer({ name: "imageforge-mcp", version: "0.
|
|
34
|
+
const server = new McpServer({ name: "imageforge-mcp", version: "0.5.0" });
|
|
114
35
|
server.registerTool("generate_image", {
|
|
115
|
-
description: "Generate one image with gpt-image-2,
|
|
36
|
+
description: "Generate one image with OpenAI gpt-image-2, a supported Zhipu image model, or MiniMax image-01 / image-01-live.",
|
|
116
37
|
inputSchema: {
|
|
117
38
|
prompt: z.string().trim().min(1).max(32_000).describe("Image description."),
|
|
118
|
-
model: z.string().optional().describe("Model name
|
|
119
|
-
base_url: z.string().optional().describe("
|
|
120
|
-
api_key: z.string().optional().describe("Per-call API key;
|
|
39
|
+
model: z.string().optional().describe("Model name: OpenAI gpt-image-2, Zhipu glm-image / cogview-4-250304 / cogview-4 / cogview-3-flash, or MiniMax image-01 / image-01-live."),
|
|
40
|
+
base_url: z.string().optional().describe("Per-call provider API base URL override."),
|
|
41
|
+
api_key: z.string().optional().describe("Per-call provider API key; environment variables are preferred."),
|
|
42
|
+
provider: z.enum(["openai", "zhipu", "minimax"]).optional().describe("Image provider. Defaults to IMAGEFORGE_PROVIDER, then openai."),
|
|
43
|
+
watermark_enabled: z.boolean().optional().describe("Provider watermark switch. Zhipu sends it when set; false may require watermark-removal account permission. MiniMax sends it as aigc_watermark. Unsupported providers silently ignore it. ImageForge never removes watermarks locally."),
|
|
121
44
|
size: z.string().default("1024x1024").describe("Output size, for example 1536x1024."),
|
|
122
|
-
quality:
|
|
123
|
-
output_format: outputFormatSchema.
|
|
45
|
+
quality: generateQualitySchema.default("auto"),
|
|
46
|
+
output_format: outputFormatSchema.optional().describe("Output format. OpenAI: png/jpeg/webp; Zhipu: ignored; MiniMax: jpeg only. Defaults to png, or jpeg for MiniMax."),
|
|
124
47
|
output_path: z.string().trim().min(1).optional().describe("Optional local path to save the generated image. Relative paths resolve from the MCP working directory. Existing files are not overwritten."),
|
|
125
|
-
reference_images: z.array(z.string()).max(16).optional().describe("Optional reference images as absolute local paths or HTTP(S) URLs."),
|
|
48
|
+
reference_images: z.array(z.string()).max(16).optional().describe("Optional reference images as absolute local paths or HTTP(S) URLs. OpenAI: up to 16. MiniMax: exactly one PNG/JPEG under 10 MB. Zhipu rejects this parameter."),
|
|
126
49
|
},
|
|
127
|
-
}, async ({ prompt, model, base_url, api_key, size, quality, output_format, output_path, reference_images }) => {
|
|
128
|
-
const
|
|
50
|
+
}, async ({ prompt, model, base_url, api_key, provider, watermark_enabled, size, quality, output_format, output_path, reference_images }) => {
|
|
51
|
+
const selectedProvider = provider ?? resolveProvider(process.env.IMAGEFORGE_PROVIDER);
|
|
52
|
+
if (selectedProvider === "zhipu" && reference_images?.length) {
|
|
53
|
+
throw new Error("Zhipu image generation does not support reference_images.");
|
|
54
|
+
}
|
|
55
|
+
if (selectedProvider === "minimax" && (reference_images?.length ?? 0) > 1) {
|
|
56
|
+
throw new Error("MiniMax image generation supports at most one reference image.");
|
|
57
|
+
}
|
|
58
|
+
const effectiveOutputFormat = output_format ?? (selectedProvider === "minimax" ? "jpeg" : "png");
|
|
59
|
+
const config = resolveConfig({ provider: selectedProvider, apiKey: api_key, baseUrl: base_url, model });
|
|
129
60
|
const inputImages = reference_images?.length ? await loadImages(reference_images) : undefined;
|
|
130
61
|
const image = await requestImage({
|
|
131
62
|
prompt,
|
|
132
63
|
config,
|
|
133
64
|
size,
|
|
134
65
|
quality,
|
|
135
|
-
outputFormat:
|
|
66
|
+
outputFormat: effectiveOutputFormat,
|
|
136
67
|
inputImages,
|
|
68
|
+
watermarkEnabled: watermark_enabled,
|
|
137
69
|
});
|
|
138
|
-
return imageResult(image,
|
|
70
|
+
return imageResult(image, output_path);
|
|
139
71
|
});
|
|
140
72
|
server.registerTool("edit_image", {
|
|
141
73
|
description: "Edit one or more input images with gpt-image-2.",
|
|
@@ -146,12 +78,12 @@ export function createServer() {
|
|
|
146
78
|
base_url: z.string().optional().describe("OpenAI-compatible base URL ending in /v1."),
|
|
147
79
|
api_key: z.string().optional().describe("Per-call API key; OPENAI_API_KEY is preferred."),
|
|
148
80
|
size: z.string().default("1024x1024").describe("Output size, for example 1536x1024."),
|
|
149
|
-
quality:
|
|
81
|
+
quality: editQualitySchema.default("auto"),
|
|
150
82
|
output_format: outputFormatSchema.default("png"),
|
|
151
83
|
output_path: z.string().trim().min(1).optional().describe("Optional local path to save the edited image. Relative paths resolve from the MCP working directory. Existing files are not overwritten."),
|
|
152
84
|
},
|
|
153
85
|
}, async ({ prompt, input_images, model, base_url, api_key, size, quality, output_format, output_path }) => {
|
|
154
|
-
const config = resolveConfig({ apiKey: api_key, baseUrl: base_url, model });
|
|
86
|
+
const config = resolveConfig({ provider: "openai", apiKey: api_key, baseUrl: base_url, model });
|
|
155
87
|
const image = await requestImage({
|
|
156
88
|
prompt,
|
|
157
89
|
config,
|
|
@@ -160,14 +92,24 @@ export function createServer() {
|
|
|
160
92
|
outputFormat: output_format,
|
|
161
93
|
inputImages: await loadImages(input_images),
|
|
162
94
|
});
|
|
163
|
-
return imageResult(image,
|
|
95
|
+
return imageResult(image, output_path);
|
|
164
96
|
});
|
|
165
97
|
return server;
|
|
166
98
|
}
|
|
99
|
+
export function isMainModule(entryPath = process.argv[1], moduleUrl = import.meta.url) {
|
|
100
|
+
if (!entryPath)
|
|
101
|
+
return false;
|
|
102
|
+
try {
|
|
103
|
+
return realpathSync(entryPath) === realpathSync(fileURLToPath(moduleUrl));
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
167
109
|
async function main() {
|
|
168
110
|
await createServer().connect(new StdioServerTransport());
|
|
169
111
|
}
|
|
170
|
-
if (
|
|
112
|
+
if (isMainModule()) {
|
|
171
113
|
main().catch((error) => {
|
|
172
114
|
console.error(error instanceof Error ? error.message : error);
|
|
173
115
|
process.exitCode = 1;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,eAAe,GAEhB,MAAM,gBAAgB,CAAC;AAExB,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;AAC1F,MAAM,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC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Input.js";
|
|
2
|
+
export type ProviderId = "openai" | "zhipu" | "minimax";
|
|
3
|
+
export type Quality = "auto" | "low" | "medium" | "high" | "standard" | "hd";
|
|
4
|
+
export type OutputFormat = "png" | "jpeg" | "webp";
|
|
5
|
+
export interface GeneratedImage {
|
|
6
|
+
data: Buffer;
|
|
7
|
+
mimeType: "image/png" | "image/jpeg" | "image/webp";
|
|
8
|
+
}
|
|
9
|
+
export interface ImageConfig {
|
|
10
|
+
provider: ProviderId;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
model: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function resolveProvider(value: string | undefined): ProviderId;
|
|
16
|
+
export declare function resolveConfig(input: {
|
|
17
|
+
provider?: ProviderId;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
model?: string;
|
|
21
|
+
}): ImageConfig;
|
|
22
|
+
export declare function requestOpenAIImage(input: {
|
|
23
|
+
prompt: string;
|
|
24
|
+
config: ImageConfig;
|
|
25
|
+
size: string;
|
|
26
|
+
quality: Quality;
|
|
27
|
+
outputFormat: OutputFormat;
|
|
28
|
+
inputImages?: LoadedImage[];
|
|
29
|
+
fetchImpl?: typeof fetch;
|
|
30
|
+
}): Promise<GeneratedImage>;
|
|
31
|
+
export declare function requestZhipuImage(input: {
|
|
32
|
+
prompt: string;
|
|
33
|
+
config: ImageConfig;
|
|
34
|
+
size: string;
|
|
35
|
+
quality: Quality;
|
|
36
|
+
watermarkEnabled?: boolean;
|
|
37
|
+
fetchImpl?: typeof fetch;
|
|
38
|
+
downloadFetchImpl?: typeof fetch;
|
|
39
|
+
}): Promise<GeneratedImage>;
|
|
40
|
+
export declare function requestMinimaxImage(input: {
|
|
41
|
+
prompt: string;
|
|
42
|
+
config: ImageConfig;
|
|
43
|
+
size: string;
|
|
44
|
+
quality: Quality;
|
|
45
|
+
outputFormat?: OutputFormat;
|
|
46
|
+
watermarkEnabled?: boolean;
|
|
47
|
+
inputImages?: LoadedImage[];
|
|
48
|
+
fetchImpl?: typeof fetch;
|
|
49
|
+
}): Promise<GeneratedImage>;
|
|
50
|
+
export declare function requestImage(input: Parameters<typeof requestOpenAIImage>[0] & {
|
|
51
|
+
watermarkEnabled?: boolean;
|
|
52
|
+
downloadFetchImpl?: typeof fetch;
|
|
53
|
+
}): Promise<GeneratedImage>;
|