@codesys/mcp-toolkit 1.0.1 → 1.0.4

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/README.md CHANGED
@@ -1,254 +1,254 @@
1
- # @codesys/mcp-toolkit
2
-
3
- ![npm](https://img.shields.io/npm/v/@codesys/mcp-toolkit)
4
- ![License](https://img.shields.io/github/license/johannesPettersson80/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
- ## 🌟 Features
9
-
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)
45
-
46
- ```bash
47
- npm install -g @codesys/mcp-toolkit
48
- ```
49
-
50
- This installs the package globally, making the `codesys-mcp-toolkit` command available in your terminal.
51
-
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:
77
-
78
- ```json
79
- {
80
- "mcpServers": {
81
- "codesys_local": {
82
- "command": "npx",
83
- "args": [
84
- "-y",
85
- "@codesys/mcp-toolkit",
86
- "--codesys-path", "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe",
87
- "--codesys-profile", "CODESYS V3.5 SP21"
88
- ]
89
- }
90
- }
91
- }
92
- ```
93
-
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
97
-
98
- 4. Restart Claude Desktop to apply the changes
99
-
100
- ## 🛠️ Usage Examples
101
-
102
- ### Creating a Function Block with Properties
103
-
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
- ```
107
-
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
113
-
114
- ### Opening and Compiling a Project
115
-
116
- ```
117
- Ask Claude: "Can you open the project at C:/MyProjects/TestProject.project using CODESYS Local and compile it?"
118
- ```
119
-
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
1
+ # @codesys/mcp-toolkit
2
+
3
+ ![npm](https://img.shields.io/npm/v/@codesys/mcp-toolkit)
4
+ ![License](https://img.shields.io/github/license/johannesPettersson80/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
+ ## 🌟 Features
9
+
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)
45
+
46
+ ```bash
47
+ npm install -g @codesys/mcp-toolkit
48
+ ```
49
+
50
+ This installs the package globally, making the `codesys-mcp-toolkit` command available in your terminal.
51
+
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:
77
+
78
+ ```json
79
+ {
80
+ "mcpServers": {
81
+ "codesys_local": {
82
+ "command": "npx",
83
+ "args": [
84
+ "-y",
85
+ "@codesys/mcp-toolkit",
86
+ "--codesys-path", "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe",
87
+ "--codesys-profile", "CODESYS V3.5 SP21"
88
+ ]
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
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
97
+
98
+ 4. Restart Claude Desktop to apply the changes
99
+
100
+ ## 🛠️ Usage Examples
101
+
102
+ ### Creating a Function Block with Properties
103
+
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
+ ```
107
+
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
113
+
114
+ ### Opening and Compiling a Project
115
+
116
+ ```
117
+ Ask Claude: "Can you open the project at C:/MyProjects/TestProject.project using CODESYS Local and compile it?"
118
+ ```
119
+
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