@vint.tri/report_gen_mcp 1.0.29 → 1.0.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.
Files changed (3) hide show
  1. package/dist/index.js +35 -29
  2. package/package.json +1 -1
  3. package/src/index.ts +35 -30
package/dist/index.js CHANGED
@@ -12,39 +12,39 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
12
12
  const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
13
13
  const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
14
14
  const zod_1 = require("zod");
15
- // Check for mandatory REPORTS_DIR environment variable
16
- const reportsDir = process.env.REPORTS_DIR;
17
- if (!reportsDir) {
18
- console.error('Error: REPORTS_DIR environment variable is required.');
19
- console.error('Please set the REPORTS_DIR environment variable to specify where reports should be generated.');
20
- console.error('Example:');
21
- console.error(' export REPORTS_DIR=/path/to/reports && npx @vint.tri/report_gen_mcp@latest');
22
- console.error('Or:');
23
- console.error(' REPORTS_DIR=/path/to/reports npx @vint.tri/report_gen_mcp@latest');
24
- process.exit(1);
25
- }
26
- // Ensure the reports directory exists
27
- try {
28
- fs_extra_1.default.ensureDirSync(reportsDir);
29
- }
30
- catch (error) {
31
- console.error(`Error: Cannot create or access the reports directory: ${reportsDir}`);
32
- console.error('Please ensure the path is valid and you have write permissions.');
33
- process.exit(1);
15
+ // Check if we're running in stdio mode (no command-line arguments)
16
+ const isStdioMode = process.argv.length === 2;
17
+ // For CLI and HTTP API modes, check for mandatory REPORTS_DIR environment variable
18
+ let reportsDir = undefined;
19
+ if (!isStdioMode) {
20
+ reportsDir = process.env.REPORTS_DIR;
21
+ if (!reportsDir) {
22
+ console.error('Error: REPORTS_DIR environment variable is required.');
23
+ console.error('Please set the REPORTS_DIR environment variable to specify where reports should be generated.');
24
+ console.error('Example:');
25
+ console.error(' export REPORTS_DIR=/path/to/reports && npx @vint.tri/report_gen_mcp@latest');
26
+ console.error('Or:');
27
+ console.error(' REPORTS_DIR=/path/to/reports npx @vint.tri/report_gen_mcp@latest');
28
+ process.exit(1);
29
+ }
30
+ // Ensure the reports directory exists
31
+ try {
32
+ fs_extra_1.default.ensureDirSync(reportsDir);
33
+ }
34
+ catch (error) {
35
+ console.error(`Error: Cannot create or access the reports directory: ${reportsDir}`);
36
+ console.error('Please ensure the path is valid and you have write permissions.');
37
+ process.exit(1);
38
+ }
34
39
  }
35
40
  const app = (0, express_1.default)();
36
41
  const port = 3000;
37
42
  app.use(express_1.default.json());
38
43
  app.post('/generate-report', async (req, res) => {
39
- // Check if tempDirectory parameter is provided
40
- const { document, charts, outputFile = 'report.html', tempDirectory } = req.body;
41
- if (!tempDirectory) {
42
- return res.status(400).json({
43
- error: 'tempDirectory parameter is required. Please provide the directory where reports should be generated.',
44
- example: 'curl -X POST http://localhost:3000/generate-report -H "Content-Type: application/json" -d \'{"document": "# Report", "charts": {}, "tempDirectory": "/path/to/reports"}\''
45
- });
46
- }
47
- const outputPath = path_1.default.resolve(tempDirectory, outputFile);
44
+ // For HTTP API mode, use the REPORTS_DIR environment variable
45
+ // This endpoint only runs in non-stdio mode where reportsDir is guaranteed to be defined
46
+ const { document, charts, outputFile = 'report.html' } = req.body;
47
+ const outputPath = path_1.default.resolve(reportsDir, outputFile);
48
48
  try {
49
49
  const result = await (0, reportGenerator_1.generateReport)(document, charts, outputPath);
50
50
  // Send the file content back to the client
@@ -74,7 +74,13 @@ commander_1.program
74
74
  .description('Generate a report in the directory specified by REPORTS_DIR environment variable')
75
75
  .action(async (opts) => {
76
76
  const charts = JSON.parse(opts.charts);
77
- const result = await (0, reportGenerator_1.generateReport)(opts.document, charts, path_1.default.resolve(reportsDir, opts.output));
77
+ // Read the document file content if a file path is provided
78
+ let documentContent = opts.document;
79
+ if (opts.document && fs_extra_1.default.existsSync(opts.document)) {
80
+ documentContent = await fs_extra_1.default.readFile(opts.document, 'utf8');
81
+ }
82
+ // This command only runs in non-stdio mode where reportsDir is guaranteed to be defined
83
+ const result = await (0, reportGenerator_1.generateReport)(documentContent, charts, path_1.default.resolve(reportsDir, opts.output));
78
84
  console.log(result);
79
85
  });
80
86
  // Handle stdio mode for Claude Desktop integration
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vint.tri/report_gen_mcp",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "CLI tool for generating HTML reports with embedded charts",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -10,25 +10,31 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
10
10
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
11
11
  import { z } from 'zod';
12
12
 
13
- // Check for mandatory REPORTS_DIR environment variable
14
- const reportsDir = process.env.REPORTS_DIR;
15
- if (!reportsDir) {
16
- console.error('Error: REPORTS_DIR environment variable is required.');
17
- console.error('Please set the REPORTS_DIR environment variable to specify where reports should be generated.');
18
- console.error('Example:');
19
- console.error(' export REPORTS_DIR=/path/to/reports && npx @vint.tri/report_gen_mcp@latest');
20
- console.error('Or:');
21
- console.error(' REPORTS_DIR=/path/to/reports npx @vint.tri/report_gen_mcp@latest');
22
- process.exit(1);
23
- }
13
+ // Check if we're running in stdio mode (no command-line arguments)
14
+ const isStdioMode = process.argv.length === 2;
15
+
16
+ // For CLI and HTTP API modes, check for mandatory REPORTS_DIR environment variable
17
+ let reportsDir: string | undefined = undefined;
18
+ if (!isStdioMode) {
19
+ reportsDir = process.env.REPORTS_DIR;
20
+ if (!reportsDir) {
21
+ console.error('Error: REPORTS_DIR environment variable is required.');
22
+ console.error('Please set the REPORTS_DIR environment variable to specify where reports should be generated.');
23
+ console.error('Example:');
24
+ console.error(' export REPORTS_DIR=/path/to/reports && npx @vint.tri/report_gen_mcp@latest');
25
+ console.error('Or:');
26
+ console.error(' REPORTS_DIR=/path/to/reports npx @vint.tri/report_gen_mcp@latest');
27
+ process.exit(1);
28
+ }
24
29
 
25
- // Ensure the reports directory exists
26
- try {
27
- fs.ensureDirSync(reportsDir);
28
- } catch (error) {
29
- console.error(`Error: Cannot create or access the reports directory: ${reportsDir}`);
30
- console.error('Please ensure the path is valid and you have write permissions.');
31
- process.exit(1);
30
+ // Ensure the reports directory exists
31
+ try {
32
+ fs.ensureDirSync(reportsDir);
33
+ } catch (error) {
34
+ console.error(`Error: Cannot create or access the reports directory: ${reportsDir}`);
35
+ console.error('Please ensure the path is valid and you have write permissions.');
36
+ process.exit(1);
37
+ }
32
38
  }
33
39
 
34
40
  const app = express();
@@ -37,17 +43,10 @@ const port = 3000;
37
43
  app.use(express.json());
38
44
 
39
45
  app.post('/generate-report', async (req, res) => {
40
- // Check if tempDirectory parameter is provided
41
- const { document, charts, outputFile = 'report.html', tempDirectory } = req.body;
42
-
43
- if (!tempDirectory) {
44
- return res.status(400).json({
45
- error: 'tempDirectory parameter is required. Please provide the directory where reports should be generated.',
46
- example: 'curl -X POST http://localhost:3000/generate-report -H "Content-Type: application/json" -d \'{"document": "# Report", "charts": {}, "tempDirectory": "/path/to/reports"}\''
47
- });
48
- }
49
-
50
- const outputPath = path.resolve(tempDirectory, outputFile);
46
+ // For HTTP API mode, use the REPORTS_DIR environment variable
47
+ // This endpoint only runs in non-stdio mode where reportsDir is guaranteed to be defined
48
+ const { document, charts, outputFile = 'report.html' } = req.body;
49
+ const outputPath = path.resolve(reportsDir!, outputFile);
51
50
 
52
51
  try {
53
52
  const result = await generateReport(document, charts, outputPath);
@@ -80,7 +79,13 @@ program
80
79
  .description('Generate a report in the directory specified by REPORTS_DIR environment variable')
81
80
  .action(async (opts) => {
82
81
  const charts = JSON.parse(opts.charts);
83
- const result = await generateReport(opts.document, charts, path.resolve(reportsDir, opts.output));
82
+ // Read the document file content if a file path is provided
83
+ let documentContent = opts.document;
84
+ if (opts.document && fs.existsSync(opts.document)) {
85
+ documentContent = await fs.readFile(opts.document, 'utf8');
86
+ }
87
+ // This command only runs in non-stdio mode where reportsDir is guaranteed to be defined
88
+ const result = await generateReport(documentContent, charts, path.resolve(reportsDir!, opts.output));
84
89
  console.log(result);
85
90
  });
86
91