@codesys/mcp-toolkit 1.4.7 → 1.4.8

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,14 @@ 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.4.8] - 2025-05-02
9
+ ### Fixed
10
+ - Fixed critical bug with project creation in persistent sessions
11
+ - Added SKIP_OPEN option to create_project script for session compatibility
12
+ - Improved handling of project creation in sessions to avoid "project in use" errors
13
+ - Added better error recovery when project file exists but can't be opened in a session
14
+ - Added helpful user messages explaining session limitations with project operations
15
+
8
16
  ## [1.4.7] - 2025-05-02
9
17
  ### Fixed
10
18
  - Fixed create_project freezing in persistent sessions
@@ -4,6 +4,8 @@ import sys, scriptengine as script_engine, os, shutil, time, traceback
4
4
  # Paths will be correctly escaped in the template substitution
5
5
  TEMPLATE_PROJECT_PATH = '{TEMPLATE_PROJECT_PATH}'
6
6
  PROJECT_FILE_PATH = '{PROJECT_FILE_PATH}'
7
+ # Optional flag to skip opening the project after creation (useful for sessions)
8
+ SKIP_OPEN = '{SKIP_OPEN}' == 'true'
7
9
 
8
10
  # Print raw paths for debugging
9
11
  print("DEBUG: Template path (raw): %s" % repr(TEMPLATE_PROJECT_PATH))
@@ -61,6 +63,13 @@ try:
61
63
 
62
64
  print("DEBUG: File copy complete.")
63
65
 
66
+ # For sessions, we may want to skip opening the project to avoid conflicts
67
+ if SKIP_OPEN:
68
+ print("DEBUG: SKIP_OPEN is set to true, skipping project open step.")
69
+ print("Project Created from Template Copy at: %s" % PROJECT_FILE_PATH)
70
+ print("SCRIPT_SUCCESS: Project copied from template (open step skipped for session compatibility).")
71
+ sys.exit(0)
72
+
64
73
  # 2. Open the newly copied project file
65
74
  print("DEBUG: Opening the copied project: %s" % PROJECT_FILE_PATH)
66
75
  # Set flags for silent opening
@@ -71,24 +80,31 @@ try:
71
80
  # print("WARN: VersionUpdateFlags not found, using integer flags for open (1 | 2 = 3).")
72
81
  # update_mode = 3
73
82
 
74
- project = script_engine.projects.open(PROJECT_FILE_PATH, update_flags=update_mode)
75
- print("DEBUG: script_engine.projects.open returned: %s" % project)
76
- if project:
77
- print("DEBUG: Pausing briefly after open...")
78
- time.sleep(1.0) # Allow CODESYS to potentially initialize things
79
- try:
80
- print("DEBUG: Explicitly saving project after opening copy...")
81
- project.save();
82
- print("DEBUG: Project save after opening copy succeeded.")
83
- except Exception as save_err:
84
- print("WARN: Explicit save after opening copy failed: %s" % save_err)
85
- # Decide if this is critical - maybe not, but good to know.
86
- print("Project Created from Template Copy at: %s" % PROJECT_FILE_PATH)
87
- print("SCRIPT_SUCCESS: Project copied from template and opened successfully.")
83
+ try:
84
+ project = script_engine.projects.open(PROJECT_FILE_PATH, update_flags=update_mode)
85
+ print("DEBUG: script_engine.projects.open returned: %s" % project)
86
+ if project:
87
+ print("DEBUG: Pausing briefly after open...")
88
+ time.sleep(1.0) # Allow CODESYS to potentially initialize things
89
+ try:
90
+ print("DEBUG: Explicitly saving project after opening copy...")
91
+ project.save();
92
+ print("DEBUG: Project save after opening copy succeeded.")
93
+ except Exception as save_err:
94
+ print("WARN: Explicit save after opening copy failed: %s" % save_err)
95
+ # Decide if this is critical - maybe not, but good to know.
96
+ print("Project Created from Template Copy at: %s" % PROJECT_FILE_PATH)
97
+ print("SCRIPT_SUCCESS: Project copied from template and opened successfully.")
98
+ sys.exit(0)
99
+ else:
100
+ error_message = "Failed to open project copy %s after copying template %s. projects.open returned None." % (PROJECT_FILE_PATH, TEMPLATE_PROJECT_PATH)
101
+ print(error_message); print("SCRIPT_ERROR: %s" % error_message); sys.exit(1)
102
+ except Exception as open_err:
103
+ print("WARN: Error opening project after creation: %s" % open_err)
104
+ # Even though we couldn't open it, the project was still created successfully
105
+ print("Project Created from Template Copy at: %s (but could not be opened automatically)" % PROJECT_FILE_PATH)
106
+ print("SCRIPT_SUCCESS: Project copied from template (but open operation failed: %s)." % open_err)
88
107
  sys.exit(0)
