@vint.tri/report_gen_mcp 1.7.0 → 1.7.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.
@@ -498,6 +498,50 @@
498
498
  }
499
499
  ```
500
500
 
501
+ ### Изображения, сгенерированные с помощью generate-image (Chutes AI)
502
+
503
+ При использовании инструмента `generate-image` для генерации изображений с помощью Chutes AI, важно правильно форматировать параметры. Все числовые параметры должны быть представлены как числа, а не как строки.
504
+
505
+ ✅ ПРАВИЛЬНО (числовые параметры как числа):
506
+ ```json
507
+ {
508
+ "method": "tools/call",
509
+ "params": {
510
+ "name": "generate-image",
511
+ "arguments": {
512
+ "prompt": "a dog made of US dollar bills",
513
+ "width": 512,
514
+ "height": 512,
515
+ "guidance_scale": 7.5,
516
+ "negative_prompt": "blurry, low quality",
517
+ "num_inference_steps": 50,
518
+ "seed": 0
519
+ }
520
+ }
521
+ }
522
+ ```
523
+
524
+ ❌ НЕПРАВИЛЬНО (числовые параметры как строки):
525
+ ```json
526
+ {
527
+ "method": "tools/call",
528
+ "params": {
529
+ "name": "generate-image",
530
+ "arguments": {
531
+ "prompt": "a dog made of US dollar bills",
532
+ "width": "512",
533
+ "height": "512",
534
+ "guidance_scale": "7.5",
535
+ "negative_prompt": "blurry, low quality",
536
+ "num_inference_steps": "50",
537
+ "seed": "0"
538
+ }
539
+ }
540
+ }
541
+ ```
542
+
543
+ **ВАЖНО:** Все числовые параметры (`width`, `height`, `guidance_scale`, `num_inference_steps`, `seed`) должны быть представлены как числа, а не как строки в кавычках. Это критически важно для корректной работы инструмента.
544
+
501
545
  ### Изображения по URL
502
546
 
503
547
  ```json
