@codesys/mcp-toolkit 1.1.4 → 1.2.1
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/.claude/settings.local.json +25 -0
- package/CHANGELOG.md +36 -26
- package/CLAUDE.md +26 -0
- package/CONTRIBUTING.md +72 -72
- package/LICENSE +21 -21
- package/README.md +152 -145
- package/README.md.enhanced +155 -155
- package/codesys-mcp-toolkit-1.2.0.tgz +0 -0
- package/codesys-mcp-toolkit-1.2.1.tgz +0 -0
- package/dist/codesys_interop.js +29 -2
- package/dist/scripts/check_status.py +21 -0
- package/dist/scripts/compile_project.py +65 -0
- package/dist/scripts/create_method.py +80 -0
- package/dist/scripts/create_pou.py +96 -0
- package/dist/scripts/create_project.py +54 -0
- package/dist/scripts/create_property.py +78 -0
- package/dist/scripts/ensure_project_open.py +154 -0
- package/dist/scripts/find_object_by_path.py +111 -0
- package/dist/scripts/get_pou_code.py +91 -0
- package/dist/scripts/get_project_structure.py +72 -0
- package/dist/scripts/open_project.py +25 -0
- package/dist/scripts/save_project.py +29 -0
- package/dist/scripts/set_pou_code.py +104 -0
- package/dist/server.js +124 -11
- package/dist/sessionManager.js +401 -0
- package/docs/index.md +26 -26
- package/docs/installation.md +84 -84
- package/docs/session_management.md +84 -0
- package/examples/README.md +78 -78
- package/examples/sample_config.json +32 -32
- package/package.json +51 -48
- package/scriptDoc.txt +8679 -8679
- package/scripts/build.js +25 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# CODESYS MCP Session Management
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The CODESYS MCP Toolkit now supports persistent sessions, which significantly improves performance when executing multiple operations in sequence. This document explains how to use the session management functionality.
|
|
6
|
+
|
|
7
|
+
## Why Session Management?
|
|
8
|
+
|
|
9
|
+
Previously, each MCP command would start a new CODESYS process, execute the operation, and then shut down the process. This approach is inefficient when performing multiple operations, such as:
|
|
10
|
+
|
|
11
|
+
- Creating multiple POUs
|
|
12
|
+
- Editing multiple code sections
|
|
13
|
+
- Complex project setup with many steps
|
|
14
|
+
|
|
15
|
+
With session management, you can:
|
|
16
|
+
1. Start a CODESYS session once
|
|
17
|
+
2. Execute multiple operations without restarting CODESYS
|
|
18
|
+
3. Close the session when you're finished
|
|
19
|
+
|
|
20
|
+
This can reduce execution time from minutes to seconds for complex tasks.
|
|
21
|
+
|
|
22
|
+
## Using Session Management with Claude
|
|
23
|
+
|
|
24
|
+
You can now use the `start_session` and `stop_session` commands in your Claude interactions with CODESYS:
|
|
25
|
+
|
|
26
|
+
### Starting a Session
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
Using the CODESYS Local server, run the start_session command to open a persistent CODESYS session.
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Using the Session
|
|
33
|
+
|
|
34
|
+
Once the session is started, all subsequent operations will use the persistent session automatically:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
Using the CODESYS Local server, create a new project at C:/MyProjects/Test.project
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
Using the CODESYS Local server, add a POU named MainProgram of type Program with ST language
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Checking Session Status
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
Using the CODESYS Local server, run the session_status command to check the current state of the CODESYS session.
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Stopping the Session
|
|
51
|
+
|
|
52
|
+
When you're done with all operations, you should close the session to free up resources:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
Using the CODESYS Local server, run the stop_session command to close the CODESYS session.
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Recommended Workflow
|
|
59
|
+
|
|
60
|
+
For the best performance, we recommend the following workflow when working with CODESYS projects:
|
|
61
|
+
|
|
62
|
+
1. Start the session: `Using the CODESYS Local server, run the start_session command to open a persistent CODESYS session.`
|
|
63
|
+
2. Execute all required operations (create project, create POUs, edit code, etc.)
|
|
64
|
+
3. Stop the session: `Using the CODESYS Local server, run the stop_session command to close the CODESYS session.`
|
|
65
|
+
|
|
66
|
+
## Technical Notes
|
|
67
|
+
|
|
68
|
+
- Sessions will automatically close after 5 minutes of inactivity to prevent resource leaks
|
|
69
|
+
- The session status can be in one of the following states: `IDLE`, `STARTING`, `RUNNING`, `BUSY`, `STOPPING`, `STOPPED`, or `ERROR`
|
|
70
|
+
- If a session operation fails, the system will automatically fall back to the standard one-time execution mode
|
|
71
|
+
|
|
72
|
+
## Limitations
|
|
73
|
+
|
|
74
|
+
- The session management is still experimental and may not work with all CODESYS operations
|
|
75
|
+
- Only one session can be active at a time per MCP server instance
|
|
76
|
+
- Some operations that modify the CODESYS environment itself may require restarting the session
|
|
77
|
+
|
|
78
|
+
## Troubleshooting
|
|
79
|
+
|
|
80
|
+
If you encounter issues with session management:
|
|
81
|
+
|
|
82
|
+
1. Check the session status: `Using the CODESYS Local server, run the session_status command`
|
|
83
|
+
2. If the status is `ERROR`, try stopping the session and starting a new one
|
|
84
|
+
3. If problems persist, fall back to using standard operations without explicit session management
|
package/examples/README.md
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
# CODESYS MCP Toolkit Examples
|
|
2
|
-
|
|
3
|
-
This directory contains examples of how to use the CODESYS MCP toolkit effectively.
|
|
4
|
-
|
|
5
|
-
## Example Configuration Files
|
|
6
|
-
|
|
7
|
-
### Basic MCP Configuration
|
|
8
|
-
|
|
9
|
-
`claude_desktop_config.json` - Example configuration for Claude Desktop:
|
|
10
|
-
|
|
11
|
-
```json
|
|
12
|
-
{
|
|
13
|
-
"mcpServers": {
|
|
14
|
-
"codesys_local": {
|
|
15
|
-
"command": "npx",
|
|
16
|
-
"args": [
|
|
17
|
-
"-y",
|
|
18
|
-
"@codesys/mcp-toolkit",
|
|
19
|
-
"--codesys-path", "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe",
|
|
20
|
-
"--codesys-profile", "CODESYS V3.5 SP21"
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Example Prompts
|
|
28
|
-
|
|
29
|
-
Here are some example prompts you can use with Claude Desktop:
|
|
30
|
-
|
|
31
|
-
### Create a Motor Controller Function Block
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
Using the CODESYS Local server, please create a MotorController function block with the following:
|
|
35
|
-
|
|
36
|
-
1. Properties:
|
|
37
|
-
- SpeedSetpoint (INT)
|
|
38
|
-
- ActualSpeed (INT)
|
|
39
|
-
- IsRunning (BOOL)
|
|
40
|
-
|
|
41
|
-
2. Methods:
|
|
42
|
-
- Start() - Sets IsRunning to TRUE
|
|
43
|
-
- Stop() - Sets IsRunning to FALSE
|
|
44
|
-
- SetSpeed(speed: INT) - Sets SpeedSetpoint to the given value
|
|
45
|
-
|
|
46
|
-
Create this in a new project at C:/MyProjects/MotorControl.project
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### Open and Analyze an Existing Project
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
Using the CODESYS Local server, please open the project at C:/MyProjects/ExistingProject.project and show me its structure. Then, show me the code for the main POU.
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Compile a Project
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
Using the CODESYS Local server, please open the project at C:/MyProjects/MyProject.project and compile it. Let me know if there are any errors.
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## Programmatic Usage Examples
|
|
62
|
-
|
|
63
|
-
If you're integrating directly with the server code, here are some examples:
|
|
64
|
-
|
|
65
|
-
### CLI Usage
|
|
66
|
-
|
|
67
|
-
Run the server directly:
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
codesys-mcp-toolkit --codesys-path "C:\Program Files\CODESYS 3.5.21.0\CODESYS\Common\CODESYS.exe" --codesys-profile "CODESYS V3.5 SP21"
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Use Cases
|
|
74
|
-
|
|
75
|
-
* Automated PLC project creation
|
|
76
|
-
* Standardized Function Block library management
|
|
77
|
-
* Continuous integration for CODESYS projects
|
|
78
|
-
* Documentation generation from CODESYS projects
|
|
1
|
+
# CODESYS MCP Toolkit Examples
|
|
2
|
+
|
|
3
|
+
This directory contains examples of how to use the CODESYS MCP toolkit effectively.
|
|
4
|
+
|
|
5
|
+
## Example Configuration Files
|
|
6
|
+
|
|
7
|
+
### Basic MCP Configuration
|
|
8
|
+
|
|
9
|
+
`claude_desktop_config.json` - Example configuration for Claude Desktop:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"mcpServers": {
|
|
14
|
+
"codesys_local": {
|
|
15
|
+
"command": "npx",
|
|
16
|
+
"args": [
|
|
17
|
+
"-y",
|
|
18
|
+
"@codesys/mcp-toolkit",
|
|
19
|
+
"--codesys-path", "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe",
|
|
20
|
+
"--codesys-profile", "CODESYS V3.5 SP21"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example Prompts
|
|
28
|
+
|
|
29
|
+
Here are some example prompts you can use with Claude Desktop:
|
|
30
|
+
|
|
31
|
+
### Create a Motor Controller Function Block
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Using the CODESYS Local server, please create a MotorController function block with the following:
|
|
35
|
+
|
|
36
|
+
1. Properties:
|
|
37
|
+
- SpeedSetpoint (INT)
|
|
38
|
+
- ActualSpeed (INT)
|
|
39
|
+
- IsRunning (BOOL)
|
|
40
|
+
|
|
41
|
+
2. Methods:
|
|
42
|
+
- Start() - Sets IsRunning to TRUE
|
|
43
|
+
- Stop() - Sets IsRunning to FALSE
|
|
44
|
+
- SetSpeed(speed: INT) - Sets SpeedSetpoint to the given value
|
|
45
|
+
|
|
46
|
+
Create this in a new project at C:/MyProjects/MotorControl.project
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Open and Analyze an Existing Project
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
Using the CODESYS Local server, please open the project at C:/MyProjects/ExistingProject.project and show me its structure. Then, show me the code for the main POU.
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Compile a Project
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
Using the CODESYS Local server, please open the project at C:/MyProjects/MyProject.project and compile it. Let me know if there are any errors.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Programmatic Usage Examples
|
|
62
|
+
|
|
63
|
+
If you're integrating directly with the server code, here are some examples:
|
|
64
|
+
|
|
65
|
+
### CLI Usage
|
|
66
|
+
|
|
67
|
+
Run the server directly:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
codesys-mcp-toolkit --codesys-path "C:\Program Files\CODESYS 3.5.21.0\CODESYS\Common\CODESYS.exe" --codesys-profile "CODESYS V3.5 SP21"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Use Cases
|
|
74
|
+
|
|
75
|
+
* Automated PLC project creation
|
|
76
|
+
* Standardized Function Block library management
|
|
77
|
+
* Continuous integration for CODESYS projects
|
|
78
|
+
* Documentation generation from CODESYS projects
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mcpServers": {
|
|
3
|
-
"codesys_local": {
|
|
4
|
-
"command": "npx",
|
|
5
|
-
"args": [
|
|
6
|
-
"-y",
|
|
7
|
-
"@codesys/mcp-toolkit",
|
|
8
|
-
"--codesys-path", "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe",
|
|
9
|
-
"--codesys-profile", "CODESYS V3.5 SP21"
|
|
10
|
-
]
|
|
11
|
-
},
|
|
12
|
-
"filesystem": {
|
|
13
|
-
"command": "npx",
|
|
14
|
-
"args": [
|
|
15
|
-
"-y",
|
|
16
|
-
"@modelcontextprotocol/server-filesystem",
|
|
17
|
-
"C:/MyProjects"
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
|
-
"memory": {
|
|
21
|
-
"command": "npx",
|
|
22
|
-
"args": [
|
|
23
|
-
"-y",
|
|
24
|
-
"@modelcontextprotocol/server-memory"
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
"puppeteer": {
|
|
28
|
-
"command": "npx",
|
|
29
|
-
"args": ["-y", "@modelcontextprotocol/server-puppeteer"]
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"mcpServers": {
|
|
3
|
+
"codesys_local": {
|
|
4
|
+
"command": "npx",
|
|
5
|
+
"args": [
|
|
6
|
+
"-y",
|
|
7
|
+
"@codesys/mcp-toolkit",
|
|
8
|
+
"--codesys-path", "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe",
|
|
9
|
+
"--codesys-profile", "CODESYS V3.5 SP21"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"filesystem": {
|
|
13
|
+
"command": "npx",
|
|
14
|
+
"args": [
|
|
15
|
+
"-y",
|
|
16
|
+
"@modelcontextprotocol/server-filesystem",
|
|
17
|
+
"C:/MyProjects"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"memory": {
|
|
21
|
+
"command": "npx",
|
|
22
|
+
"args": [
|
|
23
|
+
"-y",
|
|
24
|
+
"@modelcontextprotocol/server-memory"
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"puppeteer": {
|
|
28
|
+
"command": "npx",
|
|
29
|
+
"args": ["-y", "@modelcontextprotocol/server-puppeteer"]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,48 +1,51 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@codesys/mcp-toolkit",
|
|
3
|
-
"version": "1.1
|
|
4
|
-
"description": "Model Context Protocol (MCP) server for CODESYS automation platform",
|
|
5
|
-
"main": "dist/server.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"codesys-mcp-tool": "./dist/bin.js"
|
|
8
|
-
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"start": "node ./dist/server.js"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@codesys/mcp-toolkit",
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "Model Context Protocol (MCP) server for CODESYS automation platform",
|
|
5
|
+
"main": "dist/server.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"codesys-mcp-tool": "./dist/bin.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"build": "tsc && node scripts/build.js",
|
|
12
|
+
"start": "node ./dist/server.js",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"codesys",
|
|
17
|
+
"mcp",
|
|
18
|
+
"modelcontextprotocol",
|
|
19
|
+
"plc",
|
|
20
|
+
"automation",
|
|
21
|
+
"programming"
|
|
22
|
+
],
|
|
23
|
+
"author": "Your Name <your.email@example.com>",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"type": "commonjs",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/johannesPettersson80/codesys-mcp-toolkit.git"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/johannesPettersson80/codesys-mcp-toolkit#readme",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/johannesPettersson80/codesys-mcp-toolkit/issues"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@modelcontextprotocol/sdk": "^1.10.2",
|
|
39
|
+
"axios": "^1.6.8",
|
|
40
|
+
"commander": "^11.1.0",
|
|
41
|
+
"uuid": "^9.0.0",
|
|
42
|
+
"yargs": "^17.7.2",
|
|
43
|
+
"zod": "^3.24.3"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^20.14.1",
|
|
47
|
+
"@types/uuid": "^9.0.0",
|
|
48
|
+
"@types/yargs": "^17.0.33",
|
|
49
|
+
"typescript": "^5.5.3"
|
|
50
|
+
}
|
|
51
|
+
}
|