@vint.tri/report_gen_mcp 1.7.29 → 1.7.30

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAsgBA;;;;;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":";AAgYA;;;;;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
@@ -4,12 +4,12 @@ import { program } from 'commander';
4
4
  import { generateReport } from './utils/reportGenerator.js';
5
5
  import path from 'path';
6
6
  import fs from 'fs-extra';
7
- import os from 'os';
8
7
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
8
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
10
9
  import { z } from 'zod';
11
10
  import { pathToFileURL } from 'url';
12
11
  import { ImageGenerator } from './mcp/imageGenerationServer.js';
12
+ import { createReportFromTextTool } from './tools/createReportFromText.js';
13
13
  // Check if we're running in stdio mode (no command-line arguments)
14
14
  const isStdioMode = process.argv.length === 2;
15
15
  // For CLI and HTTP API modes, check for mandatory REPORTS_DIR environment variable
@@ -103,165 +103,39 @@ 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.29"
106
+ version: "1.7.30"
107
107
  }, {
108
108
  // Disable health check to prevent automatic calls
109
109
  capabilities: {
110
110
  tools: {}
111
111
  }
112
112
  });
113
- // Register the generate-report tool
114
- mcpServer.registerTool("generate-report", {
115
- description: "Generate an HTML report with embedded charts and images",
116
- inputSchema: {
117
- document: z.string().describe("Markdown document with element placeholders [[chart:id]] or [[image:id]]"),
118
- elements: z.record(z.union([
119
- // Chart configurations
120
- z.object({
121
- type: z.enum(["bar", "line", "pie", "doughnut", "radar", "polarArea"]),
122
- config: z.object({
123
- labels: z.array(z.string()),
124
- datasets: z.array(z.object({
125
- label: z.string().optional(),
126
- data: z.array(z.number()),
127
- backgroundColor: z.array(z.string()).optional(),
128
- borderColor: z.array(z.string()).optional(),
129
- fill: z.boolean().optional(),
130
- })),
131
- options: z.object({
132
- title: z.string().optional(),
133
- }).optional(),
134
- }),
135
- }).describe("Chart configuration"),
136
- // Pollinations.ai generated images
137
- z.object({
138
- type: z.literal("pollinations"),
139
- config: z.object({
140
- prompt: z.string().describe("Text description of the image to generate"),
141
- width: z.number().optional().default(512).describe("Width of the image in pixels"),
142
- height: z.number().optional().default(512).describe("Height of the image in pixels"),
143
- model: z.string().optional().default("flux").describe("Model to use for image generation"),
144
- seed: z.number().optional().describe("Seed for reproducible image generation"),
145
- nologo: z.boolean().optional().default(true).describe("Remove logo from the image"),
146
- enhance: z.boolean().optional().default(true).describe("Enhance image quality"),
147
- }),
148
- }).describe("Pollinations.ai generated image configuration"),
149
- // URL images (including local file URLs and web URLs)
150
- z.object({
151
- type: z.literal("url"),
152
- config: z.object({
153
- url: z.string().describe("URL of the image (can be file:// or http(s)://)"),
154
- alt: z.string().optional().describe("Alternative text for the image"),
155
- width: z.number().optional().describe("Width of the image in pixels"),
156
- height: z.number().optional().describe("Height of the image in pixels"),
157
- }),
158
- }).describe("Image from URL configuration"),
159
- // Local images (backward compatibility)
160
- z.object({
161
- type: z.literal("image"),
162
- config: z.object({
163
- url: z.string().describe("File URL of the image"),
164
- alt: z.string().optional().describe("Alternative text for the image"),
165
- width: z.number().optional().describe("Width of the image in pixels"),
166
- height: z.number().optional().describe("Height of the image in pixels"),
167
- }),
168
- }).describe("Local image file configuration"),
169
- // AssetId support for neural network responses (new format)
170
- z.object({
171
- type: z.literal("url"),
172
- assetId: z.string().optional().describe("Asset ID for generated images (used by neural networks)"),
173
- config: z.object({
174
- url: z.string().optional().describe("URL of the image (can be populated from assetId)"),
175
- alt: z.string().optional().describe("Alternative text for the image"),
176
- width: z.number().optional().default(512).describe("Width of the image in pixels"),
177
- height: z.number().optional().default(512).describe("Height of the image in pixels"),
178
- }).optional(),
179
- }).describe("Image with assetId support for neural network responses"),
180
- ])).describe("Report elements (charts and images) mapped by ID"),
181
- outputFile: z.string().optional().describe("Output HTML file path"),
182
- tempDirectory: z.string().optional().describe("Temporary directory for file storage (optional, will use REPORTS_DIR environment variable if set)"),
183
- },
113
+ // Register the NEW, simplified tool
114
+ mcpServer.registerTool(createReportFromTextTool.name, {
115
+ description: createReportFromTextTool.description,
116
+ inputSchema: createReportFromTextTool.inputSchema,
184
117
  }, async (params) => {
185
- // --- НАЧАЛО БЛОКА НАДЕЖНОЙ ОБРАБОТКИ ПАРАМЕТРОВ ---
186
118
  let processedParams = params;
187
- try {
188
- // Если параметры - это строка, парсим ее как JSON
189
- if (typeof processedParams === 'string') {
190
- processedParams = JSON.parse(processedParams);
191
- }
192
- // Если есть вложенный объект `arguments`, используем его
193
- if (processedParams.arguments && typeof processedParams.arguments === 'object') {
194
- processedParams = processedParams.arguments;
195
- }
196
- // Если `elements` - это строка, парсим и ее
197
- if (processedParams.elements && typeof processedParams.elements === 'string') {
198
- processedParams.elements = JSON.parse(processedParams.elements);
199
- }
200
- }
201
- catch (e) {
202
- throw new Error('Invalid JSON format in parameters. Ensure all parameters, especially "elements", are valid JSON.');
203
- }
204
- // --- КОНЕЦ БЛОКА НАДЕЖНОЙ ОБРАБОТКИ ПАРАМЕТРОВ ---
205
- // Extract parameters correctly, ensuring outputFile is not nested within elements
206
- const { document, elements, charts, outputFile = 'report.html', tempDirectory } = processedParams;
207
- // Поддержка обратной совместимости: если переданы charts, используем их как elements
208
- const reportElements = elements || charts || {};
209
- // Determine the output directory:
210
- // 1. Use REPORTS_DIR environment variable if set
211
- // 2. Fall back to tempDirectory parameter if provided
212
- // 3. Default to system temp directory if neither is available
213
- let outputDir;
214
- if (process.env.REPORTS_DIR) {
215
- outputDir = process.env.REPORTS_DIR;
216
- // Ensure the reports directory exists
217
- try {
218
- fs.ensureDirSync(outputDir);
219
- }
220
- catch (error) {
221
- throw new Error(`Cannot create or access the reports directory: ${outputDir}`);
222
- }
223
- }
224
- else if (tempDirectory) {
225
- outputDir = tempDirectory;
226
- }
227
- else {
228
- outputDir = os.tmpdir();
119
+ if (params.arguments && typeof params.arguments === 'object') {
120
+ processedParams = params.arguments;
229
121
  }
230
- const outputPath = path.resolve(outputDir, outputFile);
231
- try {
232
- const result = await generateReport(document, reportElements, outputPath);
233
- // Generate proper file URL
234
- const fileUrl = pathToFileURL(outputPath).href;
235
- // Read the file content
236
- const fileContent = await fs.readFile(outputPath, 'utf8');
237
- // Create a comprehensive result object
238
- const comprehensiveResult = {
239
- success: true,
240
- message: "Report generated successfully",
241
- filePath: outputPath,
242
- fileUrl: fileUrl,
243
- fileContent: fileContent
244
- };
245
- // Return comprehensive information for neural network to use
246
- // Neural network should present to user: file path, web link, and file content
247
- return {
248
- content: [
249
- {
250
- type: "text",
251
- text: `Report generated successfully.
122
+ const result = await createReportFromTextTool.execute(processedParams);
123
+ const fileUrl = pathToFileURL(result.filePath).href;
124
+ const fileContent = await fs.readFile(result.filePath, 'utf8');
125
+ return {
126
+ content: [
127
+ {
128
+ type: "text",
129
+ text: `Report generated successfully.
252
130
 
253
131
  FOR THE NEURAL NETWORK: Please present the following information to the user:
254
- 1. Path to file: ${outputPath}
132
+ 1. Path to file: ${result.filePath}
255
133
  2. Web browser link: ${fileUrl}
256
134
  3. File content:
257
135
  ${fileContent}`
258
- }
259
- ]
260
- };
261
- }
262
- catch (error) {
263
- throw error;
264
- }
136
+ }
137
+ ]
138
+ };
265
139
  });
266
140
  // Register a new tool for editing existing reports
267
141
  mcpServer.registerTool("edit-report", {
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ export declare const createReportFromTextTool: {
3
+ name: string;
4
+ description: string;
5
+ inputSchema: {
6
+ documentText: z.ZodString;
7
+ outputFile: z.ZodString;
8
+ };
9
+ execute: ({ documentText, outputFile }: {
10
+ documentText: string;
11
+ outputFile: string;
12
+ }) => Promise<{
13
+ success: boolean;
14
+ filePath: string;
15
+ }>;
16
+ };
17
+ //# sourceMappingURL=createReportFromText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createReportFromText.d.ts","sourceRoot":"","sources":["../../src/tools/createReportFromText.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAyCxB,eAAO,MAAM,wBAAwB;;;;;;;4CAOW;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;;;;CAM3F,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { generateReport } from '../utils/reportGenerator.js';
2
+ import { z } from 'zod';
3
+ // Эта функция будет извлекать данные из текста и генерировать элементы
4
+ function extractElementsFromText(documentText) {
5
+ const elements = {};
6
+ let newDocument = documentText;
7
+ // Пример: ищем финансовые данные для графика
8
+ const revenueMatches = [...documentText.matchAll(/Доход: \$([\d,.]+) миллиарда/gi)];
9
+ if (revenueMatches.length > 0) {
10
+ const labels = revenueMatches.map((match, i) => `Квартал ${i + 1}`);
11
+ const data = revenueMatches.map(match => parseFloat(match[1].replace(/,/g, '')));
12
+ elements['revenue_chart'] = {
13
+ type: 'bar',
14
+ config: {
15
+ labels: labels,
16
+ datasets: [{
17
+ label: 'Общий доход, млрд $',
18
+ data: data,
19
+ backgroundColor: ['rgba(54, 162, 235, 0.6)']
20
+ }]
21
+ }
22
+ };
23
+ newDocument += '\n\n## Визуализация дохода\n\n[[chart:revenue_chart]]';
24
+ }
25
+ // Пример: добавляем изображение на основе контекста
26
+ if (/apple/i.test(documentText)) {
27
+ elements['context_image'] = {
28
+ type: 'pollinations',
29
+ config: {
30
+ prompt: 'a modern and sleek design representing apple products innovation'
31
+ }
32
+ };
33
+ newDocument += '\n\n## Иллюстрация\n\n[[image:context_image]]';
34
+ }
35
+ return { newDocument, elements };
36
+ }
37
+ export const createReportFromTextTool = {
38
+ name: "create-report-from-text",
39
+ description: "Creates a full HTML report from a given text by automatically generating charts and images.",
40
+ inputSchema: {
41
+ documentText: z.string().describe("The full text of the report in Markdown format."),
42
+ outputFile: z.string().describe("The desired output HTML file name (e.g., 'report.html').")
43
+ },
44
+ execute: async ({ documentText, outputFile }) => {
45
+ const { newDocument, elements } = extractElementsFromText(documentText);
46
+ // Вызываем старый генератор с автоматически созданными параметрами
47
+ return await generateReport(newDocument, elements, outputFile);
48
+ }
49
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vint.tri/report_gen_mcp",
3
- "version": "1.7.29",
3
+ "version": "1.7.30",
4
4
  "description": "CLI tool for generating HTML reports with embedded charts and images",
5
5
  "main": "dist/index.js",
6
6
  "bin": {