codesysultra 1.0.5 → 1.0.6

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.
@@ -329,9 +329,9 @@ function registerTools(server, config) {
329
329
  }
330
330
  }));
331
331
  server.tool("get_all_tools", // Tool Name
332
- "Retrieves all available tools and methods from the CODESYS project.", // Tool Description
332
+ "Retrieves all available CODESYS script engine APIs, modules, POU types, and implementation languages.", // Tool Description
333
333
  {
334
- projectFilePath: zod_1.z.string().describe("Path to the CODESYS project file (e.g., 'C:/Projects/MyPLC.project').")
334
+ projectFilePath: zod_1.z.string().describe("Path to a CODESYS project file (e.g., 'C:/Projects/MyPLC.project'). Used for context, but the tool retrieves system APIs regardless of specific project.")
335
335
  }, (args) => __awaiter(this, void 0, void 0, function* () {
336
336
  const { projectFilePath } = args;
337
337
  let absPath = path.normalize(path.isAbsolute(projectFilePath) ? projectFilePath : path.join(WORKSPACE_DIR, projectFilePath));
@@ -1,89 +1,143 @@
1
- import sys, scriptengine as script_engine, os, traceback, inspect
1
+ import sys, scriptengine as script_engine, os, traceback, inspect, pkgutil
2
2
 
3
- {{ENSURE_PROJECT_OPEN_PYTHON_SNIPPET}}
4
-
5
- def get_all_tools_and_methods():
3
+ def get_codesys_system_api():
6
4
  try:
7
- project = ensure_project_open(PROJECT_FILE_PATH)
5
+ print("\\n=== CODESYS Script Engine System API ===\\n")
8
6
 
9
- print("\\n=== CODESYS Available Tools and Methods ===\\n")
7
+ print("=== Script Engine Modules ===")
8
+ print("scriptengine module:")
9
+ for name in dir(script_engine):
10
+ if not name.startswith('_'):
11
+ try:
12
+ obj = getattr(script_engine, name)
13
+ obj_type = type(obj).__name__
14
+ print(" %s (%s)" % (name, obj_type))
15
+
16
+ if inspect.isclass(obj):
17
+ try:
18
+ methods = [m for m in dir(obj) if not m.startswith('_') and callable(getattr(obj, m))]
19
+ if methods:
20
+ print(" Available methods:")
21
+ for method in sorted(methods)[:20]:
22
+ print(" - %s" % method)
23
+ if len(methods) > 20:
24
+ print(" ... and %d more" % (len(methods) - 20))
25
+ except Exception as e:
26
+ print(" Error listing methods: %s" % e)
27
+ except Exception as e:
28
+ print(" Error: %s" % e)
29
+ except Exception as e:
30
+ print(" Error: %s" % e)
10
31
 
11
- def analyze_object(obj, indent=0, visited=None):
12
- if visited is None:
13
- visited = set()
14
-
15
- obj_id = id(obj)
16
- if obj_id in visited:
17
- return
18
- visited.add(obj_id)
19
-
20
- indent_str = " " * indent
21
- try:
22
- name = getattr(obj, 'get_name', lambda: str(obj))() or "Unnamed"
23
- obj_type = type(obj).__name__
24
- except:
25
- name = "Unknown"
26
- obj_type = "Unknown"
32
+ print("\\n=== Script Engine Functions ===")
33
+ script_functions = []
34
+ for name in dir(script_engine):
35
+ if not name.startswith('_') and callable(getattr(script_engine, name)):
36
+ script_functions.append(name)
37
+
38
+ for func in sorted(script_functions):
39
+ print(" - %s()" % func)
40
+
41
+ print("\\n=== Available Enums ===")
42
+ try:
43
+ enums = []
44
+ for name in dir(script_engine):
45
+ obj = getattr(script_engine, name)
46
+ if inspect.isclass(obj) and issubclass(obj, int):
47
+ enums.append((name, obj))
27
48
 
28
- print("%s- %s (%s)" % (indent_str, name, obj_type))
49
+ for enum_name, enum_obj in sorted(enums):
50
+ print("\\n%s:" % enum_name)
51
+ try:
52
+ members = [(name, value) for name, value in enum_obj.__dict__.items() if not name.startswith('_')]
53
+ for member_name, member_value in sorted(members, key=lambda x: x[0]):
54
+ print(" %s = %s" % (member_name, member_value))
55
+ except Exception as e:
56
+ print(" Error: %s" % e)
57
+ except Exception as e:
58
+ print(" Error listing enums: %s" % e)
59
+
60
+ print("\\n=== Project Management ===")
61
+ print("script_engine.projects module functions:")
62
+ project_functions = []
63
+ for name in dir(script_engine.projects):
64
+ if not name.startswith('_') and callable(getattr(script_engine.projects, name)):
65
+ project_functions.append(name)
66
+
67
+ for func in sorted(project_functions):
68
+ print(" - %s()" % func)
69
+
70
+ print("\\n=== POU Types ===")
71
+ try:
72
+ pou_types = []
73
+ for name in dir(script_engine):
74
+ obj = getattr(script_engine, name)
75
+ if inspect.isclass(obj) and 'PouType' in name:
76
+ pou_types.append((name, obj))
29
77
 
30
- try:
31
- members = inspect.getmembers(obj)
32
- methods = []
33
- properties = []
34
-
35
- for member_name, member in members:
36
- if member_name.startswith('_'):
37
- continue
38
- if inspect.ismethod(member) or inspect.isfunction(member):
39
- try:
40
- sig = inspect.signature(member)
41
- methods.append(" %s%s" % (indent_str, member_name))
42
- except:
43
- methods.append(" %s%s" % (indent_str, member_name))
44
- elif not inspect.ismethod(member) and not inspect.isfunction(member):
45
- try:
46
- val = getattr(obj, member_name)
47
- if not inspect.ismethod(val) and not inspect.isfunction(val):
48
- properties.append(" %s%s: %s" % (indent_str, member_name, type(val).__name__))
49
- except:
50
- pass
51
-
52
- if methods:
53
- print("%s Methods:" % indent_str)
54
- for method in methods:
55
- print(method)
56
-
57
- if properties:
58
- print("%s Properties:" % indent_str)
59
- for prop in properties:
60
- print(prop)
61
-
62
- except Exception as e:
63
- print("%s Error analyzing object: %s" % (indent_str, str(e)))
78
+ for type_name, type_obj in pou_types:
79
+ print(" %s:" % type_name)
80
+ try:
81
+ values = [(name, getattr(type_obj, name)) for name in dir(type_obj) if not name.startswith('_') and name.isupper()]
82
+ for value_name, value_value in values:
83
+ print(" %s = %s" % (value_name, value_value))
84
+ except Exception as e:
85
+ print(" Error: %s" % e)
86
+ except Exception as e:
87
+ print(" Error: %s" % e)
88
+
89
+ print("\\n=== Implementation Languages ===")
90
+ try:
91
+ impl_langs = []
92
+ for name in dir(script_engine):
93
+ obj = getattr(script_engine, name)
94
+ if inspect.isclass(obj) and 'ImplementationLanguage' in name:
95
+ impl_langs.append((name, obj))
64
96
 
65
- try:
66
- if hasattr(obj, 'get_children'):
67
- children = obj.get_children(False)
68
- if children:
69
- print("%s Children: %d" % (indent_str, len(children)))
70
- for child in children:
71
- analyze_object(child, indent + 1, visited)
72
- except Exception as e:
73
- print("%s Error getting children: %s" % (indent_str, str(e)))
97
+ for lang_name, lang_obj in impl_langs:
98
+ print(" %s:" % lang_name)
99
+ try:
100
+ values = [(name, getattr(lang_obj, name)) for name in dir(lang_obj) if not name.startswith('_') and name.isupper()]
101
+ for value_name, value_value in values:
102
+ print(" %s = %s" % (value_name, value_value))
103
+ except Exception as e:
104
+ print(" Error: %s" % e)
105
+ except Exception as e:
106
+ print(" Error: %s" % e)
107
+
108
+ print("\\n=== Version Info ===")
109
+ try:
110
+ version = getattr(script_engine, '__version__', 'Unknown')
111
+ print(" Script Engine Version: %s" % version)
112
+ except Exception as e:
113
+ print(" Error getting version: %s" % e)
74
114
 
75
- analyze_object(project, max_depth=3)
115
+ print("\\n=== API Usage Examples ===")
116
+ print("Example 1: Open a project")
117
+ print(" project = script_engine.projects.open('C:/Projects/MyProject.project')")
118
+ print("")
119
+ print("Example 2: Create a POU")
120
+ print(" parent = project.get_children()[0]")
121
+ print(" pou = parent.create_pou(name='MyPOU', type=script_engine.PouType.Program)")
122
+ print("")
123
+ print("Example 3: Get project structure")
124
+ print(" def analyze(obj, indent=0):")
125
+ print(" print(' ' * indent + obj.get_name())")
126
+ print(" if hasattr(obj, 'get_children'):")
127
+ print(" for child in obj.get_children():")
128
+ print(" analyze(child, indent+1)")
129
+ print(" analyze(project)")
76
130
 
77
131
  print("\\n=== Analysis Complete ===")
78
- print("SCRIPT_SUCCESS: All tools and methods retrieved successfully.")
132
+ print("SCRIPT_SUCCESS: CODESYS system API retrieved successfully.")
79
133
  sys.exit(0)
80
134
 
81
135
  except Exception as e:
82
136
  detailed_error = traceback.format_exc()
83
- error_message = "Error analyzing CODESYS project '%s': %s\\n%s" % (PROJECT_FILE_PATH, e, detailed_error)
137
+ error_message = "Error retrieving CODESYS system API: %s\\n%s" % (e, detailed_error)
84
138
  print(error_message)
85
139
  print("SCRIPT_ERROR: %s" % error_message)
86
140
  sys.exit(1)
87
141
 
88
142
  if __name__ == "__main__":
89
- get_all_tools_and_methods()
143
+ get_codesys_system_api()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codesysultra",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Model Context Protocol (MCP) server for CODESYS automation platform",
5
5
  "main": "dist/server.js",
6
6
  "bin": {