lunisphere-mcp 1.0.0 → 1.1.0

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/README.md CHANGED
@@ -2,19 +2,22 @@
2
2
 
3
3
  Local PC agent for [Lunisphere MCP Relay](https://mcp.lunisphere.com). Connects your local workspace to remote MCP clients (Gemini, Claude, Cursor) via outbound HTTPS long-polling with zero tunnel or port-forwarding setup.
4
4
 
5
- ## Usage
5
+ ## One-Command Auto-Setup & Startup
6
6
 
7
- Run directly with `npx`:
7
+ Run once in your workspace folder (run from an **Administrator terminal** on Windows to register silent elevated startup without future UAC prompts):
8
8
 
9
9
  ```bash
10
- npx lunisphere-mcp --server="https://mcp.lunisphere.com" --key="YOUR_DEVICE_KEY" --dir="."
10
+ npx -y lunisphere-mcp@latest --server="https://mcp.lunisphere.com" --key="YOUR_DEVICE_KEY" --dir="." --allow-shell --setup
11
11
  ```
12
12
 
13
- Or install globally:
13
+ What `--setup` does:
14
+ 1. Installs or updates `lunisphere-mcp@latest` globally from npm.
15
+ 2. Saves configuration to `~/.lunisphere-mcp/config.json`.
16
+ 3. Registers silent OS startup (no console window popup) and starts the agent in the background immediately.
17
+ 4. Automatically checks npm for newer releases on every startup and updates silently.
18
+
19
+ ## Uninstall Startup
14
20
 
15
21
  ```bash
16
- npm install -g lunisphere-mcp
17
- lunisphere-mcp --server="https://mcp.lunisphere.com" --key="YOUR_DEVICE_KEY" --dir="."
22
+ lunisphere-mcp --uninstall
18
23
  ```
19
-
20
- Add `--allow-shell` to enable `cmd_execute` and `bg_*` background job tools.
package/bin/cli.js CHANGED
@@ -1,68 +1,158 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const path = require('path');
5
- const { LocalToolkit } = require('../lib/tools');
6
- const { RelayPoller } = require('../lib/poller');
7
-
8
- function parseArgs(argv) {
9
- const args = {};
10
- for (let i = 0; i < argv.length; i++) {
11
- const token = argv[i];
12
- if (token.startsWith('--')) {
13
- const eq = token.indexOf('=');
14
- if (eq !== -1) {
15
- args[token.slice(2, eq)] = token.slice(eq + 1);
16
- } else {
17
- const key = token.slice(2);
18
- const next = argv[i + 1];
19
- if (next && !next.startsWith('--')) {
20
- args[key] = next;
21
- i++;
22
- } else {
23
- args[key] = true;
24
- }
25
- }
26
- }
27
- }
28
- return args;
29
- }
30
-
31
- const args = parseArgs(process.argv.slice(2));
32
-
33
- if (args.help || !args.key) {
34
- console.log(`
35
- Lunisphere MCP PC Client
36
- Usage:
37
- lunisphere-mcp --server="https://mcp.lunisphere.com" --key="dk_..." --dir="." [--allow-shell]
38
-
39
- Options:
40
- --server Relay server base URL (default: https://mcp.lunisphere.com)
41
- --key Device Key copied from your dashboard (required)
42
- --dir Workspace directory to expose (default: current directory)
43
- --allow-shell Enable cmd_execute and bg_* background job tools (off by default)
44
- `);
45
- process.exit(args.help ? 0 : 1);
46
- }
47
-
48
- const serverUrl = args.server || 'https://mcp.lunisphere.com';
49
- const rootDir = path.resolve(args.dir || process.cwd());
50
- const allowShell = Boolean(args['allow-shell']);
51
-
52
- console.log('===============================================');
53
- console.log(' Lunisphere MCP PC Client');
54
- console.log(` Server: ${serverUrl}`);
55
- console.log(` Workspace: ${rootDir}`);
56
- console.log(` Shell: ${allowShell ? 'ENABLED' : 'DISABLED (read/write sandbox only)'}`);
57
- console.log('===============================================');
58
-
59
- const toolkit = new LocalToolkit({ rootDir, allowShell });
60
- const poller = new RelayPoller({ serverUrl, deviceKey: args.key, toolkit });
61
-
62
- process.on('SIGINT', () => {
63
- console.log('\n[STOP] Shutting down Lunisphere MCP Client...');
64
- poller.stop();
65
- process.exit(0);
66
- });
67
-
68
- poller.start();
2
+ 'use strict';
3
+
4
+ const path = require('path');
5
+ const pkg = require('../package.json');
6
+ const { LocalToolkit } = require('../lib/tools');
7
+ const { RelayPoller } = require('../lib/poller');
8
+ const { ensureLatestAndMaybeRespawn } = require('../lib/updater');
9
+ const {
10
+ loadConfig,
11
+ saveConfig,
12
+ writePid,
13
+ stopExistingAgent,
14
+ appendLog,
15
+ runSetup,
16
+ uninstallStartup
17
+ } = require('../lib/autostart');
18
+
19
+ function parseArgs(argv) {
20
+ const args = {};
21
+ for (let i = 0; i < argv.length; i++) {
22
+ const token = argv[i];
23
+ if (token.startsWith('--')) {
24
+ const eq = token.indexOf('=');
25
+ if (eq !== -1) {
26
+ args[token.slice(2, eq)] = token.slice(eq + 1);
27
+ } else {
28
+ const key = token.slice(2);
29
+ const next = argv[i + 1];
30
+ if (next && !next.startsWith('--')) {
31
+ args[key] = next;
32
+ i++;
33
+ } else {
34
+ args[key] = true;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ return args;
40
+ }
41
+
42
+ async function main() {
43
+ const rawArgv = process.argv.slice(2);
44
+ const args = parseArgs(rawArgv);
45
+
46
+ if (args.help || args.h) {
47
+ console.log(`
48
+ Lunisphere MCP PC Client v${pkg.version}
49
+ Usage:
50
+ lunisphere-mcp --server="https://mcp.lunisphere.com" --key="dk_..." --dir="." [--allow-shell] [--setup]
51
+ lunisphere-mcp --service
52
+ lunisphere-mcp --uninstall
53
+
54
+ Options:
55
+ --server Relay server base URL (default: https://mcp.lunisphere.com)
56
+ --key Device Key copied from your dashboard
57
+ --dir Workspace directory to expose (default: current directory)
58
+ --allow-shell Enable cmd_execute and bg_* background job tools (off by default)
59
+ --setup Install latest globally, save config, register silent OS startup, and run in background
60
+ --service Run silently using saved configuration (used by OS startup)
61
+ --no-update Skip npm latest version check on startup
62
+ --uninstall Remove OS startup registration and saved config
63
+ `);
64
+ process.exit(0);
65
+ }
66
+
67
+ if (args.uninstall) {
68
+ uninstallStartup();
69
+ process.exit(0);
70
+ }
71
+
72
+ if (args.service) {
73
+ const origLog = console.log;
74
+ const origErr = console.error;
75
+ console.log = (...parts) => appendLog(parts.join(' '));
76
+ console.error = (...parts) => appendLog('[ERR] ' + parts.join(' '));
77
+ console.warn = (...parts) => appendLog('[WARN] ' + parts.join(' '));
78
+ void origLog;
79
+ void origErr;
80
+ }
81
+
82
+ const saved = loadConfig();
83
+ const deviceKey = args.key || (saved && saved.key);
84
+
85
+ if (!deviceKey) {
86
+ console.error('Missing --key. Copy your setup command from https://mcp.lunisphere.com.');
87
+ process.exit(1);
88
+ }
89
+
90
+ const serverUrl = args.server || (saved && saved.server) || 'https://mcp.lunisphere.com';
91
+ const rootDir = path.resolve(args.dir || (saved && saved.dir) || process.cwd());
92
+ const allowShell = args['allow-shell'] !== undefined
93
+ ? Boolean(args['allow-shell'])
94
+ : Boolean(saved && saved.allowShell);
95
+
96
+ if (args.setup) {
97
+ await runSetup({
98
+ serverUrl,
99
+ deviceKey,
100
+ rootDir,
101
+ allowShell,
102
+ currentVersion: pkg.version
103
+ });
104
+ process.exit(0);
105
+ }
106
+
107
+ // Auto-check latest version on startup unless disabled or already respawned
108
+ const updateState = await ensureLatestAndMaybeRespawn({
109
+ currentVersion: pkg.version,
110
+ argv: rawArgv,
111
+ skipUpdate: Boolean(args['no-update'])
112
+ });
113
+ if (updateState.respawning) {
114
+ return;
115
+ }
116
+
117
+ if (args.key && !args.service) {
118
+ saveConfig({
119
+ server: serverUrl,
120
+ key: deviceKey,
121
+ dir: rootDir,
122
+ allowShell,
123
+ autoUpdate: true,
124
+ updatedAt: new Date().toISOString()
125
+ });
126
+ }
127
+
128
+ stopExistingAgent();
129
+ writePid(process.pid);
130
+
131
+ console.log('===============================================');
132
+ console.log(` Lunisphere MCP PC Client v${pkg.version}`);
133
+ console.log(` Server: ${serverUrl}`);
134
+ console.log(` Workspace: ${rootDir}`);
135
+ console.log(` Shell: ${allowShell ? 'ENABLED' : 'DISABLED (read/write sandbox only)'}`);
136
+ console.log('===============================================');
137
+
138
+ const toolkit = new LocalToolkit({ rootDir, allowShell });
139
+ const poller = new RelayPoller({ serverUrl, deviceKey, toolkit });
140
+
141
+ process.on('SIGINT', () => {
142
+ console.log('\n[STOP] Shutting down Lunisphere MCP Client...');
143
+ poller.stop();
144
+ process.exit(0);
145
+ });
146
+
147
+ process.on('SIGTERM', () => {
148
+ poller.stop();
149
+ process.exit(0);
150
+ });
151
+
152
+ poller.start();
153
+ }
154
+
155
+ main().catch((err) => {
156
+ console.error('[FATAL]', err.message);
157
+ process.exit(1);
158
+ });
@@ -0,0 +1,271 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+ const { execFileSync, spawn } = require('child_process');
7
+ const {
8
+ fetchLatestVersion,
9
+ compareSemver,
10
+ getGlobalCliPath,
11
+ getGlobalInstalledVersion,
12
+ installLatestGlobal
13
+ } = require('./updater');
14
+
15
+ const CONFIG_DIR = path.join(os.homedir(), '.lunisphere-mcp');
16
+ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
17
+ const PID_FILE = path.join(CONFIG_DIR, 'agent.pid');
18
+ const LOG_FILE = path.join(CONFIG_DIR, 'agent.log');
19
+ const TASK_NAME = 'LunisphereMCPRelay';
20
+
21
+ function ensureConfigDir() {
22
+ if (!fs.existsSync(CONFIG_DIR)) {
23
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
24
+ }
25
+ }
26
+
27
+ function saveConfig(cfg) {
28
+ ensureConfigDir();
29
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(cfg, null, 2), 'utf8');
30
+ }
31
+
32
+ function loadConfig() {
33
+ if (!fs.existsSync(CONFIG_FILE)) return null;
34
+ try {
35
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
36
+ } catch (_) {
37
+ return null;
38
+ }
39
+ }
40
+
41
+ function writePid(pid) {
42
+ ensureConfigDir();
43
+ fs.writeFileSync(PID_FILE, String(pid), 'utf8');
44
+ }
45
+
46
+ function stopExistingAgent() {
47
+ if (!fs.existsSync(PID_FILE)) return;
48
+ try {
49
+ const oldPid = parseInt(fs.readFileSync(PID_FILE, 'utf8').trim(), 10);
50
+ if (oldPid && oldPid !== process.pid) {
51
+ try {
52
+ process.kill(oldPid, 'SIGTERM');
53
+ } catch (_) {}
54
+ }
55
+ } catch (_) {}
56
+ }
57
+
58
+ function appendLog(line) {
59
+ try {
60
+ ensureConfigDir();
61
+ if (fs.existsSync(LOG_FILE) && fs.statSync(LOG_FILE).size > 1024 * 1024) {
62
+ fs.truncateSync(LOG_FILE, 0);
63
+ }
64
+ fs.appendFileSync(LOG_FILE, `${new Date().toISOString()} ${line}\n`, 'utf8');
65
+ } catch (_) {}
66
+ }
67
+
68
+ function installWindowsStartup(cliPath) {
69
+ ensureConfigDir();
70
+ const vbsPath = path.join(CONFIG_DIR, 'launch.vbs');
71
+ const nodePath = process.execPath.replace(/"/g, '""');
72
+ const safeCli = cliPath.replace(/"/g, '""');
73
+ const vbsContent = [
74
+ 'Set sh = CreateObject("WScript.Shell")',
75
+ `sh.Run """${nodePath}"" ""${safeCli}"" --service", 0, False`,
76
+ ''
77
+ ].join('\r\n');
78
+ fs.writeFileSync(vbsPath, vbsContent, 'utf8');
79
+
80
+ const taskCmd = `wscript.exe "${vbsPath}"`;
81
+ let mode = 'user';
82
+
83
+ try {
84
+ execFileSync(
85
+ 'schtasks.exe',
86
+ ['/Create', '/TN', TASK_NAME, '/TR', taskCmd, '/SC', 'ONLOGON', '/RL', 'HIGHEST', '/F'],
87
+ { stdio: 'pipe', windowsHide: true }
88
+ );
89
+ mode = 'admin';
90
+ } catch (_) {
91
+ try {
92
+ execFileSync(
93
+ 'schtasks.exe',
94
+ ['/Create', '/TN', TASK_NAME, '/TR', taskCmd, '/SC', 'ONLOGON', '/F'],
95
+ { stdio: 'pipe', windowsHide: true }
96
+ );
97
+ mode = 'user-task';
98
+ } catch (_) {
99
+ execFileSync(
100
+ 'reg.exe',
101
+ ['ADD', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/V', TASK_NAME, '/T', 'REG_SZ', '/D', taskCmd, '/F'],
102
+ { stdio: 'pipe', windowsHide: true }
103
+ );
104
+ mode = 'user-registry';
105
+ }
106
+ }
107
+
108
+ stopExistingAgent();
109
+ const child = spawn('wscript.exe', [vbsPath], {
110
+ detached: true,
111
+ stdio: 'ignore',
112
+ windowsHide: true
113
+ });
114
+ child.unref();
115
+
116
+ return { mode, vbsPath };
117
+ }
118
+
119
+ function installMacStartup(cliPath) {
120
+ const agentsDir = path.join(os.homedir(), 'Library', 'LaunchAgents');
121
+ if (!fs.existsSync(agentsDir)) fs.mkdirSync(agentsDir, { recursive: true });
122
+ const plistPath = path.join(agentsDir, 'com.lunisphere.mcp.plist');
123
+ const plist = `<?xml version="1.0" encoding="UTF-8"?>
124
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
125
+ <plist version="1.0">
126
+ <dict>
127
+ <key>Label</key><string>com.lunisphere.mcp</string>
128
+ <key>ProgramArguments</key>
129
+ <array>
130
+ <string>${process.execPath}</string>
131
+ <string>${cliPath}</string>
132
+ <string>--service</string>
133
+ </array>
134
+ <key>RunAtLoad</key><true/>
135
+ <key>KeepAlive</key><true/>
136
+ <key>StandardOutPath</key><string>${LOG_FILE}</string>
137
+ <key>StandardErrorPath</key><string>${LOG_FILE}</string>
138
+ </dict>
139
+ </plist>
140
+ `;
141
+ fs.writeFileSync(plistPath, plist, 'utf8');
142
+ try { execFileSync('launchctl', ['unload', plistPath], { stdio: 'ignore' }); } catch (_) {}
143
+ execFileSync('launchctl', ['load', '-w', plistPath], { stdio: 'pipe' });
144
+ return { mode: 'launchd', plistPath };
145
+ }
146
+
147
+ function installLinuxStartup(cliPath) {
148
+ const systemdDir = path.join(os.homedir(), '.config', 'systemd', 'user');
149
+ fs.mkdirSync(systemdDir, { recursive: true });
150
+ const unitPath = path.join(systemdDir, 'lunisphere-mcp.service');
151
+ const unit = `[Unit]
152
+ Description=Lunisphere MCP Relay Client
153
+ After=network-online.target
154
+
155
+ [Service]
156
+ ExecStart="${process.execPath}" "${cliPath}" --service
157
+ Restart=always
158
+ RestartSec=5
159
+
160
+ [Install]
161
+ WantedBy=default.target
162
+ `;
163
+ fs.writeFileSync(unitPath, unit, 'utf8');
164
+ try {
165
+ execFileSync('systemctl', ['--user', 'daemon-reload'], { stdio: 'ignore' });
166
+ execFileSync('systemctl', ['--user', 'enable', '--now', 'lunisphere-mcp.service'], { stdio: 'pipe' });
167
+ return { mode: 'systemd-user', unitPath };
168
+ } catch (_) {
169
+ stopExistingAgent();
170
+ const out = fs.openSync(LOG_FILE, 'a');
171
+ const child = spawn(process.execPath, [cliPath, '--service'], {
172
+ detached: true,
173
+ stdio: ['ignore', out, out]
174
+ });
175
+ child.unref();
176
+ return { mode: 'background', unitPath };
177
+ }
178
+ }
179
+
180
+ async function runSetup({ serverUrl, deviceKey, rootDir, allowShell, currentVersion }) {
181
+ console.log('[SETUP] Checking latest lunisphere-mcp version on npm...');
182
+ const latest = await fetchLatestVersion('lunisphere-mcp');
183
+ const globalVer = getGlobalInstalledVersion();
184
+ let globalCli = getGlobalCliPath();
185
+
186
+ const needsInstall =
187
+ !globalCli ||
188
+ !globalVer ||
189
+ (latest && compareSemver(latest, globalVer) > 0) ||
190
+ compareSemver(currentVersion, globalVer) > 0;
191
+
192
+ if (needsInstall) {
193
+ const targetVer = latest || currentVersion;
194
+ console.log(`[SETUP] Installing global lunisphere-mcp@${targetVer}...`);
195
+ try {
196
+ globalCli = installLatestGlobal('lunisphere-mcp');
197
+ } catch (err) {
198
+ console.warn(`[SETUP] Global npm install warning: ${err.message}`);
199
+ }
200
+ } else {
201
+ console.log(`[SETUP] Latest version (${globalVer}) is already installed globally.`);
202
+ }
203
+
204
+ const cliPath = globalCli || path.resolve(__dirname, '..', 'bin', 'cli.js');
205
+
206
+ saveConfig({
207
+ server: serverUrl,
208
+ key: deviceKey,
209
+ dir: rootDir,
210
+ allowShell: Boolean(allowShell),
211
+ autoUpdate: true,
212
+ updatedAt: new Date().toISOString()
213
+ });
214
+ console.log(`[SETUP] Configuration saved to ${CONFIG_FILE}`);
215
+
216
+ let startupInfo;
217
+ if (process.platform === 'win32') {
218
+ startupInfo = installWindowsStartup(cliPath);
219
+ } else if (process.platform === 'darwin') {
220
+ startupInfo = installMacStartup(cliPath);
221
+ } else {
222
+ startupInfo = installLinuxStartup(cliPath);
223
+ }
224
+
225
+ if (startupInfo.mode === 'admin') {
226
+ console.log('[STARTUP] Registered silently in Administrator mode (zero popups on boot).');
227
+ } else if (process.platform === 'win32') {
228
+ console.log(`[STARTUP] Registered silently in User mode (${startupInfo.mode}, zero popups on boot).`);
229
+ console.log('[NOTE] Run this setup command once from an Administrator terminal if you want elevated Admin mode on boot.');
230
+ } else {
231
+ console.log(`[STARTUP] Registered background service (${startupInfo.mode}).`);
232
+ }
233
+
234
+ console.log(`[ONLINE] Background agent started. Log: ${LOG_FILE}`);
235
+ }
236
+
237
+ function uninstallStartup() {
238
+ stopExistingAgent();
239
+ if (process.platform === 'win32') {
240
+ try { execFileSync('schtasks.exe', ['/Delete', '/TN', TASK_NAME, '/F'], { stdio: 'ignore', windowsHide: true }); } catch (_) {}
241
+ try {
242
+ execFileSync(
243
+ 'reg.exe',
244
+ ['DELETE', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/V', TASK_NAME, '/F'],
245
+ { stdio: 'ignore', windowsHide: true }
246
+ );
247
+ } catch (_) {}
248
+ } else if (process.platform === 'darwin') {
249
+ const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', 'com.lunisphere.mcp.plist');
250
+ try { execFileSync('launchctl', ['unload', plistPath], { stdio: 'ignore' }); } catch (_) {}
251
+ try { fs.unlinkSync(plistPath); } catch (_) {}
252
+ } else {
253
+ try { execFileSync('systemctl', ['--user', 'disable', '--now', 'lunisphere-mcp.service'], { stdio: 'ignore' }); } catch (_) {}
254
+ }
255
+ if (fs.existsSync(CONFIG_FILE)) fs.unlinkSync(CONFIG_FILE);
256
+ if (fs.existsSync(PID_FILE)) fs.unlinkSync(PID_FILE);
257
+ console.log('[UNINSTALL] Startup entry and saved configuration removed.');
258
+ }
259
+
260
+ module.exports = {
261
+ CONFIG_DIR,
262
+ CONFIG_FILE,
263
+ LOG_FILE,
264
+ saveConfig,
265
+ loadConfig,
266
+ writePid,
267
+ stopExistingAgent,
268
+ appendLog,
269
+ runSetup,
270
+ uninstallStartup
271
+ };
package/lib/updater.js ADDED
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ const { execFileSync, spawn } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ function compareSemver(a, b) {
8
+ const pa = String(a || '0.0.0').replace(/^v/, '').split('.').map((n) => parseInt(n, 10) || 0);
9
+ const pb = String(b || '0.0.0').replace(/^v/, '').split('.').map((n) => parseInt(n, 10) || 0);
10
+ for (let i = 0; i < 3; i++) {
11
+ if ((pa[i] || 0) > (pb[i] || 0)) return 1;
12
+ if ((pa[i] || 0) < (pb[i] || 0)) return -1;
13
+ }
14
+ return 0;
15
+ }
16
+
17
+ function getNpmBin() {
18
+ return process.platform === 'win32' ? 'npm.cmd' : 'npm';
19
+ }
20
+
21
+ function getGlobalCliPath() {
22
+ try {
23
+ const npmRoot = execFileSync(getNpmBin(), ['root', '-g'], {
24
+ encoding: 'utf8',
25
+ timeout: 8000,
26
+ windowsHide: true,
27
+ shell: process.platform === 'win32'
28
+ }).trim();
29
+ const candidate = path.join(npmRoot, 'lunisphere-mcp', 'bin', 'cli.js');
30
+ if (fs.existsSync(candidate)) return candidate;
31
+ } catch (_) {}
32
+ return null;
33
+ }
34
+
35
+ function getGlobalInstalledVersion() {
36
+ try {
37
+ const cliPath = getGlobalCliPath();
38
+ if (!cliPath) return null;
39
+ const pkgPath = path.resolve(path.dirname(cliPath), '..', 'package.json');
40
+ if (!fs.existsSync(pkgPath)) return null;
41
+ return JSON.parse(fs.readFileSync(pkgPath, 'utf8')).version || null;
42
+ } catch (_) {
43
+ return null;
44
+ }
45
+ }
46
+
47
+ async function fetchLatestVersion(pkgName = 'lunisphere-mcp') {
48
+ const controller = new AbortController();
49
+ const timer = setTimeout(() => controller.abort(), 4500);
50
+ try {
51
+ const res = await fetch(`https://registry.npmjs.org/${pkgName}/latest`, {
52
+ signal: controller.signal,
53
+ headers: { Accept: 'application/json' }
54
+ });
55
+ if (!res.ok) return null;
56
+ const data = await res.json();
57
+ return data && data.version ? String(data.version).trim() : null;
58
+ } catch (_) {
59
+ return null;
60
+ } finally {
61
+ clearTimeout(timer);
62
+ }
63
+ }
64
+
65
+ function installLatestGlobal(pkgName = 'lunisphere-mcp') {
66
+ execFileSync(getNpmBin(), ['install', '-g', `${pkgName}@latest`], {
67
+ stdio: 'pipe',
68
+ timeout: 60000,
69
+ windowsHide: true,
70
+ shell: process.platform === 'win32'
71
+ });
72
+ return getGlobalCliPath();
73
+ }
74
+
75
+ async function ensureLatestAndMaybeRespawn({ currentVersion, argv, skipUpdate }) {
76
+ if (skipUpdate) return { updated: false };
77
+ const latest = await fetchLatestVersion('lunisphere-mcp');
78
+ if (!latest || compareSemver(latest, currentVersion) <= 0) {
79
+ return { updated: false, latest };
80
+ }
81
+
82
+ console.log(`[UPDATE] New version ${latest} found (current ${currentVersion}). Updating...`);
83
+ try {
84
+ const globalCli = installLatestGlobal('lunisphere-mcp');
85
+ const targetScript = globalCli || path.resolve(__dirname, '..', 'bin', 'cli.js');
86
+ const nextArgs = [targetScript, ...argv.filter((a) => a !== '--no-update'), '--no-update'];
87
+ const isService = argv.includes('--service');
88
+ const child = spawn(process.execPath, nextArgs, {
89
+ stdio: isService ? 'ignore' : 'inherit',
90
+ detached: isService,
91
+ windowsHide: isService
92
+ });
93
+ if (isService) {
94
+ child.unref();
95
+ process.exit(0);
96
+ }
97
+ child.on('exit', (code) => process.exit(code == null ? 0 : code));
98
+ return { updated: true, respawning: true, latest };
99
+ } catch (err) {
100
+ console.warn(`[UPDATE] Auto-update failed (${err.message}); continuing on ${currentVersion}.`);
101
+ return { updated: false, error: err.message };
102
+ }
103
+ }
104
+
105
+ module.exports = {
106
+ compareSemver,
107
+ fetchLatestVersion,
108
+ getGlobalCliPath,
109
+ getGlobalInstalledVersion,
110
+ installLatestGlobal,
111
+ ensureLatestAndMaybeRespawn
112
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lunisphere-mcp",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Local PC agent for Lunisphere MCP Relay — connect your local workspace to Gemini, Claude, or Cursor with zero tunnel setup.",
5
5
  "bin": {
6
6
  "lunisphere-mcp": "bin/cli.js"