@wonderwhy-er/desktop-commander 0.1.5 → 0.1.7

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@wonderwhy-er/desktop-commander",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "MCP server for terminal operations and file editing",
5
5
  "license": "MIT",
6
6
  "author": "Eduards Ruzga",
@@ -8,13 +8,15 @@
8
8
  "bugs": "https://github.com/wonderwhy-er/ClaudeComputerCommander/issues",
9
9
  "type": "module",
10
10
  "bin": {
11
- "mcp-desktop-commander": "dist/index.js"
11
+ "mcp-desktop-commander": "dist/index.js",
12
+ "mcp-desktop-commander-setup": "setup-claude-server.js"
12
13
  },
13
14
  "files": [
14
- "dist"
15
+ "dist",
16
+ "setup-claude-server.js"
15
17
  ],
16
18
  "scripts": {
17
- "build": "tsc && shx chmod +x dist/*.js",
19
+ "build": "tsc && shx chmod +x dist/*.js setup-claude-server.js",
18
20
  "watch": "tsc --watch",
19
21
  "start": "node dist/index.js",
20
22
  "setup": "npm install && npm run build && node setup-claude-server.js",
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+ import { homedir, platform } from 'os';
3
+ import { join } from 'path';
4
+ import { readFileSync, writeFileSync, existsSync, appendFileSync } from 'fs';
5
+ import { fileURLToPath } from 'url';
6
+ import { dirname } from 'path';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+
11
+ // Determine OS and set appropriate config path and command
12
+ const isWindows = platform() === 'win32';
13
+ const claudeConfigPath = isWindows
14
+ ? join(process.env.APPDATA, 'Claude', 'claude_desktop_config.json')
15
+ : join(homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
16
+
17
+ // Setup logging
18
+ const LOG_FILE = join(__dirname, 'setup.log');
19
+
20
+ function logToFile(message, isError = false) {
21
+ const timestamp = new Date().toISOString();
22
+ const logMessage = `${timestamp} - ${isError ? 'ERROR: ' : ''}${message}\n`;
23
+ try {
24
+ appendFileSync(LOG_FILE, logMessage);
25
+ // For setup script, we'll still output to console but in JSON format
26
+ const jsonOutput = {
27
+ type: isError ? 'error' : 'info',
28
+ timestamp,
29
+ message
30
+ };
31
+ process.stdout.write(JSON.stringify(jsonOutput) + '\n');
32
+ } catch (err) {
33
+ // Last resort error handling
34
+ process.stderr.write(JSON.stringify({
35
+ type: 'error',
36
+ timestamp: new Date().toISOString(),
37
+ message: `Failed to write to log file: ${err.message}`
38
+ }) + '\n');
39
+ }
40
+ }
41
+
42
+ // Check if config file exists and create default if not
43
+ if (!existsSync(claudeConfigPath)) {
44
+ logToFile(`Claude config file not found at: ${claudeConfigPath}`);
45
+ logToFile('Creating default config file...');
46
+
47
+ // Create the directory if it doesn't exist
48
+ const configDir = dirname(claudeConfigPath);
49
+ if (!existsSync(configDir)) {
50
+ import('fs').then(fs => fs.mkdirSync(configDir, { recursive: true }));
51
+ }
52
+
53
+ // Create default config
54
+ const defaultConfig = {
55
+ "serverConfig": isWindows
56
+ ? {
57
+ "command": "cmd.exe",
58
+ "args": ["/c"]
59
+ }
60
+ : {
61
+ "command": "/bin/sh",
62
+ "args": ["-c"]
63
+ }
64
+ };
65
+
66
+ writeFileSync(claudeConfigPath, JSON.stringify(defaultConfig, null, 2));
67
+ logToFile('Default config file created. Please update it with your Claude API credentials.');
68
+ }
69
+
70
+ try {
71
+ // Read existing config
72
+ const configData = readFileSync(claudeConfigPath, 'utf8');
73
+ const config = JSON.parse(configData);
74
+
75
+ // Prepare the new server config based on OS
76
+ // Determine if running through npx or locally
77
+ const isNpx = process.env.npm_lifecycle_event === undefined;
78
+
79
+ const serverConfig = isNpx ? {
80
+ "command": "npx",
81
+ "args": [
82
+ "@wonderwhy-er/desktop-commander"
83
+ ]
84
+ } : {
85
+ "command": "node",
86
+ "args": [
87
+ join(__dirname, 'dist', 'index.js')
88
+ ]
89
+ };
90
+
91
+ // Add or update the terminal server config
92
+ if (!config.mcpServers) {
93
+ config.mcpServers = {};
94
+ }
95
+
96
+ config.mcpServers.desktopCommander = serverConfig;
97
+
98
+ // Add puppeteer server if not present
99
+ if (!config.mcpServers.puppeteer) {
100
+ config.mcpServers.puppeteer = {
101
+ "command": "npx",
102
+ "args": ["-y", "@modelcontextprotocol/server-puppeteer"]
103
+ };
104
+ }
105
+
106
+ // Write the updated config back
107
+ writeFileSync(claudeConfigPath, JSON.stringify(config, null, 2), 'utf8');
108
+
109
+ logToFile('Successfully added MCP servers to Claude configuration!');
110
+ logToFile(`Configuration location: ${claudeConfigPath}`);
111
+ logToFile('\nTo use the servers:\n1. Restart Claude if it\'s currently running\n2. The servers will be available in Claude\'s MCP server list');
112
+
113
+ } catch (error) {
114
+ logToFile(`Error updating Claude configuration: ${error}`, true);
115
+ process.exit(1);
116
+ }