@vint.tri/report_gen_mcp 1.2.1 → 1.2.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/dist/charts/bar.js +2 -2
- package/dist/charts/doughnut.js +2 -2
- package/dist/charts/line.js +1 -1
- package/dist/charts/pie.js +2 -2
- package/dist/charts/polarArea.js +2 -2
- package/dist/charts/radar.js +2 -2
- package/dist/index.js +54 -2
- package/dist/utils/reportGenerator.js +31 -1
- package/package.json +1 -1
package/dist/charts/bar.js
CHANGED
|
@@ -4,8 +4,8 @@ export const barSchema = z.object({
|
|
|
4
4
|
datasets: z.array(z.object({
|
|
5
5
|
label: z.string(),
|
|
6
6
|
data: z.array(z.number()),
|
|
7
|
-
backgroundColor: z.array(z.string()).optional(),
|
|
8
|
-
borderColor: z.array(z.string()).optional(),
|
|
7
|
+
backgroundColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
8
|
+
borderColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
9
9
|
})),
|
|
10
10
|
options: z.object({
|
|
11
11
|
title: z.string().optional(),
|
package/dist/charts/doughnut.js
CHANGED
|
@@ -3,8 +3,8 @@ export const doughnutSchema = z.object({
|
|
|
3
3
|
labels: z.array(z.string()),
|
|
4
4
|
datasets: z.array(z.object({
|
|
5
5
|
data: z.array(z.number()),
|
|
6
|
-
backgroundColor: z.array(z.string()).optional(),
|
|
7
|
-
borderColor: z.array(z.string()).optional(),
|
|
6
|
+
backgroundColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
7
|
+
borderColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
8
8
|
})),
|
|
9
9
|
options: z.object({
|
|
10
10
|
title: z.string().optional(),
|
package/dist/charts/line.js
CHANGED
|
@@ -4,7 +4,7 @@ export const lineSchema = z.object({
|
|
|
4
4
|
datasets: z.array(z.object({
|
|
5
5
|
label: z.string(),
|
|
6
6
|
data: z.array(z.number()),
|
|
7
|
-
borderColor: z.array(z.string()).optional(),
|
|
7
|
+
borderColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
8
8
|
fill: z.boolean().optional(),
|
|
9
9
|
})),
|
|
10
10
|
options: z.object({
|
package/dist/charts/pie.js
CHANGED
|
@@ -3,8 +3,8 @@ export const pieSchema = z.object({
|
|
|
3
3
|
labels: z.array(z.string()),
|
|
4
4
|
datasets: z.array(z.object({
|
|
5
5
|
data: z.array(z.number()),
|
|
6
|
-
backgroundColor: z.array(z.string()).optional(),
|
|
7
|
-
borderColor: z.array(z.string()).optional(),
|
|
6
|
+
backgroundColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
7
|
+
borderColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
8
8
|
})),
|
|
9
9
|
options: z.object({
|
|
10
10
|
title: z.string().optional(),
|
package/dist/charts/polarArea.js
CHANGED
|
@@ -3,8 +3,8 @@ export const polarAreaSchema = z.object({
|
|
|
3
3
|
labels: z.array(z.string()),
|
|
4
4
|
datasets: z.array(z.object({
|
|
5
5
|
data: z.array(z.number()),
|
|
6
|
-
backgroundColor: z.array(z.string()).optional(),
|
|
7
|
-
borderColor: z.array(z.string()).optional(),
|
|
6
|
+
backgroundColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
7
|
+
borderColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
8
8
|
})),
|
|
9
9
|
options: z.object({
|
|
10
10
|
title: z.string().optional(),
|
package/dist/charts/radar.js
CHANGED
|
@@ -4,8 +4,8 @@ export const radarSchema = z.object({
|
|
|
4
4
|
datasets: z.array(z.object({
|
|
5
5
|
label: z.string(),
|
|
6
6
|
data: z.array(z.number()),
|
|
7
|
-
backgroundColor: z.array(z.string()).optional(),
|
|
8
|
-
borderColor: z.array(z.string()).optional(),
|
|
7
|
+
backgroundColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
8
|
+
borderColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
9
9
|
})),
|
|
10
10
|
options: z.object({
|
|
11
11
|
title: z.string().optional(),
|
package/dist/index.js
CHANGED
|
@@ -109,6 +109,51 @@ if (process.argv.length === 2) {
|
|
|
109
109
|
tools: {}
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
|
+
// Utility function to normalize chart configuration data for MCP tool
|
|
113
|
+
// Converts string values to arrays where the schema expects arrays
|
|
114
|
+
function normalizeChartConfigForMCP(config) {
|
|
115
|
+
if (!config || typeof config !== 'object') {
|
|
116
|
+
return config;
|
|
117
|
+
}
|
|
118
|
+
const normalizedConfig = { ...config };
|
|
119
|
+
// Normalize datasets
|
|
120
|
+
if (normalizedConfig.datasets && Array.isArray(normalizedConfig.datasets)) {
|
|
121
|
+
normalizedConfig.datasets = normalizedConfig.datasets.map((dataset) => {
|
|
122
|
+
if (!dataset || typeof dataset !== 'object') {
|
|
123
|
+
return dataset;
|
|
124
|
+
}
|
|
125
|
+
const normalizedDataset = { ...dataset };
|
|
126
|
+
// Convert string values to arrays for color properties
|
|
127
|
+
const colorProperties = ['backgroundColor', 'borderColor'];
|
|
128
|
+
for (const prop of colorProperties) {
|
|
129
|
+
if (normalizedDataset[prop] && typeof normalizedDataset[prop] === 'string') {
|
|
130
|
+
normalizedDataset[prop] = [normalizedDataset[prop]];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return normalizedDataset;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return normalizedConfig;
|
|
137
|
+
}
|
|
138
|
+
// Utility function to normalize elements before MCP schema validation
|
|
139
|
+
function normalizeElementsForMCP(elements) {
|
|
140
|
+
if (!elements || typeof elements !== 'object') {
|
|
141
|
+
return elements;
|
|
142
|
+
}
|
|
143
|
+
const normalizedElements = { ...elements };
|
|
144
|
+
for (const [id, element] of Object.entries(normalizedElements)) {
|
|
145
|
+
if (element && typeof element === 'object' && element.type) {
|
|
146
|
+
const elementType = element.type;
|
|
147
|
+
// Only normalize chart elements, not image elements
|
|
148
|
+
if (['bar', 'line', 'pie', 'doughnut', 'radar', 'polarArea'].includes(elementType)) {
|
|
149
|
+
if (element.config) {
|
|
150
|
+
element.config = normalizeChartConfigForMCP(element.config);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return normalizedElements;
|
|
156
|
+
}
|
|
112
157
|
// Register the generate-report tool
|
|
113
158
|
mcpServer.registerTool("generate-report", {
|
|
114
159
|
description: "Generate an HTML report with embedded charts",
|
|
@@ -122,8 +167,8 @@ if (process.argv.length === 2) {
|
|
|
122
167
|
datasets: z.array(z.object({
|
|
123
168
|
label: z.string().optional(),
|
|
124
169
|
data: z.array(z.number()),
|
|
125
|
-
backgroundColor: z.array(z.string()).optional(),
|
|
126
|
-
borderColor: z.array(z.string()).optional(),
|
|
170
|
+
backgroundColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
171
|
+
borderColor: z.union([z.string(), z.array(z.string())]).optional(),
|
|
127
172
|
fill: z.boolean().optional(),
|
|
128
173
|
})),
|
|
129
174
|
options: z.object({
|
|
@@ -170,6 +215,13 @@ if (process.argv.length === 2) {
|
|
|
170
215
|
else if (params.arguments && typeof params.arguments === 'object') {
|
|
171
216
|
processedParams = params.arguments;
|
|
172
217
|
}
|
|
218
|
+
// Normalize elements before extracting them to fix string/array issues
|
|
219
|
+
if (processedParams.elements) {
|
|
220
|
+
processedParams.elements = normalizeElementsForMCP(processedParams.elements);
|
|
221
|
+
}
|
|
222
|
+
if (processedParams.charts) {
|
|
223
|
+
processedParams.charts = normalizeElementsForMCP(processedParams.charts);
|
|
224
|
+
}
|
|
173
225
|
// Extract parameters correctly, ensuring outputFile is not nested within elements
|
|
174
226
|
const { document, elements, charts, outputFile = 'report.html', tempDirectory } = processedParams;
|
|
175
227
|
// Поддержка обратной совместимости: если переданы charts, используем их как elements
|
|
@@ -20,6 +20,32 @@ const imageRenderers = {
|
|
|
20
20
|
pollinations: { schema: pollinationsImageSchema, renderer: renderPollinationsImage },
|
|
21
21
|
url: { schema: urlImageSchema, renderer: renderUrlImage },
|
|
22
22
|
};
|
|
23
|
+
// Utility function to normalize chart configuration data
|
|
24
|
+
// Converts string values to arrays where the schema expects arrays
|
|
25
|
+
function normalizeChartConfig(config) {
|
|
26
|
+
if (!config || typeof config !== 'object') {
|
|
27
|
+
return config;
|
|
28
|
+
}
|
|
29
|
+
const normalizedConfig = { ...config };
|
|
30
|
+
// Normalize datasets
|
|
31
|
+
if (normalizedConfig.datasets && Array.isArray(normalizedConfig.datasets)) {
|
|
32
|
+
normalizedConfig.datasets = normalizedConfig.datasets.map((dataset) => {
|
|
33
|
+
if (!dataset || typeof dataset !== 'object') {
|
|
34
|
+
return dataset;
|
|
35
|
+
}
|
|
36
|
+
const normalizedDataset = { ...dataset };
|
|
37
|
+
// Convert string values to arrays for color properties
|
|
38
|
+
const colorProperties = ['backgroundColor', 'borderColor'];
|
|
39
|
+
for (const prop of colorProperties) {
|
|
40
|
+
if (normalizedDataset[prop] && typeof normalizedDataset[prop] === 'string') {
|
|
41
|
+
normalizedDataset[prop] = [normalizedDataset[prop]];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return normalizedDataset;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return normalizedConfig;
|
|
48
|
+
}
|
|
23
49
|
export async function generateReport(document, elements, outputFile) {
|
|
24
50
|
// Validate elements
|
|
25
51
|
for (const [id, element] of Object.entries(elements)) {
|
|
@@ -29,7 +55,11 @@ export async function generateReport(document, elements, outputFile) {
|
|
|
29
55
|
const { schema } = chartRenderers[chartElement.type];
|
|
30
56
|
if (!schema)
|
|
31
57
|
throw new Error(`Unsupported chart type: ${chartElement.type}`);
|
|
32
|
-
|
|
58
|
+
// Normalize the chart configuration before validation
|
|
59
|
+
const normalizedConfig = normalizeChartConfig(chartElement.config);
|
|
60
|
+
schema.parse(normalizedConfig);
|
|
61
|
+
// Update the element with normalized config for rendering
|
|
62
|
+
element.config = normalizedConfig;
|
|
33
63
|
}
|
|
34
64
|
else if (element.type in imageRenderers) {
|
|
35
65
|
// Это изображение
|