@codesys/mcp-toolkit 1.5.3 → 1.5.5

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/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.5.5] - 2025-05-02
9
+ ### Fixed
10
+ - Added enhanced command.json file verification to debug session communication
11
+ - Improved logging for command file operations to diagnose IPC issues
12
+ - Added command data verification to detect potential file corruption
13
+
14
+ ## [1.5.4] - 2025-05-02
15
+ ### Fixed
16
+ - Added `--no-session` flag to disable session management when CODESYS UI hangs
17
+ - Improved session handling with better error detection and user feedback
18
+ - Removed hardcoded session disable flag in favor of command-line option
19
+ - Added safeguards to prevent UI blocking during session operations
20
+
8
21
  ## [1.5.3] - 2025-05-02
9
22
  ### Fixed
10
23
  - Added automatic session startup when server starts
package/dist/bin.js CHANGED
@@ -38,6 +38,8 @@ commander_1.program
38
38
  // Add workspace option if needed, defaults to cwd
39
39
  .option('-w, --workspace <dir>', 'Workspace directory for relative project paths', process.cwd() // Default to current working directory
40
40
  )
41
+ // Add option to disable session management
42
+ .option('--no-session', 'Disable session management (use one-time script execution only)', false)
41
43
  .parse(process.argv); // Parse the arguments
42
44
  const options = commander_1.program.opts();
43
45
  // --- Log the options Commander parsed ---
@@ -54,8 +56,10 @@ console.error(`========================================`);
54
56
  const serverConfig = {
55
57
  codesysPath: options.codesysPath.trim(),
56
58
  profileName: options.codesysProfile.trim(),
57
- workspaceDir: options.workspace.trim() // Pass workspace dir
59
+ workspaceDir: options.workspace.trim(), // Pass workspace dir
60
+ enableSessionManagement: options.session // Determined by --no-session flag (default: true)
58
61
  };
62
+ console.error(`BIN.TS: Session management is ${serverConfig.enableSessionManagement ? 'enabled' : 'disabled'}`);
59
63
  // --- End Prepare Config ---
60
64
  // --- Call the server setup function ---
61
65
  console.error("BIN.TS: Calling startMcpServer...");
