@codesys/mcp-toolkit 1.1.4 → 1.2.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.
@@ -0,0 +1,23 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(grep:*)",
5
+ "Bash(grep:*)",
6
+ "Bash(npm version:*)",
7
+ "Bash(npm version:*)",
8
+ "Bash(cat:*)",
9
+ "Bash(cat:*)",
10
+ "Bash(npm run build:*)",
11
+ "Bash(npm run build:*)",
12
+ "Bash(npm install:*)",
13
+ "Bash(npm install:*)",
14
+ "Bash(npx tsc:*)",
15
+ "Bash(npx tsc:*)",
16
+ "Bash(npm pack:*)",
17
+ "Bash(npm pack:*)",
18
+ "Bash(npm publish:*)",
19
+ "Bash(npm publish:*)"
20
+ ],
21
+ "deny": []
22
+ }
23
+ }
package/CHANGELOG.md CHANGED
@@ -1,26 +1,32 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [1.0.0] - 2025-04-23
9
-
10
- ### Added
11
- - Initial release of the MCP server for CODESYS
12
- - Command-line interface with configuration options
13
- - Project management functionality:
14
- - Opening existing CODESYS projects
15
- - Creating new CODESYS projects
16
- - Saving projects
17
- - POU (Program Organization Unit) management:
18
- - Creating POUs (Programs, Function Blocks, Functions)
19
- - Setting POU code (declaration and implementation)
20
- - Creating properties and methods for Function Blocks
21
- - Project compilation support
22
- - Resources for querying:
23
- - Project status
24
- - Project structure
25
- - POU code
26
- - Documentation for installation and usage
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.2.0] - 2025-05-02
9
+ ### Added
10
+ - Session management functionality with `start_session`, `stop_session`, and `session_status` commands
11
+ - Persistent CODESYS sessions for improved performance with multiple operations
12
+ - Documentation for session management
13
+
14
+ ## [1.0.0] - 2025-04-23
15
+
16
+ ### Added
17
+ - Initial release of the MCP server for CODESYS
18
+ - Command-line interface with configuration options
19
+ - Project management functionality:
20
+ - Opening existing CODESYS projects
21
+ - Creating new CODESYS projects
22
+ - Saving projects
23
+ - POU (Program Organization Unit) management:
24
+ - Creating POUs (Programs, Function Blocks, Functions)
25
+ - Setting POU code (declaration and implementation)
26
+ - Creating properties and methods for Function Blocks
27
+ - Project compilation support
28
+ - Resources for querying:
29
+ - Project status
30
+ - Project structure
31
+ - POU code
32
+ - Documentation for installation and usage
package/CLAUDE.md ADDED
@@ -0,0 +1,26 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Build Commands
6
+ - `npm run build` - Compile TypeScript to JavaScript
7
+ - `npm start` - Start the MCP server
8
+ - `tsc` - Run TypeScript compiler manually
9
+
10
+ ## Coding Style Guidelines
11
+ - **Imports**: Import 'os' first if needed, then group related imports
12
+ - **Naming**: Use camelCase for variables/functions, PascalCase for classes/interfaces
13
+ - **Types**: TypeScript with interfaces for structured data, avoid implicit 'any'
14
+ - **Error Handling**: Check conditions early, throw meaningful errors with context
15
+ - **Comments**: Add JSDoc comments for functions, especially exported ones
16
+ - **Formatting**: Follow existing indentation (2 spaces) and code patterns
17
+ - **Path Handling**: Use path.join() for cross-platform compatibility
18
+ - **Promises**: Prefer async/await over raw promises when possible
19
+ - **Logging**: Use console.error for diagnostic/debug messages
20
+
21
+ ## Project Structure
22
+ - `/src` - TypeScript source files
23
+ - `/scripts` - Python scripts for CODESYS integration
24
+ - `/dist` - Compiled JavaScript (generated)
25
+ - `/docs` - Documentation files
26
+ - `/examples` - Example configurations and usage
package/CONTRIBUTING.md CHANGED
@@ -1,72 +1,72 @@
1
- # Contributing to @codesys/mcp-toolkit
2
-
3
- Thank you for considering contributing to the CODESYS MCP Toolkit! This document provides guidelines and steps for contributing.
4
-
5
- ## Code of Conduct
6
-
7
- Please be respectful and considerate of others when contributing to this project. We aim to foster an inclusive and welcoming community.
8
-
9
- ## How Can I Contribute?
10
-
11
- ### Reporting Bugs
12
-
13
- Bug reports help improve the project! When reporting bugs:
14
-
15
- 1. Check if the bug has already been reported
16
- 2. Use the bug report template
17
- 3. Include detailed steps to reproduce the issue
18
- 4. Describe the expected vs. actual behavior
19
- 5. Include screenshots if applicable
20
- 6. Provide environment details (OS, Node.js version, etc.)
21
-
22
- ### Suggesting Features
23
-
24
- We welcome feature suggestions! When suggesting features:
25
-
26
- 1. Describe the problem your feature would solve
27
- 2. Explain how your feature would work
28
- 3. Consider potential alternatives
29
- 4. Provide examples of similar features in other projects (if applicable)
30
-
31
- ### Pull Requests
32
-
33
- 1. Fork the repository
34
- 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
35
- 3. Make your changes
36
- 4. Run tests and ensure they pass
37
- 5. Commit your changes (`git commit -m 'Add amazing feature'`)
38
- 6. Push to your branch (`git push origin feature/amazing-feature`)
39
- 7. Open a Pull Request
40
-
41
- ## Development Setup
42
-
43
- 1. Clone the repository
44
- ```bash
45
- git clone https://github.com/yourusername/codesys-mcp-toolkit.git
46
- cd codesys-mcp-toolkit
47
- ```
48
-
49
- 2. Install dependencies
50
- ```bash
51
- npm install
52
- ```
53
-
54
- 3. Build the project
55
- ```bash
56
- npm run build
57
- ```
58
-
59
- ## Style Guidelines
60
-
61
- - Follow existing code formatting patterns
62
- - Use meaningful variable and function names
63
- - Add comments where necessary to explain complex logic
64
- - Update documentation when changing functionality
65
-
66
- ## Testing
67
-
68
- - Add tests for new features
69
- - Ensure all tests pass before submitting a PR
70
- - Consider edge cases in your tests
71
-
72
- Thank you for contributing!
1
+ # Contributing to @codesys/mcp-toolkit
2
+
3
+ Thank you for considering contributing to the CODESYS MCP Toolkit! This document provides guidelines and steps for contributing.
4
+
5
+ ## Code of Conduct
6
+
7
+ Please be respectful and considerate of others when contributing to this project. We aim to foster an inclusive and welcoming community.
8
+
9
+ ## How Can I Contribute?
10
+
11
+ ### Reporting Bugs
12
+
13
+ Bug reports help improve the project! When reporting bugs:
14
+
15
+ 1. Check if the bug has already been reported
16
+ 2. Use the bug report template
17
+ 3. Include detailed steps to reproduce the issue
18
+ 4. Describe the expected vs. actual behavior
19
+ 5. Include screenshots if applicable
20
+ 6. Provide environment details (OS, Node.js version, etc.)
21
+
22
+ ### Suggesting Features
23
+
24
+ We welcome feature suggestions! When suggesting features:
25
+
26
+ 1. Describe the problem your feature would solve
27
+ 2. Explain how your feature would work
28
+ 3. Consider potential alternatives
29
+ 4. Provide examples of similar features in other projects (if applicable)
30
+
31
+ ### Pull Requests
32
+
33
+ 1. Fork the repository
34
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
35
+ 3. Make your changes
36
+ 4. Run tests and ensure they pass
37
+ 5. Commit your changes (`git commit -m 'Add amazing feature'`)
38
+ 6. Push to your branch (`git push origin feature/amazing-feature`)
39
+ 7. Open a Pull Request
40
+
41
+ ## Development Setup
42
+
43
+ 1. Clone the repository
44
+ ```bash
45
+ git clone https://github.com/yourusername/codesys-mcp-toolkit.git
46
+ cd codesys-mcp-toolkit
47
+ ```
48
+
49
+ 2. Install dependencies
50
+ ```bash
51
+ npm install
52
+ ```
53
+
54
+ 3. Build the project
55
+ ```bash
56
+ npm run build
57
+ ```
58
+
59
+ ## Style Guidelines
60
+
61
+ - Follow existing code formatting patterns
62
+ - Use meaningful variable and function names
63
+ - Add comments where necessary to explain complex logic
64
+ - Update documentation when changing functionality
65
+
66
+ ## Testing
67
+
68
+ - Add tests for new features
69
+ - Ensure all tests pass before submitting a PR
70
+ - Consider edge cases in your tests
71
+
72
+ Thank you for contributing!
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 CODESYS MCP Server Contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 CODESYS MCP Server Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,145 +1,152 @@
1
-
2
- # @codesys/mcp-toolkit
3
-
4
- ![npm](https://img.shields.io/npm/v/@codesys/mcp-toolkit)
5
- ![License](https://img.shields.io/github/license/johannesPettersson80/codesys-mcp-toolkit)
6
- ![Node Version](https://img.shields.io/node/v/@codesys/mcp-toolkit)
7
-
8
- 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 via the CODESYS Scripting Engine.
9
-
10
- ## 🌟 Features
11
-
12
- - **Project Management**
13
- - Open existing CODESYS projects (`open_project`)
14
- - Create new projects from standard templates (`create_project`)
15
- - Save project changes (`save_project`)
16
-
17
- - **POU Management**
18
- - Create Programs, Function Blocks, and Functions (`create_pou`)
19
- - Set declaration and implementation code (`set_pou_code`)
20
- - Create properties for Function Blocks (`create_property`)
21
- - Create methods for Function Blocks (`create_method`)
22
- - Compile projects (`compile_project`)
23
-
24
- - **MCP Resources**
25
- - `codesys://project/status`: Check scripting status and currently open project state.
26
- - `codesys://project/{+project_path}/structure`: Retrieve the object structure of a specified project.
27
- - `codesys://project/{+project_path}/pou/{+pou_path}/code`: Read the declaration and implementation code for a specified POU, Method, or Property accessor.
28
-
29
- ## 📋 Prerequisites
30
-
31
- - **CODESYS V3**: A working CODESYS V3 installation (tested with 3.5 SP21) with the **Scripting Engine** component enabled during installation.
32
- - **Node.js**: Version 18.0.0 or later is recommended.
33
- - **MCP Client**: An MCP-enabled application (e.g., Claude Desktop).
34
-
35
- *(Note: CODESYS uses Python 2.7 internally for its scripting engine, but this toolkit handles the interaction; you do not need to manage Python separately.)*
36
-
37
- ## 🚀 Installation
38
-
39
- The recommended way to install is globally using npm:
40
-
41
- ```bash
42
- npm install -g @codesys/mcp-toolkit
43
- ```
44
-
45
- This installs the package globally, making the `codesys-mcp-tool` command available in your system's terminal PATH.
46
-
47
- *(Advanced users can also install from source for development - see CONTRIBUTING.md if available).*
48
-
49
- ## 🔧 Configuration (IMPORTANT!)
50
-
51
- This toolkit needs to know where your CODESYS installation is and which profile to use. Configuration is typically done within your MCP Client application (like Claude Desktop).
52
-
53
- ### Recommended Configuration Method (Direct Command)
54
-
55
- Due to potential environment variable issues (especially with `PATH`) when launching Node.js tools via wrappers like `npx` within certain host applications (e.g., Claude Desktop), it is **strongly recommended** to configure your MCP client to run the installed command `codesys-mcp-tool` **directly**.
56
-
57
- **Example for Claude Desktop (`settings.json` -> `mcpServers`):**
58
-
59
- ```json
60
- {
61
- "mcpServers": {
62
- // ... other servers ...
63
- "codesys_local": {
64
- "command": "codesys-mcp-tool", // <<< Use the direct command name
65
- "args": [
66
- // Pass arguments directly to the tool using flags
67
- "--codesys-path", "C:\\Program Files\\Path\\To\\Your\\CODESYS\\Common\\CODESYS.exe",
68
- "--codesys-profile", "Your CODESYS Profile Name"
69
- // Optional: Add --workspace "/path/to/your/projects" if needed
70
- ]
71
- }
72
- // ... other servers ...
73
- }
74
- }
75
- ```
76
-
77
- **Key Steps:**
78
- 1. Replace `"C:\\Program Files\\Path\\To\\Your\\CODESYS\\Common\\CODESYS.exe"` with the **full, correct path** to your specific `CODESYS.exe` file.
79
- 2. Replace `"Your CODESYS Profile Name"` with the **exact name** of the CODESYS profile you want to use (visible in the CODESYS UI).
80
- 3. Ensure the `codesys-mcp-tool` command is accessible in the system PATH where the MCP Client application runs. Global installation via `npm install -g` usually handles this.
81
- 4. Restart your MCP Client application (e.g., Claude Desktop) to apply the settings changes.
82
-
83
- ### Alternative Configuration (Using `npx` - Not Recommended)
84
-
85
- Launching with `npx` has been observed to cause immediate errors (`'C:\Program' is not recognized...`) in some environments, likely due to how `npx` handles the execution environment. **Use the Direct Command method above if possible.** If you must use `npx`:
86
-
87
- ```json
88
- // Example using npx (POTENTIALLY PROBLEMATIC - USE WITH CAUTION):
89
- {
90
- "mcpServers": {
91
- "codesys_local": {
92
- "command": "npx",
93
- "args": [
94
- "-y", // Tells npx to install temporarily if not found globally
95
- "@codesys/mcp-toolkit",
96
- // Arguments for the tool MUST come AFTER the package name
97
- "--codesys-path", "C:\\Program Files\\Path\\To\\Your\\CODESYS\\Common\\CODESYS.exe",
98
- "--codesys-profile", "Your CODESYS Profile Name"
99
- ]
100
- }
101
- }
102
- }
103
- ```
104
- *(Note: The `--` separator after the package name might sometimes help `npx` but is not guaranteed to fix the environment issue.)*
105
-
106
- ## 🛠️ Command-Line Arguments
107
-
108
- When running `codesys-mcp-tool` directly or configuring it, you can use these arguments:
109
-
110
- * `-p, --codesys-path <path>`: Full path to `CODESYS.exe`. (Required, overrides `CODESYS_PATH` env var, has a default but relying on it is not recommended).
111
- * `-f, --codesys-profile <profile>`: Name of the CODESYS profile. (Required, overrides `CODESYS_PROFILE` env var, has a default but relying on it is not recommended).
112
- * `-w, --workspace <dir>`: Workspace directory for resolving relative project paths passed to tools. Defaults to the directory where the command was launched (which might be unpredictable when run by another application). Setting this explicitly might be needed if using relative paths.
113
- * `-h, --help`: Show help message.
114
- * `--version`: Show package version.
115
-
116
- ## 🔍 Troubleshooting
117
-
118
- * **`'C:\Program' is not recognized...` error immediately after connection:**
119
- * **Cause:** This typically happens when the tool is launched via `npx` within an environment like Claude Desktop. The execution environment (`PATH` variable) provided to the process likely causes an internal CODESYS command (like running Python) to fail.
120
- * **Solution:** Configure your MCP Client to run the command **directly** (`"command": "codesys-mcp-tool"`) instead of using `"command": "npx"`. See the **Recommended Configuration Method** section above.
121
-
122
- * **Tool Fails / Errors in Output:**
123
- * Check the logs from your MCP Client application (e.g., Claude Desktop logs). Look for `INTEROP:` messages or Python `DEBUG:` / `ERROR:` messages printed to stderr from the CODESYS script execution.
124
- * Ensure the `--codesys-path` and `--codesys-profile` arguments passed to the command are correct and point to a valid CODESYS installation with scripting enabled.
125
- * Verify the project paths and object paths you are passing to tools are correct (use forward slashes `/`).
126
- * Make sure no other CODESYS instances are running in conflicting ways (e.g., holding a lock on the profile).
127
-
128
- * **`command not found: codesys-mcp-tool`:**
129
- * Ensure the package was installed globally (`npm install -g @codesys/mcp-toolkit`).
130
- * Ensure the npm global bin directory is in your system's `PATH` environment variable. Find it with `npm config get prefix` and add the `bin` subdirectory (or the main directory itself on Windows) to your PATH.
131
-
132
- * **Check Logs:**
133
- * Claude Desktop logs: `C:\Users\<YourUsername>\AppData\Roaming\Claude\logs\` (Windows)
134
-
135
- ## 🤝 Contributing
136
- Contributions, issues, and feature requests are welcome! Feel free to check the issues page. (Optionally add a CONTRIBUTING.md file with more details).
137
-
138
- ## 📝 License
139
- This project is licensed under the MIT License - see the LICENSE file for details.
140
-
141
- ## 🙏 Acknowledgements
142
- - The CODESYS GmbH team for the powerful CODESYS platform and its scripting engine.
143
- - The Model Context Protocol project for defining the interaction standard.
144
- - All contributors and users who help improve this toolkit.
145
-
1
+
2
+ # @codesys/mcp-toolkit
3
+
4
+ ![npm](https://img.shields.io/npm/v/@codesys/mcp-toolkit)
5
+ ![License](https://img.shields.io/github/license/johannesPettersson80/codesys-mcp-toolkit)
6
+ ![Node Version](https://img.shields.io/node/v/@codesys/mcp-toolkit)
7
+
8
+ 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 via the CODESYS Scripting Engine.
9
+
10
+ ## 🌟 Features
11
+
12
+ - **Project Management**
13
+ - Open existing CODESYS projects (`open_project`)
14
+ - Create new projects from standard templates (`create_project`)
15
+ - Save project changes (`save_project`)
16
+
17
+ - **POU Management**
18
+ - Create Programs, Function Blocks, and Functions (`create_pou`)
19
+ - Set declaration and implementation code (`set_pou_code`)
20
+ - Create properties for Function Blocks (`create_property`)
21
+ - Create methods for Function Blocks (`create_method`)
22
+ - Compile projects (`compile_project`)
23
+
24
+ - **Session Management** (New!)
25
+ - Start a persistent CODESYS session (`start_session`)
26
+ - Execute multiple operations without restarting CODESYS
27
+ - Check session status (`session_status`)
28
+ - Close the session when finished (`stop_session`)
29
+ - See [Session Management Documentation](docs/session_management.md) for details
30
+
31
+ - **MCP Resources**
32
+ - `codesys://project/status`: Check scripting status and currently open project state.
33
+ - `codesys://project/{+project_path}/structure`: Retrieve the object structure of a specified project.
34
+ - `codesys://project/{+project_path}/pou/{+pou_path}/code`: Read the declaration and implementation code for a specified POU, Method, or Property accessor.
35
+
36
+ ## 📋 Prerequisites
37
+
38
+ - **CODESYS V3**: A working CODESYS V3 installation (tested with 3.5 SP21) with the **Scripting Engine** component enabled during installation.
39
+ - **Node.js**: Version 18.0.0 or later is recommended.
40
+ - **MCP Client**: An MCP-enabled application (e.g., Claude Desktop).
41
+
42
+ *(Note: CODESYS uses Python 2.7 internally for its scripting engine, but this toolkit handles the interaction; you do not need to manage Python separately.)*
43
+
44
+ ## 🚀 Installation
45
+
46
+ The recommended way to install is globally using npm:
47
+
48
+ ```bash
49
+ npm install -g @codesys/mcp-toolkit
50
+ ```
51
+
52
+ This installs the package globally, making the `codesys-mcp-tool` command available in your system's terminal PATH.
53
+
54
+ *(Advanced users can also install from source for development - see CONTRIBUTING.md if available).*
55
+
56
+ ## 🔧 Configuration (IMPORTANT!)
57
+
58
+ This toolkit needs to know where your CODESYS installation is and which profile to use. Configuration is typically done within your MCP Client application (like Claude Desktop).
59
+
60
+ ### Recommended Configuration Method (Direct Command)
61
+
62
+ Due to potential environment variable issues (especially with `PATH`) when launching Node.js tools via wrappers like `npx` within certain host applications (e.g., Claude Desktop), it is **strongly recommended** to configure your MCP client to run the installed command `codesys-mcp-tool` **directly**.
63
+
64
+ **Example for Claude Desktop (`settings.json` -> `mcpServers`):**
65
+
66
+ ```json
67
+ {
68
+ "mcpServers": {
69
+ // ... other servers ...
70
+ "codesys_local": {
71
+ "command": "codesys-mcp-tool", // <<< Use the direct command name
72
+ "args": [
73
+ // Pass arguments directly to the tool using flags
74
+ "--codesys-path", "C:\\Program Files\\Path\\To\\Your\\CODESYS\\Common\\CODESYS.exe",
75
+ "--codesys-profile", "Your CODESYS Profile Name"
76
+ // Optional: Add --workspace "/path/to/your/projects" if needed
77
+ ]
78
+ }
79
+ // ... other servers ...
80
+ }
81
+ }
82
+ ```
83
+
84
+ **Key Steps:**
85
+ 1. Replace `"C:\\Program Files\\Path\\To\\Your\\CODESYS\\Common\\CODESYS.exe"` with the **full, correct path** to your specific `CODESYS.exe` file.
86
+ 2. Replace `"Your CODESYS Profile Name"` with the **exact name** of the CODESYS profile you want to use (visible in the CODESYS UI).
87
+ 3. Ensure the `codesys-mcp-tool` command is accessible in the system PATH where the MCP Client application runs. Global installation via `npm install -g` usually handles this.
88
+ 4. Restart your MCP Client application (e.g., Claude Desktop) to apply the settings changes.
89
+
90
+ ### Alternative Configuration (Using `npx` - Not Recommended)
91
+
92
+ Launching with `npx` has been observed to cause immediate errors (`'C:\Program' is not recognized...`) in some environments, likely due to how `npx` handles the execution environment. **Use the Direct Command method above if possible.** If you must use `npx`:
93
+
94
+ ```json
95
+ // Example using npx (POTENTIALLY PROBLEMATIC - USE WITH CAUTION):
96
+ {
97
+ "mcpServers": {
98
+ "codesys_local": {
99
+ "command": "npx",
100
+ "args": [
101
+ "-y", // Tells npx to install temporarily if not found globally
102
+ "@codesys/mcp-toolkit",
103
+ // Arguments for the tool MUST come AFTER the package name
104
+ "--codesys-path", "C:\\Program Files\\Path\\To\\Your\\CODESYS\\Common\\CODESYS.exe",
105
+ "--codesys-profile", "Your CODESYS Profile Name"
106
+ ]
107
+ }
108
+ }
109
+ }
110
+ ```
111
+ *(Note: The `--` separator after the package name might sometimes help `npx` but is not guaranteed to fix the environment issue.)*
112
+
113
+ ## 🛠️ Command-Line Arguments
114
+
115
+ When running `codesys-mcp-tool` directly or configuring it, you can use these arguments:
116
+
117
+ * `-p, --codesys-path <path>`: Full path to `CODESYS.exe`. (Required, overrides `CODESYS_PATH` env var, has a default but relying on it is not recommended).
118
+ * `-f, --codesys-profile <profile>`: Name of the CODESYS profile. (Required, overrides `CODESYS_PROFILE` env var, has a default but relying on it is not recommended).
119
+ * `-w, --workspace <dir>`: Workspace directory for resolving relative project paths passed to tools. Defaults to the directory where the command was launched (which might be unpredictable when run by another application). Setting this explicitly might be needed if using relative paths.
120
+ * `-h, --help`: Show help message.
121
+ * `--version`: Show package version.
122
+
123
+ ## 🔍 Troubleshooting
124
+
125
+ * **`'C:\Program' is not recognized...` error immediately after connection:**
126
+ * **Cause:** This typically happens when the tool is launched via `npx` within an environment like Claude Desktop. The execution environment (`PATH` variable) provided to the process likely causes an internal CODESYS command (like running Python) to fail.
127
+ * **Solution:** Configure your MCP Client to run the command **directly** (`"command": "codesys-mcp-tool"`) instead of using `"command": "npx"`. See the **Recommended Configuration Method** section above.
128
+
129
+ * **Tool Fails / Errors in Output:**
130
+ * Check the logs from your MCP Client application (e.g., Claude Desktop logs). Look for `INTEROP:` messages or Python `DEBUG:` / `ERROR:` messages printed to stderr from the CODESYS script execution.
131
+ * Ensure the `--codesys-path` and `--codesys-profile` arguments passed to the command are correct and point to a valid CODESYS installation with scripting enabled.
132
+ * Verify the project paths and object paths you are passing to tools are correct (use forward slashes `/`).
133
+ * Make sure no other CODESYS instances are running in conflicting ways (e.g., holding a lock on the profile).
134
+
135
+ * **`command not found: codesys-mcp-tool`:**
136
+ * Ensure the package was installed globally (`npm install -g @codesys/mcp-toolkit`).
137
+ * Ensure the npm global bin directory is in your system's `PATH` environment variable. Find it with `npm config get prefix` and add the `bin` subdirectory (or the main directory itself on Windows) to your PATH.
138
+
139
+ * **Check Logs:**
140
+ * Claude Desktop logs: `C:\Users\<YourUsername>\AppData\Roaming\Claude\logs\` (Windows)
141
+
142
+ ## 🤝 Contributing
143
+ Contributions, issues, and feature requests are welcome! Feel free to check the issues page. (Optionally add a CONTRIBUTING.md file with more details).
144
+
145
+ ## 📝 License
146
+ This project is licensed under the MIT License - see the LICENSE file for details.
147
+
148
+ ## 🙏 Acknowledgements
149
+ - The CODESYS GmbH team for the powerful CODESYS platform and its scripting engine.
150
+ - The Model Context Protocol project for defining the interaction standard.
151
+ - All contributors and users who help improve this toolkit.
152
+