@codesys/mcp-toolkit 1.5.3 → 1.5.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.
- package/CHANGELOG.md +19 -0
- package/dist/bin.js +5 -1
- package/dist/codesys_interop.js +3 -6
- package/dist/direct_session_command.js +18 -3
- package/dist/server.js +43 -16
- package/dist/sessionManager.js +18 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,25 @@ 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.6] - 2025-05-02
|
|
9
|
+
### Fixed
|
|
10
|
+
- Fixed session manager null reference error in interop.ts
|
|
11
|
+
- Added additional null checks for session manager
|
|
12
|
+
- Improved error handling when session manager is undefined
|
|
13
|
+
|
|
14
|
+
## [1.5.5] - 2025-05-02
|
|
15
|
+
### Fixed
|
|
16
|
+
- Added enhanced command.json file verification to debug session communication
|
|
17
|
+
- Improved logging for command file operations to diagnose IPC issues
|
|
18
|
+
- Added command data verification to detect potential file corruption
|
|
19
|
+
|
|
20
|
+
## [1.5.4] - 2025-05-02
|
|
21
|
+
### Fixed
|
|
22
|
+
- Added `--no-session` flag to disable session management when CODESYS UI hangs
|
|
23
|
+
- Improved session handling with better error detection and user feedback
|
|
24
|
+
- Removed hardcoded session disable flag in favor of command-line option
|
|
25
|
+
- Added safeguards to prevent UI blocking during session operations
|
|
26
|
+
|
|
8
27
|
## [1.5.3] - 2025-05-02
|
|
9
28
|
### Fixed
|
|
10
29
|
- 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...");
|
package/dist/codesys_interop.js
CHANGED
|
@@ -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
|
|
95
|
-
|
|
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 (
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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,52 @@ function startMcpServer(config) {
|
|
|
117
117
|
}
|
|
118
118
|
// --- End Helper Function ---
|
|
119
119
|
// --- Initialize Session Manager ---
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
console.error('SERVER.TS: Session
|
|
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 (will remain undefined if session management is disabled)
|
|
124
|
+
let sessionManager = undefined;
|
|
125
|
+
if (enableSessionManagement) {
|
|
126
|
+
try {
|
|
127
|
+
sessionManager = new sessionManager_1.CodesysSessionManager(codesysExePath, codesysProfileName);
|
|
128
|
+
console.error('SERVER.TS: Session manager initialized');
|
|
129
|
+
// Only start a session if explicitly enabled and manager was created successfully
|
|
130
|
+
if (sessionManager) {
|
|
131
|
+
try {
|
|
132
|
+
// Check if session is already active
|
|
133
|
+
console.error('SERVER.TS: Checking if session is already active...');
|
|
134
|
+
const isActive = (0, direct_session_command_1.isSessionActive)();
|
|
135
|
+
if (isActive) {
|
|
136
|
+
console.error('SERVER.TS: Session is already active');
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
console.error('SERVER.TS: Session not active, starting new session...');
|
|
140
|
+
console.error('SERVER.TS: IMPORTANT: If CODESYS hangs during session startup, use --no-session flag');
|
|
141
|
+
yield sessionManager.startSession();
|
|
142
|
+
console.error('SERVER.TS: Session start initiated');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error(`SERVER.TS: Error starting session: ${error.message}`);
|
|
147
|
+
console.error('SERVER.TS: Will fallback to one-time execution for operations');
|
|
148
|
+
// Continue without session, will fallback to one-time execution
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
console.error('SERVER.TS: Session manager creation failed');
|
|
153
|
+
}
|
|
129
154
|
}
|
|
130
|
-
|
|
131
|
-
console.error(
|
|
132
|
-
|
|
133
|
-
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error(`SERVER.TS: Failed to create session manager: ${error.message}`);
|
|
157
|
+
console.error('SERVER.TS: Will fallback to one-time execution for operations');
|
|
158
|
+
sessionManager = undefined;
|
|
134
159
|
}
|
|
135
160
|
}
|
|
136
|
-
|
|
137
|
-
console.error(
|
|
138
|
-
|
|
161
|
+
else {
|
|
162
|
+
console.error('SERVER.TS: Session management is disabled, will use one-time script execution');
|
|
163
|
+
}
|
|
164
|
+
if (!sessionManager) {
|
|
165
|
+
console.error('SERVER.TS: Session manager is not available - one-time script execution will be used');
|
|
139
166
|
}
|
|
140
167
|
// --- End Session Manager Initialization ---
|
|
141
168
|
// --- Preload script templates ---
|
package/dist/sessionManager.js
CHANGED
|
@@ -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
|
-
|
|
643
|
-
|
|
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
|
}
|