passport-bridge 0.8.1 → 0.9.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 +81 -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 +89 -0
- package/dist/bridgeConfig.d.ts +1 -0
- package/dist/bridgeShutdown.d.ts +17 -0
- package/dist/cli.d.ts +2 -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 +10 -2
- 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 +2 -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/cliSupport.d.ts +102 -0
- package/dist/completion.d.ts +2 -0
- package/dist/completion.js +18 -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/passport.d.ts +7 -0
- package/dist/passport.js +2 -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 +15 -15
- package/package.json +13 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type AssertProfileName = (name: string) => void;
|
|
2
|
+
export type ActiveProfileDocument = {
|
|
3
|
+
kind: "missing";
|
|
4
|
+
} | {
|
|
5
|
+
kind: "present";
|
|
6
|
+
profile: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function activeProfilePath(): string;
|
|
9
|
+
export declare function readActiveProfileDocument(assertName: AssertProfileName): ActiveProfileDocument;
|
|
10
|
+
/** Best-effort read for command resolution. A stale or damaged pointer must
|
|
11
|
+
* never make the CLI guess a credential; callers can fall back to the normal
|
|
12
|
+
* sole-profile rule or report ambiguity. */
|
|
13
|
+
export declare function readActiveProfile(assertName: AssertProfileName): string | undefined;
|
|
14
|
+
export declare function writeActiveProfileAtomic(name: string, assertName: AssertProfileName): void;
|
|
15
|
+
/** The active-profile pointer contains no credential material. If an old or
|
|
16
|
+
* damaged installation left a symlink at that exact path, selecting a profile
|
|
17
|
+
* may safely unlink the symlink itself (never its target) before recreating the
|
|
18
|
+
* owner-only regular file. Other non-regular targets still fail closed. */
|
|
19
|
+
export declare function prepareActiveProfileForSelection(): void;
|
|
20
|
+
export declare function clearActiveProfileAtomic(): void;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const CLI_MCP_RESPONSE_MAX_BYTES: number;
|
|
2
|
+
/** Bound one-shot MCP JSON responses in total and long-lived SSE responses per
|
|
3
|
+
* event. The wrapper always cancels and unlocks the original reader on every
|
|
4
|
+
* terminal path so failed or abandoned CLI calls release their socket. */
|
|
5
|
+
export declare function boundMcpResponse(response: Response, maxBytes?: number): Promise<Response>;
|
|
6
|
+
export declare function boundedMcpFetch(base: typeof fetch, maxBytes?: number): typeof fetch;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const DEFAULT_API_RESPONSE_BYTES: number;
|
|
2
|
+
/** Parse a Fetch JSON response without trusting Content-Length or allowing a
|
|
3
|
+
* chunked Passport response to grow the client process without bound. */
|
|
4
|
+
export declare function readBoundedJson<T>(response: Response, maxBytes?: number): Promise<T>;
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
3
|
+
export { workspaceOfToken } from "./tokenWorkspace.js";
|
|
4
|
+
/** Everything but the MCP protocol goes to stderr — stdout is the transport. */
|
|
5
|
+
export declare function log(...args: unknown[]): void;
|
|
6
|
+
/**
|
|
7
|
+
* Shown to the AI client (and logged) when the bridge refuses to switch tenants:
|
|
8
|
+
* the on-disk credential now belongs to a DIFFERENT workspace than this process
|
|
9
|
+
* started serving. We fail closed rather than silently attribute activity to the
|
|
10
|
+
* wrong workspace.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TENANT_FLIP_MESSAGE = "This machine's Passport credential now belongs to a different workspace. Reconnect this client from the Passport app.";
|
|
13
|
+
export declare class BridgeCredentialError extends Error {
|
|
14
|
+
readonly status: 401;
|
|
15
|
+
constructor(status: 401);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Holds the long-lived refresh token and mints short-lived access tokens
|
|
19
|
+
* from the cloud, transparently refreshing on expiry or a 401.
|
|
20
|
+
*/
|
|
21
|
+
export declare class TokenManager {
|
|
22
|
+
private readonly onRotate?;
|
|
23
|
+
private readonly coordinate?;
|
|
24
|
+
private readonly requestTimeoutMs?;
|
|
25
|
+
private readonly requestSignal?;
|
|
26
|
+
private readonly fetcher;
|
|
27
|
+
private origin;
|
|
28
|
+
private refreshToken;
|
|
29
|
+
private access?;
|
|
30
|
+
private expiresAt;
|
|
31
|
+
private inflight?;
|
|
32
|
+
private pendingRotation?;
|
|
33
|
+
/** The workspace this process started serving, read from its initial refresh
|
|
34
|
+
* token. The tenant-flip guard refuses to adopt an on-disk credential whose
|
|
35
|
+
* workspace differs from this. */
|
|
36
|
+
private readonly homeWorkspace;
|
|
37
|
+
private tenantFlipLogged;
|
|
38
|
+
/**
|
|
39
|
+
* @param onRotate durably persist a rotated refresh token before its access
|
|
40
|
+
* token is usable. Rejection leaves the child pending for local retry.
|
|
41
|
+
* Without it (e.g. env-only auth), the server is told not to rotate.
|
|
42
|
+
* @param coordinate cross-process coordination for a shared profile (Cursor
|
|
43
|
+
* runs one bridge per window): `reload` returns the freshest persisted
|
|
44
|
+
* refresh token, `lock` serializes the exchange across processes. Without
|
|
45
|
+
* them, a sibling process's rotation makes our in-memory token a replay —
|
|
46
|
+
* which the server treats as theft and answers by revoking the family.
|
|
47
|
+
*/
|
|
48
|
+
constructor(endpoint: string, refreshToken: string, onRotate?: ((next: string, previous: string) => void | Promise<void>) | undefined, coordinate?: {
|
|
49
|
+
reload: () => string | undefined;
|
|
50
|
+
lock: <T>(fn: () => Promise<T>) => Promise<T>;
|
|
51
|
+
} | undefined, requestTimeoutMs?: number | undefined, requestSignal?: AbortSignal | undefined, fetcher?: typeof fetch);
|
|
52
|
+
private assertHomeWorkspace;
|
|
53
|
+
private settlePendingRotation;
|
|
54
|
+
accessToken(force?: boolean): Promise<string>;
|
|
55
|
+
/** Adopt a newly persisted credential after an interactive recovery. The
|
|
56
|
+
* original workspace remains authoritative for this running bridge. */
|
|
57
|
+
replaceRefreshToken(next: string): void;
|
|
58
|
+
/** Adopt a newly persisted credential and its approved gateway endpoint. */
|
|
59
|
+
replaceCredential(next: string, endpoint: string): void;
|
|
60
|
+
private exchange;
|
|
61
|
+
/** fetch wrapper that attaches the current access token and refreshes on 401. */
|
|
62
|
+
authedFetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
63
|
+
}
|
|
64
|
+
export type BridgeRecoveryFlow = {
|
|
65
|
+
verifyUrl: string;
|
|
66
|
+
userCode: string;
|
|
67
|
+
/** Waits for device approval and durably replaces the saved credential. */
|
|
68
|
+
waitForCredential: (signal: AbortSignal) => Promise<{
|
|
69
|
+
refreshToken: string;
|
|
70
|
+
endpoint: string;
|
|
71
|
+
}>;
|
|
72
|
+
};
|
|
73
|
+
export type BridgeRecovery = {
|
|
74
|
+
start: () => Promise<BridgeRecoveryFlow>;
|
|
75
|
+
};
|
|
76
|
+
export type BridgeRunOptions = {
|
|
77
|
+
/** Test hook for an in-process downstream transport. */
|
|
78
|
+
downstreamTransport?: Transport;
|
|
79
|
+
/** Test hook for an in-process upstream connection. */
|
|
80
|
+
connectUpstream?: (client: Client) => Promise<void>;
|
|
81
|
+
recovery?: BridgeRecovery;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* The proxy: a stdio MCP server (what the AI client talks to) that forwards
|
|
85
|
+
* verbatim to the cloud gateway over Streamable HTTP. Tool definitions and
|
|
86
|
+
* arguments pass through unchanged; cancellation and progress are forwarded;
|
|
87
|
+
* a periodic re-list notifies the client when the toolset changes.
|
|
88
|
+
*/
|
|
89
|
+
export declare function runBridge(endpoint: string, tokens: TokenManager, options?: BridgeRunOptions): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function bridgePollIntervalMs(env?: Readonly<Record<string, string | undefined>>): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
upstream: Closeable;
|
|
8
|
+
server: Closeable;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
exit?: (code: number) => void;
|
|
11
|
+
onFailure?: () => void;
|
|
12
|
+
};
|
|
13
|
+
/** Stop polling, await both MCP transports, and only then exit. The deadline
|
|
14
|
+
* prevents a broken transport from wedging a terminal client indefinitely;
|
|
15
|
+
* duplicate signals share the same close attempt and cannot race exits. */
|
|
16
|
+
export declare function createBoundedBridgeShutdown(options: BridgeShutdownOptions): () => Promise<void>;
|
|
17
|
+
export {};
|
package/dist/cli.d.ts
ADDED
|
@@ -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", "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
|
@@ -14,6 +14,7 @@ export const COMMANDS = [
|
|
|
14
14
|
"prompts",
|
|
15
15
|
"discover",
|
|
16
16
|
"session",
|
|
17
|
+
"access",
|
|
17
18
|
"completion",
|
|
18
19
|
"help",
|
|
19
20
|
"version"
|
|
@@ -26,7 +27,7 @@ const FLAGS = {
|
|
|
26
27
|
caller: { kind: "value" },
|
|
27
28
|
help: { kind: "boolean" },
|
|
28
29
|
cloud: { kind: "value", commands: ["login"] },
|
|
29
|
-
workspace: { kind: "value", commands: ["login"] },
|
|
30
|
+
workspace: { kind: "value", commands: ["login", "access"] },
|
|
30
31
|
client: { kind: "value", commands: ["login"] },
|
|
31
32
|
"no-open": { kind: "boolean", commands: ["login"] },
|
|
32
33
|
app: { kind: "value", commands: ["search"] },
|
|
@@ -36,7 +37,13 @@ const FLAGS = {
|
|
|
36
37
|
wait: { kind: "value", commands: ["run", "connect"] },
|
|
37
38
|
alias: { kind: "value", commands: ["connect"] },
|
|
38
39
|
open: { kind: "boolean", commands: ["connect"] },
|
|
39
|
-
out: { kind: "value", commands: ["resources", "prompts"] }
|
|
40
|
+
out: { kind: "value", commands: ["resources", "prompts"] },
|
|
41
|
+
input: { kind: "value", commands: ["access"] },
|
|
42
|
+
algorithm: { kind: "value", commands: ["access"] },
|
|
43
|
+
"private-key-file": { kind: "value", commands: ["access"] },
|
|
44
|
+
"public-jwk-file": { kind: "value", commands: ["access"] },
|
|
45
|
+
"delegation-id": { kind: "value", commands: ["access"] },
|
|
46
|
+
"client-id": { kind: "value", commands: ["access"] }
|
|
40
47
|
};
|
|
41
48
|
export class ArgError extends Error {
|
|
42
49
|
}
|
|
@@ -138,6 +145,7 @@ function validateShape(command, positionals) {
|
|
|
138
145
|
prompts: 1,
|
|
139
146
|
discover: 0,
|
|
140
147
|
session: 0,
|
|
148
|
+
access: 2,
|
|
141
149
|
completion: 1,
|
|
142
150
|
help: 1,
|
|
143
151
|
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 {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a search result for the CLI's describe contract.
|
|
3
|
+
*
|
|
4
|
+
* `tool` and `parameters` are the original Passport fields. `name` and
|
|
5
|
+
* `inputSchema` are compatibility aliases for clients that consume the
|
|
6
|
+
* conventional MCP vocabulary. Keep all server-provided fields intact.
|
|
7
|
+
*/
|
|
8
|
+
export declare function describedToolPayload(exact: Record<string, unknown>, fallbackName: string): Record<string, unknown>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ParsedArgs } from "./cliArgs.js";
|
|
2
|
+
import { type CommandResult, type Env } from "./cliSupport.js";
|
|
3
|
+
export declare function completionResult(args: ParsedArgs): CommandResult;
|
|
4
|
+
export declare function profilesResult(_args: ParsedArgs): CommandResult;
|
|
5
|
+
export declare function useProfileResult(args: ParsedArgs, env: Env): CommandResult;
|
|
6
|
+
export declare function versionResult(args: ParsedArgs, env: Env): CommandResult;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ParsedArgs } from "./cliArgs.js";
|
|
2
|
+
import { CliFailure, type CommandResult, type Runtime } from "./cliSupport.js";
|
|
3
|
+
export declare function helpResult(args: ParsedArgs): CommandResult;
|
|
4
|
+
export declare function emitResult(result: CommandResult, args: ParsedArgs, runtime: Runtime): void;
|
|
5
|
+
export declare function asFailure(error: unknown): CliFailure;
|
|
6
|
+
export declare function emitFailure(error: CliFailure, json: boolean, quiet: boolean, runtime: Runtime): void;
|
|
7
|
+
export declare function failurePayload(error: CliFailure): Record<string, unknown>;
|
package/dist/cliOutput.js
CHANGED
|
@@ -19,6 +19,7 @@ function helpText(verb) {
|
|
|
19
19
|
prompts: "passport prompts [name] [--set key=value] [--out <file>]\nLists or gets workspace MCP prompts. Binary content requires --out or --json.",
|
|
20
20
|
discover: "passport discover\nScans supported local MCP configuration, submits privacy-minimized inventory, and exits 5 when a managed policy reports a violation.",
|
|
21
21
|
session: 'passport session\nReads newline-delimited {"id"?:string|number,"argv":string[]} requests from stdin and emits one JSON response per line. Reuses one authenticated MCP session. Supported request commands: status, search, describe, run, connect, resources, prompts, discover.',
|
|
22
|
+
access: "passport access <keygen|actions|run|invoke|status|cancel>\nkeygen writes a new owner-only private key and separate public JWK. Other commands use PASSPORT_ENDPOINT, PASSPORT_CLIENT_ID, and PASSPORT_PRIVATE_KEY_FILE.\n access actions [--delegation-id <id>]\n access run --input <json-file>\n access invoke --input <json-file> --caller <stable-id>\n access status <invocation-id>\n access cancel <run-id>",
|
|
22
23
|
completion: "passport completion <bash|zsh|fish>\nPrints an offline shell-completion script to stdout.",
|
|
23
24
|
help: "passport help [verb]",
|
|
24
25
|
version: "passport version\nWorks without a profile or network."
|
|
@@ -44,6 +45,7 @@ Usage: passport <command> [options]
|
|
|
44
45
|
prompts List or get MCP prompts
|
|
45
46
|
discover Scan this computer for direct MCP configuration
|
|
46
47
|
session Reuse one authenticated MCP session for NDJSON commands
|
|
48
|
+
access Use the signed managed access gateway
|
|
47
49
|
completion Generate bash, zsh, or fish completion
|
|
48
50
|
help Show command help
|
|
49
51
|
version Show CLI version and local context
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type CliPaginationLimits = {
|
|
2
|
+
maxPages: number;
|
|
3
|
+
maxItems: number;
|
|
4
|
+
maxSerializedBytes: number;
|
|
5
|
+
maxCursorBytes: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const DEFAULT_CLI_PAGINATION_LIMITS: Readonly<CliPaginationLimits>;
|
|
8
|
+
/** Aggregate the MCP pages a one-shot CLI command prints while bounding every
|
|
9
|
+
* attacker/provider-controlled dimension. Cursor cycles fail closed. */
|
|
10
|
+
export declare function collectCliPages<TItem, TPage extends {
|
|
11
|
+
nextCursor?: string;
|
|
12
|
+
}>(kind: "resource" | "prompt", load: (cursor: string | undefined) => Promise<TPage>, itemsFrom: (page: TPage) => readonly TItem[], limits?: CliPaginationLimits): Promise<{
|
|
13
|
+
last: TPage;
|
|
14
|
+
items: TItem[];
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Dependency-free protocol messages shared by the CLI entrypoint and MCP
|
|
2
|
+
* client. Keeping this separate lets `passport version` run directly from an
|
|
3
|
+
* extracted tarball without loading the MCP SDK or touching the network. */
|
|
4
|
+
export declare const SERVER_TOO_OLD = "This Passport server is too old for the CLI. Ask your admin to deploy the CLI-compatible server release first.";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ParsedArgs } from "./cliArgs.js";
|
|
2
|
+
import { type CommandResult, type Runtime } from "./cliSupport.js";
|
|
3
|
+
import { type DoctorReport } from "./doctor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Run the same local, auth, server, and protocol checks as doctor, with a
|
|
6
|
+
* machine-friendly `ready` field for agents and CI preflight scripts.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ready(args: ParsedArgs, runtime: Runtime): Promise<CommandResult>;
|
|
9
|
+
export declare function formatReadyReport(report: DoctorReport): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ToolCall } from "./cliClient.js";
|
|
2
|
+
import { CliFailure } from "./cliSupport.js";
|
|
3
|
+
export declare function firstText(result: ToolCall): string;
|
|
4
|
+
export declare function hasNonText(result: ToolCall): boolean;
|
|
5
|
+
export declare function payloadOf(result: ToolCall, label: string): Record<string, unknown>;
|
|
6
|
+
export declare function refusalOf(result: ToolCall): CliFailure | undefined;
|
|
7
|
+
export declare function requireSuccess(result: ToolCall): ToolCall;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ParsedArgs } from "./cliArgs.js";
|
|
2
|
+
import { CliFailure, type CommandResult, type Runtime } from "./cliSupport.js";
|
|
3
|
+
export declare const CLI_SESSION_LINE_MAX_BYTES: number;
|
|
4
|
+
export declare const CLI_SESSION_ARGV_MAX_ITEMS = 128;
|
|
5
|
+
export type SessionRequest = {
|
|
6
|
+
id?: string | number;
|
|
7
|
+
argv: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Split an async byte stream into bounded UTF-8 lines. The limit applies before
|
|
11
|
+
* decoding, so a caller cannot grow an unbounded string while omitting `\n`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function readBoundedSessionLines(input: AsyncIterable<string | Uint8Array>, signal: AbortSignal, maxBytes?: number): AsyncGenerator<string>;
|
|
14
|
+
export declare function parseSessionRequest(line: string): SessionRequest | undefined;
|
|
15
|
+
export declare function writeCliSessionFailure(runtime: Runtime, error: CliFailure): Promise<void>;
|
|
16
|
+
/** Keep one token manager and MCP client alive while processing sequential
|
|
17
|
+
* NDJSON requests. Authorization and policy still run at the gateway for every
|
|
18
|
+
* operation; only local process, token-exchange, initialization, and protocol
|
|
19
|
+
* assertion overhead is shared. */
|
|
20
|
+
export declare function runCliSession(args: ParsedArgs, runtime: Runtime, dispatch: (args: ParsedArgs, runtime: Runtime) => Promise<CommandResult>): Promise<CommandResult>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type ChildProcess } from "node:child_process";
|
|
2
|
+
import { type ParsedArgs } from "./cliArgs.js";
|
|
3
|
+
import type { CliAuth, CliGateway } from "./cliClient.js";
|
|
4
|
+
import { type Profile } from "./credentials.js";
|
|
5
|
+
export { readBoundedJson } from "./boundedResponse.js";
|
|
6
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
7
|
+
export type Env = NodeJS.ProcessEnv;
|
|
8
|
+
export type Runtime = {
|
|
9
|
+
env: Env;
|
|
10
|
+
stdin?: AsyncIterable<string | Uint8Array>;
|
|
11
|
+
stdout: Pick<NodeJS.WriteStream, "write">;
|
|
12
|
+
stderr: Pick<NodeJS.WriteStream, "write">;
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
sharedGateway?: {
|
|
15
|
+
gateway: CliGateway;
|
|
16
|
+
auth: CliAuth;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export type CliNextAction = {
|
|
20
|
+
argv: string[];
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
export type CliRemediation = {
|
|
24
|
+
action: string;
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
export type CliRetry = {
|
|
28
|
+
command: "run";
|
|
29
|
+
tool: string;
|
|
30
|
+
waitSeconds: number;
|
|
31
|
+
arguments: "none" | "reuse_original";
|
|
32
|
+
};
|
|
33
|
+
export type ProfileSelectionSource = "explicit" | "environment" | "active" | "detected-client" | "sole-profile" | "ambiguous" | "none";
|
|
34
|
+
export type StoredProfileSelection = {
|
|
35
|
+
profile?: string;
|
|
36
|
+
source: ProfileSelectionSource;
|
|
37
|
+
names: string[];
|
|
38
|
+
/** Profiles that are safe candidates for the current CLI surface. */
|
|
39
|
+
cliCandidates: string[];
|
|
40
|
+
};
|
|
41
|
+
export type CommandResult = {
|
|
42
|
+
json: unknown;
|
|
43
|
+
human?: string | Buffer;
|
|
44
|
+
essential?: boolean;
|
|
45
|
+
raw?: boolean;
|
|
46
|
+
exitCode?: number;
|
|
47
|
+
};
|
|
48
|
+
export declare class CliFailure extends Error {
|
|
49
|
+
readonly exitCode: number;
|
|
50
|
+
readonly cause: string;
|
|
51
|
+
readonly details: {
|
|
52
|
+
approvalId?: string;
|
|
53
|
+
app?: string;
|
|
54
|
+
connectUrl?: string;
|
|
55
|
+
hint?: string;
|
|
56
|
+
profiles?: string[];
|
|
57
|
+
next?: CliNextAction[];
|
|
58
|
+
remediation?: CliRemediation;
|
|
59
|
+
retry?: CliRetry;
|
|
60
|
+
requiredInput?: string[];
|
|
61
|
+
};
|
|
62
|
+
constructor(message: string, exitCode: number, cause: string, details?: {
|
|
63
|
+
approvalId?: string;
|
|
64
|
+
app?: string;
|
|
65
|
+
connectUrl?: string;
|
|
66
|
+
hint?: string;
|
|
67
|
+
profiles?: string[];
|
|
68
|
+
next?: CliNextAction[];
|
|
69
|
+
remediation?: CliRemediation;
|
|
70
|
+
retry?: CliRetry;
|
|
71
|
+
requiredInput?: string[];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export declare function failure(message: string, exitCode: number, cause: string, details?: CliFailure["details"]): never;
|
|
75
|
+
export declare function timeoutMs(args: ParsedArgs): number;
|
|
76
|
+
export declare function profileName(raw: string): string;
|
|
77
|
+
export declare function endpoint(raw: string): string;
|
|
78
|
+
export declare function cloudOrigin(raw: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Resolve a local profile without ever guessing between workspaces. Explicit
|
|
81
|
+
* CLI and environment selectors win over the active pointer. In the absence
|
|
82
|
+
* of those selectors, exactly one CLI-owned profile is deterministic enough
|
|
83
|
+
* to migrate to the active pointer; otherwise only the historical sole
|
|
84
|
+
* profile fallback is retained.
|
|
85
|
+
*/
|
|
86
|
+
export declare function selectStoredProfile(args: ParsedArgs | undefined, env: Env, creds?: Record<string, Profile>, persistDetected?: boolean): StoredProfileSelection;
|
|
87
|
+
export declare function sameOriginWebUrl(raw: string, trustedOrigin: string, label: string): string;
|
|
88
|
+
export declare function resolveCliAuth(args: ParsedArgs, env: Env): CliAuth;
|
|
89
|
+
export declare function callerFrom(args: ParsedArgs, env: Env): string | undefined;
|
|
90
|
+
export declare function sanitize(message: string): string;
|
|
91
|
+
export declare function timedFetch(input: string | URL, init: RequestInit, ms: number, parent: AbortSignal): Promise<Response>;
|
|
92
|
+
export declare function safeApiError(response: Response, fallback: string): Promise<string>;
|
|
93
|
+
export declare function sleep(ms: number, signal: AbortSignal): Promise<void>;
|
|
94
|
+
type UrlLauncher = (command: string, args: string[], options: {
|
|
95
|
+
stdio: "ignore";
|
|
96
|
+
detached: true;
|
|
97
|
+
shell: false;
|
|
98
|
+
}) => Pick<ChildProcess, "on" | "unref">;
|
|
99
|
+
/** Open only a validated web URL. A provider-controlled query string must stay
|
|
100
|
+
* one opaque process argument and never cross a command-shell boundary. */
|
|
101
|
+
export declare function openUrl(url: string, platform?: NodeJS.Platform, launch?: UrlLauncher): boolean;
|
|
102
|
+
export declare function firstSentence(value: string): string;
|