@codesys/mcp-toolkit 1.5.8 → 2.0.0-alpha.0

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 (110) hide show
  1. package/CHANGELOG.md +153 -189
  2. package/LICENSE +21 -21
  3. package/README.md +224 -107
  4. package/dist/actions.d.ts +28 -0
  5. package/dist/actions.js +98 -0
  6. package/dist/actions.js.map +1 -0
  7. package/dist/bridge/bridge.d.ts +105 -0
  8. package/dist/bridge/bridge.js +400 -0
  9. package/dist/bridge/bridge.js.map +1 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.js +196 -0
  12. package/dist/cli.js.map +1 -0
  13. package/dist/codesys/cache.d.ts +48 -0
  14. package/dist/codesys/cache.js +82 -0
  15. package/dist/codesys/cache.js.map +1 -0
  16. package/dist/codesys/changes.d.ts +57 -0
  17. package/dist/codesys/changes.js +133 -0
  18. package/dist/codesys/changes.js.map +1 -0
  19. package/dist/codesys/decl.d.ts +45 -0
  20. package/dist/codesys/decl.js +251 -0
  21. package/dist/codesys/decl.js.map +1 -0
  22. package/dist/codesys/devices.d.ts +34 -0
  23. package/dist/codesys/devices.js +82 -0
  24. package/dist/codesys/devices.js.map +1 -0
  25. package/dist/codesys/diff.d.ts +13 -0
  26. package/dist/codesys/diff.js +61 -0
  27. package/dist/codesys/diff.js.map +1 -0
  28. package/dist/codesys/install.d.ts +40 -0
  29. package/dist/codesys/install.js +144 -0
  30. package/dist/codesys/install.js.map +1 -0
  31. package/dist/codesys/library-browse.d.ts +19 -0
  32. package/dist/codesys/library-browse.js +57 -0
  33. package/dist/codesys/library-browse.js.map +1 -0
  34. package/dist/codesys/outline.d.ts +32 -0
  35. package/dist/codesys/outline.js +219 -0
  36. package/dist/codesys/outline.js.map +1 -0
  37. package/dist/codesys/simulation.d.ts +34 -0
  38. package/dist/codesys/simulation.js +57 -0
  39. package/dist/codesys/simulation.js.map +1 -0
  40. package/dist/codesys/st.d.ts +36 -0
  41. package/dist/codesys/st.js +69 -0
  42. package/dist/codesys/st.js.map +1 -0
  43. package/dist/daemon.d.ts +46 -0
  44. package/dist/daemon.js +173 -0
  45. package/dist/daemon.js.map +1 -0
  46. package/dist/driver.d.ts +25 -0
  47. package/dist/driver.js +33 -0
  48. package/dist/driver.js.map +1 -0
  49. package/dist/panel/sim-panel.html +357 -0
  50. package/dist/panel/viewer.html +126 -0
  51. package/dist/panel-types.d.ts +20 -0
  52. package/dist/panel-types.js +3 -0
  53. package/dist/panel-types.js.map +1 -0
  54. package/dist/panel.d.ts +27 -0
  55. package/dist/panel.js +208 -0
  56. package/dist/panel.js.map +1 -0
  57. package/dist/server.d.ts +5 -0
  58. package/dist/server.js +33 -974
  59. package/dist/server.js.map +1 -0
  60. package/dist/tools.d.ts +103 -0
  61. package/dist/tools.js +793 -0
  62. package/dist/tools.js.map +1 -0
  63. package/dist/viewer.d.ts +14 -0
  64. package/dist/viewer.js +125 -0
  65. package/dist/viewer.js.map +1 -0
  66. package/package.json +37 -21
  67. package/watcher/mcp_compat.py +147 -0
  68. package/watcher/mcp_ops.py +1178 -0
  69. package/watcher/mcp_sim.py +246 -0
  70. package/watcher/watcher.py +255 -0
  71. package/.claude/settings.local.json +0 -29
  72. package/CLAUDE.md +0 -26
  73. package/CONTRIBUTING.md +0 -72
  74. package/README.md.enhanced +0 -155
  75. package/codesys-mcp-toolkit-1.2.0.tgz +0 -0
  76. package/codesys-mcp-toolkit-1.2.1.tgz +0 -0
  77. package/codesys-mcp-toolkit-1.5.7.tgz +0 -0
  78. package/codesys-mcp-toolkit-1.5.8.tgz +0 -0
  79. package/dist/bin.js +0 -75
  80. package/dist/check_session_paths.js +0 -149
  81. package/dist/codesys_interop.js +0 -435
  82. package/dist/direct_session_command.js +0 -293
  83. package/dist/scriptLoader.js +0 -165
  84. package/dist/scripts/check_status.py +0 -21
  85. package/dist/scripts/compile_project.py +0 -65
  86. package/dist/scripts/create_method.py +0 -80
  87. package/dist/scripts/create_pou.py +0 -102
  88. package/dist/scripts/create_project.py +0 -116
  89. package/dist/scripts/create_property.py +0 -78
  90. package/dist/scripts/ensure_project_open.py +0 -154
  91. package/dist/scripts/find_object_by_path.py +0 -111
  92. package/dist/scripts/get_pou_code.py +0 -91
  93. package/dist/scripts/get_project_structure.py +0 -72
  94. package/dist/scripts/open_project.py +0 -25
  95. package/dist/scripts/save_project.py +0 -29
  96. package/dist/scripts/session_status.py +0 -281
  97. package/dist/scripts/set_pou_code.py +0 -109
  98. package/dist/scripts/start_session.py +0 -809
  99. package/dist/scripts/stop_session.py +0 -324
  100. package/dist/sessionManager.js +0 -798
  101. package/docs/configuration.md +0 -141
  102. package/docs/index.md +0 -26
  103. package/docs/installation.md +0 -84
  104. package/docs/session_management.md +0 -110
  105. package/examples/README.md +0 -78
  106. package/examples/sample_config.json +0 -32
  107. package/replacements_session_status.txt +0 -16
  108. package/scriptDoc.txt +0 -8679
  109. package/scripts/build.js +0 -25
  110. package/scripts/fix_fstrings.py +0 -76
