local-mcp 3.0.428 → 3.0.430
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 +53 -76
- package/bundled.js +35 -1
- package/index.js +74 -26
- package/launch-event.js +47 -14
- package/link.js +265 -0
- package/package.json +6 -5
- package/setup.js +63 -102
- package/unconfigure.js +514 -27
package/link.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// #125 (decisión «A» de Darío, 2026-10-28): una máquina instalada con npx se vincula a la cuenta de la
|
|
3
|
+
// persona con un código, como `gh auth login`. El binario del server pide el link con su propia llave
|
|
4
|
+
// y lo vuelve a llamar cada 5 s: mientras hay un link vivo, el binario consulta /account-link/code/status.
|
|
5
|
+
// Las dos rutas se firman con la llave raíz de la máquina, que Node no tiene (machine-link-url.v1,
|
|
6
|
+
// account-link-code.v1). Un solo subcomando, sin TTY y sin escribir nada (lmcp-mac#1451, lmcp-win#1224):
|
|
7
|
+
// link --json → {url, code, expires_at, local_required} | {linked: true, account}
|
|
8
|
+
// | {awaiting_local: true, account} | {error, account?} (error: exit ≠ 0)
|
|
9
|
+
// #128: con `local_required` (la raíz falla K2) la máquina aprueba además la confirmación web. lmcp-win#1273:
|
|
10
|
+
// la web encuentra la máquina sólo por el código, así que npm lo muestra igual que en el caso normal; después
|
|
11
|
+
// `link --json` contesta awaiting_local, el binario guarda pending_id y firma con `link --approve --json` o
|
|
12
|
+
// `link --deny --json`, sólo tras un «y» o una «n» explícitos acá. El {error: 'local_required'} de los
|
|
13
|
+
// binarios anteriores no trae código: sin él no hay nada que confirmar en la web, y npm lo dice.
|
|
14
|
+
// `account` es la pista enmascarada de la API (d***@gmail.com). A la telemetría va sólo el estado y una
|
|
15
|
+
// clase de error: nunca el código, el link ni la cuenta.
|
|
16
|
+
const { execFileSync } = require('child_process')
|
|
17
|
+
const readline = require('readline')
|
|
18
|
+
|
|
19
|
+
const RESUME = 'npx -y local-mcp@latest link'
|
|
20
|
+
const MY_LMCP = 'https://www.local-mcp.com/my-installs'
|
|
21
|
+
const ESPERA_MS = 120000
|
|
22
|
+
const CADA_MS = 5000 // account-link-code.v1: status «at most every 5 s»
|
|
23
|
+
|
|
24
|
+
function _execDefault(bin, timeout = 30000) {
|
|
25
|
+
return (args) => {
|
|
26
|
+
try {
|
|
27
|
+
// LMCP_NPM_VERSION, as index.js gives the stdio server: it is what reports the heartbeat as npm-wrapper.
|
|
28
|
+
const env = { ...process.env, LMCP_NPM_VERSION: require('./package.json').version || '' }
|
|
29
|
+
return { status: 0, stdout: execFileSync(bin, args, { timeout, env, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true }).toString() }
|
|
30
|
+
} catch (e) {
|
|
31
|
+
if (e.code === 'ENOENT' || e.code === 'EACCES') throw e
|
|
32
|
+
return { status: typeof e.status === 'number' ? e.status : 1, stdout: e.stdout ? e.stdout.toString() : '' }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The answer typed in the terminal, or null: without a TTY (an agent) or past the deadline nobody answers.
|
|
38
|
+
function _askDefault(question, ms) {
|
|
39
|
+
if (!process.stdin.isTTY) return Promise.resolve(null)
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
|
|
42
|
+
const t = setTimeout(() => { rl.close(); resolve(null) }, ms)
|
|
43
|
+
rl.question(question, (a) => { clearTimeout(t); rl.close(); resolve(a) })
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function _leer(exec, args) {
|
|
48
|
+
let r
|
|
49
|
+
try { r = exec(args) } catch { return { error: 'no_binary' } }
|
|
50
|
+
let d = null
|
|
51
|
+
try { d = JSON.parse(String(r.stdout || '').trim()) } catch { /* abajo */ }
|
|
52
|
+
// lmcp-api#761 §5: a key from the table, or http_<status>; anything else is bad_output, never «error».
|
|
53
|
+
if (d && typeof d === 'object' && typeof d.error === 'string') return { error: /^[a-z0-9_]{1,40}$/.test(d.error) ? d.error : 'bad_output', account: d.account }
|
|
54
|
+
if (r.status !== 0) return { error: 'exit_' + r.status }
|
|
55
|
+
if (!d || typeof d !== 'object') return { error: 'bad_output' }
|
|
56
|
+
return d
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const REPORT = 'hello@local-mcp.com'
|
|
60
|
+
|
|
61
|
+
// Signing in fixes none of these: there is nothing for the web to confirm, so the person reports it.
|
|
62
|
+
const SIN_ARREGLO_EN_LA_WEB = {
|
|
63
|
+
local_required: 'This computer needs a link code to confirm on the web, and LMCP did not give one',
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// lmcp-api#761 §5 (decisión A, 2026-10-30): the text and what to do for each key `link --json` returns.
|
|
67
|
+
const SETUP_AGAIN = 'npx -y local-mcp@latest setup'
|
|
68
|
+
const RED = ['Could not reach LMCP.', `Check your internet connection and run: ${RESUME}`]
|
|
69
|
+
const TABLA = {
|
|
70
|
+
forwarding_off: ["Linking needs LMCP's cloud connection, which is turned off on this computer.", `Turn it on in LMCP's settings, then run: ${RESUME}`],
|
|
71
|
+
no_token: ['This computer has no LMCP connection yet.', `Run ${SETUP_AGAIN} again, then ${RESUME}. If it keeps happening, report it to ${REPORT}`],
|
|
72
|
+
network: RED,
|
|
73
|
+
no_answer: RED,
|
|
74
|
+
try_later: ['Too many attempts right now.', `Wait a few minutes and run: ${RESUME}`],
|
|
75
|
+
linking_off: ['Linking computers to an account is turned off right now.', `Try again later: ${RESUME}`],
|
|
76
|
+
bad_signature: ["This computer's clock is off.", `Set the date and time automatically, then run: ${RESUME}`],
|
|
77
|
+
not_linkable: ["This computer can't be linked to an account.", `Please report it to ${REPORT}`],
|
|
78
|
+
// lmcp-mac#1550: the binary cannot read this computer's token until the app is opened again.
|
|
79
|
+
open_lmcp_app: ['LMCP needs to be opened again on this computer.', `Quit LMCP, open it again, then run: ${RESUME}`],
|
|
80
|
+
// lmcp-win#1270: the device key could not be read, created or enrolled. A 5xx or a locked keychain pass, and
|
|
81
|
+
// link tries again from the start. npx may have no app, so the text does not name one.
|
|
82
|
+
no_key: ["Could not prepare this computer's key.", `Wait a few minutes and run: ${RESUME}. If it keeps happening, report it to ${REPORT}`],
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function _falla(print, track) {
|
|
86
|
+
return (clase, texto) => {
|
|
87
|
+
const fila = TABLA[clase]
|
|
88
|
+
if (fila) {
|
|
89
|
+
print(`\n ⚠ ${fila[0]}`)
|
|
90
|
+
print(` ${fila[1]}`)
|
|
91
|
+
track('failed', clase)
|
|
92
|
+
return { state: 'failed', error: clase }
|
|
93
|
+
}
|
|
94
|
+
const propia = SIN_ARREGLO_EN_LA_WEB[clase]
|
|
95
|
+
print(`\n ⚠ ${texto || propia || 'Could not get a link code for this machine'} (${clase}).`)
|
|
96
|
+
if (propia) print(` Please report it to ${REPORT}, or run ${RESUME} again later.`)
|
|
97
|
+
else print(` Sign in or create your account in My LMCP — ${MY_LMCP} — then run: ${RESUME}`)
|
|
98
|
+
track('failed', clase)
|
|
99
|
+
return { state: 'failed', error: clase }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// The binary keeps the one-time id on these: the same command works again a bit later.
|
|
104
|
+
const REINTENTABLES = ['try_later', 'network', 'no_device_key']
|
|
105
|
+
|
|
106
|
+
// #128: sign the approval or the denial of a pending local link (the binary keeps pending_id). Used by
|
|
107
|
+
// the y/n question and by `npx -y local-mcp@latest link --approve|--deny`.
|
|
108
|
+
async function runDecision(modo, opts = {}) {
|
|
109
|
+
const print = opts.print || ((s) => console.log(s))
|
|
110
|
+
const track = opts.track || (() => {})
|
|
111
|
+
const falla = _falla(print, track)
|
|
112
|
+
const que = modo === 'approve' ? 'approve' : 'decline'
|
|
113
|
+
if (!opts.bin && !opts.exec) return falla('no_binary', `Could not ${que} the link on this computer`)
|
|
114
|
+
// #140: written out, so the scan of npm/test/servidor-minimo-138.test.js reads each command.
|
|
115
|
+
const r = _leer(opts.exec || _execDefault(opts.bin), modo === 'approve' ? ['link', '--approve', '--json'] : ['link', '--deny', '--json'])
|
|
116
|
+
if (REINTENTABLES.includes(r.error)) {
|
|
117
|
+
print(`\n ⚠ Could not ${que} the link on this computer yet (${r.error}).`)
|
|
118
|
+
print(` Try again: ${RESUME} --${modo}`)
|
|
119
|
+
track('failed', r.error)
|
|
120
|
+
return { state: 'retry', error: r.error }
|
|
121
|
+
}
|
|
122
|
+
if (r.error) return falla(r.error, `Could not ${que} the link on this computer`)
|
|
123
|
+
if (modo === 'approve' && r.linked === true) {
|
|
124
|
+
print(` ✓ Linked to ${r.account || 'your LMCP account'}.`)
|
|
125
|
+
track('linked')
|
|
126
|
+
return { state: 'linked', account: r.account || null }
|
|
127
|
+
}
|
|
128
|
+
if (modo === 'deny' && r.denied === true) {
|
|
129
|
+
print(' Not linked: you declined it on this computer.')
|
|
130
|
+
track('failed', 'denied')
|
|
131
|
+
return { state: 'denied' }
|
|
132
|
+
}
|
|
133
|
+
return falla('bad_output', `Could not ${que} the link on this computer`)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function runLink(opts = {}) {
|
|
137
|
+
const print = opts.print || ((s) => console.log(s))
|
|
138
|
+
const track = opts.track || (() => {})
|
|
139
|
+
const sleep = opts.sleep || ((ms) => new Promise(r => setTimeout(r, ms)))
|
|
140
|
+
const now = opts.now || Date.now
|
|
141
|
+
const ask = opts.ask || _askDefault
|
|
142
|
+
const tty = opts.tty !== undefined ? opts.tty : !!process.stdin.isTTY
|
|
143
|
+
const falla = _falla(print, track)
|
|
144
|
+
if (!opts.bin && !opts.exec) return falla('no_binary')
|
|
145
|
+
const exec = opts.exec || _execDefault(opts.bin)
|
|
146
|
+
|
|
147
|
+
const pedido = _leer(exec, ['link', '--json'])
|
|
148
|
+
if (pedido.error === 'linked_elsewhere') {
|
|
149
|
+
// Neutral, without the account hint: whoever runs setup may not be the account's owner.
|
|
150
|
+
print('\n This computer is already linked to an LMCP account.')
|
|
151
|
+
track('failed', 'linked_elsewhere')
|
|
152
|
+
return { state: 'failed', error: 'linked_elsewhere' }
|
|
153
|
+
}
|
|
154
|
+
// local_lost (exit 1): the API gave out the one-time approval id and it got lost. Final, not «keep waiting».
|
|
155
|
+
const perdida = () => {
|
|
156
|
+
print(`\n ⚠ The approval request expired. Run ${RESUME} to start again.`)
|
|
157
|
+
track('failed', 'local_lost')
|
|
158
|
+
return { state: 'failed', error: 'local_lost' }
|
|
159
|
+
}
|
|
160
|
+
if (pedido.error === 'local_lost') return perdida()
|
|
161
|
+
if (pedido.error) return falla(pedido.error)
|
|
162
|
+
if (pedido.linked === true) {
|
|
163
|
+
print(`\n ✓ This machine is already linked to your LMCP account${pedido.account ? ' (' + pedido.account + ')' : ''}.`)
|
|
164
|
+
track('linked')
|
|
165
|
+
return { state: 'linked', account: pedido.account || null }
|
|
166
|
+
}
|
|
167
|
+
const local = pedido.local_required === true
|
|
168
|
+
const url = pedido.url, code = pedido.code
|
|
169
|
+
if (pedido.awaiting_local !== true) {
|
|
170
|
+
if (typeof url !== 'string' || typeof code !== 'string') return falla(local ? 'local_required' : 'bad_output')
|
|
171
|
+
print('\n Link this machine to your LMCP account:')
|
|
172
|
+
print(` Open ${url}`)
|
|
173
|
+
print(' (sign in or create your account there, then confirm)')
|
|
174
|
+
print(` Or enter the code ${code} in My LMCP — ${MY_LMCP}`)
|
|
175
|
+
if (local) {
|
|
176
|
+
print(' After you confirm on the web, this computer asks you to approve it here: that last step links it.')
|
|
177
|
+
print(' Waiting for the web confirmation…')
|
|
178
|
+
track('shown', 'local_required')
|
|
179
|
+
} else {
|
|
180
|
+
print(' Waiting for approval…')
|
|
181
|
+
track('shown')
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const hasta = now() + (opts.timeoutMs || ESPERA_MS)
|
|
186
|
+
const vinculada = (e) => {
|
|
187
|
+
print(` ✓ Linked to ${e.account || 'your LMCP account'}.`)
|
|
188
|
+
track('linked')
|
|
189
|
+
return { state: 'linked', url, code, account: e.account || null }
|
|
190
|
+
}
|
|
191
|
+
let e = pedido.awaiting_local === true ? pedido : null
|
|
192
|
+
while (e || now() < hasta) {
|
|
193
|
+
if (!e) { await sleep(CADA_MS); e = _leer(exec, ['link', '--json']) }
|
|
194
|
+
if (e.linked === true) return vinculada(e)
|
|
195
|
+
if (e.error === 'local_lost') return perdida()
|
|
196
|
+
if (e.awaiting_local === true && !tty) {
|
|
197
|
+
// An agent ran setup: nobody can type y here. The person approves by hand, with the same binary.
|
|
198
|
+
const cmd = (modo) => `${RESUME} --${modo}`
|
|
199
|
+
print(` Confirm on the web, then approve linking to ${e.account || 'your LMCP account'} on this computer. In a terminal, run:`)
|
|
200
|
+
print(` ${cmd('approve')}`)
|
|
201
|
+
print(` or, to decline it:`)
|
|
202
|
+
print(` ${cmd('deny')}`)
|
|
203
|
+
track('timeout', 'awaiting_local')
|
|
204
|
+
return { state: 'awaiting_local', url, code }
|
|
205
|
+
}
|
|
206
|
+
if (e.awaiting_local === true) {
|
|
207
|
+
const resp = String(await ask(` Confirm on the web, then type y here to approve linking to ${e.account || 'your LMCP account'} [y/n]: `,
|
|
208
|
+
Math.max(hasta - now(), 0)) || '').trim().toLowerCase()
|
|
209
|
+
if (resp === 'y' || resp === 'yes' || resp === 'n' || resp === 'no') {
|
|
210
|
+
const d = await runDecision(resp[0] === 'y' ? 'approve' : 'deny', { exec, print, track })
|
|
211
|
+
// Retryable: the id is still in the binary. With time left, ask again (e stays the same answer).
|
|
212
|
+
if (d.state === 'retry' && now() < hasta) { await sleep(CADA_MS); continue }
|
|
213
|
+
return { ...d, url, code }
|
|
214
|
+
} else {
|
|
215
|
+
print(` Not approved on this computer. To approve it, run in a terminal: ${RESUME}`)
|
|
216
|
+
track('timeout', 'awaiting_local')
|
|
217
|
+
return { state: 'timeout', url, code }
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// The link again (not approved yet), local_required or a failed check: keep waiting until the deadline.
|
|
221
|
+
e = null
|
|
222
|
+
}
|
|
223
|
+
print(` Not approved yet. When you have approved it, or for a new code, run: ${RESUME}`)
|
|
224
|
+
track('timeout')
|
|
225
|
+
return { state: 'timeout', url, code }
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// lmcp-api#761 §1–2: before link, the binary registers the machine's relay token (without opening the
|
|
229
|
+
// tunnel) and beats once, so the key it enrols at link is bound to that token (bearer, never tofu) and
|
|
230
|
+
// first_seen exists. The binary keeps the token where it keeps its relay token: the answer never carries it.
|
|
231
|
+
// {"ok": true, "reused": bool} | {"ok": false, "code": "no_network|rate_limited|no_token|forwarding_off|open_lmcp_app"}
|
|
232
|
+
// Not fatal and silent: only telemetry here, because link retries it and prints the text, so a failure
|
|
233
|
+
// is not said twice. Any other answer (a binary without the subcommand, exit 2) is `unsupported`.
|
|
234
|
+
const CODIGO_DE_REGISTRO = { no_network: 'network', rate_limited: 'try_later', no_token: 'no_token', forwarding_off: 'forwarding_off', open_lmcp_app: 'open_lmcp_app' }
|
|
235
|
+
|
|
236
|
+
async function runRegister(opts = {}) {
|
|
237
|
+
const track = opts.track || (() => {})
|
|
238
|
+
if (!opts.bin && !opts.exec) return { state: 'unsupported' }
|
|
239
|
+
let d = null
|
|
240
|
+
try {
|
|
241
|
+
const r = (opts.exec || _execDefault(opts.bin, 60000))(['register', '--json'])
|
|
242
|
+
d = JSON.parse(String(r.stdout || '').trim())
|
|
243
|
+
} catch { return { state: 'unsupported' } }
|
|
244
|
+
if (d && d.ok === true) { track(d.reused === true ? 'reused' : 'ok'); return { state: 'registered', reused: d.reused === true } }
|
|
245
|
+
const clave = d && d.ok === false ? CODIGO_DE_REGISTRO[d.code] : undefined
|
|
246
|
+
if (!clave) return { state: 'unsupported' }
|
|
247
|
+
track('failed', clave)
|
|
248
|
+
return { state: 'failed', error: clave }
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// `npx local-mcp link [--approve|--deny]`: the same binary and the same telemetry step as setup.
|
|
252
|
+
async function runLinkCommand(args = []) {
|
|
253
|
+
const setup = require('./setup')
|
|
254
|
+
const { CACHE_DIR } = require('./download')
|
|
255
|
+
const opts = {
|
|
256
|
+
bin: setup._findServerBinary(require('./bundled').bundledServerPath(), CACHE_DIR),
|
|
257
|
+
track: (status, error) => setup._trackSetupStep('account_link', status, '', error ? { error } : {}),
|
|
258
|
+
}
|
|
259
|
+
const modo = args.includes('--approve') ? 'approve' : args.includes('--deny') ? 'deny' : null
|
|
260
|
+
if (modo) return runDecision(modo, opts)
|
|
261
|
+
// lmcp-api#761 §2: link beats and registers too when it has to; the binary does it inside `link`.
|
|
262
|
+
return runLink(opts)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
module.exports = { runLink, runLinkCommand, runDecision, runRegister, RESUME }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "local-mcp",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.430",
|
|
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": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"download.js",
|
|
16
16
|
"bundled.js",
|
|
17
17
|
"setup.js",
|
|
18
|
+
"link.js",
|
|
18
19
|
"launch-event.js",
|
|
19
20
|
"user-agent.js",
|
|
20
21
|
"unconfigure.js",
|
|
@@ -25,10 +26,10 @@
|
|
|
25
26
|
"node": ">=20"
|
|
26
27
|
},
|
|
27
28
|
"optionalDependencies": {
|
|
28
|
-
"local-mcp-darwin-arm64": "3.0.
|
|
29
|
-
"local-mcp-darwin-x64": "3.0.
|
|
30
|
-
"local-mcp-windows-x64": "3.0.
|
|
31
|
-
"local-mcp-windows-arm64": "3.0.
|
|
29
|
+
"local-mcp-darwin-arm64": "3.0.430",
|
|
30
|
+
"local-mcp-darwin-x64": "3.0.430",
|
|
31
|
+
"local-mcp-windows-x64": "3.0.430",
|
|
32
|
+
"local-mcp-windows-arm64": "3.0.430"
|
|
32
33
|
},
|
|
33
34
|
"os": [
|
|
34
35
|
"darwin",
|
package/setup.js
CHANGED
|
@@ -13,6 +13,7 @@ const path = require('path')
|
|
|
13
13
|
const os = require('os')
|
|
14
14
|
const { execSync, execFileSync } = require('child_process')
|
|
15
15
|
const download = require('./download')
|
|
16
|
+
const { runLink, runRegister } = require('./link')
|
|
16
17
|
|
|
17
18
|
const HOME = os.homedir()
|
|
18
19
|
const NPX_COMMAND = 'npx'
|
|
@@ -25,11 +26,19 @@ const NPX_ARGS = ['-y', 'local-mcp@latest']
|
|
|
25
26
|
function _resolveNpxPath() {
|
|
26
27
|
try {
|
|
27
28
|
const candidate = path.join(path.dirname(process.execPath), 'npx')
|
|
28
|
-
if (fs.existsSync(candidate)) return candidate
|
|
29
|
+
if (fs.existsSync(candidate)) return _stableNpxPath(candidate)
|
|
29
30
|
} catch {}
|
|
30
31
|
return NPX_COMMAND
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
// #124 (4): Homebrew's process.execPath is the versioned Cellar path; the next `brew upgrade node@22`
|
|
35
|
+
// deletes it and every configured client breaks. opt/<formula> is Homebrew's stable link to it.
|
|
36
|
+
function _stableNpxPath(p, exists = fs.existsSync) {
|
|
37
|
+
const m = /^(.*)\/Cellar\/([^/]+)\/[^/]+\/bin\/([^/]+)$/.exec(p)
|
|
38
|
+
const opt = m && `${m[1]}/opt/${m[2]}/bin/${m[3]}`
|
|
39
|
+
return opt && exists(opt) ? opt : p
|
|
40
|
+
}
|
|
41
|
+
|
|
33
42
|
// Write a shell launcher script that wraps npx with a Node version check and
|
|
34
43
|
// curl-based telemetry. This gives us visibility into failures that happen
|
|
35
44
|
// BEFORE Node loads our code (e.g. old nvm default in Claude Desktop's PATH).
|
|
@@ -49,7 +58,9 @@ function _writeLaunchScript(npxAbsPath, cacheDir, isWin = _IS_WIN) {
|
|
|
49
58
|
// appended a SECOND copy of whatever the MCP host passed, so a client
|
|
50
59
|
// configured with args ended up running `npx -y local-mcp@latest -y
|
|
51
60
|
// local-mcp@latest` (#1394 §C).
|
|
52
|
-
|
|
61
|
+
// #124 (4): winget's Node lives in a versioned folder; if it is gone, the npx on PATH. goto, not
|
|
62
|
+
// an if (...) block: a path with parentheses (Program Files (x86)) would close the block.
|
|
63
|
+
const script = `@echo off\r\nif not exist "${npxAbsPath}" goto path_npx\r\n"${npxAbsPath}" -y local-mcp@latest\r\nexit /b %errorlevel%\r\n:path_npx\r\nnpx -y local-mcp@latest\r\n`
|
|
53
64
|
fs.writeFileSync(cmdPath, script)
|
|
54
65
|
return cmdPath
|
|
55
66
|
} catch {
|
|
@@ -73,7 +84,10 @@ function _writeLaunchScript(npxAbsPath, cacheDir, isWin = _IS_WIN) {
|
|
|
73
84
|
' printf \'LMCP requires Node 16+. Current: %s\\nFix: nvm alias default 22 && nvm uninstall %s — then restart Claude Desktop.\\n\' "$NODE_VER" "$NODE_VER" >&2',
|
|
74
85
|
' exit 1',
|
|
75
86
|
'fi',
|
|
76
|
-
|
|
87
|
+
// #124 (4): the path written here can disappear (a Node upgrade); then the npx on PATH.
|
|
88
|
+
`NPX="${npxAbsPath}"`,
|
|
89
|
+
'[ -x "$NPX" ] || NPX="$(command -v npx || echo npx)"',
|
|
90
|
+
'exec "$NPX" -y local-mcp@latest "$@"',
|
|
77
91
|
].join('\n') + '\n'
|
|
78
92
|
fs.writeFileSync(launcherPath, script, { mode: 0o755 })
|
|
79
93
|
return launcherPath
|
|
@@ -416,6 +430,7 @@ async function runSetup(opts = {}) {
|
|
|
416
430
|
const configured = []
|
|
417
431
|
const failed = []
|
|
418
432
|
let clientsRun = null // #3212: en la Mac, el reporte del binario
|
|
433
|
+
let clientes = []
|
|
419
434
|
// #3212 — Windows now shares the exact darwin path: the go-server binary
|
|
420
435
|
// decides and writes (lmcp-server --configure-clients --json), never a
|
|
421
436
|
// second JS-side client list. Linux has no runtime-native writer yet
|
|
@@ -423,7 +438,7 @@ async function runSetup(opts = {}) {
|
|
|
423
438
|
if (process.platform === 'darwin' || _IS_WIN) {
|
|
424
439
|
const launcher = _launcherArgsForConfigureClients(process.platform, stableCommand, stableArgs)
|
|
425
440
|
clientsRun = runConfigureClients(_findServerBinary(_embeddedServer || _bundled, CACHE_DIR), launcher.command, launcher.args)
|
|
426
|
-
|
|
441
|
+
clientes = (clientsRun.report && clientsRun.report.clients) || []
|
|
427
442
|
_trackSetupStep('detect', clientsRun.runtime === 'ok' ? 'ok' : clientsRun.runtime, '', {
|
|
428
443
|
clientsFound: clientes.filter(c => c.status !== 'not_installed').map(c => c.id),
|
|
429
444
|
clientsNotFound: clientes.filter(c => c.status === 'not_installed').map(c => c.id),
|
|
@@ -444,7 +459,7 @@ async function runSetup(opts = {}) {
|
|
|
444
459
|
}
|
|
445
460
|
}
|
|
446
461
|
if (clientsRun.runtime !== 'ok') {
|
|
447
|
-
console.error(`⚠ AI apps not configured yet (${clientsRun.runtime}) —
|
|
462
|
+
console.error(`⚠ AI apps not configured yet (${clientsRun.runtime}) — run 'npx -y local-mcp@latest setup' again, or see https://local-mcp.com/setup`)
|
|
448
463
|
} else if (clientes.length > 0 && clientes.every(c => c.status === 'not_installed')) {
|
|
449
464
|
console.log('\n No AI client detected yet — LMCP is installed and ready.')
|
|
450
465
|
console.log(' Install one (Claude Desktop, Cursor, VS Code...), then run:')
|
|
@@ -460,11 +475,27 @@ async function runSetup(opts = {}) {
|
|
|
460
475
|
// signing in on the web (My LMCP); the machine links by download token or device code.
|
|
461
476
|
|
|
462
477
|
// Health check — verify binary works before showing success
|
|
463
|
-
const healthOk = _runHealthCheck()
|
|
478
|
+
const healthOk = _runHealthCheck(_findServerBinary(_embeddedServer || _bundled, CACHE_DIR))
|
|
464
479
|
_trackSetupStep('binary_health', healthOk ? 'ok' : 'failed', '', {})
|
|
465
480
|
|
|
481
|
+
// lmcp-api#761 §1–2: the binary registers this installation's relay token (no tunnel) and beats once,
|
|
482
|
+
// before the link: the key it enrols is bound to that token, and first_seen exists.
|
|
483
|
+
await runRegister({
|
|
484
|
+
bin: _findServerBinary(_embeddedServer || _bundled, CACHE_DIR),
|
|
485
|
+
track: (status, error) => _trackSetupStep('relay_register', status, '', error ? { error } : {}),
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
// #125 (decisión «A»): the machine links to the person's account with a code, printed for them and
|
|
489
|
+
// for the agent running the setup; it waits up to ~2 min for the approval on the web.
|
|
490
|
+
const accountLink = await runLink({
|
|
491
|
+
bin: _findServerBinary(_embeddedServer || _bundled, CACHE_DIR),
|
|
492
|
+
track: (status, error) => _trackSetupStep('account_link', status, '', error ? { error } : {}),
|
|
493
|
+
})
|
|
494
|
+
|
|
466
495
|
// setup_complete summary
|
|
467
|
-
|
|
496
|
+
const fin = _setupCompleteStatus(clientsRun, clientes)
|
|
497
|
+
_trackSetupStep('setup_complete', fin.status, '', {
|
|
498
|
+
error: fin.error,
|
|
468
499
|
clientsFound: configured,
|
|
469
500
|
clientsNotFound: failed.map(f => f.name || f),
|
|
470
501
|
})
|
|
@@ -559,42 +590,12 @@ async function runSetup(opts = {}) {
|
|
|
559
590
|
const trayPermissions = _IS_MAC ? (clientsRun ? await _fetchTrayPermissions() : null) : 'not_applicable'
|
|
560
591
|
// npx also downloads no proxies and launches no client (#112).
|
|
561
592
|
|
|
562
|
-
//
|
|
563
|
-
//
|
|
564
|
-
//
|
|
565
|
-
//
|
|
566
|
-
//
|
|
567
|
-
//
|
|
568
|
-
{
|
|
569
|
-
try {
|
|
570
|
-
// On darwin the token lives in config.json, read by the Swift tray. Off darwin
|
|
571
|
-
// the go-server reads ONLY CACHE_DIR/.cloud-token (#1390 finding 2) — check and
|
|
572
|
-
// write there instead, so this doesn't mint a second, unredeemable token under
|
|
573
|
-
// the same (now-correct, per finding 1) machine_id the go-server would otherwise
|
|
574
|
-
// register for itself on first run.
|
|
575
|
-
const cfg = (_safeReadConfig(cfgFile)).data || {}
|
|
576
|
-
const cfgToken = (cfg.cloud_token && typeof cfg.cloud_token === 'string'
|
|
577
|
-
&& cfg.cloud_token.startsWith('lmcp-')) ? cfg.cloud_token : ''
|
|
578
|
-
const existing = _IS_MAC ? cfgToken : (cfgToken || _readCachedCloudToken(download.CACHE_DIR))
|
|
579
|
-
let token = existing
|
|
580
|
-
if (!token) {
|
|
581
|
-
token = await _registerAnonToken()
|
|
582
|
-
if (token) {
|
|
583
|
-
if (_IS_MAC) {
|
|
584
|
-
const cfg2 = (_safeReadConfig(cfgFile)).data || {}
|
|
585
|
-
cfg2.cloud_token = token
|
|
586
|
-
_atomicWriteConfig(cfgFile, cfg2)
|
|
587
|
-
} else {
|
|
588
|
-
_writeCloudToken(download.CACHE_DIR, token)
|
|
589
|
-
}
|
|
590
|
-
console.log(' ✓ Cloud relay activated (anonymous)')
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
} catch { /* non-fatal */ }
|
|
594
|
-
|
|
595
|
-
// #120: the account is created or signed in on the web; nothing here takes an email.
|
|
596
|
-
console.log('\n \x1b[1mYour LMCP account:\x1b[0m sign in or create it in My LMCP — https://www.local-mcp.com/my-installs')
|
|
597
|
-
}
|
|
593
|
+
// lmcp-npm#141, lmcp-api#761: Node registers no relay token and writes none. The binary does it
|
|
594
|
+
// (runRegister above, `register --json`), without opening the tunnel, and keeps it where it keeps its
|
|
595
|
+
// relay token; the tunnel only comes up after approval. A token that already exists is kept: setup
|
|
596
|
+
// neither reads it to replace it nor deletes it.
|
|
597
|
+
// #120: the account is created or signed in on the web; nothing here takes an email. #125: the
|
|
598
|
+
// machine's link to it was printed above (runLink).
|
|
598
599
|
|
|
599
600
|
// LMCP_METHOD lets install.sh pass 'curl' so we can distinguish it from
|
|
600
601
|
// a direct 'npx local-mcp setup' invocation in the analytics.
|
|
@@ -612,6 +613,8 @@ async function runSetup(opts = {}) {
|
|
|
612
613
|
catalog: rep.catalog || null,
|
|
613
614
|
clients: rep.clients || [],
|
|
614
615
|
permissions: trayPermissions || 'unknown_until_tray_runs',
|
|
616
|
+
// #125: what the agent hands to the person (the code is theirs to type; never telemetry).
|
|
617
|
+
account_link: accountLink,
|
|
615
618
|
}
|
|
616
619
|
process.stdout.write(JSON.stringify(out) + '\n')
|
|
617
620
|
}
|
|
@@ -626,7 +629,9 @@ async function runSetup(opts = {}) {
|
|
|
626
629
|
// too, which would have fallen through to stdio mode and hung until the timeout (#1390
|
|
627
630
|
// finding 3), on top of checking a path+name (local-mcp-server, no .exe) the go-server
|
|
628
631
|
// binary never has.
|
|
629
|
-
function _healthCheckSpec(platform = process.platform, home = HOME, cacheDir = download.CACHE_DIR) {
|
|
632
|
+
function _healthCheckSpec(platform = process.platform, home = HOME, cacheDir = download.CACHE_DIR, found = null) {
|
|
633
|
+
// #124 (2): the binary setup found (bundled in npm since 3.0.423); the paths below are the fallback.
|
|
634
|
+
if (found) return { binPath: found, args: platform === 'darwin' ? ['--export-tools'] : ['--version'] }
|
|
630
635
|
if (platform === 'darwin') {
|
|
631
636
|
return { binPath: path.join(home, '.local', 'share', 'local-mcp', 'bin', 'local-mcp-server'), args: ['--export-tools'] }
|
|
632
637
|
}
|
|
@@ -634,9 +639,18 @@ function _healthCheckSpec(platform = process.platform, home = HOME, cacheDir = d
|
|
|
634
639
|
return { binPath: path.join(cacheDir, binName), args: ['--version'] }
|
|
635
640
|
}
|
|
636
641
|
|
|
637
|
-
|
|
642
|
+
// #124 (3): a client already configured by an earlier install is set up, not a failure; a failure
|
|
643
|
+
// says why in `error` (Windows reported failed with setup exiting 0).
|
|
644
|
+
function _setupCompleteStatus(clientsRun, clientes) {
|
|
645
|
+
if (clientes.some(c => c.status === 'configured' || c.status === 'already')) return { status: 'ok' }
|
|
646
|
+
if (!clientsRun || clientsRun.runtime !== 'ok') return { status: 'failed', error: 'runtime_' + ((clientsRun && clientsRun.runtime) || 'none') }
|
|
647
|
+
if (clientes.every(c => c.status === 'not_installed')) return { status: 'failed', error: 'no_client_detected' }
|
|
648
|
+
return { status: 'failed', error: 'clients_failed' }
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function _runHealthCheck(found) {
|
|
638
652
|
try {
|
|
639
|
-
const { binPath, args } = _healthCheckSpec()
|
|
653
|
+
const { binPath, args } = _healthCheckSpec(process.platform, HOME, download.CACHE_DIR, found)
|
|
640
654
|
if (!fs.existsSync(binPath)) return false
|
|
641
655
|
const result = execFileSync(binPath, args, {
|
|
642
656
|
timeout: 10000,
|
|
@@ -707,61 +721,8 @@ function _installRefDir(platform = process.platform, home = HOME, cacheDir = dow
|
|
|
707
721
|
return cacheDir
|
|
708
722
|
}
|
|
709
723
|
|
|
710
|
-
// On darwin the anon cloud_token is persisted in config.json (cfgFile), which the Swift
|
|
711
|
-
// tray already reads. Off darwin, the go-server reads it EXCLUSIVELY from
|
|
712
|
-
// getCacheDir()/.cloud-token as a plain trimmed string (tunnel.go:454,513-523) — it never
|
|
713
|
-
// looks at config.json — so writing the token to cfgFile there left it registered under a
|
|
714
|
-
// key nothing could ever redeem (#1390 finding 2). getCacheDir() in the go-server resolves
|
|
715
|
-
// to the exact same directory as CACHE_DIR here (tunnel.go:1107-1113 vs. download.js:39-41).
|
|
716
724
|
const { _cloudTokenPath, _readCachedCloudToken } = download
|
|
717
725
|
|
|
718
|
-
function _writeCloudToken(cacheDir, token) {
|
|
719
|
-
fs.mkdirSync(cacheDir, { recursive: true })
|
|
720
|
-
// 0o600 matches tokenFileMode in tunnel.go — best-effort on Windows, where POSIX bits
|
|
721
|
-
// are largely ignored, but real restriction on Linux.
|
|
722
|
-
fs.writeFileSync(_cloudTokenPath(cacheDir), token, { mode: 0o600 })
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
/// Claim an anonymous tunnel token via /tunnel/register-anon so cloud relay
|
|
726
|
-
/// activates without asking for an email (2026-04-19 anon-first rollout). The
|
|
727
|
-
/// token is keyed on the Mac's machine_id (IOPlatformUUID, shared via Keychain
|
|
728
|
-
/// with the Swift daemon). Returns the token string or '' on failure — callers
|
|
729
|
-
/// treat failure as non-fatal.
|
|
730
|
-
async function _registerAnonToken() {
|
|
731
|
-
return new Promise((resolve) => {
|
|
732
|
-
const { https } = require('./user-agent')
|
|
733
|
-
const machineId = _getMachineId()
|
|
734
|
-
// lmcp-npm#92: no id, no registration. The binary mints its id and registers itself.
|
|
735
|
-
if (!machineId) return resolve('')
|
|
736
|
-
const payload = JSON.stringify({ machine_id: machineId })
|
|
737
|
-
const req = https.request({
|
|
738
|
-
host: BACKEND_HOST,
|
|
739
|
-
port: 443,
|
|
740
|
-
method: 'POST',
|
|
741
|
-
path: '/tunnel/register-anon',
|
|
742
|
-
headers: {
|
|
743
|
-
'Content-Type': 'application/json',
|
|
744
|
-
'Content-Length': Buffer.byteLength(payload),
|
|
745
|
-
},
|
|
746
|
-
timeout: 8000,
|
|
747
|
-
}, (res) => {
|
|
748
|
-
let buf = ''
|
|
749
|
-
res.on('data', (chunk) => { buf += chunk })
|
|
750
|
-
res.on('end', () => {
|
|
751
|
-
try {
|
|
752
|
-
const obj = JSON.parse(buf)
|
|
753
|
-
const tok = (obj && typeof obj.token === 'string') ? obj.token : ''
|
|
754
|
-
resolve(tok.startsWith('lmcp-') ? tok : '')
|
|
755
|
-
} catch { resolve('') }
|
|
756
|
-
})
|
|
757
|
-
})
|
|
758
|
-
req.on('error', () => resolve(''))
|
|
759
|
-
req.on('timeout', () => { try { req.destroy() } catch {} resolve('') })
|
|
760
|
-
req.write(payload)
|
|
761
|
-
req.end()
|
|
762
|
-
})
|
|
763
|
-
}
|
|
764
|
-
|
|
765
726
|
/**
|
|
766
727
|
* Detects and removes the legacy com.local-mcp.server LaunchAgent left behind
|
|
767
728
|
* by older curl installs. In the current architecture the tray app's
|
|
@@ -986,11 +947,11 @@ function _fetchClientsCatalog(totalMs = 4000) {
|
|
|
986
947
|
|
|
987
948
|
module.exports = {
|
|
988
949
|
runSetup, runConfigureClients, _findServerBinary, _launcherArgsForConfigureClients,
|
|
989
|
-
_cmdExists, _runHealthCheck,
|
|
950
|
+
_cmdExists, _runHealthCheck, _setupCompleteStatus, _stableNpxPath,
|
|
990
951
|
CLIENTS_REPORT_SCHEMA,
|
|
991
952
|
_notSupportedOnPlatformResult,
|
|
992
953
|
_launcherSpawnSpec, _writeLaunchScript, _writeLaunchSpec,
|
|
993
954
|
_getMachineId, _healthCheckSpec, _localMcpConfigDir, _installRefDir,
|
|
994
|
-
_cloudTokenPath, _readCachedCloudToken,
|
|
995
|
-
_fetchClientsCatalog,
|
|
955
|
+
_cloudTokenPath, _readCachedCloudToken, _pingInstall,
|
|
956
|
+
_fetchClientsCatalog, _trackSetupStep,
|
|
996
957
|
}
|