secondbrainos-mcp-server 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/bin/cli.js +112 -10
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -7,6 +7,7 @@ import { fileURLToPath } from 'url';
7
7
  import { homedir } from 'os';
8
8
  import { exec } from 'child_process';
9
9
  import { promisify } from 'util';
10
+ import process from 'process';
10
11
 
11
12
  const execAsync = promisify(exec);
12
13
 
@@ -14,10 +15,109 @@ const execAsync = promisify(exec);
14
15
  const __filename = fileURLToPath(import.meta.url);
15
16
  const __dirname = path.dirname(__filename);
16
17
 
18
+ /**
19
+ * Find the Node.js executable in a cross-platform way
20
+ */
21
+ async function findNodeExecutable() {
22
+ // Check if we're on Windows
23
+ const isWindows = process.platform === 'win32';
24
+
25
+ try {
26
+ let nodePath;
27
+
28
+ if (isWindows) {
29
+ // On Windows, use 'where' command
30
+ try {
31
+ const { stdout } = await execAsync('where node');
32
+ // Take the first line of output as that's typically the path
33
+ nodePath = stdout.split('\r\n')[0].trim();
34
+ } catch (error) {
35
+ // If 'where' fails, try using the process.execPath (path to current Node.js executable)
36
+ nodePath = process.execPath;
37
+ }
38
+ } else {
39
+ // On macOS/Linux, use 'which' command
40
+ try {
41
+ const { stdout } = await execAsync('which node');
42
+ nodePath = stdout.trim();
43
+ } catch (error) {
44
+ // If 'which' fails, try using the process.execPath
45
+ nodePath = process.execPath;
46
+ }
47
+ }
48
+
49
+ // Verify we have a valid path
50
+ await fs.access(nodePath);
51
+ return nodePath;
52
+ } catch (error) {
53
+ // If all methods fail, use 'node' and hope it's in the PATH
54
+ console.warn('Warning: Unable to determine exact path to Node.js executable. Using "node" command.');
55
+ return 'node';
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Get the platform-specific path for the Claude configuration directory
61
+ */
62
+ function getClaudeConfigPath() {
63
+ const platform = process.platform;
64
+
65
+ if (platform === 'win32') {
66
+ // Windows: %APPDATA%\Claude
67
+ return path.join(process.env.APPDATA || path.join(homedir(), 'AppData', 'Roaming'), 'Claude');
68
+ } else if (platform === 'darwin') {
69
+ // macOS: ~/Library/Application Support/Claude
70
+ return path.join(homedir(), 'Library', 'Application Support', 'Claude');
71
+ } else {
72
+ // Linux/other: ~/.config/claude
73
+ return path.join(homedir(), '.config', 'claude');
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Get platform-specific log path for instructions
79
+ */
80
+ function getLogPath() {
81
+ const platform = process.platform;
82
+
83
+ if (platform === 'win32') {
84
+ // Windows log path
85
+ return '%APPDATA%\\Claude\\Logs\\mcp*.log';
86
+ } else if (platform === 'darwin') {
87
+ // macOS log path
88
+ return '~/Library/Logs/Claude/mcp*.log';
89
+ } else {
90
+ // Linux/other log path
91
+ return '~/.local/share/claude/logs/mcp*.log';
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Get the platform-specific NODE_PATH value
97
+ */
98
+ function getNodeModulesPath() {
99
+ const platform = process.platform;
100
+
101
+ if (platform === 'win32') {
102
+ // Windows global modules path
103
+ const prefix = process.env.APPDATA || path.join(homedir(), 'AppData', 'Roaming');
104
+ return path.join(prefix, 'npm', 'node_modules');
105
+ } else if (platform === 'darwin' || platform === 'linux') {
106
+ // Check if it's a homebrew installation on Mac
107
+ if (platform === 'darwin' && fs.existsSync('/opt/homebrew/lib/node_modules')) {
108
+ return '/opt/homebrew/lib/node_modules';
109
+ }
110
+ // Default Unix-like path
111
+ return '/usr/local/lib/node_modules';
112
+ } else {
113
+ // Fallback
114
+ return process.env.NODE_PATH || '';
115
+ }
116
+ }
117
+
17
118
  async function main() {
18
119
  try {
19
120
  // Get command line arguments
20
-
21
121
  const args = process.argv.slice(2);
22
122
 
23
123
  let USER_ID, USER_SECRET;
@@ -81,7 +181,7 @@ async function main() {
81
181
  }
82
182
 
83
183
  // Create Claude Desktop configuration directory if it doesn't exist
84
- const claudeConfigDir = path.join(homedir(), 'Library', 'Application Support', 'Claude');
184
+ const claudeConfigDir = getClaudeConfigPath();
85
185
  const claudeConfigFile = path.join(claudeConfigDir, 'claude_desktop_config.json');
86
186
 
87
187
  try {
@@ -95,16 +195,18 @@ async function main() {
95
195
  const packageRoot = path.resolve(__dirname, '..');
96
196
  const serverPath = path.join(packageRoot, 'build', 'index.js');
97
197
 
98
- // Check if Node.js executable exists
99
- let nodePath;
198
+ // Check if serverPath exists
100
199
  try {
101
- const { stdout } = await execAsync('which node');
102
- nodePath = stdout.trim();
200
+ await fs.access(serverPath);
103
201
  } catch (error) {
104
- console.error('Error finding Node.js executable. Make sure Node.js is installed.');
202
+ console.error(`Error: Could not find server file at ${serverPath}`);
203
+ console.error('This might be due to an incomplete installation. Try reinstalling the package with: npm install -g secondbrainos-mcp-server');
105
204
  process.exit(1);
106
205
  }
107
206
 
207
+ // Find Node.js executable
208
+ const nodePath = await findNodeExecutable();
209
+
108
210
  // Create the Claude Desktop configuration
109
211
  const configContent = {
110
212
  mcpServers: {
@@ -115,7 +217,7 @@ async function main() {
115
217
  USER_ID,
116
218
  USER_SECRET,
117
219
  API_BASE_URL: 'https://api.secondbrainos.com',
118
- NODE_PATH: process.env.NODE_PATH || '/usr/local/lib/node_modules'
220
+ NODE_PATH: getNodeModulesPath()
119
221
  }
120
222
  }
121
223
  }
@@ -135,7 +237,7 @@ async function main() {
135
237
  console.log('2. Restart Claude Desktop');
136
238
  console.log('3. In the Chat Input inside Claude (i.e where you type your messages), you will now see a "🔨" icon which contains all the tools you have access to');
137
239
  console.log('\nIf you encounter issues, check the logs:');
138
- console.log(`tail -f ~/Library/Logs/Claude/mcp*.log`);
240
+ console.log(`${getLogPath()}`);
139
241
 
140
242
  } catch (error) {
141
243
  console.error('Unexpected error:', error);
@@ -143,4 +245,4 @@ async function main() {
143
245
  }
144
246
  }
145
247
 
146
- main();
248
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "secondbrainos-mcp-server",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Second Brain OS MCP Server for Claude Desktop",
5
5
  "type": "module",
6
6
  "main": "build/index.js",