@wonderwhy-er/desktop-commander 0.1.14 → 0.1.15

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