@codesys/mcp-toolkit 1.0.9 → 1.1.2

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/package.json CHANGED
@@ -1,45 +1,48 @@
1
- {
2
- "name": "@codesys/mcp-toolkit",
3
- "version": "1.0.9",
4
- "main": "dist/server.js",
5
- "bin": "./dist/bin.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
8
- "build": "tsc",
9
- "prepare": "npm run build"
10
- },
11
- "keywords": [
12
- "codesys",
13
- "mcp",
14
- "modelcontextprotocol",
15
- "plc",
16
- "automation",
17
- "programming"
18
- ],
19
- "author": "Your Name <your.email@example.com>",
20
- "license": "MIT",
21
- "type": "commonjs",
22
- "description": "Model Context Protocol (MCP) server for CODESYS automation platform",
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/johannesPettersson80/codesys-mcp-toolkit.git"
26
- },
27
- "homepage": "https://github.com/johannesPettersson80/codesys-mcp-toolkit#readme",
28
- "bugs": {
29
- "url": "https://github.com/johannesPettersson80/codesys-mcp-toolkit/issues"
30
- },
31
- "engines": {
32
- "node": ">=14.0.0"
33
- },
34
- "dependencies": {
35
- "@modelcontextprotocol/sdk": "^1.10.2",
36
- "axios": "^1.6.8",
37
- "commander": "^11.1.0",
38
- "zod": "^3.24.3"
39
- },
40
- "devDependencies": {
41
- "@types/commander": "^2.12.5",
42
- "@types/node": "^22.14.1",
43
- "typescript": "^5.8.3"
44
- }
45
- }
1
+ {
2
+ "name": "@codesys/mcp-toolkit",
3
+ "version": "1.1.2",
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
+ "keywords": [
15
+ "codesys",
16
+ "mcp",
17
+ "modelcontextprotocol",
18
+ "plc",
19
+ "automation",
20
+ "programming"
21
+ ],
22
+ "author": "Your Name <your.email@example.com>",
23
+ "license": "MIT",
24
+ "type": "commonjs",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/johannesPettersson80/codesys-mcp-toolkit.git"
28
+ },
29
+ "homepage": "https://github.com/johannesPettersson80/codesys-mcp-toolkit#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/johannesPettersson80/codesys-mcp-toolkit/issues"
32
+ },
33
+ "engines": {
34
+ "node": ">=18.0.0"
35
+ },
36
+ "dependencies": {
37
+ "@modelcontextprotocol/sdk": "^1.10.2",
38
+ "axios": "^1.6.8",
39
+ "commander": "^11.1.0",
40
+ "yargs": "^17.7.2",
41
+ "zod": "^3.24.3"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^20.14.1",
45
+ "@types/yargs": "^17.0.33",
46
+ "typescript": "^5.5.3"
47
+ }
48
+ }
@@ -1,150 +0,0 @@
1
- #!/usr/bin/env node
2
- const { exec } = require('child_process');
3
- const path = require('path');
4
- const fs = require('fs');
5
- const os = require('os');
6
- const { McpServer } = require('@modelcontextprotocol/sdk/server/mcp.js');
7
- const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
8
- const { z } = require('zod');
9
-
10
- console.error("Starting standalone CODESYS MCP server...");
11
-
12
- // Create a simple MCP server
13
- const server = new McpServer({
14
- name: "Standalone CODESYS MCP Server",
15
- version: "1.0.0",
16
- capabilities: { resources: {}, tools: {} }
17
- });
18
-
19
- // Direct implementation of executeCodesysScript
20
- async function executeCodesysScript(scriptContent, codesysExePath, codesysProfileName) {
21
- // Validate inputs
22
- if (!codesysExePath) throw new Error('CODESYS executable path was not provided');
23
- if (!codesysProfileName) throw new Error('CODESYS profile name was not provided');
24
-
25
- console.error(`DIRECT: Using CODESYS Path: ${codesysExePath}`);
26
- console.error(`DIRECT: Using CODESYS Profile: ${codesysProfileName}`);
27
-
28
- // Create temp script file
29
- const tempDir = os.tmpdir();
30
- const tempFileName = `codesys_script_${Date.now()}_${Math.random().toString(36).slice(2, 9)}.py`;
31
- const tempFilePath = path.join(tempDir, tempFileName);
32
-
33
- let output = '';
34
- let success = false;
35
-
36
- try {
37
- // Write script to temp file
38
- fs.writeFileSync(tempFilePath, scriptContent, 'latin1');
39
- console.error(`DIRECT: Wrote script to: ${tempFilePath}`);
40
-
41
- // Build command with proper quoting
42
- const commandWithArgs = `"${codesysExePath}" --profile="${codesysProfileName}" --noUI --runscript="${tempFilePath}"`;
43
- console.error(`DIRECT: Command: ${commandWithArgs}`);
44
-
45
- // Execute using exec
46
- success = await new Promise((resolve) => {
47
- exec(commandWithArgs, (error, stdout, stderr) => {
48
- if (stdout) output += stdout;
49
- if (stderr) output += stderr;
50
-
51
- console.error(`DIRECT: stdout: ${stdout.slice(0, 200)}${stdout.length > 200 ? '...' : ''}`);
52
- if (stderr) console.error(`DIRECT: stderr: ${stderr}`);
53
-
54
- if (error) {
55
- console.error(`DIRECT: Error: ${error.message}`);
56
- resolve(false);
57
- } else {
58
- resolve(true);
59
- }
60
- });
61
- });
62
-
63
- // Check for success/error markers in output
64
- if (output.includes('SCRIPT_SUCCESS')) {
65
- success = true;
66
- } else if (output.includes('SCRIPT_ERROR')) {
67
- success = false;
68
- }
69
-
70
- } catch (err) {
71
- console.error(`DIRECT: Exception: ${err.message}`);
72
- output += `\nError: ${err.message}`;
73
- success = false;
74
- } finally {
75
- // Clean up temp file
76
- try {
77
- fs.unlinkSync(tempFilePath);
78
- console.error(`DIRECT: Deleted temp file: ${tempFilePath}`);
79
- } catch (err) {
80
- console.error(`DIRECT: Failed to delete temp file: ${err.message}`);
81
- }
82
- }
83
-
84
- return { success, output };
85
- }
86
-
87
- // Implement a basic check_status tool
88
- server.tool("check_status", {}, async () => {
89
- try {
90
- const codesysPath = process.argv[2] || "C:\\Program Files\\CODESYS 3.5.21.0\\CODESYS\\Common\\CODESYS.exe";
91
- const profileName = process.argv[3] || "CODESYS V3.5 SP21";
92
-
93
- console.error(`DIRECT: Check Status with ${codesysPath} and ${profileName}`);
94
-
95
- const scriptContent = `
96
- import sys, scriptengine as script_engine, os
97
- try:
98
- print("Python script running")
99
- print("Checking CODESYS status...")
100
- scripting_ok = True
101
- primary_project = script_engine.projects.primary
102
- print("Primary project: " + str(primary_project))
103
- print("SCRIPT_SUCCESS: Status check completed")
104
- sys.exit(0)
105
- except Exception as e:
106
- print("Error: " + str(e))
107
- print("SCRIPT_ERROR: " + str(e))
108
- sys.exit(1)
109
- `;
110
-
111
- const result = await executeCodesysScript(scriptContent, codesysPath, profileName);
112
- return {
113
- content: [{ type: "text", text: `Status check ${result.success ? 'succeeded' : 'failed'}.\nOutput:\n${result.output}` }],
114
- isError: !result.success
115
- };
116
- } catch (err) {
117
- console.error(`DIRECT: Tool error: ${err.message}`);
118
- return { content: [{ type: "text", text: `Error: ${err.message}` }], isError: true };
119
- }
120
- });
121
-
122
- // Start the server
123
- async function startServer() {
124
- try {
125
- const transport = new StdioServerTransport();
126
- console.error("DIRECT: Connecting server via stdio...");
127
- await server.connect(transport);
128
- console.error("DIRECT: Server connected and listening");
129
- } catch (error) {
130
- console.error("DIRECT: Failed to start server:", error);
131
- process.exit(1);
132
- }
133
- }
134
-
135
- // Show args
136
- console.error(`DIRECT: Args: ${JSON.stringify(process.argv)}`);
137
-
138
- // Start the server
139
- startServer();
140
-
141
- // Handle shutdown
142
- process.on('SIGINT', () => {
143
- console.error('\nDIRECT: SIGINT received, shutting down...');
144
- process.exit(0);
145
- });
146
-
147
- process.on('SIGTERM', () => {
148
- console.error('\nDIRECT: SIGTERM received, shutting down...');
149
- process.exit(0);
150
- });