secondbrainos-mcp-server 1.0.2 → 1.0.4

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