mcp-hydrocoder-image 1.1.1 → 1.2.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 +134 -23
- package/dist/api/geminiClient.d.ts +3 -30
- package/dist/api/geminiClient.d.ts.map +1 -1
- package/dist/api/geminiClient.js +13 -57
- package/dist/api/geminiClient.js.map +1 -1
- package/dist/api/geminiTextClient.js +1 -1
- package/dist/api/geminiTextClient.js.map +1 -1
- package/dist/api/imageProvider.d.ts +29 -0
- package/dist/api/imageProvider.d.ts.map +1 -0
- package/dist/api/imageProvider.js +5 -0
- package/dist/api/imageProvider.js.map +1 -0
- package/dist/api/volcengineClient.d.ts +13 -0
- package/dist/api/volcengineClient.d.ts.map +1 -0
- package/dist/api/volcengineClient.js +288 -0
- package/dist/api/volcengineClient.js.map +1 -0
- package/dist/business/inputValidator.d.ts.map +1 -1
- package/dist/business/inputValidator.js +69 -1
- package/dist/business/inputValidator.js.map +1 -1
- package/dist/business/multiImagePrompt.d.ts +13 -0
- package/dist/business/multiImagePrompt.d.ts.map +1 -0
- package/dist/business/multiImagePrompt.js +135 -0
- package/dist/business/multiImagePrompt.js.map +1 -0
- package/dist/business/responseBuilder.d.ts +3 -2
- package/dist/business/responseBuilder.d.ts.map +1 -1
- package/dist/business/responseBuilder.js +69 -48
- package/dist/business/responseBuilder.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/server/errorHandler.d.ts.map +1 -1
- package/dist/server/errorHandler.js +3 -2
- package/dist/server/errorHandler.js.map +1 -1
- package/dist/server/mcpServer.d.ts +90 -29
- package/dist/server/mcpServer.d.ts.map +1 -1
- package/dist/server/mcpServer.js +429 -288
- package/dist/server/mcpServer.js.map +1 -1
- package/dist/types/mcp.d.ts +62 -15
- package/dist/types/mcp.d.ts.map +1 -1
- package/dist/types/mcp.js +15 -0
- package/dist/types/mcp.js.map +1 -1
- package/dist/utils/config.d.ts +6 -2
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +37 -12
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/errors.d.ts +9 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +50 -1
- package/dist/utils/errors.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Err, Ok } from '../types/result.js';
|
|
2
|
+
import { InputValidationError } from '../utils/errors.js';
|
|
3
|
+
const EXPLICIT_MULTI_IMAGE_PATTERNS = [
|
|
4
|
+
/第\s*[0-9一二三四五六七八九十百千]+\s*张/iu,
|
|
5
|
+
/\bimage\s*[1-9]\d*\b/iu,
|
|
6
|
+
/\bshot\s*[1-9]\d*\b/iu,
|
|
7
|
+
/\bvariation\s*[1-9]\d*\b/iu,
|
|
8
|
+
/\b(first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth)\s+image\b/iu,
|
|
9
|
+
];
|
|
10
|
+
const EXPLICIT_MULTI_IMAGE_SECTION_REGEX = /((?:第[\s ]*[0-9一二三四五六七八九十百千]+[\s ]*(?:张|幅|个)(?:图|图片)?)(?:[\s ]*(?:是|为))?|Image[_\s]*[1-9]\d*(?:\s*\([^)]*\))?(?:\s+(?:is|should\s+be))?|(?:First|Second|Third|Fourth|Fifth|Sixth|Seventh|Eighth|Ninth|Tenth)\s+Image(?:\s+(?:is|should\s+be))?|(?:For\s+)?Image[_\s]*[1-9]\d*\s*,|Shot[_\s]*[1-9]\d*(?:\s+(?:is|should\s+be))?|Variation[_\s]*[1-9]\d*(?:\s+(?:is|should\s+be))?)\s*[::,,;;、]?/giu;
|
|
11
|
+
const CHINESE_NUMBER_MAP = {
|
|
12
|
+
两: 2,
|
|
13
|
+
二: 2,
|
|
14
|
+
三: 3,
|
|
15
|
+
四: 4,
|
|
16
|
+
五: 5,
|
|
17
|
+
六: 6,
|
|
18
|
+
七: 7,
|
|
19
|
+
八: 8,
|
|
20
|
+
九: 9,
|
|
21
|
+
十: 10,
|
|
22
|
+
十一: 11,
|
|
23
|
+
十二: 12,
|
|
24
|
+
十三: 13,
|
|
25
|
+
十四: 14,
|
|
26
|
+
十五: 15,
|
|
27
|
+
};
|
|
28
|
+
function trimNonEmpty(value) {
|
|
29
|
+
return value.trim();
|
|
30
|
+
}
|
|
31
|
+
function buildAutomaticImageRequest(index) {
|
|
32
|
+
return `在满足总体要求的前提下,生成第${index}张独立图片;允许构图、景别、姿态或细节自然变化,但不要输出拼图,也不要缺少图片。`;
|
|
33
|
+
}
|
|
34
|
+
function buildNormalizedMultiImagePrompt(sharedPrompt, imageRequests) {
|
|
35
|
+
const total = imageRequests.length;
|
|
36
|
+
const sections = [
|
|
37
|
+
`总体要求:${sharedPrompt.trim()}`,
|
|
38
|
+
`请一次性生成${total}张彼此独立的图片。必须返回${total}张单独图片,不要合并成拼图,不要只返回1张。`,
|
|
39
|
+
...imageRequests.map((request, index) => `第${index + 1}张:${request.trim()}`),
|
|
40
|
+
`最终输出要求:严格返回${total}张独立图片,并分别对应第1张到第${total}张的描述。`,
|
|
41
|
+
];
|
|
42
|
+
return sections.join('\n');
|
|
43
|
+
}
|
|
44
|
+
export function hasExplicitMultiImageStructure(prompt) {
|
|
45
|
+
return EXPLICIT_MULTI_IMAGE_PATTERNS.some((pattern) => pattern.test(prompt));
|
|
46
|
+
}
|
|
47
|
+
export function inferRequestedImageCount(prompt) {
|
|
48
|
+
const arabicMatch = prompt.match(/(?:生成|创建|做|出|给我|提供|返回|输出|一组|组|共|total)?\s*([2-9]|1[0-5])\s*(?:张|幅|个|套)\s*(?:图|图片|图像|海报|产品图)?/iu);
|
|
49
|
+
if (arabicMatch?.[1]) {
|
|
50
|
+
return Number.parseInt(arabicMatch[1], 10);
|
|
51
|
+
}
|
|
52
|
+
const englishMatch = prompt.match(/\b([2-9]|1[0-5])\s*(?:images?|variations?|shots?|posters?|renders?)\b/iu);
|
|
53
|
+
if (englishMatch?.[1]) {
|
|
54
|
+
return Number.parseInt(englishMatch[1], 10);
|
|
55
|
+
}
|
|
56
|
+
const chineseMatch = prompt.match(/(?:生成|创建|做|出|给我|提供|返回|输出|一组|组)?\s*(两|二|三|四|五|六|七|八|九|十|十一|十二|十三|十四|十五)\s*(?:张|幅|个|套)\s*(?:图|图片|图像|海报|产品图)?/iu);
|
|
57
|
+
if (chineseMatch?.[1]) {
|
|
58
|
+
return CHINESE_NUMBER_MAP[chineseMatch[1]];
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
export function extractExplicitImageRequests(prompt) {
|
|
63
|
+
const matches = Array.from(prompt.matchAll(EXPLICIT_MULTI_IMAGE_SECTION_REGEX));
|
|
64
|
+
if (!matches.length) {
|
|
65
|
+
return { imageRequests: [] };
|
|
66
|
+
}
|
|
67
|
+
const imageRequests = [];
|
|
68
|
+
for (let index = 0; index < matches.length; index++) {
|
|
69
|
+
const currentMatch = matches[index];
|
|
70
|
+
if (!currentMatch) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const nextMatch = matches[index + 1];
|
|
74
|
+
const currentIndex = currentMatch.index;
|
|
75
|
+
if (currentIndex === undefined) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const segmentStart = currentIndex + currentMatch[0].length;
|
|
79
|
+
const segmentEnd = nextMatch?.index ?? prompt.length;
|
|
80
|
+
const segment = prompt.slice(segmentStart, segmentEnd).trim();
|
|
81
|
+
if (segment) {
|
|
82
|
+
imageRequests.push(segment);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const firstMatchIndex = matches[0]?.index;
|
|
86
|
+
const sharedPrompt = firstMatchIndex !== undefined ? prompt.slice(0, firstMatchIndex).trim() || undefined : undefined;
|
|
87
|
+
return {
|
|
88
|
+
...(sharedPrompt ? { sharedPrompt } : {}),
|
|
89
|
+
imageRequests,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function buildIndependentImagePrompt(sharedPrompt, imageRequest) {
|
|
93
|
+
const parts = [
|
|
94
|
+
sharedPrompt?.trim(),
|
|
95
|
+
'只生成1张独立图片,不要拼图,不要四宫格,不要在同一画面中合成多张子图。',
|
|
96
|
+
imageRequest.trim(),
|
|
97
|
+
].filter(Boolean);
|
|
98
|
+
return parts.join('\n\n');
|
|
99
|
+
}
|
|
100
|
+
export function prepareGenerateMultiImageParams(params) {
|
|
101
|
+
const inferredCount = params.outputCount ?? params.imageRequests?.length ?? inferRequestedImageCount(params.prompt);
|
|
102
|
+
if (inferredCount === undefined || inferredCount < 2) {
|
|
103
|
+
return Err(new InputValidationError('generate_multi_image requires a multi-image request with outputCount >= 2, imageRequests, or an explicit image count in the prompt', 'Provide outputCount, imageRequests, or mention an explicit count such as "4张图" or "4 images".'));
|
|
104
|
+
}
|
|
105
|
+
return Ok({
|
|
106
|
+
...params,
|
|
107
|
+
outputCount: params.outputCount ?? inferredCount,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
export function normalizeMultiImageParams(params) {
|
|
111
|
+
const imageRequests = params.imageRequests?.map(trimNonEmpty).filter(Boolean);
|
|
112
|
+
const requestedCount = imageRequests?.length ?? params.outputCount;
|
|
113
|
+
let prompt = params.prompt;
|
|
114
|
+
let promptWasNormalized = false;
|
|
115
|
+
if (imageRequests?.length) {
|
|
116
|
+
prompt = buildNormalizedMultiImagePrompt(params.prompt, imageRequests);
|
|
117
|
+
promptWasNormalized = true;
|
|
118
|
+
}
|
|
119
|
+
else if (params.outputCount && params.outputCount > 1 && !hasExplicitMultiImageStructure(params.prompt)) {
|
|
120
|
+
prompt = buildNormalizedMultiImagePrompt(params.prompt, Array.from({ length: params.outputCount }, (_, index) => buildAutomaticImageRequest(index + 1)));
|
|
121
|
+
promptWasNormalized = true;
|
|
122
|
+
}
|
|
123
|
+
const shouldPreserveMultiImagePrompt = params.skipPromptEnhancement === undefined &&
|
|
124
|
+
requestedCount !== undefined &&
|
|
125
|
+
requestedCount > 1 &&
|
|
126
|
+
(promptWasNormalized || hasExplicitMultiImageStructure(prompt));
|
|
127
|
+
return {
|
|
128
|
+
...params,
|
|
129
|
+
prompt,
|
|
130
|
+
...(imageRequests?.length ? { imageRequests } : {}),
|
|
131
|
+
...(imageRequests?.length && params.outputCount === undefined ? { outputCount: imageRequests.length } : {}),
|
|
132
|
+
...(shouldPreserveMultiImagePrompt ? { skipPromptEnhancement: true } : {}),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=multiImagePrompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiImagePrompt.js","sourceRoot":"","sources":["../../src/business/multiImagePrompt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAEzD,MAAM,6BAA6B,GAAG;IACpC,8BAA8B;IAC9B,wBAAwB;IACxB,uBAAuB;IACvB,4BAA4B;IAC5B,kFAAkF;CACnF,CAAA;AACD,MAAM,kCAAkC,GACtC,mYAAmY,CAAA;AAErY,MAAM,kBAAkB,GAA2B;IACjD,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,EAAE;IACL,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;CACP,CAAA;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAA;AACrB,CAAC;AAED,SAAS,0BAA0B,CAAC,KAAa;IAC/C,OAAO,kBAAkB,KAAK,0CA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EAAE,CAAC;KAC3E,CAAA;AACH,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Response Builder for MCP structured content responses
|
|
3
3
|
* Converts generation results and errors into MCP-compatible response format
|
|
4
4
|
*/
|
|
5
|
-
import type { GeneratedImageResult } from '../api/
|
|
5
|
+
import type { GeneratedImageResult } from '../api/imageProvider.js';
|
|
6
6
|
import type { McpToolResponse } from '../types/mcp.js';
|
|
7
7
|
import { type BaseError } from '../utils/errors.js';
|
|
8
8
|
/**
|
|
@@ -10,7 +10,8 @@ import { type BaseError } from '../utils/errors.js';
|
|
|
10
10
|
*/
|
|
11
11
|
export interface ResponseBuilder {
|
|
12
12
|
buildSuccessResponse(generationResult: GeneratedImageResult, filePath: string): McpToolResponse;
|
|
13
|
-
|
|
13
|
+
buildMultiSuccessResponse(generationResult: GeneratedImageResult, filePaths: string[]): McpToolResponse;
|
|
14
|
+
buildBase64SuccessResponse(generationResult: GeneratedImageResult, filePaths: string[]): McpToolResponse;
|
|
14
15
|
buildErrorResponse(error: BaseError | Error): McpToolResponse;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseBuilder.d.ts","sourceRoot":"","sources":["../../src/business/responseBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"responseBuilder.d.ts","sourceRoot":"","sources":["../../src/business/responseBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAA4C,MAAM,iBAAiB,CAAA;AAChG,OAAO,EACL,KAAK,SAAS,EAQf,MAAM,oBAAoB,CAAA;AA6E3B;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,oBAAoB,CAAC,gBAAgB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,CAAA;IAC/F,yBAAyB,CACvB,gBAAgB,EAAE,oBAAoB,EACtC,SAAS,EAAE,MAAM,EAAE,GAClB,eAAe,CAAA;IAClB,0BAA0B,CACxB,gBAAgB,EAAE,oBAAoB,EACtC,SAAS,EAAE,MAAM,EAAE,GAClB,eAAe,CAAA;IAClB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,GAAG,eAAe,CAAA;CAC9D;AAgED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,CAgFvD"}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Converts generation results and errors into MCP-compatible response format
|
|
4
4
|
*/
|
|
5
5
|
import * as path from 'node:path';
|
|
6
|
-
import {
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import { ConfigError, FileOperationError, GeminiAPIError, InputValidationError, NetworkError, SecurityError, VolcengineAPIError, } from '../utils/errors.js';
|
|
7
8
|
// Constants for MIME types and error handling
|
|
8
9
|
const MIME_TYPES = {
|
|
9
10
|
PNG: 'image/png',
|
|
@@ -18,6 +19,53 @@ const FILE_EXTENSIONS = {
|
|
|
18
19
|
const DEFAULT_MIME_TYPE = MIME_TYPES.PNG;
|
|
19
20
|
const UNKNOWN_ERROR_CODE = 'UNKNOWN_ERROR';
|
|
20
21
|
const DEFAULT_ERROR_SUGGESTION = 'Please try again or contact support if the problem persists';
|
|
22
|
+
function toFileUri(filePath) {
|
|
23
|
+
return pathToFileURL(path.resolve(filePath)).toString();
|
|
24
|
+
}
|
|
25
|
+
function createMetadata(generationResult, imageCount) {
|
|
26
|
+
return {
|
|
27
|
+
model: generationResult.metadata.model,
|
|
28
|
+
processingTime: 0,
|
|
29
|
+
contextMethod: 'structured_prompt',
|
|
30
|
+
timestamp: generationResult.metadata.timestamp.toISOString(),
|
|
31
|
+
imageCount,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createFileDescriptor(filePath, index, total) {
|
|
35
|
+
const fileName = path.basename(filePath);
|
|
36
|
+
const ordinal = total > 1 ? ` ${index + 1}` : '';
|
|
37
|
+
return {
|
|
38
|
+
uri: toFileUri(filePath),
|
|
39
|
+
name: fileName,
|
|
40
|
+
title: fileName,
|
|
41
|
+
mimeType: getMimeTypeFromPath(filePath),
|
|
42
|
+
description: `Generated image${ordinal}`,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function toResourceLinkContent(file) {
|
|
46
|
+
return {
|
|
47
|
+
type: 'resource_link',
|
|
48
|
+
...file,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function createStructuredContent(generationResult, filePaths, base64Included = false) {
|
|
52
|
+
return {
|
|
53
|
+
type: 'image_result',
|
|
54
|
+
files: filePaths.map((filePath, index) => createFileDescriptor(filePath, index, filePaths.length)),
|
|
55
|
+
...(base64Included ? { base64Included: true } : {}),
|
|
56
|
+
metadata: createMetadata(generationResult, filePaths.length),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getGeneratedVariants(generationResult) {
|
|
60
|
+
return generationResult.images?.length
|
|
61
|
+
? generationResult.images
|
|
62
|
+
: [
|
|
63
|
+
{
|
|
64
|
+
imageData: generationResult.imageData,
|
|
65
|
+
mimeType: generationResult.metadata.mimeType,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}
|
|
21
69
|
/**
|
|
22
70
|
* Determines MIME type based on file extension
|
|
23
71
|
* @param filePath Path to the image file
|
|
@@ -48,6 +96,7 @@ function convertErrorToStructured(error) {
|
|
|
48
96
|
if (error instanceof InputValidationError ||
|
|
49
97
|
error instanceof FileOperationError ||
|
|
50
98
|
error instanceof GeminiAPIError ||
|
|
99
|
+
error instanceof VolcengineAPIError ||
|
|
51
100
|
error instanceof NetworkError ||
|
|
52
101
|
error instanceof ConfigError ||
|
|
53
102
|
error instanceof SecurityError) {
|
|
@@ -79,31 +128,18 @@ export function createResponseBuilder() {
|
|
|
79
128
|
* @returns MCP tool response with structured content containing file path
|
|
80
129
|
*/
|
|
81
130
|
buildSuccessResponse(generationResult, filePath) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
type: 'resource',
|
|
88
|
-
resource: {
|
|
89
|
-
uri: `file://${filePath}`,
|
|
90
|
-
name: fileName,
|
|
91
|
-
mimeType,
|
|
92
|
-
},
|
|
93
|
-
metadata: {
|
|
94
|
-
model: generationResult.metadata.model,
|
|
95
|
-
processingTime: 0, // Not tracked in simplified version
|
|
96
|
-
contextMethod: 'structured_prompt',
|
|
97
|
-
timestamp: generationResult.metadata.timestamp.toISOString(),
|
|
98
|
-
},
|
|
131
|
+
const structuredContent = createStructuredContent(generationResult, [filePath]);
|
|
132
|
+
return {
|
|
133
|
+
content: structuredContent.files.map((file) => toResourceLinkContent(file)),
|
|
134
|
+
structuredContent,
|
|
135
|
+
isError: false,
|
|
99
136
|
};
|
|
137
|
+
},
|
|
138
|
+
buildMultiSuccessResponse(generationResult, filePaths) {
|
|
139
|
+
const structuredContent = createStructuredContent(generationResult, filePaths);
|
|
100
140
|
return {
|
|
101
|
-
content:
|
|
102
|
-
|
|
103
|
-
type: 'text',
|
|
104
|
-
text: JSON.stringify(structuredContent),
|
|
105
|
-
},
|
|
106
|
-
],
|
|
141
|
+
content: structuredContent.files.map((file) => toResourceLinkContent(file)),
|
|
142
|
+
structuredContent,
|
|
107
143
|
isError: false,
|
|
108
144
|
};
|
|
109
145
|
},
|
|
@@ -114,31 +150,16 @@ export function createResponseBuilder() {
|
|
|
114
150
|
* @param base64Data Base64 encoded image data
|
|
115
151
|
* @returns MCP tool response with both file URI and base64 data
|
|
116
152
|
*/
|
|
117
|
-
buildBase64SuccessResponse(generationResult,
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
name: fileName,
|
|
125
|
-
mimeType,
|
|
126
|
-
},
|
|
127
|
-
base64Data,
|
|
128
|
-
metadata: {
|
|
129
|
-
model: generationResult.metadata.model,
|
|
130
|
-
processingTime: 0,
|
|
131
|
-
contextMethod: 'structured_prompt',
|
|
132
|
-
timestamp: generationResult.metadata.timestamp.toISOString(),
|
|
133
|
-
},
|
|
134
|
-
};
|
|
153
|
+
buildBase64SuccessResponse(generationResult, filePaths) {
|
|
154
|
+
const structuredContent = createStructuredContent(generationResult, filePaths, true);
|
|
155
|
+
const imageContents = getGeneratedVariants(generationResult).map((variant) => ({
|
|
156
|
+
type: 'image',
|
|
157
|
+
data: variant.imageData.toString('base64'),
|
|
158
|
+
mimeType: variant.mimeType,
|
|
159
|
+
}));
|
|
135
160
|
return {
|
|
136
|
-
content: [
|
|
137
|
-
|
|
138
|
-
type: 'text',
|
|
139
|
-
text: JSON.stringify(responseData),
|
|
140
|
-
},
|
|
141
|
-
],
|
|
161
|
+
content: [...imageContents, ...structuredContent.files.map((file) => toResourceLinkContent(file))],
|
|
162
|
+
structuredContent,
|
|
142
163
|
isError: false,
|
|
143
164
|
};
|
|
144
165
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseBuilder.js","sourceRoot":"","sources":["../../src/business/responseBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"responseBuilder.js","sourceRoot":"","sources":["../../src/business/responseBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAGxC,OAAO,EAEL,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,kBAAkB,GACnB,MAAM,oBAAoB,CAAA;AAE3B,8CAA8C;AAC9C,MAAM,UAAU,GAAG;IACjB,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,YAAY;CACV,CAAA;AAEV,MAAM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- (default) → MCP server startup
|
|
8
8
|
*/
|
|
9
|
-
export type { GeneratedImageResult } from './api/
|
|
9
|
+
export type { GeneratedImageResult } from './api/imageProvider.js';
|
|
10
10
|
export { createMCPServer, MCPServerImpl } from './server/mcpServer.js';
|
|
11
11
|
export type { GenerateImageParams, MCPServerConfig } from './types/mcp.js';
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG;AAwBH,YAAY,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG;AAwBH,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACtE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/server/errorHandler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/server/errorHandler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAOL,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAA;AAM3B;;;;GAIG;AACH,iBAAS,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,CAqBlD;AAED;;;;;GAKG;AACH,iBAAe,kBAAkB,CAAC,CAAC,EACjC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAa3B;AA4DD;;;GAGG;AACH,eAAO,MAAM,YAAY;;;CAGf,CAAA"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Error Handler utility for unified error processing
|
|
3
3
|
* Provides centralized error handling and Result type wrapping
|
|
4
4
|
*/
|
|
5
|
-
import { ConfigError, FileOperationError, GeminiAPIError, InputValidationError, NetworkError, } from '../utils/errors.js';
|
|
5
|
+
import { ConfigError, FileOperationError, GeminiAPIError, InputValidationError, NetworkError, VolcengineAPIError, } from '../utils/errors.js';
|
|
6
6
|
import { Logger } from '../utils/logger.js';
|
|
7
7
|
// Create logger instance for error handling
|
|
8
8
|
const logger = new Logger();
|
|
@@ -62,6 +62,7 @@ function convertErrorToStructured(error) {
|
|
|
62
62
|
if (error instanceof InputValidationError ||
|
|
63
63
|
error instanceof FileOperationError ||
|
|
64
64
|
error instanceof GeminiAPIError ||
|
|
65
|
+
error instanceof VolcengineAPIError ||
|
|
65
66
|
error instanceof NetworkError ||
|
|
66
67
|
error instanceof ConfigError) {
|
|
67
68
|
const errorResponse = {
|
|
@@ -71,7 +72,7 @@ function convertErrorToStructured(error) {
|
|
|
71
72
|
suggestion: error.suggestion,
|
|
72
73
|
};
|
|
73
74
|
// Include context details for GeminiAPIError to provide better debugging info
|
|
74
|
-
if (error instanceof GeminiAPIError && error.context) {
|
|
75
|
+
if ((error instanceof GeminiAPIError || error instanceof VolcengineAPIError) && error.context) {
|
|
75
76
|
// Add non-sensitive context information
|
|
76
77
|
const { suggestion, ...otherContext } = error.context;
|
|
77
78
|
if (Object.keys(otherContext).length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../src/server/errorHandler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA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BAA2B;QACrD,UAAU,EAAE,8BAA8B;KAC3C,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,WAAW;IACX,kBAAkB;CACV,CAAA"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MCP Server implementation
|
|
3
|
-
*
|
|
3
|
+
* Supports multiple image providers with Gemini prompt enhancement when applicable
|
|
4
4
|
*/
|
|
5
5
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
6
6
|
import type { MCPServerConfig } from '../types/mcp.js';
|
|
7
|
-
/**
|
|
8
|
-
* Simplified MCP server
|
|
9
|
-
*/
|
|
10
7
|
export declare class MCPServerImpl {
|
|
11
8
|
private config;
|
|
12
9
|
private server;
|
|
@@ -17,17 +14,12 @@ export declare class MCPServerImpl {
|
|
|
17
14
|
private structuredPromptGenerator;
|
|
18
15
|
private geminiTextClient;
|
|
19
16
|
private geminiClient;
|
|
17
|
+
private volcengineClient;
|
|
20
18
|
constructor(config?: Partial<MCPServerConfig>);
|
|
21
|
-
/**
|
|
22
|
-
* Get server info
|
|
23
|
-
*/
|
|
24
19
|
getServerInfo(): {
|
|
25
20
|
name: string;
|
|
26
21
|
version: string;
|
|
27
22
|
};
|
|
28
|
-
/**
|
|
29
|
-
* Get list of registered tools
|
|
30
|
-
*/
|
|
31
23
|
getToolsList(): {
|
|
32
24
|
tools: {
|
|
33
25
|
name: string;
|
|
@@ -39,6 +31,11 @@ export declare class MCPServerImpl {
|
|
|
39
31
|
type: "string";
|
|
40
32
|
description: string;
|
|
41
33
|
};
|
|
34
|
+
provider: {
|
|
35
|
+
type: "string";
|
|
36
|
+
description: string;
|
|
37
|
+
enum: string[];
|
|
38
|
+
};
|
|
42
39
|
fileName: {
|
|
43
40
|
type: "string";
|
|
44
41
|
description: string;
|
|
@@ -122,6 +119,22 @@ export declare class MCPServerImpl {
|
|
|
122
119
|
description: string;
|
|
123
120
|
enum: string[];
|
|
124
121
|
};
|
|
122
|
+
outputFormat: {
|
|
123
|
+
type: "string";
|
|
124
|
+
description: string;
|
|
125
|
+
enum: string[];
|
|
126
|
+
};
|
|
127
|
+
outputCount: {
|
|
128
|
+
type: "integer";
|
|
129
|
+
description: string;
|
|
130
|
+
};
|
|
131
|
+
imageRequests: {
|
|
132
|
+
type: "array";
|
|
133
|
+
description: string;
|
|
134
|
+
items: {
|
|
135
|
+
type: "string";
|
|
136
|
+
};
|
|
137
|
+
};
|
|
125
138
|
skipPromptEnhancement: {
|
|
126
139
|
type: "boolean";
|
|
127
140
|
description: string;
|
|
@@ -129,31 +142,79 @@ export declare class MCPServerImpl {
|
|
|
129
142
|
};
|
|
130
143
|
required: string[];
|
|
131
144
|
};
|
|
145
|
+
outputSchema: {
|
|
146
|
+
type: "object";
|
|
147
|
+
properties: {
|
|
148
|
+
type: {
|
|
149
|
+
type: "string";
|
|
150
|
+
const: string;
|
|
151
|
+
};
|
|
152
|
+
files: {
|
|
153
|
+
type: "array";
|
|
154
|
+
items: {
|
|
155
|
+
type: "object";
|
|
156
|
+
properties: {
|
|
157
|
+
uri: {
|
|
158
|
+
type: "string";
|
|
159
|
+
};
|
|
160
|
+
name: {
|
|
161
|
+
type: "string";
|
|
162
|
+
};
|
|
163
|
+
title: {
|
|
164
|
+
type: "string";
|
|
165
|
+
};
|
|
166
|
+
mimeType: {
|
|
167
|
+
type: "string";
|
|
168
|
+
};
|
|
169
|
+
description: {
|
|
170
|
+
type: "string";
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
required: string[];
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
base64Included: {
|
|
177
|
+
type: "boolean";
|
|
178
|
+
};
|
|
179
|
+
metadata: {
|
|
180
|
+
type: "object";
|
|
181
|
+
properties: {
|
|
182
|
+
model: {
|
|
183
|
+
type: "string";
|
|
184
|
+
};
|
|
185
|
+
processingTime: {
|
|
186
|
+
type: "number";
|
|
187
|
+
};
|
|
188
|
+
contextMethod: {
|
|
189
|
+
type: "string";
|
|
190
|
+
};
|
|
191
|
+
timestamp: {
|
|
192
|
+
type: "string";
|
|
193
|
+
};
|
|
194
|
+
imageCount: {
|
|
195
|
+
type: "integer";
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
required: string[];
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
required: string[];
|
|
202
|
+
};
|
|
132
203
|
}[];
|
|
133
204
|
};
|
|
134
|
-
/**
|
|
135
|
-
* Tool execution
|
|
136
|
-
*/
|
|
137
205
|
callTool(name: string, args: unknown): Promise<import("../types/mcp.js").McpToolResponse>;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
private
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
206
|
+
private initializeGeminiSupport;
|
|
207
|
+
private initializeVolcengineSupport;
|
|
208
|
+
private getProviderClient;
|
|
209
|
+
private prepareInputImages;
|
|
210
|
+
private maybeEnhancePrompt;
|
|
211
|
+
private buildSuccessResponse;
|
|
212
|
+
private getGeneratedVariants;
|
|
213
|
+
private generateAndSave;
|
|
214
|
+
private handleGenerateMultiImage;
|
|
145
215
|
private handleGenerateImage;
|
|
146
|
-
/**
|
|
147
|
-
* Initialize MCP server with tool handlers
|
|
148
|
-
*/
|
|
149
216
|
initialize(): Server;
|
|
150
|
-
/**
|
|
151
|
-
* Setup MCP protocol handlers
|
|
152
|
-
*/
|
|
153
217
|
private setupHandlers;
|
|
154
218
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Factory function to create MCP server
|
|
157
|
-
*/
|
|
158
219
|
export declare function createMCPServer(config?: Partial<MCPServerConfig>): MCPServerImpl;
|
|
159
220
|
//# sourceMappingURL=mcpServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcpServer.d.ts","sourceRoot":"","sources":["../../src/server/mcpServer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,MAAM,EAAE,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