@@ -0,0 +1,66 @@
1
+ # Image Element Fix Summary
2
+
3
+ ## Problem Description
4
+ The MCP server was failing to generate reports when image elements with type "image" were provided. The error occurred because:
5
+
6
+ 1. The `generate-report` tool schema in `src/index.ts` only accepted "url" as a valid image type, but not "image"
7
+ 2. The report generator in `src/utils/reportGenerator.ts` had the same limitation
8
+
9
+ ## Solution Implemented
10
+
11
+ ### 1. Updated Schema Validation (src/index.ts)
12
+ Added support for "image" type elements in the Zod schema validation:
13
+
14
+ ```javascript
15
+ z.object({
16
+ type: z.literal("image"),
17
+ config: z.object({
18
+ url: z.string().url().describe("File URL of the image"),
19
+ alt: z.string().optional().describe("Alternative text for the image"),
20
+ width: z.number().optional().describe("Width of the image in pixels"),
21
+ height: z.number().optional().describe("Height of the image in pixels"),
22
+ }),
23
+ }).describe("Local image file configuration"),
24
+ ```
25
+
26
+ ### 2. Enhanced Report Generator (src/utils/reportGenerator.ts)
27
+ Updated the report generator to handle "image" type elements by:
28
+
29
+ 1. Extending the `ImageType` type definition:
30
+ ```typescript
31
+ type ImageType = 'url' | 'image';
32
+ ```
33
+
34
+ 2. Updating the interface definition:
35
+ ```typescript
36
+ interface UrlImageElement {
37
+ type: 'url' | 'image';
38
+ config: z.infer<typeof urlImageSchema>;
39
+ }
40
+ ```
41
+
42
+ 3. Adding "image" to the image renderers mapping:
43
+ ```typescript
44
+ const imageRenderers: Record<ImageType, { schema: z.ZodObject<any>; renderer: (config: any) => Promise<string> }> = {
45
+ url: { schema: urlImageSchema, renderer: renderUrlImage },
46
+ image: { schema: urlImageSchema, renderer: renderUrlImage },
47
+ };
48
+ ```
49
+
50
+ ## Testing
51
+ Created comprehensive tests to verify that the fix works correctly:
52
+
53
+ 1. **File URL Test**: Verified that local file URLs work correctly with the "image" type
54
+ 2. **Web URL Test**: Verified that web URLs also work correctly with the "image" type
55
+
56
+ Both tests passed successfully, confirming that the fix resolves the original issue.
57
+
58
+ ## Benefits
59
+ 1. **Backward Compatibility**: Existing code using "url" type continues to work
60
+ 2. **Consistency**: Both "url" and "image" types now behave identically
61
+ 3. **Neural Network Integration**: The neural network can now successfully generate reports with image elements
62
+ 4. **Flexibility**: Supports both local file URLs and web URLs with the same interface
63
+
64
+ ## Files Modified
65
+ 1. `src/index.ts` - Updated schema validation for the generate-report tool
66
+ 2. `src/utils/reportGenerator.ts` - Enhanced report generator to handle "image" type elements
@@ -0,0 +1,108 @@
1
+ # Fix for Image Generation String Parameters Issue
2
+
3
+ ## Problem Description
4
+
5
+ The neural network was sending numeric parameters as strings to the `generate-image` tool, causing validation errors:
6
+
7
+ ```
8
+ Error calling tool generate-image: Error: Error invoking remote method 'mcp:call-tool': McpError: MCP error -32602: Invalid arguments for tool generate-image: [
9
+ {
10
+ "code": "invalid_type",
11
+ "expected": "number",
12
+ "received": "string",
13
+ "path": ["width"],
14
+ "message": "Expected number, received string"
15
+ },
16
+ // Similar errors for height, guidance_scale, num_inference_steps, seed
17
+ ]
18
+ ```
19
+
20
+ ## Root Cause
21
+
22
+ The Zod schema validation in the MCP server expected actual numbers for numeric parameters, but the neural network was sending them as JSON strings.
23
+
24
+ ## Solution Implemented
25
+
26
+ ### 1. Updated Image Generation Server
27
+
28
+ Modified `src/mcp/imageGenerationServer.ts` to automatically convert string parameters to numbers:
29
+
30
+ ```typescript
31
+ // Преобразуем строковые значения в числа, если необходимо
32
+ const generationParams: Partial<ImageGenerationSettings> = {};
33
+ if (args.width !== undefined) {
34
+ generationParams.width = typeof args.width === 'string' ? parseFloat(args.width) : args.width;
35
+ }
36
+ if (args.height !== undefined) {
37
+ generationParams.height = typeof args.height === 'string' ? parseFloat(args.height) : args.height;
38
+ }
39
+ if (args.guidance_scale !== undefined) {
40
+ generationParams.guidance_scale = typeof args.guidance_scale === 'string' ? parseFloat(args.guidance_scale) : args.guidance_scale;
41
+ }
42
+ if (args.negative_prompt !== undefined) generationParams.negative_prompt = args.negative_prompt;
43
+ if (args.num_inference_steps !== undefined) {
44
+ generationParams.num_inference_steps = typeof args.num_inference_steps === 'string' ? parseInt(args.num_inference_steps) : args.num_inference_steps;
45
+ }
46
+ if (args.seed !== undefined) {
47
+ generationParams.seed = typeof args.seed === 'string' ? parseInt(args.seed) : args.seed;
48
+ }
49
+ ```
50
+
51
+ This change was applied to both `generate_image` and `generate_image_to_file` tools in the server.
52
+
53
+ ### 2. Updated Neural Network Instructions
54
+
55
+ Added clear guidelines in `FIXED_NEURAL_NETWORK_INSTRUCTIONS_v1.6.5.md` about proper parameter formatting:
56
+
57
+ #### Correct Format (Numbers as Numbers):
58
+ ```json
59
+ {
60
+ "method": "tools/call",
61
+ "params": {
62
+ "name": "generate-image",
63
+ "arguments": {
64
+ "prompt": "a dog made of US dollar bills",
65
+ "width": 512,
66
+ "height": 512,
67
+ "guidance_scale": 7.5,
68
+ "negative_prompt": "blurry, low quality",
69
+ "num_inference_steps": 50,
70
+ "seed": 0
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ #### Incorrect Format (Numbers as Strings):
77
+ ```json
78
+ {
79
+ "method": "tools/call",
80
+ "params": {
81
+ "name": "generate-image",
82
+ "arguments": {
83
+ "prompt": "a dog made of US dollar bills",
84
+ "width": "512",
85
+ "height": "512",
86
+ "guidance_scale": "7.5",
87
+ "negative_prompt": "blurry, low quality",
88
+ "num_inference_steps": "50",
89
+ "seed": "0"
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## Testing
96
+
97
+ Created `test-image-generation-string-params.js` to verify the fix works correctly with both string and mixed parameter types.
98
+
99
+ ## Backward Compatibility
100
+
101
+ The fix maintains backward compatibility by:
102
+ 1. Still accepting numeric parameters as numbers
103
+ 2. Converting string parameters to numbers when needed
104
+ 3. Not changing the external API interface
105
+
106
+ ## Impact
107
+
108
+ This fix resolves the issue where neural networks sending string-formatted numeric parameters would receive validation errors, allowing seamless image generation with the Chutes AI service.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAieA;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAgCjD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AA0eA;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAgCjD"}
package/dist/index.js CHANGED
@@ -103,7 +103,7 @@ if (process.argv.length === 2) {
103
103
  // No command specified, run in stdio mode using MCP SDK
104
104
  const mcpServer = new McpServer({
105
105
  name: "report_gen_mcp",
106
- version: "1.7.0"
106
+ version: "1.7.2"
107
107
  }, {
108
108
  // Disable health check to prevent automatic calls
109
109
  capabilities: {
@@ -153,6 +153,15 @@ if (process.argv.length === 2) {
153
153
  height: z.number().optional().describe("Height of the image in pixels"),
154
154
  }),
155
155
  }).describe("Image from URL configuration"),
156
+ z.object({
157
+ type: z.literal("image"),
158
+ config: z.object({
159
+ url: z.string().url().describe("File URL of the image"),
160
+ alt: z.string().optional().describe("Alternative text for the image"),
161
+ width: z.number().optional().describe("Width of the image in pixels"),
162
+ height: z.number().optional().describe("Height of the image in pixels"),
163
+ }),
164
+ }).describe("Local image file configuration"),
156
165
  ])).describe("Report elements (charts and images) mapped by ID"),
157
166
  outputFile: z.string().optional().describe("Output HTML file path"),
158
167
  tempDirectory: z.string().optional().describe("Temporary directory for file storage (optional, will use REPORTS_DIR environment variable if set)"),
@@ -1 +1 @@
1
- {"version":3,"file":"imageGenerationServer.d.ts","sourceRoot":"","sources":["../../src/mcp/imageGenerationServer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,UAAU,uBAAuB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,cAAM,cAAc;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,eAAe,CAA0B;;IAiBjD,OAAO,CAAC,aAAa;IAIf,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAE,OAAO,CAAC,uBAAuB,CAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAuE9G;AAyMD,iBAAe,IAAI,kBASlB;AAOD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"imageGenerationServer.d.ts","sourceRoot":"","sources":["../../src/mcp/imageGenerationServer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,UAAU,uBAAuB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,cAAM,cAAc;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,eAAe,CAA0B;;IAiBjD,OAAO,CAAC,aAAa;IAIf,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAE,OAAO,CAAC,uBAAuB,CAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAuE9G;AA+ND,iBAAe,IAAI,kBASlB;AAOD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC"}
@@ -121,19 +121,25 @@ app.registerTool("generate_image", {
121
121
  throw new Error("Параметр 'prompt' обязателен");
122
122
  }
123
123
  // Дополнительные параметры (необязательные)
124
+ // Преобразуем строковые значения в числа, если необходимо
124
125
  const generationParams = {};
125
- if (args.width !== undefined)
126
- generationParams.width = args.width;
127
- if (args.height !== undefined)
128
- generationParams.height = args.height;
129
- if (args.guidance_scale !== undefined)
130
- generationParams.guidance_scale = args.guidance_scale;
126
+ if (args.width !== undefined) {
127
+ generationParams.width = typeof args.width === 'string' ? parseFloat(args.width) : args.width;
128
+ }
129
+ if (args.height !== undefined) {
130
+ generationParams.height = typeof args.height === 'string' ? parseFloat(args.height) : args.height;
131
+ }
132
+ if (args.guidance_scale !== undefined) {
133
+ generationParams.guidance_scale = typeof args.guidance_scale === 'string' ? parseFloat(args.guidance_scale) : args.guidance_scale;
134
+ }
131
135
  if (args.negative_prompt !== undefined)
132
136
  generationParams.negative_prompt = args.negative_prompt;
133
- if (args.num_inference_steps !== undefined)
134
- generationParams.num_inference_steps = args.num_inference_steps;
135
- if (args.seed !== undefined)
136
- generationParams.seed = args.seed;
137
+ if (args.num_inference_steps !== undefined) {
138
+ generationParams.num_inference_steps = typeof args.num_inference_steps === 'string' ? parseInt(args.num_inference_steps) : args.num_inference_steps;
139
+ }
140
+ if (args.seed !== undefined) {
141
+ generationParams.seed = typeof args.seed === 'string' ? parseInt(args.seed) : args.seed;
142
+ }
137
143
  // Генерируем изображение
138
144
  const imageDataUri = await imageGen.generateImage(prompt, generationParams);
139
145
  // Извлекаем только base64 данные без префикса
@@ -216,19 +222,25 @@ app.registerTool("generate_image_to_file", {
216
222
  throw new Error("Параметр 'filename' обязателен");
217
223
  }
218
224
  // Дополнительные параметры (необязательные)
225
+ // Преобразуем строковые значения в числа, если необходимо
219
226
  const generationParams = {};
220
- if (args.width !== undefined)
221
- generationParams.width = args.width;
222
- if (args.height !== undefined)
223
- generationParams.height = args.height;
224
- if (args.guidance_scale !== undefined)
225
- generationParams.guidance_scale = args.guidance_scale;
227
+ if (args.width !== undefined) {
228
+ generationParams.width = typeof args.width === 'string' ? parseFloat(args.width) : args.width;
229
+ }
230
+ if (args.height !== undefined) {
231
+ generationParams.height = typeof args.height === 'string' ? parseFloat(args.height) : args.height;
232
+ }
233
+ if (args.guidance_scale !== undefined) {
234
+ generationParams.guidance_scale = typeof args.guidance_scale === 'string' ? parseFloat(args.guidance_scale) : args.guidance_scale;
235
+ }
226
236
  if (args.negative_prompt !== undefined)
227
237
  generationParams.negative_prompt = args.negative_prompt;
228
- if (args.num_inference_steps !== undefined)
229
- generationParams.num_inference_steps = args.num_inference_steps;
230
- if (args.seed !== undefined)
231
- generationParams.seed = args.seed;
238
+ if (args.num_inference_steps !== undefined) {
239
+ generationParams.num_inference_steps = typeof args.num_inference_steps === 'string' ? parseInt(args.num_inference_steps) : args.num_inference_steps;
240
+ }
241
+ if (args.seed !== undefined) {
242
+ generationParams.seed = typeof args.seed === 'string' ? parseInt(args.seed) : args.seed;
243
+ }
232
244
  // Генерируем изображение
233
245
  const imageDataUri = await imageGen.generateImage(prompt, generationParams);
234
246
  // Извлекаем только base64 данные без префикса
@@ -6,7 +6,7 @@ interface ChartElement {
6
6
  config: any;
7
7
  }
8
8
  interface UrlImageElement {
9
- type: 'url';
9
+ type: 'url' | 'image';
10
10
  config: z.infer<typeof urlImageSchema>;
11
11
  }
12
12
  type ImageElement = UrlImageElement;
@@ -1 +1 @@
1
- {"version":3,"file":"reportGenerator.d.ts","sourceRoot":"","sources":["../../src/utils/reportGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OA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EAAE,aAAa,CAAC,EACvC,UAAU,EAAE,MAAM;;;GA+HnB"}
@@ -18,6 +18,7 @@ const chartRenderers = {
18
18
  };
19
19
  const imageRenderers = {
20
20
  url: { schema: urlImageSchema, renderer: renderUrlImage },
21
+ image: { schema: urlImageSchema, renderer: renderUrlImage },
21
22
  };
22
23
  // Utility function to normalize chart configuration data
23
24
  // Converts string values to arrays where the schema expects arrays
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vint.tri/report_gen_mcp",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "CLI tool for generating HTML reports with embedded charts and images",
5
5
  "main": "dist/index.js",
6
6
  "bin": {