local-mcp 3.0.421 → 3.0.425
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 +3 -1
- package/bundled.js +40 -0
- package/download.js +89 -245
- package/index.js +142 -453
- package/launch-event.js +25 -4
- package/package.json +8 -1
- package/setup.js +62 -185
package/launch-event.js
CHANGED
|
@@ -27,6 +27,11 @@ const OUTCOMES = ['spawned', 'rejected-argument', 'unsupported-node', 'unsupport
|
|
|
27
27
|
const RAZONES = ['network', 'timeout', 'http-status', 'checksum-mismatch', 'disk-write',
|
|
28
28
|
'permission-denied', 'binary-missing', 'early-exit', 'signal', 'uncaught-exception', 'init-failed', 'unknown']
|
|
29
29
|
const CAMINO = 'npm-wrapper' // launch_path: quién arrancó el server
|
|
30
|
+
// 3.0.423 (lmcp-api#548): qué binario encontró el lanzamiento. El wrapper lo fija con fuente() en
|
|
31
|
+
// cuanto lo sabe; antes de saberlo (desinstalado, argumento rechazado) el evento no lo lleva.
|
|
32
|
+
const FUENTES = ['bundled', 'app_embedded', 'missing_platform']
|
|
33
|
+
let fuenteBinario
|
|
34
|
+
function fuente (valor) { if (FUENTES.includes(valor)) fuenteBinario = valor }
|
|
30
35
|
const RE_VERSION = /^\d{1,3}\.\d{1,3}\.\d{1,5}$/
|
|
31
36
|
const RE_MAQUINA = /^[A-Za-z0-9._:{}-]{1,64}$/
|
|
32
37
|
const [TIMEOUT_MS, TOPE_MS] = [3000, 4000] // el pedido · la vida del proceso suelto
|
|
@@ -86,6 +91,8 @@ function cuerpo (outcome, clase, deps = {}) {
|
|
|
86
91
|
}
|
|
87
92
|
// Una razón fuera del conjunto no viaja, y un `spawned` no lleva razón; el evento sale igual.
|
|
88
93
|
if (outcome !== 'spawned' && RAZONES.includes(deps.reason)) c.reason = deps.reason
|
|
94
|
+
const f = 'binarySource' in deps ? deps.binarySource : fuenteBinario
|
|
95
|
+
if (FUENTES.includes(f)) c.binary_source = f
|
|
89
96
|
const id = 'machineId' in deps ? deps.machineId : idDeMaquina()
|
|
90
97
|
if (typeof id === 'string' && RE_MAQUINA.test(id)) c.machine_id = id
|
|
91
98
|
return c
|
|
@@ -178,6 +185,15 @@ function reportar (outcome, clase, { enProceso = false, reason } = {}) {
|
|
|
178
185
|
if (enProceso) {
|
|
179
186
|
const idEntorno = (process.env.LMCP_MACHINE_ID || '').trim()
|
|
180
187
|
if (process.platform === 'win32' && !idEntorno) {
|
|
188
|
+
// lmcp-npm#92: el orden de _getMachineId sin el probe. Con el id guardado del cliente, ése;
|
|
189
|
+
// sin guardado y sin token, ninguno. El hardware se pide sólo para lo que reporta un 3.0.420.
|
|
190
|
+
const dl = require('./download')
|
|
191
|
+
const guardado = dl._readStoredMachineId(dl.CACHE_DIR)
|
|
192
|
+
if (guardado || !dl._readCachedCloudToken(dl.CACHE_DIR)) {
|
|
193
|
+
const c = cuerpo(outcome, clase, { machineId: guardado })
|
|
194
|
+
if (c) enviar(c, { soltar: true })
|
|
195
|
+
return
|
|
196
|
+
}
|
|
181
197
|
pendiente = { outcome, clase }
|
|
182
198
|
idDeHardwareWindows((id) => {
|
|
183
199
|
if (!pendiente) return // ya salió por el proceso suelto
|
|
@@ -201,7 +217,9 @@ function silenciar () { reportado = true }
|
|
|
201
217
|
|
|
202
218
|
function lanzarSuelto (outcome, clase, reason) {
|
|
203
219
|
// La razón viaja como argumento sólo si es del conjunto: al proceso suelto no le llega texto libre.
|
|
204
|
-
|
|
220
|
+
// La fuente del binario va detrás, también sólo si es del conjunto (RAZONES y FUENTES no se cruzan).
|
|
221
|
+
const hijo = cp.spawn(process.execPath, [__filename, outcome, clase, ...(RAZONES.includes(reason) ? [reason] : []),
|
|
222
|
+
...(FUENTES.includes(fuenteBinario) ? [fuenteBinario] : [])],
|
|
205
223
|
{ detached: true, stdio: 'ignore', windowsHide: true })
|
|
206
224
|
hijo.on('error', () => {})
|
|
207
225
|
hijo.unref()
|
|
@@ -217,12 +235,15 @@ function soltarPendiente () {
|
|
|
217
235
|
try { lanzarSuelto(outcome, clase) } catch {}
|
|
218
236
|
}
|
|
219
237
|
|
|
220
|
-
// Como programa es el proceso suelto: `node launch-event.js <outcome> <clase> [reason]`.
|
|
238
|
+
// Como programa es el proceso suelto: `node launch-event.js <outcome> <clase> [reason] [binary_source]`.
|
|
221
239
|
if (require.main === module) {
|
|
222
240
|
setTimeout(() => process.exit(0), TOPE_MS).unref()
|
|
223
|
-
const c = apagado() ? null : cuerpo(process.argv[2], process.argv[3], {
|
|
241
|
+
const c = apagado() ? null : cuerpo(process.argv[2], process.argv[3], {
|
|
242
|
+
reason: process.argv.slice(4).find(a => RAZONES.includes(a)),
|
|
243
|
+
binarySource: process.argv.slice(4).find(a => FUENTES.includes(a))
|
|
244
|
+
})
|
|
224
245
|
if (c) enviar(c)
|
|
225
246
|
}
|
|
226
247
|
|
|
227
|
-
module.exports = { PLATAFORMAS, CLASES, OUTCOMES, RAZONES, CAMINO, razonDeError, RE_VERSION, RE_MAQUINA, TOPE_ID_MS, claseDeArgumento, apagado, cuerpo, reportar, silenciar, soltarPendiente,
|
|
248
|
+
module.exports = { PLATAFORMAS, CLASES, OUTCOMES, RAZONES, CAMINO, FUENTES, fuente, razonDeError, RE_VERSION, RE_MAQUINA, TOPE_ID_MS, claseDeArgumento, apagado, cuerpo, reportar, silenciar, soltarPendiente,
|
|
228
249
|
_idDeHardwareWindows: idDeHardwareWindows } // costura de test
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "local-mcp",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.425",
|
|
4
4
|
"description": "Let ChatGPT, Claude, Cursor & any MCP client actually use your Mac or Windows PC — read & reply to email, manage your calendar, text over iMessage, find files, work with Teams, Slack, Notion & Office. Runs locally, no API keys.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"index.js",
|
|
15
15
|
"download.js",
|
|
16
|
+
"bundled.js",
|
|
16
17
|
"setup.js",
|
|
17
18
|
"launch-event.js",
|
|
18
19
|
"user-agent.js",
|
|
@@ -23,6 +24,12 @@
|
|
|
23
24
|
"engines": {
|
|
24
25
|
"node": ">=20"
|
|
25
26
|
},
|
|
27
|
+
"optionalDependencies": {
|
|
28
|
+
"local-mcp-darwin-arm64": "3.0.425",
|
|
29
|
+
"local-mcp-darwin-x64": "3.0.425",
|
|
30
|
+
"local-mcp-windows-x64": "3.0.425",
|
|
31
|
+
"local-mcp-windows-arm64": "3.0.425"
|
|
32
|
+
},
|
|
26
33
|
"os": [
|
|
27
34
|
"darwin",
|
|
28
35
|
"win32"
|
package/setup.js
CHANGED
|
@@ -318,8 +318,8 @@ async function runSetup(opts = {}) {
|
|
|
318
318
|
process.exitCode = sinLinux.exitCode
|
|
319
319
|
return
|
|
320
320
|
}
|
|
321
|
-
// Cross-platform: macOS configures the Swift tray + embedded server; Windows
|
|
322
|
-
// go-server
|
|
321
|
+
// Cross-platform: macOS configures the Swift tray + embedded server; Windows installs the
|
|
322
|
+
// go-server from the npm platform package (bundled.js) and writes the MCP client config.
|
|
323
323
|
const forceAll = opts.all || process.argv.includes('--all')
|
|
324
324
|
const refArg = process.argv.find(a => a.startsWith('--ref='))
|
|
325
325
|
if (refArg) process.env.LMCP_REF = refArg.split('=')[1]
|
|
@@ -354,7 +354,6 @@ async function runSetup(opts = {}) {
|
|
|
354
354
|
console.error(` Fix: nvm alias default 22 && nvm uninstall ${process.version} (then relaunch Claude Desktop)\n`)
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
// Pre-download binary so first launch is instant
|
|
358
357
|
// All clients use a shell launcher that wraps npx (self-healing if binary is
|
|
359
358
|
// missing/broken, and surfaces telemetry + clear errors if Node is too old).
|
|
360
359
|
let npxAbsPath = _resolveNpxPath() // baked into the launcher script
|
|
@@ -362,88 +361,52 @@ async function runSetup(opts = {}) {
|
|
|
362
361
|
let stableArgs = NPX_ARGS
|
|
363
362
|
let binaryVersion = ''
|
|
364
363
|
// ADR-0004 phase 3 (darwin): if the notarized server is already embedded in
|
|
365
|
-
// LocalMCPTray.app,
|
|
366
|
-
// binary — the launcher (→ npx → index.js) prefers the embedded one anyway,
|
|
367
|
-
// and the ad-hoc copy is what resets Automation TCC. The tray is ensured later
|
|
368
|
-
// in setup; on a fresh install where the .app isn't present yet this is null
|
|
369
|
-
// and we keep the legacy pre-download as a fallback.
|
|
364
|
+
// LocalMCPTray.app, the launcher (→ npx → index.js) prefers it.
|
|
370
365
|
const _embeddedServer = process.platform === 'darwin'
|
|
371
|
-
?
|
|
372
|
-
path.join(os.homedir(), 'Applications', 'LocalMCPTray.app', 'Contents', 'MacOS', 'local-mcp-server'),
|
|
373
|
-
path.join('/Applications', 'LocalMCPTray.app', 'Contents', 'MacOS', 'local-mcp-server'),
|
|
374
|
-
].find(p => { try { return fs.statSync(p).isFile() } catch { return false } })
|
|
366
|
+
? download.trayAppPaths().map(app => path.join(app, 'Contents', 'MacOS', 'local-mcp-server')).find(p => { try { return fs.statSync(p).isFile() } catch { return false } })
|
|
375
367
|
: null
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
368
|
+
// 3.0.423: the server comes in npm's platform package (bundled.js). Nothing is downloaded and
|
|
369
|
+
// nothing is re-signed: the Mac binary keeps its Developer ID signature.
|
|
370
|
+
const _bundled = (() => { const p = require('./bundled').bundledServerPath(); try { return p && fs.statSync(p).isFile() ? p : null } catch { return null } })()
|
|
371
|
+
const { CACHE_DIR } = download
|
|
372
|
+
if (_embeddedServer) {
|
|
373
|
+
try {
|
|
374
|
+
binaryVersion = fs.readFileSync(
|
|
375
|
+
path.join(os.homedir(), '.local', 'share', 'local-mcp', 'tray', '.version'), 'utf8'
|
|
376
|
+
).trim()
|
|
377
|
+
} catch {}
|
|
378
|
+
process.stderr.write('✓ Using server embedded in the LMCP app\n\n')
|
|
379
|
+
} else if (_bundled) {
|
|
380
|
+
try { binaryVersion = fs.readFileSync(path.join(path.dirname(_bundled), 'VERSION'), 'utf8').trim() } catch {}
|
|
381
|
+
// Windows: the go-server's --configure-clients points every AI client at
|
|
382
|
+
// %LOCALAPPDATA%\local-mcp\bin\lmcp-server.exe (lmcp-win internal/aiclients ServerBinary), so
|
|
383
|
+
// setup — which the person asked for — puts the bundled binary there. A copy, not a download.
|
|
384
|
+
// The Mac clients go through the launcher → npx, which runs the bundled binary in place.
|
|
385
|
+
// With the LMCP app installed (lmcp-tray.exe in that folder) the app already put its server there
|
|
386
|
+
// and keeps it updated: setup leaves it alone.
|
|
387
|
+
if (_IS_WIN && !fs.existsSync(path.join(CACHE_DIR, 'lmcp-tray.exe'))) {
|
|
388
|
+
const dest = path.join(CACHE_DIR, 'lmcp-server.exe')
|
|
391
389
|
try {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const tmpPath = stablePath + '.tmp'
|
|
402
|
-
fs.copyFileSync(binPath, tmpPath)
|
|
403
|
-
fs.chmodSync(tmpPath, 0o755)
|
|
404
|
-
try { execFileSync('codesign', ['--force', '--sign', '-', '--identifier', 'com.local-mcp.server', tmpPath], { stdio: 'pipe' }) } catch {}
|
|
405
|
-
// curl route-3 installs the binary one level deeper:
|
|
406
|
-
// ~/.local/share/local-mcp/bin/local-mcp-server/local-mcp-server
|
|
407
|
-
// leaving stablePath itself as a DIRECTORY. fs.renameSync throws EISDIR
|
|
408
|
-
// silently, so the npm stable binary is never written and the old curl
|
|
409
|
-
// server stays running forever (LMC-158).
|
|
410
|
-
try {
|
|
411
|
-
const st = fs.statSync(stablePath)
|
|
412
|
-
if (st.isDirectory()) {
|
|
413
|
-
process.stderr.write(' Migrating from curl install: removing old versioned directory at stable path\n')
|
|
414
|
-
fs.rmSync(stablePath, { recursive: true, force: true })
|
|
415
|
-
}
|
|
416
|
-
} catch { /* stablePath doesn't exist — nothing to do */ }
|
|
417
|
-
fs.renameSync(tmpPath, stablePath)
|
|
418
|
-
}
|
|
419
|
-
// Write the actual binary version (from /runtime/latest), not the npm package
|
|
420
|
-
// version. npm and Swift binary versions can diverge (npm-only fixes bump npm
|
|
421
|
-
// without a Swift rebuild). Writing pkg.version here caused the tray to think
|
|
422
|
-
// a newer binary was on disk and restart-loop (LMC-TODO). Runs on every
|
|
423
|
-
// platform: index.js's readCachedVersion() reads .server-version off darwin too.
|
|
424
|
-
fs.writeFileSync(path.join(CACHE_DIR, '.server-version'), binaryVersion || '')
|
|
425
|
-
const settingsSrc = path.join(path.dirname(binPath), 'settings.html')
|
|
426
|
-
const settingsDst = path.join(CACHE_DIR, 'settings.html')
|
|
427
|
-
if (fs.existsSync(settingsSrc)) fs.copyFileSync(settingsSrc, settingsDst)
|
|
428
|
-
} catch {}
|
|
429
|
-
process.stderr.write('✓ Runtime ready\n\n')
|
|
390
|
+
fs.mkdirSync(CACHE_DIR, { recursive: true })
|
|
391
|
+
fs.copyFileSync(_bundled, dest + '.tmp')
|
|
392
|
+
fs.renameSync(dest + '.tmp', dest)
|
|
393
|
+
if (binaryVersion) fs.writeFileSync(path.join(CACHE_DIR, '.go-server-version'), binaryVersion)
|
|
394
|
+
process.stderr.write(`✓ LMCP server installed in ${CACHE_DIR}\n\n`)
|
|
395
|
+
} catch (e) {
|
|
396
|
+
try { fs.unlinkSync(dest + '.tmp') } catch {}
|
|
397
|
+
process.stderr.write(` (Could not install the LMCP server in ${CACHE_DIR}: ${e.message})\n\n`)
|
|
398
|
+
}
|
|
430
399
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
400
|
+
} else {
|
|
401
|
+
process.stderr.write(` (The LMCP server for ${process.platform}-${process.arch} is not in this package; run: npx -y local-mcp@latest setup)\n\n`)
|
|
402
|
+
}
|
|
403
|
+
// The launcher uses curl (no Node dependency) to send telemetry if Node is
|
|
404
|
+
// too old, then exec's npx. Claude Desktop runs this script instead of npx
|
|
405
|
+
// directly, so failures are visible in MCP logs AND in our backend events.
|
|
406
|
+
try {
|
|
435
407
|
const spec = _writeLaunchSpec(npxAbsPath, CACHE_DIR)
|
|
436
408
|
if (spec) { stableCommand = spec.command; stableArgs = spec.args }
|
|
437
|
-
} catch
|
|
438
|
-
process.stderr.write(` (Runtime download failed, will download on first run: ${err.message})\n\n`)
|
|
439
|
-
// Still try to write a launcher even if binary download failed — the version
|
|
440
|
-
// check + telemetry path is independent of the binary.
|
|
441
|
-
try {
|
|
442
|
-
const { CACHE_DIR } = require('./download')
|
|
443
|
-
const spec = _writeLaunchSpec(npxAbsPath, CACHE_DIR)
|
|
444
|
-
if (spec) { stableCommand = spec.command; stableArgs = spec.args }
|
|
445
|
-
} catch {}
|
|
446
|
-
}
|
|
409
|
+
} catch {}
|
|
447
410
|
// stableCommand is now the shell launcher script path. It wraps npx with a
|
|
448
411
|
// Node version check + curl telemetry before exec'ing. If launcher creation
|
|
449
412
|
// failed it falls back to plain 'npx'.
|
|
@@ -458,9 +421,8 @@ async function runSetup(opts = {}) {
|
|
|
458
421
|
// second JS-side client list. Linux has no runtime-native writer yet
|
|
459
422
|
// (§3.8): a generic message, no per-client guesswork, no files written.
|
|
460
423
|
if (process.platform === 'darwin' || _IS_WIN) {
|
|
461
|
-
const { CACHE_DIR } = require('./download')
|
|
462
424
|
const launcher = _launcherArgsForConfigureClients(process.platform, stableCommand, stableArgs)
|
|
463
|
-
clientsRun = runConfigureClients(_findServerBinary(_embeddedServer, CACHE_DIR), launcher.command, launcher.args)
|
|
425
|
+
clientsRun = runConfigureClients(_findServerBinary(_embeddedServer || _bundled, CACHE_DIR), launcher.command, launcher.args)
|
|
464
426
|
const clientes = (clientsRun.report && clientsRun.report.clients) || []
|
|
465
427
|
_trackSetupStep('detect', clientsRun.runtime === 'ok' ? 'ok' : clientsRun.runtime, '', {
|
|
466
428
|
clientsFound: clientes.filter(c => c.status !== 'not_installed').map(c => c.id),
|
|
@@ -486,7 +448,7 @@ async function runSetup(opts = {}) {
|
|
|
486
448
|
} else if (clientes.length > 0 && clientes.every(c => c.status === 'not_installed')) {
|
|
487
449
|
console.log('\n No AI client detected yet — LMCP is installed and ready.')
|
|
488
450
|
console.log(' Install one (Claude Desktop, Cursor, VS Code...), then run:')
|
|
489
|
-
console.log(' npx local-mcp setup\n')
|
|
451
|
+
console.log(' npx -y local-mcp@latest setup\n')
|
|
490
452
|
console.log(' Full setup guide: https://local-mcp.com/setup')
|
|
491
453
|
}
|
|
492
454
|
}
|
|
@@ -540,7 +502,7 @@ async function runSetup(opts = {}) {
|
|
|
540
502
|
if (configured.length > 0) {
|
|
541
503
|
if (healthOk) {
|
|
542
504
|
console.log(`✅ LMCP configured for: ${configured.join(', ')}\n`)
|
|
543
|
-
console.log(' ✓ Server binary verified —
|
|
505
|
+
console.log(' ✓ Server binary verified — tools ready\n')
|
|
544
506
|
} else {
|
|
545
507
|
console.log(`⚠ LMCP configured for: ${configured.join(', ')}`)
|
|
546
508
|
console.log(' Server binary could not be verified — it may still work after restart.\n')
|
|
@@ -606,19 +568,14 @@ async function runSetup(opts = {}) {
|
|
|
606
568
|
// so the tray's DaemonSupervisor doesn't race against the old server.
|
|
607
569
|
_migrateCurlLaunchAgent()
|
|
608
570
|
|
|
609
|
-
//
|
|
610
|
-
|
|
571
|
+
// npx is server-only (owner decision): setup never downloads the tray nor loads its LaunchAgent.
|
|
572
|
+
// A tray that is already installed is left alone.
|
|
611
573
|
// Tray permissions are a macOS-only concept (contract §3.1: Windows/Linux
|
|
612
574
|
// report "not_applicable", not "unknown_until_tray_runs") — polling
|
|
613
575
|
// 127.0.0.1:8765/permissions off darwin would just cost up to 10s waiting
|
|
614
576
|
// on an endpoint that was never going to answer.
|
|
615
577
|
const trayPermissions = _IS_MAC ? (clientsRun ? await _fetchTrayPermissions() : null) : 'not_applicable'
|
|
616
|
-
|
|
617
|
-
await _installSlackProxy()
|
|
618
|
-
|
|
619
|
-
// Auto-launch the primary configured AI client (macOS only — win32/linux
|
|
620
|
-
// just name the next_step) + show "Try this now" banner.
|
|
621
|
-
await _autoLaunchClient(clientsRun)
|
|
578
|
+
// npx also downloads no proxies and launches no client (#112).
|
|
622
579
|
|
|
623
580
|
// Anon-first cloud relay activation (replaces the interactive email prompt
|
|
624
581
|
// removed 2026-04-19). When no email is set, register an anonymous tunnel
|
|
@@ -704,36 +661,6 @@ async function runSetup(opts = {}) {
|
|
|
704
661
|
process.exitCode = clientsRun.exitCode
|
|
705
662
|
}
|
|
706
663
|
|
|
707
|
-
async function _installTeamsProxy() {
|
|
708
|
-
try {
|
|
709
|
-
const { ensureTeamsProxy } = require('./download')
|
|
710
|
-
await ensureTeamsProxy()
|
|
711
|
-
} catch (err) {
|
|
712
|
-
process.stderr.write(` (teams-proxy not available: ${err.message})\n`)
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
async function _installSlackProxy() {
|
|
717
|
-
try {
|
|
718
|
-
const { ensureSlackProxy } = require('./download')
|
|
719
|
-
await ensureSlackProxy()
|
|
720
|
-
} catch (err) {
|
|
721
|
-
process.stderr.write(` (slack-proxy not available: ${err.message})\n`)
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
async function _installTray() {
|
|
726
|
-
if (process.platform === 'linux') return
|
|
727
|
-
try {
|
|
728
|
-
const { ensureTray } = require('./download')
|
|
729
|
-
const trayApp = await ensureTray()
|
|
730
|
-
if (!trayApp) return
|
|
731
|
-
console.log('\n✓ Tray installed — look for the LMCP icon in your menu bar\n')
|
|
732
|
-
} catch (err) {
|
|
733
|
-
process.stderr.write(` (Tray not available: ${err.message})\n\n`)
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
|
|
737
664
|
// Resolves what to exec to prove the installed binary launches and responds. Pulled out
|
|
738
665
|
// as a pure function (platform/home/cacheDir all parameters) so it's testable without
|
|
739
666
|
// being on each OS. darwin uses the Swift binary's --export-tools (unchanged, tool-count
|
|
@@ -794,15 +721,17 @@ function _getRef() {
|
|
|
794
721
|
// The one thing download.js's version doesn't do is seed the macOS Keychain with the
|
|
795
722
|
// ioreg-derived id so the Swift tray reads the same value setup computed. That side
|
|
796
723
|
// effect stays here, gated to darwin, instead of moving into download.js: download's
|
|
797
|
-
// _getMachineId runs on every
|
|
724
|
+
// _getMachineId runs on every ensureTray()/... call (i.e. on every
|
|
798
725
|
// npx spawn), and a Keychain write there would be needless overhead on a hot path
|
|
799
726
|
// that setup.js — which only runs once at install time — doesn't share.
|
|
800
727
|
// `deps` es la costura de test (#84): sin ella un test pedía al Keychain REAL de quien lo corre
|
|
801
728
|
// que creara o pisara la identidad de la máquina. Producto: nadie la pasa, nada cambia.
|
|
802
729
|
function _getMachineId(deps = {}) {
|
|
803
730
|
const id = download._getMachineId(deps)
|
|
804
|
-
|
|
805
|
-
|
|
731
|
+
// #94: the id can come from a config.json something else wrote. Only a contract-shaped id is
|
|
732
|
+
// seeded, and through execFile with an argument array: no shell sees it.
|
|
733
|
+
if ((deps.platform ? deps.platform === 'darwin' : _IS_MAC) && require('./launch-event').RE_MAQUINA.test(id)) {
|
|
734
|
+
try { (deps.execFileImpl || execFileSync)('security', ['add-generic-password', '-s', 'com.local-mcp.machine-id', '-a', 'machine-id', '-w', id, '-U'], { stdio: 'pipe' }) } catch {}
|
|
806
735
|
}
|
|
807
736
|
return id
|
|
808
737
|
}
|
|
@@ -869,16 +798,7 @@ function _installRefDir(platform = process.platform, home = HOME, cacheDir = dow
|
|
|
869
798
|
// looks at config.json — so writing the token to cfgFile there left it registered under a
|
|
870
799
|
// key nothing could ever redeem (#1390 finding 2). getCacheDir() in the go-server resolves
|
|
871
800
|
// to the exact same directory as CACHE_DIR here (tunnel.go:1107-1113 vs. download.js:39-41).
|
|
872
|
-
|
|
873
|
-
return path.join(cacheDir, '.cloud-token')
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
function _readCachedCloudToken(cacheDir) {
|
|
877
|
-
try {
|
|
878
|
-
const tok = fs.readFileSync(_cloudTokenPath(cacheDir), 'utf8').trim()
|
|
879
|
-
return tok.startsWith('lmcp-') ? tok : ''
|
|
880
|
-
} catch { return '' }
|
|
881
|
-
}
|
|
801
|
+
const { _cloudTokenPath, _readCachedCloudToken } = download
|
|
882
802
|
|
|
883
803
|
function _writeCloudToken(cacheDir, token) {
|
|
884
804
|
fs.mkdirSync(cacheDir, { recursive: true })
|
|
@@ -896,6 +816,8 @@ async function _registerAnonToken() {
|
|
|
896
816
|
return new Promise((resolve) => {
|
|
897
817
|
const { https } = require('./user-agent')
|
|
898
818
|
const machineId = _getMachineId()
|
|
819
|
+
// lmcp-npm#92: no id, no registration. The binary mints its id and registers itself.
|
|
820
|
+
if (!machineId) return resolve('')
|
|
899
821
|
const payload = JSON.stringify({ machine_id: machineId })
|
|
900
822
|
const req = https.request({
|
|
901
823
|
host: BACKEND_HOST,
|
|
@@ -1102,7 +1024,8 @@ function _pingInstall(clients, method, email = '', binaryVersion = '') {
|
|
|
1102
1024
|
}
|
|
1103
1025
|
|
|
1104
1026
|
// Send initial heartbeat so the machine appears as "activated" immediately
|
|
1105
|
-
// Even if the user doesn't restart their AI client right away
|
|
1027
|
+
// Even if the user doesn't restart their AI client right away. Not without an id (#92).
|
|
1028
|
+
if (!machineId) return
|
|
1106
1029
|
const hb = JSON.stringify({
|
|
1107
1030
|
machine_id: machineId,
|
|
1108
1031
|
version: binaryVersion || pkg.version,
|
|
@@ -1128,9 +1051,8 @@ function _pingInstall(clients, method, email = '', binaryVersion = '') {
|
|
|
1128
1051
|
}
|
|
1129
1052
|
|
|
1130
1053
|
// _fetchClientsCatalog fetches the served catalog (the SAME endpoint the
|
|
1131
|
-
// go-server's RefreshFromRemote uses)
|
|
1132
|
-
//
|
|
1133
|
-
// second time in this file. 4s budget (#3212 §3.9): a slow/unreachable
|
|
1054
|
+
// go-server's RefreshFromRemote uses) for uninstall (index.js), so a client's
|
|
1055
|
+
// identity is never typed a second time in this file. 4s budget (#3212 §3.9): a slow/unreachable
|
|
1134
1056
|
// backend must never block the rest of setup. Returns null on any failure —
|
|
1135
1057
|
// callers treat that as "don't launch anything," never as an error.
|
|
1136
1058
|
function _fetchClientsCatalog(totalMs = 4000) {
|
|
@@ -1149,51 +1071,6 @@ function _fetchClientsCatalog(totalMs = 4000) {
|
|
|
1149
1071
|
})
|
|
1150
1072
|
}
|
|
1151
1073
|
|
|
1152
|
-
/**
|
|
1153
|
-
* Auto-launch the primary configured AI client and print a "Try this now" banner —
|
|
1154
|
-
* derived entirely from ConfigureAll's report and the served catalog (#3212 item 23):
|
|
1155
|
-
* no client name is ever typed here. macOS actually opens the app (via the
|
|
1156
|
-
* catalog's own .app detectPath); win32/linux only name the next_step, since
|
|
1157
|
-
* neither platform has an "open this app" primitive LMCP can safely use.
|
|
1158
|
-
* Non-fatal at every step — install succeeds even if the catalog fetch or
|
|
1159
|
-
* open() fails or times out.
|
|
1160
|
-
*/
|
|
1161
|
-
async function _autoLaunchClient(clientsRun, opts = {}) {
|
|
1162
|
-
const platform = opts.platform || process.platform
|
|
1163
|
-
const exec = opts.execFileSync || execFileSync
|
|
1164
|
-
const fetchCatalog = opts.fetchCatalog || _fetchClientsCatalog
|
|
1165
|
-
|
|
1166
|
-
const clientes = (clientsRun && clientsRun.report && clientsRun.report.clients) || []
|
|
1167
|
-
// "restart"/"restart_agent_mode" are the only next_steps that name reopening
|
|
1168
|
-
// an app; "new_session" (e.g. Claude Code, a CLI) and "open_mcp_page" have no
|
|
1169
|
-
// app to relaunch, and the catalog lookup below naturally no-ops for them too
|
|
1170
|
-
// (a CLI-only entry has no macOS .app detectPath to find).
|
|
1171
|
-
const entry = clientes.find(c => c.status === 'configured' && c.next_step && c.next_step.startsWith('restart'))
|
|
1172
|
-
if (!entry) return
|
|
1173
|
-
|
|
1174
|
-
if (platform !== 'darwin') {
|
|
1175
|
-
const verb = entry.next_step === 'restart_agent_mode'
|
|
1176
|
-
? `Toggle agent mode off and back on in ${entry.name}`
|
|
1177
|
-
: `Restart ${entry.name}`
|
|
1178
|
-
console.log(`\n✅ LMCP is ready! ${verb} to activate it.\n`)
|
|
1179
|
-
return
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
const catalog = await fetchCatalog()
|
|
1183
|
-
const found = catalog && (catalog.clients || []).find(c => c.id === entry.id)
|
|
1184
|
-
const macos = found && found.platforms && found.platforms.macos
|
|
1185
|
-
const appPath = ((macos && macos.detectPaths) || []).find(p => p.endsWith('.app'))
|
|
1186
|
-
if (!appPath) return
|
|
1187
|
-
|
|
1188
|
-
try {
|
|
1189
|
-
exec('open', [appPath.replace(/^~/, HOME)], { stdio: 'pipe', timeout: 5000 })
|
|
1190
|
-
console.log(`\n✅ LMCP is ready! ${entry.name} is opening now.\n`)
|
|
1191
|
-
console.log('Try asking: "Read my last 3 emails and summarize them"\n')
|
|
1192
|
-
} catch {
|
|
1193
|
-
// open failed (app not installed or already open) — non-fatal
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
1074
|
module.exports = {
|
|
1198
1075
|
runSetup, runConfigureClients, _findServerBinary, _launcherArgsForConfigureClients,
|
|
1199
1076
|
_cmdExists, _runHealthCheck,
|
|
@@ -1201,6 +1078,6 @@ module.exports = {
|
|
|
1201
1078
|
_notSupportedOnPlatformResult,
|
|
1202
1079
|
_launcherSpawnSpec, _writeLaunchScript, _writeLaunchSpec,
|
|
1203
1080
|
_getMachineId, _healthCheckSpec, _localMcpConfigDir, _installRefDir,
|
|
1204
|
-
_cloudTokenPath, _readCachedCloudToken, _writeCloudToken, _registerAnonToken,
|
|
1205
|
-
|
|
1081
|
+
_cloudTokenPath, _readCachedCloudToken, _writeCloudToken, _registerAnonToken, _pingInstall,
|
|
1082
|
+
_fetchClientsCatalog,
|
|
1206
1083
|
}
|