@codesys/mcp-toolkit 1.0.5 → 1.0.6

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.
@@ -84,43 +84,38 @@ function executeCodesysScript(scriptContent, codesysExePath, codesysProfileName)
84
84
  // Fix: Use shell:true but ensure proper quoting for paths with spaces
85
85
  const commandWithArgs = `"${codesysExePath}" --profile="${codesysProfileName}" --noUI --runscript="${tempFilePath}"`;
86
86
  process.stderr.write(`Executing: ${commandWithArgs}\n`); // Log the command
87
- // Spawn the CODESYS process with shell:true for compatibility with CODESYS argument parsing
88
- const codesysProcess = (0, child_process_1.spawn)(commandWithArgs, {
89
- stdio: ['ignore', 'pipe', 'pipe'], // Ignore stdin, pipe stdout and stderr
90
- shell: true // Keep shell:true but with properly quoted paths
91
- });
92
- // Capture stdout
93
- codesysProcess.stdout.on('data', (data) => {
94
- const chunk = data.toString();
95
- // console.error('CODESYS stdout:', chunk); // Optional: Original debug log
96
- output += chunk;
97
- });
98
- // Capture stderr
99
- codesysProcess.stderr.on('data', (data) => {
100
- const chunk = data.toString();
101
- process.stderr.write(`CODESYS stderr: ${chunk}\n`); // Use process.stderr
102
- output += chunk; // Include stderr in the output for debugging
103
- });
104
- // Wait for the process to exit with a timeout
87
+ // Use exec instead of spawn - more reliable for command line processing
105
88
  const exitCode = yield new Promise((resolve, reject) => {
106
- // Add timeout handling
107
89
  const timeoutMs = 30000; // 30 seconds
108
- const timeout = setTimeout(() => {
90
+ let timeoutHandle = null;
91
+ // Start the command using exec
92
+ const childProcess = (0, child_process_1.exec)(commandWithArgs, (error, stdout, stderr) => {
93
+ var _a;
94
+ if (timeoutHandle)
95
+ clearTimeout(timeoutHandle);
96
+ // Save all output
97
+ if (stdout)
98
+ output += stdout;
99
+ if (stderr) {
100
+ process.stderr.write(`CODESYS stderr: ${stderr}\n`);
101
+ output += stderr;
102
+ }
103
+ if (error) {
104
+ // Command failed
105
+ process.stderr.write(`CODESYS process error: ${error.message}\n`);
106
+ resolve((_a = error.code) !== null && _a !== void 0 ? _a : 1); // Return error code
107
+ }
108
+ else {
109
+ // Command succeeded
110
+ resolve(0);
111
+ }
112
+ });
113
+ // Set a timeout
114
+ timeoutHandle = setTimeout(() => {
109
115
  process.stderr.write(`TIMEOUT: CODESYS process did not complete in ${timeoutMs}ms\n`);
110
- // Force resolve with 0 to proceed with parsing output collected so far
111
- codesysProcess.kill();
112
- resolve(0);
116
+ childProcess.kill();
117
+ resolve(0); // Continue processing with what we have
113
118
  }, timeoutMs);
114
- codesysProcess.on('close', (code) => {
115
- clearTimeout(timeout);
116
- resolve(code !== null && code !== void 0 ? code : 0);
117
- });
118
- codesysProcess.on('error', (err) => {
119
- clearTimeout(timeout);
120
- // Error starting the process itself (e.g., command not found)
121
- process.stderr.write(`Failed to start CODESYS process: ${err.message}\n`); // Use process.stderr
122
- reject(err);
123
- });
124
119
  });
125
120
  process.stderr.write(`CODESYS process exited with code: ${exitCode}\n`); // Use process.stderr
126
121
  // Determine success based on exit code and output markers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codesys/mcp-toolkit",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "dist/server.js",
5
5
  "bin": {
6
6
  "codesys-mcp-toolkit": "./dist/bin.js"
package/test-direct.js ADDED
@@ -0,0 +1,40 @@
1
+ const { spawn } = require('child_process');
2
+
3
+ // Paths
4
+ const codesysPath = "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe";
5
+ const profileName = "CODESYS V3.5 SP21";
6
+
7
+ // Log what we're doing
8
+ console.log(`Testing direct spawn of CODESYS\n`);
9
+
10
+ // Create a test Python script
11
+ const fs = require('fs');
12
+ const os = require('os');
13
+ const path = require('path');
14
+ const tempFile = path.join(os.tmpdir(), 'direct_test.py');
15
+ fs.writeFileSync(tempFile, 'print("DIRECT TEST SUCCESS")\n');
16
+
17
+ console.log(`Script file: ${tempFile}`);
18
+ console.log(`CODESYS path: ${codesysPath}`);
19
+
20
+ // Method 1: Using spawn with shell:true and proper quotes
21
+ const command = `"${codesysPath}" --profile="${profileName}" --noUI --runscript="${tempFile}"`;
22
+ console.log(`\nExecuting command: ${command}`);
23
+
24
+ try {
25
+ // Use exec instead of spawn for simpler testing
26
+ require('child_process').exec(command, (error, stdout, stderr) => {
27
+ console.log("\n--- RESULTS ---");
28
+ if (error) {
29
+ console.log(`Error: ${error.message}`);
30
+ return;
31
+ }
32
+ if (stderr) {
33
+ console.log(`stderr: ${stderr}`);
34
+ }
35
+ console.log(`stdout: ${stdout}`);
36
+ console.log("--- END RESULTS ---");
37
+ });
38
+ } catch (err) {
39
+ console.log(`Caught error: ${err.message}`);
40
+ }