codesysultra 1.0.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.
- package/CHANGELOG.md +33 -0
- package/CONTRIBUTING.md +72 -0
- package/LICENSE +190 -0
- package/README.md +156 -0
- package/dist/bin.js +71 -0
- package/dist/codesys_interop.js +270 -0
- package/dist/handlers/resources.js +193 -0
- package/dist/handlers/tools.js +332 -0
- package/dist/server.js +122 -0
- package/dist/templates/check_status.py +21 -0
- package/dist/templates/compile_project.py +55 -0
- package/dist/templates/create_method.py +68 -0
- package/dist/templates/create_pou.py +68 -0
- package/dist/templates/create_project.py +54 -0
- package/dist/templates/create_property.py +66 -0
- package/dist/templates/ensure_project_open.py +154 -0
- package/dist/templates/find_object_by_path.py +111 -0
- package/dist/templates/get_pou_code.py +73 -0
- package/dist/templates/get_project_structure.py +64 -0
- package/dist/templates/open_project.py +19 -0
- package/dist/templates/save_project.py +23 -0
- package/dist/templates/set_pou_code.py +90 -0
- package/dist/templates.js +42 -0
- package/dist/types.js +8 -0
- package/dist/utils.js +29 -0
- package/docs/configuration.md +141 -0
- package/docs/index.md +26 -0
- package/docs/installation.md +84 -0
- package/examples/README.md +78 -0
- package/examples/sample_config.json +32 -0
- package/package.json +48 -0
- package/scripts/copy-templates.js +31 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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.1.16] - 2025-05-06
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Reverted to v1.1.3 code base which has working POU creation functionality
|
|
12
|
+
- Fixed path handling by using simpler approach from v1.1.3
|
|
13
|
+
- Restored original Application object finding logic that worked in v1.1.3
|
|
14
|
+
|
|
15
|
+
## [1.0.0] - 2025-04-23
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- Initial release of the MCP server for CODESYS
|
|
19
|
+
- Command-line interface with configuration options
|
|
20
|
+
- Project management functionality:
|
|
21
|
+
- Opening existing CODESYS projects
|
|
22
|
+
- Creating new CODESYS projects
|
|
23
|
+
- Saving projects
|
|
24
|
+
- POU (Program Organization Unit) management:
|
|
25
|
+
- Creating POUs (Programs, Function Blocks, Functions)
|
|
26
|
+
- Setting POU code (declaration and implementation)
|
|
27
|
+
- Creating properties and methods for Function Blocks
|
|
28
|
+
- Project compilation support
|
|
29
|
+
- Resources for querying:
|
|
30
|
+
- Project status
|
|
31
|
+
- Project structure
|
|
32
|
+
- POU code
|
|
33
|
+
- Documentation for installation and usage
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +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!
|
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Nirithy
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# CodeSysUltra
|
|
2
|
+
|
|
3
|
+
一个为 CODESYS V3 编程环境设计的强大工具包,通过模型上下文协议(MCP)实现与 CODESYS 的无缝集成。
|
|
4
|
+
|
|
5
|
+
## 简介
|
|
6
|
+
|
|
7
|
+
CodeSysUltra 是一个基于 Node.js 的 MCP 服务器,它允许你通过 MCP 客户端(如 Claude Desktop)与 CODESYS V3 进行交互。利用 CODESYS 的脚本引擎,你可以自动化项目管理、POU 创建、代码编辑和编译等任务。
|
|
8
|
+
|
|
9
|
+
## 核心功能
|
|
10
|
+
|
|
11
|
+
### 项目管理
|
|
12
|
+
- 打开现有的 CODESYS 项目
|
|
13
|
+
- 从标准模板创建新项目
|
|
14
|
+
- 保存项目更改
|
|
15
|
+
|
|
16
|
+
### POU 管理
|
|
17
|
+
- 创建程序、功能块和函数
|
|
18
|
+
- 设置声明和实现代码
|
|
19
|
+
- 为功能块创建属性
|
|
20
|
+
- 为功能块创建方法
|
|
21
|
+
- 编译项目
|
|
22
|
+
|
|
23
|
+
### MCP 资源
|
|
24
|
+
- `codesys://project/status` - 检查脚本状态和当前打开的项目状态
|
|
25
|
+
- `codesys://project/{+project_path}/structure` - 获取指定项目的对象结构
|
|
26
|
+
- `codesys://project/{+project_path}/pou/{+pou_path}/code` - 读取指定 POU、方法或属性访问器的声明和实现代码
|
|
27
|
+
|
|
28
|
+
## 环境要求
|
|
29
|
+
|
|
30
|
+
- **CODESYS V3**:已安装的 CODESYS V3(测试版本 3.5 SP21),并在安装时启用了**脚本引擎**组件
|
|
31
|
+
- **Node.js**:建议使用 18.0.0 或更高版本
|
|
32
|
+
- **MCP 客户端**:支持 MCP 的应用程序(例如 Claude Desktop)
|
|
33
|
+
|
|
34
|
+
> 注意:CODESYS 内部使用 Python 2.7 作为脚本引擎,但本工具包会处理所有交互,你无需单独管理 Python。
|
|
35
|
+
|
|
36
|
+
## 安装方法
|
|
37
|
+
|
|
38
|
+
### 全局安装(推荐)
|
|
39
|
+
|
|
40
|
+
使用 npm 进行全局安装:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install -g codesysultra
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
安装后,`codesys-mcp-tool` 命令将可在系统终端中使用。
|
|
47
|
+
|
|
48
|
+
### 从源码安装
|
|
49
|
+
|
|
50
|
+
高级用户也可以从源码进行开发安装(如有需要,请参考 CONTRIBUTING.md)。
|
|
51
|
+
|
|
52
|
+
## 配置说明
|
|
53
|
+
|
|
54
|
+
本工具包需要知道你的 CODESYS 安装位置和要使用的配置文件。配置通常在 MCP 客户端应用程序(如 Claude Desktop)中完成。
|
|
55
|
+
|
|
56
|
+
### 推荐配置方式(直接命令)
|
|
57
|
+
|
|
58
|
+
由于在某些宿主应用程序(如 Claude Desktop)中通过 `npx` 启动 Node.js 工具时可能会出现环境变量问题(特别是 `PATH`),**强烈建议**配置 MCP 客户端直接运行已安装的 `codesys-mcp-tool` 命令。
|
|
59
|
+
|
|
60
|
+
**Claude Desktop 配置示例(`settings.json` -> `mcpServers`):**
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"mcpServers": {
|
|
65
|
+
"codesys_local": {
|
|
66
|
+
"command": "codesys-mcp-tool",
|
|
67
|
+
"args": [
|
|
68
|
+
"--codesys-path", "C:\\Program Files\\CODESYS\\Common\\CODESYS.exe",
|
|
69
|
+
"--codesys-profile", "你的配置文件名称"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**配置步骤:**
|
|
77
|
+
1. 将 `"C:\\Program Files\\CODESYS\\Common\\CODESYS.exe"` 替换为你实际的 `CODESYS.exe` 文件的完整路径
|
|
78
|
+
2. 将 `"你的配置文件名称"` 替换为你要使用的 CODESYS 配置文件的确切名称(在 CODESYS 界面中可见)
|
|
79
|
+
3. 确保 `codesys-mcp-tool` 命令在 MCP 客户端运行的系统 PATH 中可访问。通过 `npm install -g` 全局安装通常会自动处理
|
|
80
|
+
4. 重启 MCP 客户端应用程序(如 Claude Desktop)以应用设置更改
|
|
81
|
+
|
|
82
|
+
### 备选配置方式(使用 npx - 不推荐)
|
|
83
|
+
|
|
84
|
+
使用 `npx` 启动在某些环境中已被观察到会导致立即错误(如 `'C:\Program' is not recognized...`),这可能是由于 `npx` 处理执行环境的方式造成的。**如果可能,请使用上述直接命令方法。**
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"mcpServers": {
|
|
89
|
+
"codesys_local": {
|
|
90
|
+
"command": "npx",
|
|
91
|
+
"args": [
|
|
92
|
+
"-y",
|
|
93
|
+
"codesysultra",
|
|
94
|
+
"--codesys-path", "C:\\Program Files\\CODESYS\\Common\\CODESYS.exe",
|
|
95
|
+
"--codesys-profile", "你的配置文件名称"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 命令行参数
|
|
103
|
+
|
|
104
|
+
直接运行 `codesys-mcp-tool` 或配置时,可以使用以下参数:
|
|
105
|
+
|
|
106
|
+
- `-p, --codesys-path <path>` - `CODESYS.exe` 的完整路径(必需,覆盖 `CODESYS_PATH` 环境变量)
|
|
107
|
+
- `-f, --codesys-profile <profile>` - CODESYS 配置文件名称(必需,覆盖 `CODESYS_PROFILE` 环境变量)
|
|
108
|
+
- `-w, --workspace <dir>` - 工作区目录,用于解析传递给工具的相对项目路径。默认为命令启动的目录
|
|
109
|
+
- `-h, --help` - 显示帮助信息
|
|
110
|
+
- `--version` - 显示包版本
|
|
111
|
+
|
|
112
|
+
## 常见问题
|
|
113
|
+
|
|
114
|
+
### 连接后立即出现 `'C:\Program' is not recognized...` 错误
|
|
115
|
+
|
|
116
|
+
**原因**:这通常发生在通过 `npx` 在 Claude Desktop 等环境中启动工具时。提供给进程的执行环境(`PATH` 变量)可能导致内部 CODESYS 命令(如运行 Python)失败。
|
|
117
|
+
|
|
118
|
+
**解决方案**:配置 MCP 客户端直接运行命令(`"command": "codesys-mcp-tool"`),而不是使用 `"command": "npx"`。参见上面的推荐配置方式。
|
|
119
|
+
|
|
120
|
+
### 工具失败 / 输出中出现错误
|
|
121
|
+
|
|
122
|
+
- 检查 MCP 客户端应用程序的日志(例如 Claude Desktop 日志)。查找 `INTEROP:` 消息或从 CODESYS 脚本执行打印到 stderr 的 Python `DEBUG:` / `ERROR:` 消息
|
|
123
|
+
- 确保传递给命令的 `--codesys-path` 和 `--codesys-profile` 参数正确,并指向启用了脚本的有效 CODESYS 安装
|
|
124
|
+
- 验证传递给工具的项目路径和对象路径是否正确(使用正斜杠 `/`)
|
|
125
|
+
- 确保没有其他 CODESYS 实例以冲突的方式运行(例如,锁定配置文件)
|
|
126
|
+
|
|
127
|
+
### 找不到命令 `codesys-mcp-tool`
|
|
128
|
+
|
|
129
|
+
- 确保已全局安装包(`npm install -g codesysultra`)
|
|
130
|
+
- 确保 npm 全局 bin 目录在系统的 `PATH` 环境变量中。使用 `npm config get prefix` 查找,并将 `bin` 子目录(Windows 上为主目录本身)添加到你的 PATH
|
|
131
|
+
|
|
132
|
+
### 查看日志
|
|
133
|
+
|
|
134
|
+
- Claude Desktop 日志:`C:\Users\<你的用户名>\AppData\Roaming\Claude\logs\`(Windows)
|
|
135
|
+
|
|
136
|
+
## 贡献指南
|
|
137
|
+
|
|
138
|
+
欢迎贡献、提出问题和功能请求!随时查看问题页面。
|
|
139
|
+
|
|
140
|
+
## 许可证
|
|
141
|
+
|
|
142
|
+
本项目采用 Apache License 2.0 许可证 - 详见 LICENSE 文件。
|
|
143
|
+
|
|
144
|
+
## 致谢
|
|
145
|
+
|
|
146
|
+
- CODESYS GmbH 团队提供了强大的 CODESYS 平台及其脚本引擎
|
|
147
|
+
- 模型上下文协议项目定义了交互标准
|
|
148
|
+
- 所有帮助改进此工具包的贡献者和用户
|
|
149
|
+
|
|
150
|
+
## 版本历史
|
|
151
|
+
|
|
152
|
+
当前版本:1.0
|
|
153
|
+
|
|
154
|
+
## 联系方式
|
|
155
|
+
|
|
156
|
+
如有问题或建议,请通过 GitHub Issues 联系我们。
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
.parse(process.argv); // Parse the arguments
|
|
42
|
+
const options = commander_1.program.opts();
|
|
43
|
+
// --- Log the options Commander parsed ---
|
|
44
|
+
console.error(`========================================`);
|
|
45
|
+
console.error(`Starting CODESYS MCP Server v${version}`);
|
|
46
|
+
console.error(`BIN.TS Options: ${JSON.stringify(options)}`);
|
|
47
|
+
console.error(` CODESYS Path Used: ${options.codesysPath}`);
|
|
48
|
+
console.error(` CODESYS Profile Used: ${options.codesysProfile}`);
|
|
49
|
+
console.error(` Workspace Used: ${options.workspace}`);
|
|
50
|
+
console.error(` Node.js: ${process.version}`);
|
|
51
|
+
console.error(`========================================`);
|
|
52
|
+
// --- End Logging ---
|
|
53
|
+
// --- Prepare Config for Server ---
|
|
54
|
+
const serverConfig = {
|
|
55
|
+
codesysPath: options.codesysPath.trim(),
|
|
56
|
+
profileName: options.codesysProfile.trim(),
|
|
57
|
+
workspaceDir: options.workspace.trim() // Pass workspace dir
|
|
58
|
+
};
|
|
59
|
+
// --- End Prepare Config ---
|
|
60
|
+
// --- Call the server setup function ---
|
|
61
|
+
console.error("BIN.TS: Calling startMcpServer...");
|
|
62
|
+
(0, server_js_1.startMcpServer)(serverConfig)
|
|
63
|
+
.then(() => {
|
|
64
|
+
console.error("BIN.TS: startMcpServer finished (likely connected and listening).");
|
|
65
|
+
// Keep process alive (server handles shutdown)
|
|
66
|
+
})
|
|
67
|
+
.catch(error => {
|
|
68
|
+
console.error("BIN.TS: FATAL error during server startup:", error);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
});
|
|
71
|
+
console.error(">>> BIN.TS End of synchronous execution <<<");
|