@@ -1,155 +0,0 @@
1
- # @codesys/mcp-toolkit
2
-
3
- ![npm](https://img.shields.io/npm/v/@codesys/mcp-toolkit)
4
- ![License](https://img.shields.io/github/license/yourusername/codesys-mcp-toolkit)
5
-
6
- A Model Context Protocol (MCP) server for CODESYS V3 programming environments. This toolkit enables seamless interaction between MCP clients (like Claude Desktop) and CODESYS, allowing automation of project management, POU creation, code editing, and compilation tasks.
7
-
8
- <p align="center">
9
- <img src="https://github.com/yourusername/codesys-mcp-toolkit/raw/main/docs/assets/diagram.png" alt="CODESYS MCP Toolkit Architecture" width="600">
10
- </p>
11
-
12
- ## 🌟 Features
13
-
14
- - **Project Management**
15
- - Open existing CODESYS projects
16
- - Create new projects from templates
17
- - Save project changes
18
-
19
- - **POU Management**
20
- - Create Programs, Function Blocks, and Functions
21
- - Set declaration and implementation code
22
- - Create properties and methods for Function Blocks
23
- - Compile projects
24
-
25
- - **MCP Resources**
26
- - `codesys://project/status`: Check scripting status and project state
27
- - `codesys://project/{+project_path}/structure`: Retrieve project structure
28
- - `codesys://project/{+project_path}/pou/{+pou_path}/code`: Read POU code
29
-
30
- - **MCP Tools**
31
- - `open_project`: Open specified CODESYS project
32
- - `create_project`: Create new CODESYS project
33
- - `save_project`: Save currently open project
34
- - `create_pou`: Create new Program, Function Block, or Function
35
- - `set_pou_code`: Update code for a specified POU
36
- - `create_property`: Create property in a Function Block
37
- - `create_method`: Create method in a Function Block
38
- - `compile_project`: Compile the open project
39
-
40
- ## 📋 Prerequisites
41
-
42
- - **CODESYS V3**: A working CODESYS V3 installation (tested with 3.5 SP21) with **Scripting Engine** component enabled
43
- - **Node.js**: Version 18 or later required
44
- - **MCP Client**: An MCP-enabled application (e.g., Claude Desktop)
45
-
46
- ## 🚀 Installation
47
-
48
- ### Option 1: Install from npm (Recommended)
49
-
50
- ```bash
51
- npm install -g @codesys/mcp-toolkit
52
- ```
53
-
54
- This installs the package globally, making the `codesys-mcp-toolkit` command available in your terminal.
55
-
56
- ### Option 2: Install from Source
57
-
58
- ```bash
59
- # Clone the repository
60
- git clone https://github.com/yourusername/codesys-mcp-toolkit.git
61
- cd codesys-mcp-toolkit
62
-
63
- # Install dependencies
64
- npm install
65
-
66
- # Build the project
67
- npm run build
68
-
69
- # Install globally
70
- npm install -g .
71
- ```
72
-
73
- ## 🔧 Configuration
74
-
75
- ### Claude Desktop Configuration
76
-
77
- 1. Locate your Claude Desktop configuration file:
78
- - Windows: `C:\Users\<YourUsername>\AppData\Roaming\Claude\claude_desktop_config.json`
79
-
80
- 2. Add the CODESYS MCP server entry:
81
-
82
- ```json
83
- {
84
- "mcpServers": {
85
- "codesys_local": {
86
- "command": "npx",
87
- "args": [
88
- "-y",
89
- "@codesys/mcp-toolkit",
90
- "--codesys-path", "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe",
91
- "--codesys-profile", "CODESYS V3.5 SP21"
92
- ]
93
- }
94
- }
95
- }
96
- ```
97
-
98
- 3. Customize the paths to match your CODESYS installation:
99
- - `--codesys-path`: Path to your CODESYS.exe
100
- - `--codesys-profile`: Your CODESYS profile name
101
-
102
- 4. Restart Claude Desktop to apply the changes
103
-
104
- ## 🛠️ Usage Examples
105
-
106
- ### Creating a Function Block with Properties
107
-
108
- ```
109
- Ask Claude: "Using the CODESYS Local server, please create a Motor Controller function block with Start and Stop methods, plus CurrentSpeed property."
110
- ```
111
-
112
- Claude will execute these MCP tool calls:
113
- 1. `create_pou` to create the MotorController Function Block
114
- 2. `create_property` to add the CurrentSpeed property
115
- 3. `create_method` to add Start and Stop methods
116
- 4. `set_pou_code` to implement each method and property
117
-
118
- ### Opening and Compiling a Project
119
-
120
- ```
121
- Ask Claude: "Can you open the project at C:/MyProjects/TestProject.project using CODESYS Local and compile it?"
122
- ```
123
-
124
- Claude will:
125
- 1. Use `open_project` to open the specified file
126
- 2. Use `compile_project` to build the application
127
-
128
- ## 🔍 Troubleshooting
129
-
130
- ### Common Issues
131
-
132
- - **Connection Failures**: Check Claude Desktop logs for error messages
133
- - **Path Issues**: Ensure CODESYS executable path is correct
134
- - **Profile Mismatch**: Verify profile name matches exactly
135
- - **Permission Problems**: Ensure Claude has appropriate permissions
136
- - **CODESYS Already Running**: Close other CODESYS instances
137
-
138
- ### Debug Logs
139
-
140
- Check logs at:
141
- - Windows: `C:\Users\<YourUsername>\AppData\Roaming\Claude\logs\`
142
-
143
- ## 🤝 Contributing
144
-
145
- Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
146
-
147
- ## 📝 License
148
-
149
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
150
-
151
- ## 🙏 Acknowledgements
152
-
153
- - The [CODESYS](https://www.codesys.com/) team for their scripting engine
154
- - [Model Context Protocol](https://github.com/m-ld/model-context-protocol) project
155
- - All contributors who have helped improve this toolkit
Binary file
Binary file
Binary file
Binary file
package/dist/bin.js DELETED
@@ -1,75 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- /**
4
- * CODESYS MCP Server CLI
5
- * Command-line interface for starting the CODESYS MCP server
6
- * with configurable CODESYS executable paths and profile names.
7
- *
8
- * This is the entry point for the MCP toolkit when invoked as a command-line tool.
9
- * It handles argument parsing and passes configuration to server.ts via function parameters.
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- // Use Commander for initial parsing
13
- const commander_1 = require("commander");
14
- // Import the server setup function
15
- const server_js_1 = require("./server.js"); // Adjust path if needed
16
- console.error(">>> BIN.TS Starting <<<");
17
- // Define version from package.json
18
- // Use import assertion for JSON in ES modules if possible, otherwise require is okay for CommonJS
19
- let version = 'unknown';
20
- try {
21
- // Assuming CommonJS based on package.json type="commonjs"
22
- const packageJson = require('../package.json');
23
- version = packageJson.version;
24
- }
25
- catch (e) {
26
- console.error("BIN.TS: Warning - Could not read package.json for version.", e);
27
- }
28
- commander_1.program
29
- .name('codesys-mcp-tool') // Set the command name users will see
30
- .description('Model Context Protocol (MCP) server for CODESYS automation platform')
31
- .version(version)
32
- .option(// Use options consistently
33
- '-p, --codesys-path <path>', 'Path to CODESYS executable (can contain spaces, use quotes if needed)', process.env.CODESYS_PATH || 'C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe' // Default AFTER reading env var
34
- )
35
- .option('-f, --codesys-profile <profile>', // Changed alias to 'f' to avoid conflict if you add other '-p' options
36
- 'CODESYS profile name (overrides CODESYS_PROFILE env var)', process.env.CODESYS_PROFILE || 'CODESYS V3.5 SP21' // Default AFTER reading env var
37
- )
38
- // Add workspace option if needed, defaults to cwd
39
- .option('-w, --workspace <dir>', 'Workspace directory for relative project paths', process.cwd() // Default to current working directory
40
- )
41
- // Add option to disable session management
42
- .option('--no-session', 'Disable session management (use one-time script execution only)', false)
43
- .parse(process.argv); // Parse the arguments
44
- const options = commander_1.program.opts();
45
- // --- Log the options Commander parsed ---
46
- console.error(`========================================`);
47
- console.error(`Starting CODESYS MCP Server v${version}`);
48
- console.error(`BIN.TS Options: ${JSON.stringify(options)}`);
49
- console.error(` CODESYS Path Used: ${options.codesysPath}`);
50
- console.error(` CODESYS Profile Used: ${options.codesysProfile}`);
51
- console.error(` Workspace Used: ${options.workspace}`);
52
- console.error(` Node.js: ${process.version}`);
53
- console.error(`========================================`);
54
- // --- End Logging ---
55
- // --- Prepare Config for Server ---
56
- const serverConfig = {
57
- codesysPath: options.codesysPath.trim(),
58
- profileName: options.codesysProfile.trim(),
59
- workspaceDir: options.workspace.trim(), // Pass workspace dir
60
- enableSessionManagement: options.session // Determined by --no-session flag (default: true)
61
- };
62
- console.error(`BIN.TS: Session management is ${serverConfig.enableSessionManagement ? 'enabled' : 'disabled'}`);
63
- // --- End Prepare Config ---
64
- // --- Call the server setup function ---
65
- console.error("BIN.TS: Calling startMcpServer...");
66
- (0, server_js_1.startMcpServer)(serverConfig)
67
- .then(() => {
68
- console.error("BIN.TS: startMcpServer finished (likely connected and listening).");
69
- // Keep process alive (server handles shutdown)
70
- })
71
- .catch(error => {
72
- console.error("BIN.TS: FATAL error during server startup:", error);
73
- process.exit(1);
74
- });
75
- console.error(">>> BIN.TS End of synchronous execution <<<");
@@ -1,149 +0,0 @@
1
- "use strict";
2
- /**
3
- * Session Path Diagnostic Tool
4
- * This script checks the consistency of paths used in the session management system.
5
- */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || (function () {
23
- var ownKeys = function(o) {
24
- ownKeys = Object.getOwnPropertyNames || function (o) {
25
- var ar = [];
26
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
- return ar;
28
- };
29
- return ownKeys(o);
30
- };
31
- return function (mod) {
32
- if (mod && mod.__esModule) return mod;
33
- var result = {};
34
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
- __setModuleDefault(result, mod);
36
- return result;
37
- };
38
- })();
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- const path = __importStar(require("path"));
41
- const os = __importStar(require("os"));
42
- const fs = __importStar(require("fs"));
43
- // Session directory paths from direct_session_command.ts
44
- const DIRECT_SESSION_DIR = path.join(os.tmpdir(), 'codesys_session');
45
- const DIRECT_COMMAND_FILE = path.join(DIRECT_SESSION_DIR, 'command.json');
46
- const DIRECT_RESULT_FILE = path.join(DIRECT_SESSION_DIR, 'result.json');
47
- const DIRECT_SESSION_LOCK_FILE = path.join(DIRECT_SESSION_DIR, 'session.lock');
48
- const DIRECT_STATE_FILE = path.join(DIRECT_SESSION_DIR, 'session_state.json');
49
- // Constants from sessionManager.ts
50
- const SESSION_DIR = path.join(os.tmpdir(), 'codesys_session');
51
- const COMMAND_FILE = 'command.json';
52
- const RESULT_FILE = 'result.json';
53
- const STATE_FILE = 'session_state.json';
54
- const SESSION_LOCK_FILE = 'session.lock';
55
- console.log("==== Session Path Diagnostics ====");
56
- console.log("\nBase session directory check:");
57
- console.log(`- DIRECT_SESSION_DIR: ${DIRECT_SESSION_DIR}`);
58
- console.log(`- SESSION_DIR: ${SESSION_DIR}`);
59
- console.log(` Direct and manager directories match: ${DIRECT_SESSION_DIR === SESSION_DIR}`);
60
- console.log("\nExpected file paths in direct_session_command.ts:");
61
- console.log(`- Command file: ${DIRECT_COMMAND_FILE}`);
62
- console.log(`- Result file: ${DIRECT_RESULT_FILE}`);
63
- console.log(`- Lock file: ${DIRECT_SESSION_LOCK_FILE}`);
64
- console.log(`- State file: ${DIRECT_STATE_FILE}`);
65
- console.log("\nFile names in sessionManager.ts:");
66
- console.log(`- Command file: ${COMMAND_FILE}`);
67
- console.log(`- Result file: ${RESULT_FILE}`);
68
- console.log(`- Lock file: ${SESSION_LOCK_FILE}`);
69
- console.log(`- State file: ${STATE_FILE}`);
70
- console.log("\nFile existence checks:");
71
- console.log(`- Base session directory exists: ${fs.existsSync(SESSION_DIR)}`);
72
- if (fs.existsSync(SESSION_DIR)) {
73
- console.log(`- Command file exists: ${fs.existsSync(DIRECT_COMMAND_FILE)}`);
74
- console.log(`- Result file exists: ${fs.existsSync(DIRECT_RESULT_FILE)}`);
75
- console.log(`- Lock file exists: ${fs.existsSync(DIRECT_SESSION_LOCK_FILE)}`);
76
- console.log(`- State file exists: ${fs.existsSync(DIRECT_STATE_FILE)}`);
77
- console.log("\nContent checks (if files exist):");
78
- if (fs.existsSync(DIRECT_COMMAND_FILE)) {
79
- try {
80
- const commandContent = fs.readFileSync(DIRECT_COMMAND_FILE, 'utf8');
81
- console.log(`- Command file content: ${commandContent.substring(0, 150)}...`);
82
- try {
83
- const commandJson = JSON.parse(commandContent);
84
- console.log(` Status: ${commandJson.status}`);
85
- console.log(` Has command object: ${commandJson.command !== null}`);
86
- if (commandJson.command) {
87
- console.log(` Command type: ${commandJson.command.type}`);
88
- }
89
- }
90
- catch (e) {
91
- console.log(` Error parsing command file JSON: ${e}`);
92
- }
93
- }
94
- catch (e) {
95
- console.log(`- Error reading command file: ${e}`);
96
- }
97
- }
98
- if (fs.existsSync(DIRECT_RESULT_FILE)) {
99
- try {
100
- const resultContent = fs.readFileSync(DIRECT_RESULT_FILE, 'utf8');
101
- console.log(`- Result file content: ${resultContent.substring(0, 150)}...`);
102
- try {
103
- const resultJson = JSON.parse(resultContent);
104
- console.log(` Status: ${resultJson.status}`);
105
- console.log(` Has result object: ${resultJson.result !== null}`);
106
- }
107
- catch (e) {
108
- console.log(` Error parsing result file JSON: ${e}`);
109
- }
110
- }
111
- catch (e) {
112
- console.log(`- Error reading result file: ${e}`);
113
- }
114
- }
115
- if (fs.existsSync(DIRECT_SESSION_LOCK_FILE)) {
116
- try {
117
- const lockContent = fs.readFileSync(DIRECT_SESSION_LOCK_FILE, 'utf8');
118
- console.log(`- Lock file content: ${lockContent}`);
119
- const lockTime = parseFloat(lockContent);
120
- const currentTime = Date.now() / 1000; // convert to seconds
121
- const lockAgeSeconds = currentTime - lockTime;
122
- console.log(` Lock age: ${lockAgeSeconds.toFixed(1)} seconds`);
123
- }
124
- catch (e) {
125
- console.log(`- Error reading lock file: ${e}`);
126
- }
127
- }
128
- if (fs.existsSync(DIRECT_STATE_FILE)) {
129
- try {
130
- const stateContent = fs.readFileSync(DIRECT_STATE_FILE, 'utf8');
131
- console.log(`- State file content: ${stateContent.substring(0, 150)}...`);
132
- try {
133
- const stateJson = JSON.parse(stateContent);
134
- console.log(` Session ID: ${stateJson.sessionId || stateJson.session_id}`);
135
- console.log(` Status: ${stateJson.status}`);
136
- }
137
- catch (e) {
138
- console.log(` Error parsing state file JSON: ${e}`);
139
- }
140
- }
141
- catch (e) {
142
- console.log(`- Error reading state file: ${e}`);
143
- }
144
- }
145
- }
146
- else {
147
- console.log(" Cannot check files as base directory does not exist");
148
- }
149
- console.log("\n==== End of Session Path Diagnostics ====");