@zenlayer/lune-mcp 0.0.0-stage → 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 +253 -2
- package/dist/chunk-2UUMFH2N.js +357 -0
- package/dist/chunk-3OSHCYWX.js +97 -0
- package/dist/chunk-4UMZU6R2.js +11 -0
- package/dist/chunk-6CLUCGIJ.js +125 -0
- package/dist/chunk-JFOGRJQA.js +289 -0
- package/dist/chunk-MC3S3YL6.js +11 -0
- package/dist/chunk-NBO4ZVRK.js +403 -0
- package/dist/chunk-PQYX44KQ.js +28 -0
- package/dist/chunk-QASEPHOI.js +158 -0
- package/dist/cli.js +61 -0
- package/dist/doctor-M5AXEIYG.js +371 -0
- package/dist/index.js +10243 -0
- package/dist/install-7XAHE2K6.js +277 -0
- package/dist/login-FNMGXSJT.js +54 -0
- package/dist/logout-4ICTJPUQ.js +36 -0
- package/dist/main-47XGXIDD.js +9180 -0
- package/dist/oauth-login-47OUBG5B.js +23 -0
- package/dist/remote.js +10150 -0
- package/package.json +66 -4
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
KeychainCredentialProvider
|
|
4
|
+
} from "./chunk-QASEPHOI.js";
|
|
5
|
+
import {
|
|
6
|
+
KeychainStore,
|
|
7
|
+
openCredentialStore
|
|
8
|
+
} from "./chunk-6CLUCGIJ.js";
|
|
9
|
+
import {
|
|
10
|
+
probeIdentity
|
|
11
|
+
} from "./chunk-MC3S3YL6.js";
|
|
12
|
+
import {
|
|
13
|
+
BackendClient
|
|
14
|
+
} from "./chunk-2UUMFH2N.js";
|
|
15
|
+
import {
|
|
16
|
+
allAdapters
|
|
17
|
+
} from "./chunk-NBO4ZVRK.js";
|
|
18
|
+
import {
|
|
19
|
+
apiBase,
|
|
20
|
+
asIssuer,
|
|
21
|
+
mcpUrl
|
|
22
|
+
} from "./chunk-PQYX44KQ.js";
|
|
23
|
+
import {
|
|
24
|
+
CLI_INVOKE
|
|
25
|
+
} from "./chunk-4UMZU6R2.js";
|
|
26
|
+
import {
|
|
27
|
+
PACKAGE_NAME,
|
|
28
|
+
SERVER_NAME,
|
|
29
|
+
VERSION
|
|
30
|
+
} from "./chunk-3OSHCYWX.js";
|
|
31
|
+
|
|
32
|
+
// src/cli/commands/doctor.ts
|
|
33
|
+
import { readFile } from "fs/promises";
|
|
34
|
+
var ICON = { ok: "\u2705", warn: "\u26A0\uFE0F", fail: "\u274C" };
|
|
35
|
+
function isCfChallenge(status, body) {
|
|
36
|
+
return status === 403 && /cf-chl|challenge-platform|cf_chl|cloudflare/i.test(body);
|
|
37
|
+
}
|
|
38
|
+
async function doctorCommand(deps = {}) {
|
|
39
|
+
const print = deps.print ?? ((line) => void process.stderr.write(`${line}
|
|
40
|
+
`));
|
|
41
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
42
|
+
const env = deps.env ?? process.env;
|
|
43
|
+
const api = deps.apiBase ?? apiBase();
|
|
44
|
+
const issuer = deps.asIssuer ?? asIssuer();
|
|
45
|
+
const rsUrl = deps.mcpUrl ?? mcpUrl();
|
|
46
|
+
let hasFail = false;
|
|
47
|
+
const report = (status, label, detail) => {
|
|
48
|
+
if (status === "fail") hasFail = true;
|
|
49
|
+
print(`${ICON[status]} ${label}: ${detail}`);
|
|
50
|
+
};
|
|
51
|
+
print("\u2014 General \u2014");
|
|
52
|
+
const nodeVersion = deps.nodeVersion ?? process.versions.node;
|
|
53
|
+
const major = Number.parseInt(nodeVersion.split(".")[0] ?? "0", 10);
|
|
54
|
+
report(
|
|
55
|
+
major >= 20 ? "ok" : "fail",
|
|
56
|
+
"\u2460 Node version",
|
|
57
|
+
major >= 20 ? `v${nodeVersion}` : `v${nodeVersion} is too old \u2014 node >= 20 required; please upgrade`
|
|
58
|
+
);
|
|
59
|
+
const adapters = deps.adapters ?? allAdapters(deps);
|
|
60
|
+
const readConfig = deps.readConfigFile ?? ((p) => readFile(p, "utf8"));
|
|
61
|
+
const clientLines = [];
|
|
62
|
+
let clientWarn = false;
|
|
63
|
+
for (const adapter of adapters) {
|
|
64
|
+
if (!await adapter.detect()) {
|
|
65
|
+
clientLines.push(` - ${adapter.label}: not detected`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (adapter.strategy === "cli") {
|
|
69
|
+
clientLines.push(
|
|
70
|
+
` - ${adapter.label}: installed (config managed by its own CLI; run ${CLI_INVOKE} install ${adapter.id} to write it)`
|
|
71
|
+
);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const configPath = adapter.configPath;
|
|
75
|
+
if (!configPath) {
|
|
76
|
+
clientLines.push(` - ${adapter.label}: detected`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const parsed = JSON.parse(await readConfig(configPath));
|
|
81
|
+
const entry = parsed.mcpServers?.[SERVER_NAME];
|
|
82
|
+
if (entry) {
|
|
83
|
+
const shape = entry.url ? `remote \u2192 ${entry.url}` : entry.command ? `stdio \u2192 ${entry.command} ${(entry.args ?? []).join(" ")}` : "unknown shape";
|
|
84
|
+
clientLines.push(` - ${adapter.label}: ${SERVER_NAME} configured (${shape})`);
|
|
85
|
+
} else {
|
|
86
|
+
clientLines.push(
|
|
87
|
+
` - ${adapter.label}: installed but not configured \u2014 run ${CLI_INVOKE} install ${adapter.id}`
|
|
88
|
+
);
|
|
89
|
+
clientWarn = true;
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
clientLines.push(
|
|
93
|
+
` - ${adapter.label}: config missing or unparsable \u2014 run ${CLI_INVOKE} install ${adapter.id}`
|
|
94
|
+
);
|
|
95
|
+
clientWarn = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
report(clientWarn ? "warn" : "ok", "\u2461 MCP clients", `${adapters.length} known clients`);
|
|
99
|
+
for (const line of clientLines) print(line);
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetchImpl(`https://registry.npmjs.org/${PACKAGE_NAME}`, {
|
|
102
|
+
headers: { accept: "application/json" },
|
|
103
|
+
signal: AbortSignal.timeout(5e3)
|
|
104
|
+
});
|
|
105
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
106
|
+
const data = await res.json();
|
|
107
|
+
const latest = data["dist-tags"]?.latest;
|
|
108
|
+
if (latest && latest !== VERSION) {
|
|
109
|
+
report(
|
|
110
|
+
"warn",
|
|
111
|
+
"\u2462 CLI version",
|
|
112
|
+
`local v${VERSION}, latest on npm v${latest} \u2014 npx @1 picks up the new version automatically`
|
|
113
|
+
);
|
|
114
|
+
} else {
|
|
115
|
+
report("ok", "\u2462 CLI version", `v${VERSION}${latest ? " (up to date)" : ""}`);
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
report("ok", "\u2462 CLI version", `v${VERSION} (online check skipped: npm registry unreachable)`);
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const { metadataUrlsFor } = await import("./oauth-login-47OUBG5B.js");
|
|
122
|
+
const metaUrl = metadataUrlsFor(issuer)[0] ?? "";
|
|
123
|
+
const res = await fetchImpl(metaUrl, {
|
|
124
|
+
headers: { accept: "application/json" },
|
|
125
|
+
signal: AbortSignal.timeout(15e3)
|
|
126
|
+
});
|
|
127
|
+
if (!res.ok) {
|
|
128
|
+
const body = await res.text().catch(() => "");
|
|
129
|
+
if (isCfChallenge(res.status, body)) {
|
|
130
|
+
report(
|
|
131
|
+
"fail",
|
|
132
|
+
"\u2463 AS discovery",
|
|
133
|
+
`blocked by a Cloudflare challenge (${metaUrl}) \u2014 ops must add the AS paths to the CF exclusion list`
|
|
134
|
+
);
|
|
135
|
+
} else {
|
|
136
|
+
report(
|
|
137
|
+
"fail",
|
|
138
|
+
"\u2463 AS discovery",
|
|
139
|
+
`HTTP ${res.status} (${metaUrl}) \u2014 if you set LUNE_MCP_AS_ISSUER yourself, check the /oauth prefix`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
const meta = await res.json().catch(() => null);
|
|
144
|
+
if (meta?.issuer === issuer) {
|
|
145
|
+
report("ok", "\u2463 AS discovery", `metadata reachable and issuer matches (${issuer})`);
|
|
146
|
+
} else {
|
|
147
|
+
report(
|
|
148
|
+
"fail",
|
|
149
|
+
"\u2463 AS discovery",
|
|
150
|
+
`issuer mismatch (expected ${issuer}, metadata declares ${meta?.issuer ?? "missing"})`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} catch (err) {
|
|
155
|
+
report(
|
|
156
|
+
"fail",
|
|
157
|
+
"\u2463 AS discovery",
|
|
158
|
+
`unreachable: ${err instanceof Error ? err.message : String(err)} (issuer=${issuer})`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
print("\u2014 remote mode \u2014");
|
|
162
|
+
let rsOrigin = "";
|
|
163
|
+
try {
|
|
164
|
+
rsOrigin = new URL(rsUrl).origin;
|
|
165
|
+
} catch {
|
|
166
|
+
report("fail", "\u2464 Remote service", `LUNE_MCP_URL is not a valid URL: ${rsUrl}`);
|
|
167
|
+
}
|
|
168
|
+
if (rsOrigin) {
|
|
169
|
+
const prmUrl = `${rsOrigin}/.well-known/oauth-protected-resource`;
|
|
170
|
+
try {
|
|
171
|
+
const res = await fetchImpl(prmUrl, {
|
|
172
|
+
headers: { accept: "application/json" },
|
|
173
|
+
signal: AbortSignal.timeout(15e3)
|
|
174
|
+
});
|
|
175
|
+
if (!res.ok) {
|
|
176
|
+
const body = await res.text().catch(() => "");
|
|
177
|
+
if (isCfChallenge(res.status, body)) {
|
|
178
|
+
report(
|
|
179
|
+
"fail",
|
|
180
|
+
"\u2464 Remote service",
|
|
181
|
+
`blocked by a Cloudflare challenge (${prmUrl}) \u2014 ops must add the RS paths to the CF exclusion list`
|
|
182
|
+
);
|
|
183
|
+
} else {
|
|
184
|
+
report(
|
|
185
|
+
"fail",
|
|
186
|
+
"\u2464 Remote service",
|
|
187
|
+
`PRM HTTP ${res.status} (${prmUrl}) \u2014 RS not deployed or path misconfigured`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
const prm = await res.json().catch(() => null);
|
|
192
|
+
const problems = [];
|
|
193
|
+
const resource = (prm?.resource ?? "").replace(/\/+$/, "");
|
|
194
|
+
if (resource !== rsOrigin) {
|
|
195
|
+
problems.push(`PRM resource mismatch (expected ${rsOrigin}, declared ${resource || "missing"})`);
|
|
196
|
+
}
|
|
197
|
+
const asList = prm?.authorization_servers ?? [];
|
|
198
|
+
if (!asList.includes(issuer)) {
|
|
199
|
+
problems.push(
|
|
200
|
+
`PRM authorization_servers does not include ${issuer} (declared: ${asList.join(", ") || "empty"})`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const r2 = await fetchImpl(rsUrl, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
207
|
+
body: "{}",
|
|
208
|
+
signal: AbortSignal.timeout(15e3)
|
|
209
|
+
});
|
|
210
|
+
const www = r2.headers.get("www-authenticate") ?? "";
|
|
211
|
+
if (r2.status !== 401) {
|
|
212
|
+
problems.push(`unauthenticated request did not return 401 (HTTP ${r2.status})`);
|
|
213
|
+
} else if (!www.includes("resource_metadata")) {
|
|
214
|
+
problems.push(
|
|
215
|
+
"401 challenge missing the resource_metadata header (clients cannot auto-discover the AS)"
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
} catch (err) {
|
|
219
|
+
problems.push(`/mcp unreachable: ${err instanceof Error ? err.message : String(err)}`);
|
|
220
|
+
}
|
|
221
|
+
if (problems.length > 0) {
|
|
222
|
+
report("fail", "\u2464 Remote service", problems.join("; "));
|
|
223
|
+
} else {
|
|
224
|
+
report("ok", "\u2464 Remote service", `PRM correct + 401 challenge correct (${rsUrl}, AS=${issuer})`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} catch (err) {
|
|
228
|
+
report(
|
|
229
|
+
"fail",
|
|
230
|
+
"\u2464 Remote service",
|
|
231
|
+
`unreachable: ${err instanceof Error ? err.message : String(err)} (${prmUrl}) \u2014 expected if the RS is not deployed yet`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
print('\u2014 stdio mode (local credential chain; remote-only users can ignore "not signed in" here) \u2014');
|
|
236
|
+
const keychainOk = await (deps.keychainProbe ?? (() => new KeychainStore().probe()))();
|
|
237
|
+
report(
|
|
238
|
+
keychainOk ? "ok" : "warn",
|
|
239
|
+
"\u2465 System keychain",
|
|
240
|
+
keychainOk ? "read/write probe passed" : "unavailable (headless / no Secret Service?) \u2014 login needs it; as a workaround set LUNE_MCP_TOKEN or LUNE_MCP_ALLOW_FILE_CREDENTIALS=1"
|
|
241
|
+
);
|
|
242
|
+
let identity = null;
|
|
243
|
+
let storeMeta = null;
|
|
244
|
+
const envToken = env.LUNE_MCP_TOKEN?.trim();
|
|
245
|
+
try {
|
|
246
|
+
let token = null;
|
|
247
|
+
let source = "";
|
|
248
|
+
if (envToken) {
|
|
249
|
+
token = envToken;
|
|
250
|
+
source = "LUNE_MCP_TOKEN env";
|
|
251
|
+
} else {
|
|
252
|
+
const store = await (deps.openStore ?? openCredentialStore)();
|
|
253
|
+
if (store) {
|
|
254
|
+
const meta = await store.readMeta();
|
|
255
|
+
storeMeta = meta ? { is_supplier: meta.is_supplier } : null;
|
|
256
|
+
token = await new KeychainCredentialProvider({ store, apiBase: api, fetchImpl }).getAccessToken();
|
|
257
|
+
source = `${store.kind} store`;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (!token) {
|
|
261
|
+
report(
|
|
262
|
+
"warn",
|
|
263
|
+
"\u2466 Credentials",
|
|
264
|
+
`not signed in (only needed for stdio mode) \u2014 run \`${CLI_INVOKE} login\` (or set the LUNE_MCP_TOKEN env var)`
|
|
265
|
+
);
|
|
266
|
+
} else {
|
|
267
|
+
const backend = new BackendClient({
|
|
268
|
+
baseUrl: api,
|
|
269
|
+
fetchImpl,
|
|
270
|
+
credentials: {
|
|
271
|
+
getAccessToken: async () => token,
|
|
272
|
+
forceRefresh: async () => null,
|
|
273
|
+
reauthHint: () => "run login again"
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
identity = await probeIdentity(backend);
|
|
277
|
+
report(
|
|
278
|
+
"ok",
|
|
279
|
+
"\u2466 Credentials",
|
|
280
|
+
`valid (${source}): ${identity.userId}${identity.isSupplier ? ", supplier account" : ""}`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
} catch (err) {
|
|
284
|
+
report(
|
|
285
|
+
"fail",
|
|
286
|
+
"\u2466 Credentials",
|
|
287
|
+
`validation failed: ${err instanceof Error ? err.message : String(err)} \u2014 run login again`
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
if (identity && storeMeta) {
|
|
291
|
+
const consistent = storeMeta.is_supplier === identity.isSupplier;
|
|
292
|
+
report(
|
|
293
|
+
consistent ? "ok" : "warn",
|
|
294
|
+
"\u2467 Supplier cache",
|
|
295
|
+
consistent ? `consistent (is_supplier=${identity.isSupplier})` : `inconsistent (cached ${storeMeta.is_supplier}, backend ${identity.isSupplier}) \u2014 run login again to fix the supplier toolset`
|
|
296
|
+
);
|
|
297
|
+
} else {
|
|
298
|
+
report(
|
|
299
|
+
"ok",
|
|
300
|
+
"\u2467 Supplier cache",
|
|
301
|
+
identity ? "skipped (no cache in LUNE_MCP_TOKEN mode)" : "skipped (not signed in)"
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
let backendReachable = false;
|
|
305
|
+
try {
|
|
306
|
+
const t0 = Date.now();
|
|
307
|
+
const res = await fetchImpl(`${api}/v1/public/models`, {
|
|
308
|
+
headers: { accept: "application/json" },
|
|
309
|
+
signal: AbortSignal.timeout(15e3)
|
|
310
|
+
});
|
|
311
|
+
const ms = Date.now() - t0;
|
|
312
|
+
if (res.ok) {
|
|
313
|
+
backendReachable = true;
|
|
314
|
+
report("ok", "\u2468 Backend connectivity", `HTTP ${res.status}, ${ms}ms (${api})`);
|
|
315
|
+
} else {
|
|
316
|
+
const body = await res.text().catch(() => "");
|
|
317
|
+
if (isCfChallenge(res.status, body)) {
|
|
318
|
+
report(
|
|
319
|
+
"fail",
|
|
320
|
+
"\u2468 Backend connectivity",
|
|
321
|
+
"blocked by a Cloudflare challenge (403 challenge page) \u2014 CLI/MCP cannot pass a browser challenge; ops must add the API paths to the CF exclusion list"
|
|
322
|
+
);
|
|
323
|
+
} else {
|
|
324
|
+
report("fail", "\u2468 Backend connectivity", `HTTP ${res.status} (${api})`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
} catch (err) {
|
|
328
|
+
report(
|
|
329
|
+
"fail",
|
|
330
|
+
"\u2468 Backend connectivity",
|
|
331
|
+
`unreachable: ${err instanceof Error ? err.message : String(err)} (${api})`
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
if (!backendReachable) {
|
|
335
|
+
report("ok", "\u2469 Backend generation", "skipped (backend unreachable, see \u2468)");
|
|
336
|
+
} else {
|
|
337
|
+
try {
|
|
338
|
+
const res = await fetchImpl(`${api}/v1/projects`, {
|
|
339
|
+
headers: { accept: "application/json" },
|
|
340
|
+
signal: AbortSignal.timeout(15e3)
|
|
341
|
+
});
|
|
342
|
+
await res.body?.cancel().catch(() => {
|
|
343
|
+
});
|
|
344
|
+
if (res.status === 401) {
|
|
345
|
+
report("ok", "\u2469 Backend generation", `organization-enabled backend (matches lune-mcp v${VERSION})`);
|
|
346
|
+
} else if (res.status === 404) {
|
|
347
|
+
report(
|
|
348
|
+
"fail",
|
|
349
|
+
"\u2469 Backend generation",
|
|
350
|
+
`pre-organization backend at ${api}: lune-mcp v${VERSION} needs the organization-enabled backend, so every buyer tool will fail against it. Point LUNE_MCP_API_BASE at an upgraded backend`
|
|
351
|
+
);
|
|
352
|
+
} else {
|
|
353
|
+
report(
|
|
354
|
+
"warn",
|
|
355
|
+
"\u2469 Backend generation",
|
|
356
|
+
`could not tell: GET /v1/projects without credentials returned HTTP ${res.status} (expected 401 from an organization-enabled backend, 404 from an older one)`
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
} catch (err) {
|
|
360
|
+
report(
|
|
361
|
+
"warn",
|
|
362
|
+
"\u2469 Backend generation",
|
|
363
|
+
`could not tell: ${err instanceof Error ? err.message : String(err)} (${api}/v1/projects)`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return hasFail ? 1 : 0;
|
|
368
|
+
}
|
|
369
|
+
export {
|
|
370
|
+
doctorCommand
|
|
371
|
+
};
|