@@ -91,10 +91,10 @@ function executeCodesysScript(scriptContent, codesysExePath, codesysProfileName,
91
91
  if (!fs.existsSync(codesysExePath))
92
92
  throw new Error(`CODESYS executable not found at provided path: ${codesysExePath}`);
93
93
  // --- End Pre-checks ---
94
- // Session management feature control
95
- const SESSION_FEATURE_DISABLED = false; // Session feature enabled
94
+ // Session management feature is now fully controlled by the presence of sessionManager
95
+ // No need for a separate flag as server.ts will set sessionManager to undefined if disabled
96
96
  // --- Check if we should use the persistent session ---
97
- if (!SESSION_FEATURE_DISABLED && sessionManager) {
97
+ if (sessionManager) {
98
98
  const sessionState = sessionManager.getState();
99
99
  // Check if the session is active
100
100
  if (sessionState === sessionManager_1.SessionState.RUNNING || sessionState === sessionManager_1.SessionState.BUSY) {
@@ -141,9 +141,6 @@ function executeCodesysScript(scriptContent, codesysExePath, codesysProfileName,
141
141
  process.stderr.write(`INTEROP: Session not in RUNNING/BUSY state (current: ${sessionState}). Using one-time execution.\n`);
142
142
  }
143
143
  }
144
- else if (SESSION_FEATURE_DISABLED) {
145
- process.stderr.write(`INTEROP: Session feature is disabled. Using one-time execution mode.\n`);
146
- }
147
144
  else {
148
145
  process.stderr.write(`INTEROP: No session manager provided. Using one-time execution mode.\n`);
149
146
  }
@@ -143,9 +143,24 @@ function executeScriptDirect(scriptContent_1) {
143
143
  timestamp: Date.now()
144
144
  };
145
145
  console.error(`DIRECT_SESSION: Writing command to ${COMMAND_FILE}`);
146
- // Write command to file
147
- fs.writeFileSync(COMMAND_FILE, JSON.stringify(commandData, null, 2));
148
- console.error(`DIRECT_SESSION: Command written to file`);
146
+ console.error(`DIRECT_SESSION: Command data: ${JSON.stringify(commandData)}`);
147
+ try {
148
+ // Write command to file
149
+ fs.writeFileSync(COMMAND_FILE, JSON.stringify(commandData, null, 2));
150
+ console.error(`DIRECT_SESSION: Command written to file`);
151
+ // Verify the file was written correctly
152
+ try {
153
+ const verifyContent = fs.readFileSync(COMMAND_FILE, 'utf8');
154
+ console.error(`DIRECT_SESSION: Verification - Command file now contains: ${verifyContent.substring(0, 100)}...`);
155
+ }
156
+ catch (verifyErr) {
157
+ console.error(`DIRECT_SESSION: Verification failed - could not read command file: ${verifyErr}`);
158
+ }
159
+ }
160
+ catch (writeErr) {
161
+ console.error(`DIRECT_SESSION: ERROR writing command file: ${writeErr}`);
162
+ throw writeErr; // Re-throw to propagate the error
163
+ }
149
164
  // Poll for result
150
165
  return new Promise((resolve, reject) => {
151
166
  let pollCount = 0;
package/dist/server.js CHANGED
@@ -117,25 +117,38 @@ function startMcpServer(config) {
117
117
  }
118
118
  // --- End Helper Function ---
119
119
  // --- Initialize Session Manager ---
120
- const sessionManager = new sessionManager_1.CodesysSessionManager(codesysExePath, codesysProfileName);
121
- console.error('SERVER.TS: Session manager initialized');
122
- // Explicitly start the session when server starts
123
- try {
124
- // Check if session is already active
125
- console.error('SERVER.TS: Checking if session is already active...');
126
- const isActive = (0, direct_session_command_1.isSessionActive)();
127
- if (isActive) {
128
- console.error('SERVER.TS: Session is already active');
120
+ // Default to true if not specified
121
+ const enableSessionManagement = config.enableSessionManagement !== false;
122
+ console.error(`SERVER.TS: Session management is ${enableSessionManagement ? 'enabled' : 'disabled'}`);
123
+ // Create session manager instance
124
+ let sessionManager;
125
+ if (enableSessionManagement) {
126
+ sessionManager = new sessionManager_1.CodesysSessionManager(codesysExePath, codesysProfileName);
127
+ console.error('SERVER.TS: Session manager initialized');
128
+ // Only start a session if explicitly enabled
129
+ try {
130
+ // Check if session is already active
131
+ console.error('SERVER.TS: Checking if session is already active...');
132
+ const isActive = (0, direct_session_command_1.isSessionActive)();
133
+ if (isActive) {
134
+ console.error('SERVER.TS: Session is already active');
135
+ }
136
+ else {
137
+ console.error('SERVER.TS: Session not active, starting new session...');
138
+ console.error('SERVER.TS: IMPORTANT: If CODESYS hangs during session startup, use --no-session flag');
139
+ yield sessionManager.startSession();
140
+ console.error('SERVER.TS: Session start initiated');
141
+ }
129
142
  }
130
- else {
131
- console.error('SERVER.TS: Session not active, starting new session...');
132
- yield sessionManager.startSession();
133
- console.error('SERVER.TS: Session start initiated');
143
+ catch (error) {
144
+ console.error(`SERVER.TS: Error starting session: ${error.message}`);
145
+ console.error('SERVER.TS: Will fallback to one-time execution for operations');
146
+ // Continue without session, will fallback to one-time execution
134
147
  }
135
148
  }
136
- catch (error) {
137
- console.error(`SERVER.TS: Error starting session: ${error.message}`);
138
- // Continue without session, will fallback to one-time execution
149
+ else {
150
+ console.error('SERVER.TS: Session management is disabled, will use one-time script execution');
151
+ sessionManager = undefined;
139
152
  }
140
153
  // --- End Session Manager Initialization ---
141
154
  // --- Preload script templates ---
@@ -639,8 +639,24 @@ class CodesysSessionManager extends events_1.EventEmitter {
639
639
  };
640
640
  // Send the command by writing to the command file
641
641
  console.error(`SESSION_MANAGER: Writing command to file ${this.commandFilePath}`);
642
- fs.writeFileSync(this.commandFilePath, JSON.stringify(commandData, null, 2));
643
- console.error(`SESSION_MANAGER: Command written to file`);
642
+ console.error(`SESSION_MANAGER: Command data: ${JSON.stringify(commandData)}`);
643
+ try {
644
+ // Write command to file
645
+ fs.writeFileSync(this.commandFilePath, JSON.stringify(commandData, null, 2));
646
+ console.error(`SESSION_MANAGER: Command written to file`);
647
+ // Verify the file was written correctly
648
+ try {
649
+ const verifyContent = fs.readFileSync(this.commandFilePath, 'utf8');
650
+ console.error(`SESSION_MANAGER: Verification - Command file now contains: ${verifyContent.substring(0, 100)}...`);
651
+ }
652
+ catch (verifyErr) {
653
+ console.error(`SESSION_MANAGER: Verification failed - could not read command file: ${verifyErr}`);
654
+ }
655
+ }
656
+ catch (writeErr) {
657
+ console.error(`SESSION_MANAGER: ERROR writing command file: ${writeErr}`);
658
+ throw writeErr; // Re-throw to propagate the error
659
+ }
644
660
  // Start reading the result file
645
661
  this.readResultFile(scriptId);
646
662
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codesys/mcp-toolkit",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "description": "Model Context Protocol (MCP) server for CODESYS automation platform",
5
5
  "main": "dist/server.js",
6
6
  "bin": {