@codesys/mcp-toolkit 1.0.1 → 1.0.3

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,7 +5,26 @@ 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.0.0] - 2025-04-23
8
+ ## [1.0.3] - 2025-04-23
9
+
10
+ ### Fixed
11
+ - Fixed path handling for CODESYS executable paths with spaces
12
+ - Updated spawn method to use shell:true with quoted paths
13
+ - Improved documentation and sample configuration
14
+
15
+ ## [1.0.2] - 2025-04-22
16
+
17
+ ### Added
18
+ - Improved error handling for script execution
19
+ - Better feedback in console logs
20
+
21
+ ## [1.0.1] - 2025-04-21
22
+
23
+ ### Fixed
24
+ - Resolved issues with project path resolution
25
+ - Fixed property accessor path handling
26
+
27
+ ## [1.0.0] - 2025-04-20
9
28
 
10
29
  ### Added
11
30
  - Initial release of the MCP server for CODESYS
package/README.md CHANGED
@@ -1,79 +1,20 @@
1
- # @codesys/mcp-toolkit
1
+ # CODESYS MCP Toolkit
2
2
 
3
- ![npm](https://img.shields.io/npm/v/@codesys/mcp-toolkit)
4
- ![License](https://img.shields.io/github/license/johannesPettersson80/codesys-mcp-toolkit)
3
+ A Model Context Protocol (MCP) toolkit for interfacing between Claude and CODESYS programming environments.
5
4
 
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.
5
+ ## Overview
7
6
 
8
- ## 🌟 Features
7
+ This toolkit provides a bridge between Claude Desktop and CODESYS V3, allowing Claude to interact with CODESYS projects through a standardized Model Context Protocol (MCP).
9
8
 
10
- - **Project Management**
11
- - Open existing CODESYS projects
12
- - Create new projects from templates
13
- - Save project changes
14
-
15
- - **POU Management**
16
- - Create Programs, Function Blocks, and Functions
17
- - Set declaration and implementation code
18
- - Create properties and methods for Function Blocks
19
- - Compile projects
20
-
21
- - **MCP Resources**
22
- - `codesys://project/status`: Check scripting status and project state
23
- - `codesys://project/{+project_path}/structure`: Retrieve project structure
24
- - `codesys://project/{+project_path}/pou/{+pou_path}/code`: Read POU code
25
-
26
- - **MCP Tools**
27
- - `open_project`: Open specified CODESYS project
28
- - `create_project`: Create new CODESYS project
29
- - `save_project`: Save currently open project
30
- - `create_pou`: Create new Program, Function Block, or Function
31
- - `set_pou_code`: Update code for a specified POU
32
- - `create_property`: Create property in a Function Block
33
- - `create_method`: Create method in a Function Block
34
- - `compile_project`: Compile the open project
35
-
36
- ## 📋 Prerequisites
37
-
38
- - **CODESYS V3**: A working CODESYS V3 installation (tested with 3.5 SP21) with **Scripting Engine** component enabled
39
- - **Node.js**: Version 18 or later required
40
- - **MCP Client**: An MCP-enabled application (e.g., Claude Desktop)
41
-
42
- ## 🚀 Installation
43
-
44
- ### Option 1: Install from npm (Recommended)
9
+ ## Installation
45
10
 
46
11
  ```bash
47
- npm install -g @codesys/mcp-toolkit
12
+ npm install @codesys/mcp-toolkit
48
13
  ```
49
14
 
50
- This installs the package globally, making the `codesys-mcp-toolkit` command available in your terminal.
15
+ ## Configuration
51
16
 
52
- ### Option 2: Install from Source
53
-
54
- ```bash
55
- # Clone the repository
56
- git clone https://github.com/johannesPettersson80/codesys-mcp-toolkit.git
57
- cd codesys-mcp-toolkit
58
-
59
- # Install dependencies
60
- npm install
61
-
62
- # Build the project
63
- npm run build
64
-
65
- # Install globally
66
- npm install -g .
67
- ```
68
-
69
- ## 🔧 Configuration
70
-
71
- ### Claude Desktop Configuration
72
-
73
- 1. Locate your Claude Desktop configuration file:
74
- - Windows: `C:\Users\<YourUsername>\AppData\Roaming\Claude\claude_desktop_config.json`
75
-
76
- 2. Add the CODESYS MCP server entry:
17
+ Add the following to your Claude Desktop configuration file (`claude_desktop_config.json`):
77
18
 
78
19
  ```json
79
20
  {
@@ -91,164 +32,48 @@ npm install -g .
91
32
  }
92
33
  ```
93
34
 
94
- 3. Customize the paths to match your CODESYS installation:
95
- - `--codesys-path`: Path to your CODESYS.exe
96
- - `--codesys-profile`: Your CODESYS profile name
35
+ ### Path Handling
97
36
 
98
- 4. Restart Claude Desktop to apply the changes
37
+ The toolkit now properly handles paths with spaces when launching CODESYS. You don't need to add additional quotes in your configuration.
99
38
 
100
- ## 🛠️ Usage Examples
39
+ ## Available Tools
101
40
 
102
- ### Creating a Function Block with Properties
41
+ This toolkit provides several MCP tools for interacting with CODESYS projects:
103
42
 
104
- ```
105
- Ask Claude: "Using the CODESYS Local server, please create a Motor Controller function block with Start and Stop methods, plus CurrentSpeed property."
106
- ```
43
+ - `open_project`: Open an existing CODESYS project
44
+ - `create_project`: Create a new CODESYS project from a template
45
+ - `save_project`: Save the current CODESYS project
46
+ - `create_pou`: Create a new Program Organization Unit (POU)
47
+ - `set_pou_code`: Set the declaration and implementation code for a POU
48
+ - `create_property`: Create a property in a Function Block
49
+ - `create_method`: Create a method in a Function Block
50
+ - `compile_project`: Compile the current CODESYS project
107
51
 
108
- Claude will execute these MCP tool calls:
109
- 1. `create_pou` to create the MotorController Function Block
110
- 2. `create_property` to add the CurrentSpeed property
111
- 3. `create_method` to add Start and Stop methods
112
- 4. `set_pou_code` to implement each method and property
52
+ ## Example Usage
113
53
 
114
- ### Opening and Compiling a Project
54
+ Claude can use these tools to perform complex CODESYS operations, for example:
115
55
 
116
56
  ```
117
- Ask Claude: "Can you open the project at C:/MyProjects/TestProject.project using CODESYS Local and compile it?"
57
+ Create a new motor controller FB with properties for speed, state, and temperature
118
58
  ```
119
59
 
120
- Claude will:
121
- 1. Use `open_project` to open the specified file
122
- 2. Use `compile_project` to build the application
123
-
124
- ## 🔍 Troubleshooting
125
-
126
- ### Common Issues
127
-
128
- - **Connection Failures**: Check Claude Desktop logs for error messages
129
- - **Path Issues**: Ensure CODESYS executable path is correct
130
- - **Profile Mismatch**: Verify profile name matches exactly
131
- - **Permission Problems**: Ensure Claude has appropriate permissions
132
- - **CODESYS Already Running**: Close other CODESYS instances
133
-
134
- ### Debug Logs
135
-
136
- Check logs at:
137
- - Windows: `C:\Users\<YourUsername>\AppData\Roaming\Claude\logs\`
138
-
139
- ## 📖 Detailed OOP Workflow Guide
140
-
141
- When creating object-oriented structures with this toolkit, follow this step-by-step workflow for best results:
142
-
143
- ### Creating Function Blocks with Properties and Methods
144
-
145
- 1. **Create the Function Block**
146
- ```
147
- create_pou(
148
- projectFilePath: "path/to/project.project",
149
- name: "PumpController",
150
- type: "FunctionBlock",
151
- language: "ST",
152
- parentPath: "Application"
153
- )
154
- ```
155
-
156
- 2. **Create Properties**
157
- ```
158
- create_property(
159
- projectFilePath: "path/to/project.project",
160
- parentPouPath: "Application/PumpController",
161
- propertyName: "SpeedSetpoint",
162
- propertyType: "INT"
163
- )
164
- ```
165
-
166
- 3. **Create Methods**
167
- ```
168
- create_method(
169
- projectFilePath: "path/to/project.project",
170
- parentPouPath: "Application/PumpController",
171
- methodName: "Start",
172
- returnType: "" // Empty for no return value
173
- )
174
- ```
175
-
176
- 4. **Implement Methods**
177
- ```
178
- set_pou_code(
179
- projectFilePath: "path/to/project.project",
180
- pouPath: "Application/PumpController/Start",
181
- implementationCode: "isRunning := TRUE;"
182
- )
183
- ```
184
-
185
- 5. **Declare Backing Variables**
186
- ```
187
- set_pou_code(
188
- projectFilePath: "path/to/project.project",
189
- pouPath: "Application/PumpController",
190
- declarationCode: "VAR PRIVATE\n _speedSetpoint : INT;\n _isRunning : BOOL;\nEND_VAR"
191
- )
192
- ```
193
-
194
- 6. **Implement Property Accessors**
195
- - For GET accessor:
196
- ```
197
- set_pou_code(
198
- projectFilePath: "path/to/project.project",
199
- pouPath: "Application/PumpController/SpeedSetpoint/Get",
200
- implementationCode: "SpeedSetpoint := _speedSetpoint;"
201
- )
202
- ```
203
- - For SET accessor:
204
- ```
205
- set_pou_code(
206
- projectFilePath: "path/to/project.project",
207
- pouPath: "Application/PumpController/SpeedSetpoint/Set",
208
- implementationCode: "_speedSetpoint := SpeedSetpoint;"
209
- )
210
- ```
211
-
212
- 7. **Save Project**
213
- ```
214
- save_project(
215
- projectFilePath: "path/to/project.project"
216
- )
217
- ```
218
-
219
- ### Important Path Usage Notes
220
-
221
- - Use forward slashes (`/`) in all object paths
222
- - Ensure paths are precise and target the specific object
223
- - For property accessors, always specify the full path including `/Get` or `/Set`
224
-
225
- ### CODESYS Naming Conventions
226
-
227
- - **POUs** (Programs, FBs, Functions): PascalCase (e.g., `MotorControl`)
228
- - **Interfaces**: PascalCase with I_ prefix (e.g., `I_AxisCommands`)
229
- - **DUTs** (Structs, Enums): PascalCase (e.g., `MachineState`, `E_OperationMode`)
230
- - **Variables**: camelCase (e.g., `motorSpeed`)
231
- - **Backing variables**: camelCase with _ prefix (e.g., `_speedSetpoint`)
232
- - **Constants**: UPPER_SNAKE_CASE (e.g., `MAX_RPM`)
233
- - **Properties & Methods**: PascalCase with descriptive names
234
-
235
- ### Recommended Property Naming
236
-
237
- - Control values: Add `Setpoint` suffix (e.g., `SpeedSetpoint`)
238
- - Measured values: Add `Actual` suffix (e.g., `TemperatureActual`)
239
- - Status indicators: Use `Is` or `Has` prefix (e.g., `IsRunning`, `HasError`)
240
- - Configuration: Use descriptive prefixes (e.g., `MaxSpeed`, `MinPressure`)
241
-
242
- ## 🤝 Contributing
243
-
244
- Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
245
-
246
- ## 📝 License
247
-
248
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
249
-
250
- ## 🙏 Acknowledgements
251
-
252
- - The [CODESYS](https://www.codesys.com/) team for their scripting engine
253
- - [Model Context Protocol](https://github.com/m-ld/model-context-protocol) project
254
- - All contributors who have helped improve this toolkit
60
+ Claude will then:
61
+ 1. Create a Function Block (FB) in your CODESYS project
62
+ 2. Add appropriate properties with getters and setters
63
+ 3. Add methods for control operations
64
+ 4. Implement the logic in Structured Text (ST)
65
+
66
+ ## Troubleshooting
67
+
68
+ ### Path Issues
69
+
70
+ If you encounter issues with paths:
71
+
72
+ - Ensure your CODESYS path is correct in the configuration
73
+ - Make sure the toolkit can locate your CODESYS installation
74
+ - Verify the CODESYS profile name matches your installation
75
+
76
+ ### Common Error Messages
77
+
78
+ - `C:\Program is not recognized...`: Update to the latest version of the toolkit which fixes path handling with spaces
79
+ - `Failed to start CODESYS process`: Check if CODESYS is installed at the specified path
@@ -88,10 +88,11 @@ function executeCodesysScript(scriptContent, codesysExePath, codesysProfileName)
88
88
  `--runscript=${tempFilePath}`
89
89
  ];
90
90
  process.stderr.write(`Executing: "${codesysExePath}" with args: ${JSON.stringify(argsArray)}\n`);
91
- // Spawn the CODESYS process WITHOUT shell:true for the main command
92
- const codesysProcess = (0, child_process_1.spawn)(codesysExePath, argsArray, {
91
+ process.stderr.write('>>>> DEBUG: Attempting spawn with shell:true to handle paths with spaces. <<<<\n');
92
+ // Spawn the CODESYS process WITH shell:true to handle paths with spaces properly
93
+ const codesysProcess = (0, child_process_1.spawn)(`"${codesysExePath}"`, argsArray, {
93
94
  stdio: ['ignore', 'pipe', 'pipe'],
94
- shell: false
95
+ shell: true
95
96
  });
96
97
  // Capture stdout & stderr
97
98
  codesysProcess.stdout.on('data', (data) => {
@@ -8,6 +8,7 @@
8
8
  "--codesys-path", "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe",
9
9
  "--codesys-profile", "CODESYS V3.5 SP21"
10
10
  ]
11
+ // Note: Path with spaces is handled by the toolkit now. No need for additional quotes.
11
12
  },
12
13
  "filesystem": {
13
14
  "command": "npx",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codesys/mcp-toolkit",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "dist/server.js",
5
5
  "bin": {
6
6
  "codesys-mcp-toolkit": "./dist/bin.js"