passport-bridge 0.8.2 → 0.10.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 +100 -3
- package/dist/accessClient.d.ts +128 -0
- package/dist/accessClient.js +436 -0
- package/dist/activeProfile.d.ts +21 -0
- package/dist/boundedFile.d.ts +2 -0
- package/dist/boundedMcpFetch.d.ts +6 -0
- package/dist/boundedResponse.d.ts +4 -0
- package/dist/bridge.d.ts +98 -0
- package/dist/bridge.js +49 -42
- package/dist/bridgeConfig.d.ts +1 -0
- package/dist/bridgePoller.d.ts +34 -0
- package/dist/bridgePoller.js +123 -0
- package/dist/bridgeShutdown.d.ts +20 -0
- package/dist/bridgeShutdown.js +5 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +4 -0
- package/dist/cliAccess.d.ts +3 -0
- package/dist/cliAccess.js +119 -0
- package/dist/cliArgs.d.ts +16 -0
- package/dist/cliArgs.js +14 -3
- package/dist/cliClient.d.ts +62 -0
- package/dist/cliConnect.d.ts +22 -0
- package/dist/cliDeadline.d.ts +9 -0
- package/dist/cliDescribe.d.ts +8 -0
- package/dist/cliLogin.d.ts +3 -0
- package/dist/cliOffline.d.ts +6 -0
- package/dist/cliOutput.d.ts +7 -0
- package/dist/cliOutput.js +4 -0
- package/dist/cliPagination.d.ts +15 -0
- package/dist/cliProtocol.d.ts +4 -0
- package/dist/cliReady.d.ts +9 -0
- package/dist/cliResult.d.ts +7 -0
- package/dist/cliSession.d.ts +20 -0
- package/dist/cliSetup.d.ts +10 -0
- package/dist/cliSetup.js +157 -0
- package/dist/cliSupport.d.ts +102 -0
- package/dist/completion.d.ts +2 -0
- package/dist/completion.js +20 -2
- package/dist/credentialStorage.d.ts +12 -0
- package/dist/credentials.d.ts +64 -0
- package/dist/discover.d.ts +52 -0
- package/dist/doctor.d.ts +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/legacyCliSecurity.d.ts +10 -0
- package/dist/managedSkills.d.ts +7 -0
- package/dist/managedSkills.js +268 -0
- package/dist/managedSkillsContract.generated.d.ts +82 -0
- package/dist/managedSkillsContract.generated.js +32 -0
- package/dist/managedSkillsFiles.d.ts +23 -0
- package/dist/managedSkillsFiles.js +215 -0
- package/dist/managedSkillsIpc.d.ts +5 -0
- package/dist/managedSkillsIpc.js +44 -0
- package/dist/managedSkillsValidation.d.ts +14 -0
- package/dist/managedSkillsValidation.js +118 -0
- package/dist/passport.d.ts +7 -0
- package/dist/passport.js +4 -0
- package/dist/privateStableFile.d.ts +13 -0
- package/dist/recoveryCleanup.d.ts +5 -0
- package/dist/recoveryIdentity.d.ts +22 -0
- package/dist/tokenWorkspace.d.ts +3 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +13 -2
package/dist/bridge.js
CHANGED
|
@@ -9,6 +9,7 @@ import { VERSION } from "./version.js";
|
|
|
9
9
|
import { bridgePollIntervalMs } from "./bridgeConfig.js";
|
|
10
10
|
import { readBoundedJson } from "./boundedResponse.js";
|
|
11
11
|
import { createBoundedBridgeShutdown } from "./bridgeShutdown.js";
|
|
12
|
+
import { BridgePoller } from "./bridgePoller.js";
|
|
12
13
|
import { workspaceOfToken } from "./tokenWorkspace.js";
|
|
13
14
|
export { workspaceOfToken } from "./tokenWorkspace.js";
|
|
14
15
|
/** Everything but the MCP protocol goes to stderr — stdout is the transport. */
|
|
@@ -285,7 +286,6 @@ export async function runBridge(endpoint, tokens, options = {}) {
|
|
|
285
286
|
let state = "connecting";
|
|
286
287
|
let recoveryInFlight;
|
|
287
288
|
let recoveryAbort;
|
|
288
|
-
let pollTimer;
|
|
289
289
|
let lastSignature = "";
|
|
290
290
|
const connectCandidate = async (candidate) => {
|
|
291
291
|
if (options.connectUpstream) {
|
|
@@ -338,42 +338,45 @@ export async function runBridge(endpoint, tokens, options = {}) {
|
|
|
338
338
|
server.notification({ method: "notifications/prompts/list_changed" })
|
|
339
339
|
]);
|
|
340
340
|
};
|
|
341
|
-
const enterDegraded = async (error) => {
|
|
341
|
+
const enterDegraded = async (error, generationAlreadyInvalidated = false) => {
|
|
342
342
|
const hadUpstream = Boolean(upstream);
|
|
343
343
|
const previous = upstream;
|
|
344
344
|
state = "degraded";
|
|
345
345
|
upstream = undefined;
|
|
346
346
|
upstreamHasUrlElicitation = false;
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
347
|
+
// Invalidate the generation before closing the old client. A poll that
|
|
348
|
+
// finishes during reconnect cannot notify the downstream for a superseded
|
|
349
|
+
// upstream surface.
|
|
350
|
+
if (!generationAlreadyInvalidated)
|
|
351
|
+
await poller?.rotate();
|
|
350
352
|
void previous?.close().catch(() => undefined);
|
|
351
353
|
const status = isBridgeCredentialError(error) ? "credential rejected" : "unavailable";
|
|
352
354
|
log(`Passport ${status}; serving fail-closed recovery mode.`);
|
|
353
355
|
if (hadUpstream)
|
|
354
356
|
await notifySurfacesChanged().catch(() => undefined);
|
|
355
357
|
};
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
},
|
|
375
|
-
|
|
376
|
-
|
|
358
|
+
const poller = new BridgePoller({
|
|
359
|
+
intervalMs: pollMs,
|
|
360
|
+
poll: (signal) => {
|
|
361
|
+
const client = upstream;
|
|
362
|
+
if (!client || state !== "ready")
|
|
363
|
+
return Promise.resolve(undefined);
|
|
364
|
+
return toolSignature(client, signal);
|
|
365
|
+
},
|
|
366
|
+
onSignature: async (signature, generation) => {
|
|
367
|
+
if (!poller?.isCurrent(generation) || !upstream || state !== "ready")
|
|
368
|
+
return;
|
|
369
|
+
if (signature === lastSignature)
|
|
370
|
+
return;
|
|
371
|
+
await notifySurfacesChanged();
|
|
372
|
+
if (poller?.isCurrent(generation) && upstream && state === "ready") {
|
|
373
|
+
lastSignature = signature;
|
|
374
|
+
log("tools changed; notified client");
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
isCredentialError: isBridgeCredentialError,
|
|
378
|
+
onCredentialError: (error) => enterDegraded(error, true)
|
|
379
|
+
});
|
|
377
380
|
const connectUpstream = async () => {
|
|
378
381
|
const urlElicitation = server.getClientCapabilities()?.elicitation?.url;
|
|
379
382
|
if (state === "ready" && upstreamHasUrlElicitation === Boolean(urlElicitation))
|
|
@@ -392,6 +395,9 @@ export async function runBridge(endpoint, tokens, options = {}) {
|
|
|
392
395
|
upstream = undefined;
|
|
393
396
|
state = "connecting";
|
|
394
397
|
connecting = (async () => {
|
|
398
|
+
// Publish `connecting` before yielding so simultaneous recovery or
|
|
399
|
+
// capability-negotiation callers share this one reconnect attempt.
|
|
400
|
+
await poller?.rotate();
|
|
395
401
|
// URL mode is never claimed on behalf of a client that did not advertise
|
|
396
402
|
// it. The bridge has historically offered no form-elicitation surface,
|
|
397
403
|
// so leaving form mode unadvertised preserves its gateway fallback.
|
|
@@ -414,15 +420,13 @@ export async function runBridge(endpoint, tokens, options = {}) {
|
|
|
414
420
|
state = "ready";
|
|
415
421
|
lastSignature = await toolSignature(candidate);
|
|
416
422
|
log(`connected to ${activeEndpoint}`);
|
|
417
|
-
|
|
418
|
-
startPolling();
|
|
423
|
+
poller?.start();
|
|
419
424
|
})()
|
|
420
425
|
.catch(async (error) => {
|
|
421
426
|
if (previous && !isBridgeCredentialError(error)) {
|
|
422
427
|
upstream = previous;
|
|
423
428
|
state = "ready";
|
|
424
|
-
|
|
425
|
-
startPolling();
|
|
429
|
+
poller?.start();
|
|
426
430
|
log("URL elicitation negotiation was unavailable; continuing with the existing Passport session.");
|
|
427
431
|
return;
|
|
428
432
|
}
|
|
@@ -551,17 +555,15 @@ export async function runBridge(endpoint, tokens, options = {}) {
|
|
|
551
555
|
server.onclose = () => {
|
|
552
556
|
removeProcessSignalHandlers();
|
|
553
557
|
recoveryAbort?.abort();
|
|
554
|
-
|
|
555
|
-
clearInterval(pollTimer);
|
|
556
|
-
pollTimer = undefined;
|
|
558
|
+
void poller?.stop();
|
|
557
559
|
void upstream?.close().catch(() => undefined);
|
|
558
560
|
};
|
|
559
561
|
await server.connect(options.downstreamTransport ?? new StdioServerTransport());
|
|
560
562
|
log("ready on stdio");
|
|
561
563
|
if (upstream)
|
|
562
|
-
|
|
564
|
+
poller.start();
|
|
563
565
|
const shutdown = createBoundedBridgeShutdown({
|
|
564
|
-
|
|
566
|
+
poller,
|
|
565
567
|
upstream: { close: () => upstream?.close() ?? Promise.resolve() },
|
|
566
568
|
server,
|
|
567
569
|
onFailure: () => log("shutdown did not drain cleanly")
|
|
@@ -574,13 +576,9 @@ export async function runBridge(endpoint, tokens, options = {}) {
|
|
|
574
576
|
process.off("SIGTERM", onSignal);
|
|
575
577
|
};
|
|
576
578
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
// one meta-tool per app carries the catalog in its DESCRIPTION, so policy
|
|
581
|
-
// changes inside an app (a pass change, tools toggled) alter descriptions
|
|
582
|
-
// while the name set stays identical — a names-only signature missed them and
|
|
583
|
-
// the client's view went stale until an app restart.
|
|
579
|
+
/** Canonical hash of the complete visible tool definitions. Kept pure so the
|
|
580
|
+
* bridge can prove hashing cost independently from MCP transport latency. */
|
|
581
|
+
export function canonicalToolSignature(tools) {
|
|
584
582
|
const digest = createHash("sha256");
|
|
585
583
|
for (const t of [...tools].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
586
584
|
digest.update(t.name).update("\0");
|
|
@@ -589,3 +587,12 @@ async function toolSignature(client) {
|
|
|
589
587
|
}
|
|
590
588
|
return digest.digest("hex");
|
|
591
589
|
}
|
|
590
|
+
export async function toolSignature(client, signal) {
|
|
591
|
+
const { tools } = await client.listTools({}, signal ? { signal } : undefined);
|
|
592
|
+
// Hash the full visible definitions, not just names: in `apps` discovery mode
|
|
593
|
+
// one meta-tool per app carries the catalog in its DESCRIPTION, so policy
|
|
594
|
+
// changes inside an app (a pass change, tools toggled) alter descriptions
|
|
595
|
+
// while the name set stays identical — a names-only signature missed them and
|
|
596
|
+
// the client's view went stale until an app restart.
|
|
597
|
+
return canonicalToolSignature(tools);
|
|
598
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function bridgePollIntervalMs(env?: Readonly<Record<string, string | undefined>>): number;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type BridgePollerOptions = {
|
|
2
|
+
intervalMs: number;
|
|
3
|
+
poll: (signal: AbortSignal) => Promise<string | undefined>;
|
|
4
|
+
onSignature: (signature: string, generation: number) => Promise<void> | void;
|
|
5
|
+
isCredentialError?: (error: unknown) => boolean;
|
|
6
|
+
onCredentialError?: (error: unknown) => Promise<void> | void;
|
|
7
|
+
onError?: (error: unknown) => Promise<void> | void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Runs at most one tool-surface poll at a time. A generation invalidates any
|
|
11
|
+
* result that belongs to a superseded upstream connection; rotate() aborts and
|
|
12
|
+
* drains the in-flight request before the caller installs its replacement.
|
|
13
|
+
*/
|
|
14
|
+
export declare class BridgePoller {
|
|
15
|
+
private readonly options;
|
|
16
|
+
private timer;
|
|
17
|
+
private active;
|
|
18
|
+
private readonly callbacks;
|
|
19
|
+
private generation;
|
|
20
|
+
private stopped;
|
|
21
|
+
constructor(options: BridgePollerOptions);
|
|
22
|
+
start(): void;
|
|
23
|
+
/** Invalidate and drain the current poll while keeping the timer reusable. */
|
|
24
|
+
rotate(): Promise<void>;
|
|
25
|
+
/** Permanently stop polling and drain the active request. */
|
|
26
|
+
stop(): Promise<void>;
|
|
27
|
+
/** Testable/manual trigger; timer ticks use the same single-flight path. */
|
|
28
|
+
pollNow(): Promise<void>;
|
|
29
|
+
isCurrent(generation: number): boolean;
|
|
30
|
+
private execute;
|
|
31
|
+
private clearActive;
|
|
32
|
+
private drainActive;
|
|
33
|
+
private trackCallback;
|
|
34
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs at most one tool-surface poll at a time. A generation invalidates any
|
|
3
|
+
* result that belongs to a superseded upstream connection; rotate() aborts and
|
|
4
|
+
* drains the in-flight request before the caller installs its replacement.
|
|
5
|
+
*/
|
|
6
|
+
export class BridgePoller {
|
|
7
|
+
options;
|
|
8
|
+
timer;
|
|
9
|
+
active;
|
|
10
|
+
callbacks = new Set();
|
|
11
|
+
generation = 0;
|
|
12
|
+
stopped = false;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
if (!Number.isSafeInteger(options.intervalMs) || options.intervalMs < 1) {
|
|
16
|
+
throw new Error("Bridge poll interval must be a positive integer.");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
start() {
|
|
20
|
+
if (this.stopped || this.timer)
|
|
21
|
+
return;
|
|
22
|
+
this.generation++;
|
|
23
|
+
this.timer = setInterval(() => {
|
|
24
|
+
void this.pollNow();
|
|
25
|
+
}, this.options.intervalMs);
|
|
26
|
+
this.timer.unref?.();
|
|
27
|
+
}
|
|
28
|
+
/** Invalidate and drain the current poll while keeping the timer reusable. */
|
|
29
|
+
async rotate() {
|
|
30
|
+
this.generation++;
|
|
31
|
+
await this.drainActive();
|
|
32
|
+
}
|
|
33
|
+
/** Permanently stop polling and drain the active request. */
|
|
34
|
+
async stop() {
|
|
35
|
+
if (!this.stopped) {
|
|
36
|
+
this.stopped = true;
|
|
37
|
+
this.generation++;
|
|
38
|
+
if (this.timer)
|
|
39
|
+
clearInterval(this.timer);
|
|
40
|
+
this.timer = undefined;
|
|
41
|
+
}
|
|
42
|
+
await this.drainActive();
|
|
43
|
+
}
|
|
44
|
+
/** Testable/manual trigger; timer ticks use the same single-flight path. */
|
|
45
|
+
pollNow() {
|
|
46
|
+
if (this.stopped)
|
|
47
|
+
return Promise.resolve();
|
|
48
|
+
if (this.active)
|
|
49
|
+
return this.active.promise;
|
|
50
|
+
if (this.callbacks.size)
|
|
51
|
+
return Promise.allSettled(this.callbacks).then(() => undefined);
|
|
52
|
+
const active = {
|
|
53
|
+
generation: this.generation,
|
|
54
|
+
controller: new AbortController(),
|
|
55
|
+
promise: Promise.resolve()
|
|
56
|
+
};
|
|
57
|
+
this.active = active;
|
|
58
|
+
active.promise = this.execute(active);
|
|
59
|
+
return active.promise;
|
|
60
|
+
}
|
|
61
|
+
isCurrent(generation) {
|
|
62
|
+
return !this.stopped && generation === this.generation;
|
|
63
|
+
}
|
|
64
|
+
async execute(active) {
|
|
65
|
+
let signature;
|
|
66
|
+
try {
|
|
67
|
+
signature = await this.options.poll(active.controller.signal);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
this.clearActive(active);
|
|
71
|
+
if (!this.isCurrent(active.generation))
|
|
72
|
+
return;
|
|
73
|
+
if (this.options.isCredentialError?.(error)) {
|
|
74
|
+
// Invalidate before invoking the asynchronous transition callback, so
|
|
75
|
+
// a reconnect cannot accept a result from this failed generation.
|
|
76
|
+
this.generation++;
|
|
77
|
+
await this.trackCallback(() => this.options.onCredentialError?.(error));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
await this.trackCallback(() => this.options.onError?.(error));
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.clearActive(active);
|
|
85
|
+
if (!this.isCurrent(active.generation) || signature === undefined)
|
|
86
|
+
return;
|
|
87
|
+
await this.trackCallback(async () => {
|
|
88
|
+
try {
|
|
89
|
+
await this.options.onSignature(signature, active.generation);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
await this.options.onError?.(error);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
clearActive(active) {
|
|
97
|
+
if (this.active === active)
|
|
98
|
+
this.active = undefined;
|
|
99
|
+
}
|
|
100
|
+
async drainActive() {
|
|
101
|
+
while (this.active || this.callbacks.size) {
|
|
102
|
+
const active = this.active;
|
|
103
|
+
if (active)
|
|
104
|
+
active.controller.abort();
|
|
105
|
+
const waits = [...(active ? [active.promise] : []), ...this.callbacks];
|
|
106
|
+
await Promise.allSettled(waits);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
trackCallback(callback) {
|
|
110
|
+
const promise = (async () => {
|
|
111
|
+
try {
|
|
112
|
+
await callback();
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Poll callbacks are lifecycle housekeeping. A notification failure
|
|
116
|
+
// must not become a detached rejection or wedge future polling.
|
|
117
|
+
}
|
|
118
|
+
})();
|
|
119
|
+
this.callbacks.add(promise);
|
|
120
|
+
void promise.finally(() => this.callbacks.delete(promise));
|
|
121
|
+
return promise;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const BRIDGE_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
2
|
+
type Closeable = {
|
|
3
|
+
close(): Promise<void>;
|
|
4
|
+
};
|
|
5
|
+
type BridgeShutdownOptions = {
|
|
6
|
+
pollTimer?: ReturnType<typeof setInterval> | (() => ReturnType<typeof setInterval> | undefined);
|
|
7
|
+
poller?: {
|
|
8
|
+
stop(): Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
upstream: Closeable;
|
|
11
|
+
server: Closeable;
|
|
12
|
+
timeoutMs?: number;
|
|
13
|
+
exit?: (code: number) => void;
|
|
14
|
+
onFailure?: () => void;
|
|
15
|
+
};
|
|
16
|
+
/** Stop polling, await both MCP transports, and only then exit. The deadline
|
|
17
|
+
* prevents a broken transport from wedging a terminal client indefinitely;
|
|
18
|
+
* duplicate signals share the same close attempt and cannot race exits. */
|
|
19
|
+
export declare function createBoundedBridgeShutdown(options: BridgeShutdownOptions): () => Promise<void>;
|
|
20
|
+
export {};
|
package/dist/bridgeShutdown.js
CHANGED
|
@@ -17,7 +17,11 @@ export function createBoundedBridgeShutdown(options) {
|
|
|
17
17
|
const timedOut = new Promise((resolve) => {
|
|
18
18
|
deadline = setTimeout(() => resolve("timeout"), timeoutMs);
|
|
19
19
|
});
|
|
20
|
-
const closed = Promise.allSettled([
|
|
20
|
+
const closed = Promise.allSettled([
|
|
21
|
+
options.poller?.stop() ?? Promise.resolve(),
|
|
22
|
+
options.server.close(),
|
|
23
|
+
options.upstream.close()
|
|
24
|
+
]).then((results) => results.every((result) => result.status === "fulfilled") ? "closed" : "failed");
|
|
21
25
|
const outcome = await Promise.race([closed, timedOut]);
|
|
22
26
|
if (deadline)
|
|
23
27
|
clearTimeout(deadline);
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
CHANGED
|
@@ -26,6 +26,10 @@ function arg(flag, fallback = "") {
|
|
|
26
26
|
}
|
|
27
27
|
async function main() {
|
|
28
28
|
const command = process.argv[2] ?? "serve";
|
|
29
|
+
if (command === "managed-skills") {
|
|
30
|
+
const { managedSkillsIpcMain } = await import("./managedSkillsIpc.js");
|
|
31
|
+
return managedSkillsIpcMain();
|
|
32
|
+
}
|
|
29
33
|
if (process.argv.includes("--help") || process.argv.includes("-h") || command === "help")
|
|
30
34
|
return help();
|
|
31
35
|
if (command === "--version" || command === "-V" || command === "version")
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { value } from "./cliArgs.js";
|
|
2
|
+
import { failure, timeoutMs } from "./cliSupport.js";
|
|
3
|
+
import { AccessGatewayClient, assertCallerId, defaultAccessPrivateKeyFile, defaultAccessPublicJwkFile, generateAccessKey, parseAccessInputFile, writeGeneratedAccessKey } from "./accessClient.js";
|
|
4
|
+
function algorithm(raw, fallback = "ES256") {
|
|
5
|
+
const selected = raw ?? fallback;
|
|
6
|
+
if (selected !== "ES256" && selected !== "RS256")
|
|
7
|
+
return failure("--algorithm must be ES256 or RS256.", 6, "usage");
|
|
8
|
+
return selected;
|
|
9
|
+
}
|
|
10
|
+
function clientFor(args, runtime, requireCaller = false) {
|
|
11
|
+
const endpoint = runtime.env.PASSPORT_ENDPOINT;
|
|
12
|
+
const clientId = value(args, "client-id") ?? runtime.env.PASSPORT_CLIENT_ID;
|
|
13
|
+
const privateKeyFile = value(args, "private-key-file") ?? runtime.env.PASSPORT_PRIVATE_KEY_FILE;
|
|
14
|
+
if (!endpoint)
|
|
15
|
+
return failure("PASSPORT_ENDPOINT is required.", 2, "auth");
|
|
16
|
+
if (!clientId)
|
|
17
|
+
return failure("PASSPORT_CLIENT_ID is required.", 2, "auth");
|
|
18
|
+
if (!privateKeyFile)
|
|
19
|
+
return failure("PASSPORT_PRIVATE_KEY_FILE is required.", 2, "auth");
|
|
20
|
+
const workspaceId = value(args, "workspace") ?? runtime.env.PASSPORT_WORKSPACE_ID ?? clientId.split("~", 1)[0];
|
|
21
|
+
if (!workspaceId)
|
|
22
|
+
return failure("A workspace id is required (use --workspace or PASSPORT_WORKSPACE_ID).", 6, "usage");
|
|
23
|
+
const caller = value(args, "caller") ?? runtime.env.PASSPORT_CALLER_ID;
|
|
24
|
+
if (requireCaller && !caller)
|
|
25
|
+
return failure("--caller or PASSPORT_CALLER_ID is required for invocations.", 6, "usage");
|
|
26
|
+
const configuredAlgorithm = value(args, "algorithm") ?? runtime.env.PASSPORT_ACCESS_ALGORITHM;
|
|
27
|
+
return new AccessGatewayClient({
|
|
28
|
+
endpoint,
|
|
29
|
+
workspaceId,
|
|
30
|
+
clientId,
|
|
31
|
+
privateKeyFile,
|
|
32
|
+
...(configuredAlgorithm ? { algorithm: algorithm(configuredAlgorithm) } : {}),
|
|
33
|
+
...(caller ? { callerId: assertCallerId(caller) } : {}),
|
|
34
|
+
timeoutMs: timeoutMs(args),
|
|
35
|
+
signal: runtime.signal
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export async function access(args, runtime) {
|
|
39
|
+
const subcommand = args.positionals[0];
|
|
40
|
+
if (subcommand === "keygen") {
|
|
41
|
+
if (args.positionals.length !== 1)
|
|
42
|
+
return failure("access keygen does not accept positional arguments.", 6, "usage");
|
|
43
|
+
const selected = algorithm(value(args, "algorithm"), "ES256");
|
|
44
|
+
const privateKeyFile = value(args, "private-key-file") ?? defaultAccessPrivateKeyFile(runtime.env);
|
|
45
|
+
const publicJwkFile = value(args, "public-jwk-file") ?? defaultAccessPublicJwkFile(privateKeyFile);
|
|
46
|
+
const result = writeGeneratedAccessKey(generateAccessKey(selected), privateKeyFile, publicJwkFile);
|
|
47
|
+
return {
|
|
48
|
+
json: {
|
|
49
|
+
algorithm: selected,
|
|
50
|
+
privateKeyFile: result.privateKeyFile,
|
|
51
|
+
publicJwkFile: result.publicJwkFile,
|
|
52
|
+
publicJwk: result.publicJwk
|
|
53
|
+
},
|
|
54
|
+
human: [
|
|
55
|
+
`Generated ${selected} workload key.`,
|
|
56
|
+
`Private key: ${result.privateKeyFile}`,
|
|
57
|
+
`Public JWK: ${result.publicJwkFile}`,
|
|
58
|
+
"Register the public JWK with a Passport administrator before making access requests."
|
|
59
|
+
].join("\n"),
|
|
60
|
+
essential: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (subcommand !== "actions" &&
|
|
64
|
+
subcommand !== "run" &&
|
|
65
|
+
subcommand !== "invoke" &&
|
|
66
|
+
subcommand !== "status" &&
|
|
67
|
+
subcommand !== "cancel") {
|
|
68
|
+
return failure("access requires keygen, actions, run, invoke, status, or cancel.", 6, "usage", {
|
|
69
|
+
hint: "Run: passport help access"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if ((subcommand === "actions" || subcommand === "run" || subcommand === "invoke") && args.positionals.length !== 1) {
|
|
73
|
+
return failure(`access ${subcommand} does not accept positional arguments.`, 6, "usage");
|
|
74
|
+
}
|
|
75
|
+
if ((subcommand === "status" || subcommand === "cancel") && args.positionals.length !== 2) {
|
|
76
|
+
return failure(`access ${subcommand} requires exactly one id.`, 6, "usage");
|
|
77
|
+
}
|
|
78
|
+
const client = clientFor(args, runtime, subcommand === "invoke");
|
|
79
|
+
if (subcommand === "actions") {
|
|
80
|
+
const actions = await client.actions(value(args, "delegation-id"));
|
|
81
|
+
return {
|
|
82
|
+
json: { actions },
|
|
83
|
+
human: actions.length
|
|
84
|
+
? actions
|
|
85
|
+
.map((action) => {
|
|
86
|
+
const capability = action.capability;
|
|
87
|
+
return `${capability.appId}.${action.tool} · ${capability.resource} · ${capability.connectionId}`;
|
|
88
|
+
})
|
|
89
|
+
.join("\n")
|
|
90
|
+
: "No permitted managed actions."
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (subcommand === "run") {
|
|
94
|
+
const input = value(args, "input");
|
|
95
|
+
if (!input)
|
|
96
|
+
return failure("access run requires --input <json-file>.", 6, "usage");
|
|
97
|
+
const run = await client.createRun(parseAccessInputFile(input));
|
|
98
|
+
return { json: { run }, human: JSON.stringify(run, null, 2) };
|
|
99
|
+
}
|
|
100
|
+
if (subcommand === "invoke") {
|
|
101
|
+
const input = value(args, "input");
|
|
102
|
+
if (!input)
|
|
103
|
+
return failure("access invoke requires --input <json-file>.", 6, "usage");
|
|
104
|
+
const result = await client.invoke(parseAccessInputFile(input));
|
|
105
|
+
return { json: result, human: JSON.stringify(result, null, 2) };
|
|
106
|
+
}
|
|
107
|
+
if (subcommand === "status") {
|
|
108
|
+
const invocationId = args.positionals[1];
|
|
109
|
+
if (!invocationId)
|
|
110
|
+
return failure("access status requires an invocation id.", 6, "usage");
|
|
111
|
+
const receipt = await client.status(invocationId);
|
|
112
|
+
return { json: { receipt }, human: JSON.stringify(receipt, null, 2) };
|
|
113
|
+
}
|
|
114
|
+
const runId = args.positionals[1];
|
|
115
|
+
if (!runId)
|
|
116
|
+
return failure("access cancel requires a run id.", 6, "usage");
|
|
117
|
+
const run = await client.cancel(runId);
|
|
118
|
+
return { json: { run }, human: JSON.stringify(run, null, 2) };
|
|
119
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const COMMANDS: readonly ["login", "logout", "profiles", "use", "status", "doctor", "ready", "search", "describe", "run", "connect", "resources", "prompts", "discover", "setup", "session", "access", "completion", "help", "version"];
|
|
2
|
+
export type Command = (typeof COMMANDS)[number];
|
|
3
|
+
export declare class ArgError extends Error {
|
|
4
|
+
}
|
|
5
|
+
export type ParsedArgs = {
|
|
6
|
+
command: Command;
|
|
7
|
+
positionals: string[];
|
|
8
|
+
values: Record<string, string>;
|
|
9
|
+
repeats: Record<string, string[]>;
|
|
10
|
+
booleans: Set<string>;
|
|
11
|
+
};
|
|
12
|
+
/** Parse without dependencies. Long options can appear before or after the verb. */
|
|
13
|
+
export declare function parseArgs(argv: string[]): ParsedArgs;
|
|
14
|
+
export declare function bool(args: ParsedArgs, name: string): boolean;
|
|
15
|
+
export declare function value(args: ParsedArgs, name: string): string | undefined;
|
|
16
|
+
export declare function repeated(args: ParsedArgs, name: string): string[];
|
package/dist/cliArgs.js
CHANGED
|
@@ -13,7 +13,9 @@ export const COMMANDS = [
|
|
|
13
13
|
"resources",
|
|
14
14
|
"prompts",
|
|
15
15
|
"discover",
|
|
16
|
+
"setup",
|
|
16
17
|
"session",
|
|
18
|
+
"access",
|
|
17
19
|
"completion",
|
|
18
20
|
"help",
|
|
19
21
|
"version"
|
|
@@ -26,8 +28,9 @@ const FLAGS = {
|
|
|
26
28
|
caller: { kind: "value" },
|
|
27
29
|
help: { kind: "boolean" },
|
|
28
30
|
cloud: { kind: "value", commands: ["login"] },
|
|
29
|
-
workspace: { kind: "value", commands: ["login"] },
|
|
30
|
-
client: { kind: "value", commands: ["login"] },
|
|
31
|
+
workspace: { kind: "value", commands: ["login", "access"] },
|
|
32
|
+
client: { kind: "value", commands: ["login", "setup"] },
|
|
33
|
+
apply: { kind: "boolean", commands: ["setup"] },
|
|
31
34
|
"no-open": { kind: "boolean", commands: ["login"] },
|
|
32
35
|
app: { kind: "value", commands: ["search"] },
|
|
33
36
|
args: { kind: "value", commands: ["run"] },
|
|
@@ -36,7 +39,13 @@ const FLAGS = {
|
|
|
36
39
|
wait: { kind: "value", commands: ["run", "connect"] },
|
|
37
40
|
alias: { kind: "value", commands: ["connect"] },
|
|
38
41
|
open: { kind: "boolean", commands: ["connect"] },
|
|
39
|
-
out: { kind: "value", commands: ["resources", "prompts"] }
|
|
42
|
+
out: { kind: "value", commands: ["resources", "prompts"] },
|
|
43
|
+
input: { kind: "value", commands: ["access"] },
|
|
44
|
+
algorithm: { kind: "value", commands: ["access"] },
|
|
45
|
+
"private-key-file": { kind: "value", commands: ["access"] },
|
|
46
|
+
"public-jwk-file": { kind: "value", commands: ["access"] },
|
|
47
|
+
"delegation-id": { kind: "value", commands: ["access"] },
|
|
48
|
+
"client-id": { kind: "value", commands: ["access"] }
|
|
40
49
|
};
|
|
41
50
|
export class ArgError extends Error {
|
|
42
51
|
}
|
|
@@ -137,7 +146,9 @@ function validateShape(command, positionals) {
|
|
|
137
146
|
resources: 1,
|
|
138
147
|
prompts: 1,
|
|
139
148
|
discover: 0,
|
|
149
|
+
setup: 3,
|
|
140
150
|
session: 0,
|
|
151
|
+
access: 2,
|
|
141
152
|
completion: 1,
|
|
142
153
|
help: 1,
|
|
143
154
|
version: 0
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
export { SERVER_TOO_OLD } from "./cliProtocol.js";
|
|
4
|
+
export declare const MIN_CLI_SERVER_VERSION: string;
|
|
5
|
+
export declare const CLI_PROTOCOL_TOOLS: readonly ["passport_search_tools", "passport_call", "passport_manage_connections", "passport_wait_for_connection"];
|
|
6
|
+
export declare function supportsCliServerInfo(info: {
|
|
7
|
+
name?: string;
|
|
8
|
+
version?: string;
|
|
9
|
+
} | undefined): boolean;
|
|
10
|
+
export type CliAuth = {
|
|
11
|
+
kind: "profile";
|
|
12
|
+
endpoint: string;
|
|
13
|
+
profile: string;
|
|
14
|
+
refreshToken: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "agent-key";
|
|
17
|
+
endpoint: string;
|
|
18
|
+
agentKey: string;
|
|
19
|
+
};
|
|
20
|
+
export type ToolCall = CallToolResult;
|
|
21
|
+
export type CliProtocolDiagnostics = {
|
|
22
|
+
server?: {
|
|
23
|
+
name: string;
|
|
24
|
+
version: string;
|
|
25
|
+
};
|
|
26
|
+
serverCompatible: boolean;
|
|
27
|
+
tools: string[];
|
|
28
|
+
toolsExact: boolean;
|
|
29
|
+
};
|
|
30
|
+
type GatewayOptions = {
|
|
31
|
+
auth: CliAuth;
|
|
32
|
+
caller?: string;
|
|
33
|
+
timeoutMs: number;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
};
|
|
36
|
+
/** One authenticated MCP session for one CLI invocation. */
|
|
37
|
+
export declare class CliGateway {
|
|
38
|
+
private readonly client;
|
|
39
|
+
private readonly transport;
|
|
40
|
+
private readonly timeoutMs;
|
|
41
|
+
private readonly signal?;
|
|
42
|
+
private readonly apiFetch;
|
|
43
|
+
readonly origin: string;
|
|
44
|
+
private closed;
|
|
45
|
+
private constructor();
|
|
46
|
+
static connect(options: GatewayOptions): Promise<CliGateway>;
|
|
47
|
+
/** A CLI-surface credential must always receive all four stable meta-tools. */
|
|
48
|
+
assertCliProtocol(): Promise<void>;
|
|
49
|
+
/** Side-effect-free serverInfo + tools/list detail for `passport doctor`. */
|
|
50
|
+
protocolDiagnostics(): Promise<CliProtocolDiagnostics>;
|
|
51
|
+
callTool(name: string, args: Record<string, unknown>, timeoutMs?: number): Promise<ToolCall>;
|
|
52
|
+
/** Authenticated same-origin REST call for control-plane commands such as
|
|
53
|
+
* fleet discovery. The caller supplies only a path; credentials never leave
|
|
54
|
+
* the Passport origin pinned by the saved profile. */
|
|
55
|
+
fetchApi(path: string, init?: RequestInit): Promise<Response>;
|
|
56
|
+
listResources(): Promise<Awaited<ReturnType<Client["listResources"]>>>;
|
|
57
|
+
readResource(uri: string): ReturnType<Client["readResource"]>;
|
|
58
|
+
listPrompts(): Promise<Awaited<ReturnType<Client["listPrompts"]>>>;
|
|
59
|
+
getPrompt(name: string, args: Record<string, string>): ReturnType<Client["getPrompt"]>;
|
|
60
|
+
close(): Promise<void>;
|
|
61
|
+
private requestOptions;
|
|
62
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ParsedArgs } from "./cliArgs.js";
|
|
2
|
+
import type { CliAuth, CliGateway, ToolCall } from "./cliClient.js";
|
|
3
|
+
import { type CommandResult, type Runtime } from "./cliSupport.js";
|
|
4
|
+
export type GatewayRunner = <T>(args: ParsedArgs, runtime: Runtime, fn: (gateway: CliGateway, auth: CliAuth) => Promise<T>) => Promise<T>;
|
|
5
|
+
export type ManagePayload = {
|
|
6
|
+
workspace: {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
member: {
|
|
11
|
+
id: string;
|
|
12
|
+
email: string;
|
|
13
|
+
};
|
|
14
|
+
client: string;
|
|
15
|
+
surface: string;
|
|
16
|
+
auth: string;
|
|
17
|
+
connections: Array<Record<string, unknown>>;
|
|
18
|
+
connectAllUrl?: string;
|
|
19
|
+
note?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function managePayload(result: ToolCall): ManagePayload;
|
|
22
|
+
export declare function connect(args: ParsedArgs, runtime: Runtime, withGateway: GatewayRunner): Promise<CommandResult>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type DeadlineClock = {
|
|
2
|
+
set(callback: () => void, ms: number): NodeJS.Timeout;
|
|
3
|
+
clear(timer: NodeJS.Timeout): void;
|
|
4
|
+
};
|
|
5
|
+
/** A CLI request deadline must keep the short-lived command alive. A pending
|
|
6
|
+
* Promise does not hold Node's event loop open, so this timer is intentionally
|
|
7
|
+
* referenced until the operation settles or the deadline fires. */
|
|
8
|
+
export declare function withCliDeadline<T>(promise: Promise<T>, ms: number, onTimeout: () => void, clock?: DeadlineClock): Promise<T>;
|
|
9
|
+
export {};
|