89
- else:
90
- error_message = "Failed to open project copy %s after copying template %s. projects.open returned None." % (PROJECT_FILE_PATH, TEMPLATE_PROJECT_PATH)
91
- print(error_message); print("SCRIPT_ERROR: %s" % error_message); sys.exit(1)
92
108
  except Exception as e:
93
109
  detailed_error = traceback.format_exc()
94
110
  error_message = "Error creating project '%s' from template '%s': %s\\n%s" % (PROJECT_FILE_PATH, TEMPLATE_PROJECT_PATH, e, detailed_error)
package/dist/server.js CHANGED
@@ -377,9 +377,14 @@ function startMcpServer(config) {
377
377
  const normalizedTargetPath = absPath.replace(/\\/g, '/');
378
378
  const normalizedTemplatePath = templatePath.replace(/\\/g, '/');
379
379
  console.error(`Using normalized paths for script: Target=${normalizedTargetPath}, Template=${normalizedTemplatePath}`);
380
+ // When running in a session, skip the open step to avoid conflicts
381
+ const inSession = sessionManager &&
382
+ (sessionManager.getState() === sessionManager_1.SessionState.RUNNING ||
383
+ sessionManager.getState() === sessionManager_1.SessionState.BUSY);
380
384
  const scriptContent = (0, scriptLoader_1.interpolateScript)(scriptTemplate, {
381
385
  'PROJECT_FILE_PATH': normalizedTargetPath,
382
- 'TEMPLATE_PROJECT_PATH': normalizedTemplatePath
386
+ 'TEMPLATE_PROJECT_PATH': normalizedTemplatePath,
387
+ 'SKIP_OPEN': inSession ? 'true' : 'false'
383
388
  });
384
389
  console.error(">>> create_project (copy-then-open): PREPARED SCRIPT:", scriptContent.substring(0, 500) + "...");
385
390
  // Use a longer timeout for project creation operations in sessions (120 seconds)
@@ -427,6 +432,30 @@ function startMcpServer(config) {
427
432
  }
428
433
  }
429
434
  const success = result.success && result.output.includes("SCRIPT_SUCCESS");
435
+ // Special handling for cases where project was created but couldn't be opened automatically
436
+ if (success && inSession && result.output.includes("open operation failed")) {
437
+ return {
438
+ content: [{
439
+ type: "text",
440
+ text: `Project created from template: ${absPath}\n` +
441
+ `Note: The project was created successfully, but couldn't be opened automatically because you're in a session.\n` +
442
+ `You can use open_project to open it now, or create a POU directly with create_pou.`
443
+ }],
444
+ isError: false
445
+ };
446
+ }
447
+ // Special handling for skipped open operations in sessions
448
+ if (success && inSession && result.output.includes("open step skipped for session compatibility")) {
449
+ return {
450
+ content: [{
451
+ type: "text",
452
+ text: `Project created from template: ${absPath}\n` +
453
+ `Note: The project opening step was skipped because you're in a session.\n` +
454
+ `You can use open_project to open it now, or create a POU directly with create_pou.`
455
+ }],
456
+ isError: false
457
+ };
458
+ }
430
459
  return {
431
460
  content: [{
432
461
  type: "text",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codesys/mcp-toolkit",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "description": "Model Context Protocol (MCP) server for CODESYS automation platform",
5
5
  "main": "dist/server.js",
6
6
  "bin": {