passport-bridge 0.7.1 → 0.8.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/dist/passport.js CHANGED
@@ -2,14 +2,14 @@
2
2
  import { realpathSync, writeFileSync } from "node:fs";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { bool, parseArgs, repeated, value } from "./cliArgs.js";
5
- import { SERVER_TOO_OLD } from "./cliProtocol.js";
6
5
  import { removeProfile, withProfileLock } from "./credentials.js";
7
6
  import { VERSION } from "./version.js";
8
7
  import { login } from "./cliLogin.js";
9
8
  import { asFailure, emitFailure, emitResult, helpResult } from "./cliOutput.js";
10
- import { completionResult, versionResult } from "./cliOffline.js";
9
+ import { completionResult, profilesResult, useProfileResult, versionResult } from "./cliOffline.js";
10
+ import { connect, managePayload } from "./cliConnect.js";
11
11
  import { firstText, hasNonText, payloadOf, refusalOf, requireSuccess } from "./cliResult.js";
12
- import { callerFrom, endpoint, failure, firstSentence, openUrl, readBoundedJson, resolveCliAuth, safeApiError, sanitize, sleep, timedFetch, timeoutMs } from "./cliSupport.js";
12
+ import { callerFrom, endpoint, failure, firstSentence, readBoundedJson, resolveCliAuth, safeApiError, sanitize, sleep, timedFetch, timeoutMs } from "./cliSupport.js";
13
13
  import { readBoundedUtf8Descriptor } from "./boundedFile.js";
14
14
  import { runCliSession, writeCliSessionFailure } from "./cliSession.js";
15
15
  export { refusalOf } from "./cliResult.js";
@@ -64,21 +64,6 @@ async function logout(args, runtime) {
64
64
  runtime.stderr.write(`${warning}\n`);
65
65
  return { json: { profile: auth.profile, removed: true, revoked }, human: `Signed out profile "${auth.profile}".` };
66
66
  }
67
- function managePayload(result) {
68
- requireSuccess(result);
69
- const payload = payloadOf(result, "connection");
70
- if (!payload.workspace ||
71
- typeof payload.workspace !== "object" ||
72
- !payload.member ||
73
- typeof payload.member !== "object" ||
74
- typeof payload.client !== "string" ||
75
- payload.surface !== "cli" ||
76
- typeof payload.auth !== "string" ||
77
- !Array.isArray(payload.connections)) {
78
- return failure(SERVER_TOO_OLD, 1, "server_too_old");
79
- }
80
- return payload;
81
- }
82
67
  async function status(args, runtime) {
83
68
  return withGateway(args, runtime, async (gateway, auth) => {
84
69
  const managed = managePayload(await gateway.callTool("passport_manage_connections", { includeLinks: false }));
@@ -86,8 +71,35 @@ async function status(args, runtime) {
86
71
  app: String(row.app ?? ""),
87
72
  name: String(row.name ?? row.app ?? ""),
88
73
  status: String(row.status ?? "unknown"),
89
- toolCount: Number(row.toolCount ?? 0)
74
+ toolCount: Number(row.toolCount ?? 0),
75
+ ...(row.status === "needs_your_signin"
76
+ ? auth.kind === "profile"
77
+ ? {
78
+ remediation: {
79
+ cause: "needs_connect",
80
+ next: {
81
+ argv: ["passport", "connect", String(row.app ?? ""), "--wait", "120"],
82
+ description: "Complete member sign-in, then retry the tool call."
83
+ }
84
+ }
85
+ }
86
+ : {
87
+ remediation: {
88
+ cause: "member_profile_required",
89
+ action: "use_member_profile_or_managed_connection",
90
+ description: "Use an interactive member profile, delegate the agent to a member, or configure a company-managed connection."
91
+ }
92
+ }
93
+ : {})
90
94
  }));
95
+ const connectionActions = auth.kind === "profile"
96
+ ? mcps
97
+ .filter((mcp) => mcp.status === "needs_your_signin" && /^[A-Za-z0-9._-]+$/.test(mcp.app))
98
+ .map((mcp) => ({
99
+ argv: ["passport", "connect", mcp.app, "--wait", "120"],
100
+ description: `Connect ${mcp.name}.`
101
+ }))
102
+ : [];
91
103
  const data = {
92
104
  workspace: { id: String(managed.workspace.id), name: String(managed.workspace.name) },
93
105
  member: { id: String(managed.member.id), email: String(managed.member.email) },
@@ -95,7 +107,8 @@ async function status(args, runtime) {
95
107
  auth: managed.auth,
96
108
  ...(auth.kind === "profile" ? { profile: auth.profile } : {}),
97
109
  client: managed.client,
98
- mcps
110
+ mcps,
111
+ ...(connectionActions.length ? { next: connectionActions } : {})
99
112
  };
100
113
  const lines = [
101
114
  `${data.workspace.name} (${data.workspace.id})`,
@@ -104,7 +117,13 @@ async function status(args, runtime) {
104
117
  ...(auth.kind === "profile" ? [`Profile: ${auth.profile}`] : []),
105
118
  `Client: ${managed.client} · Surface: ${managed.surface} · Auth: ${managed.auth}`,
106
119
  ...(mcps.length
107
- ? mcps.map((mcp) => `${mcp.name} (${mcp.app}): ${mcp.status} · ${mcp.toolCount} permitted tool${mcp.toolCount === 1 ? "" : "s"}`)
120
+ ? mcps.map((mcp) => `${mcp.name} (${mcp.app}): ${mcp.status} · ${mcp.toolCount} permitted tool${mcp.toolCount === 1 ? "" : "s"}${mcp.status === "needs_your_signin"
121
+ ? auth.kind === "agent-key"
122
+ ? " · Requires an interactive member profile, delegation, or a company-managed connection"
123
+ : /^[A-Za-z0-9._-]+$/.test(mcp.app)
124
+ ? ` · Run: passport connect ${mcp.app} --wait 120`
125
+ : " · Run passport status --json for the safe connect argv"
126
+ : ""}`)
108
127
  : ["No visible MCPs."])
109
128
  ];
110
129
  return { json: data, human: lines.join("\n") };
@@ -210,7 +229,15 @@ async function describe(args, runtime) {
210
229
  .map((hit) => String(hit.tool ?? ""))
211
230
  .filter(Boolean);
212
231
  const suffix = suggestions.length ? ` Near matches: ${suggestions.join(", ")}.` : "";
213
- return failure(`Unknown tool "${name}".${suffix}`, 6, "unknown_tool");
232
+ return failure(`Unknown tool "${name}".${suffix}`, 6, "unknown_tool", {
233
+ hint: `Run: passport search "${name}"`,
234
+ next: [
235
+ {
236
+ argv: ["passport", "search", name],
237
+ description: "Search permitted tool names."
238
+ }
239
+ ]
240
+ });
214
241
  }
215
242
  const schema = exact.parameters ?? {};
216
243
  const human = [
@@ -227,18 +254,53 @@ async function run(args, runtime) {
227
254
  const tool = args.positionals[0];
228
255
  const toolArgs = runArguments(args);
229
256
  const waitSeconds = value(args, "wait") ? Number(value(args, "wait")) : 0;
230
- return withGateway(args, runtime, async (gateway) => {
257
+ return withGateway(args, runtime, async (gateway, auth) => {
231
258
  const deadlineAt = waitSeconds ? Date.now() + waitSeconds * 1000 : 0;
259
+ let waitingForApproval = false;
232
260
  let result = await gateway.callTool("passport_call", { tool, args: toolArgs });
233
261
  for (;;) {
234
262
  const refusal = refusalOf(result);
235
- if (!refusal)
263
+ if (!refusal) {
264
+ if (waitingForApproval && !bool(args, "quiet"))
265
+ runtime.stderr.write("Approval received. Continuing...\n");
236
266
  break;
267
+ }
268
+ if (refusal.cause === "needs_connect" && auth.kind === "agent-key") {
269
+ return failure("This agent key cannot create a person's sign-in link.", 3, "member_profile_required", {
270
+ app: refusal.details.app,
271
+ hint: "Use an interactive member profile, delegate the agent to a member, or configure a company-managed connection.",
272
+ remediation: {
273
+ action: "use_member_profile_or_managed_connection",
274
+ description: "Use an interactive member profile, delegate the agent to a member, or configure a company-managed connection."
275
+ }
276
+ });
277
+ }
278
+ if (refusal.cause === "approval_pending") {
279
+ refusal.details.retry = {
280
+ command: "run",
281
+ tool,
282
+ waitSeconds: waitSeconds || 120,
283
+ arguments: Object.keys(toolArgs).length ? "reuse_original" : "none"
284
+ };
285
+ if (!Object.keys(toolArgs).length) {
286
+ refusal.details.next = [
287
+ {
288
+ argv: ["passport", "run", tool, "--wait", String(waitSeconds || 120)],
289
+ description: "Retry this tool and wait for approval."
290
+ }
291
+ ];
292
+ }
293
+ }
237
294
  if (refusal.cause !== "approval_pending" || !waitSeconds)
238
295
  throw refusal;
239
296
  const remaining = deadlineAt - Date.now();
240
297
  if (remaining <= 0)
241
298
  throw refusal;
299
+ if (!waitingForApproval && !bool(args, "quiet")) {
300
+ const approval = refusal.details.approvalId ? ` (${refusal.details.approvalId})` : "";
301
+ runtime.stderr.write(`Approval pending${approval}. Waiting up to ${waitSeconds} seconds...\n`);
302
+ waitingForApproval = true;
303
+ }
242
304
  await sleep(Math.min(APPROVAL_RETRY_MS, remaining), runtime.signal);
243
305
  if (Date.now() >= deadlineAt)
244
306
  throw refusal;
@@ -307,105 +369,6 @@ function jsonObject(raw, label) {
307
369
  return failure(`${label} must be a valid JSON object.`, 6, "usage");
308
370
  }
309
371
  }
310
- async function connect(args, runtime) {
311
- const alias = value(args, "alias");
312
- if (alias !== undefined && !/^[A-Za-z0-9 -]{1,32}$/.test(alias.trim()))
313
- return failure("--alias must contain 1-32 letters, numbers, spaces, or hyphens.", 6, "usage");
314
- const requested = args.positionals;
315
- return withGateway(args, runtime, async (gateway) => {
316
- let managed = managePayload(await gateway.callTool("passport_manage_connections", {
317
- ...(alias !== undefined ? { alias: alias.trim() } : {}),
318
- ...(requested.length ? { apps: requested } : {})
319
- }));
320
- const rows = requested.length
321
- ? requested.map((app) => findConnection(managed.connections, app))
322
- : managed.connections;
323
- const human = connectionLines(managed, rows, requested.length > 0);
324
- const urls = connectionUrls(managed, rows, requested.length > 0);
325
- if (bool(args, "open")) {
326
- if (urls.length > 1)
327
- return failure("--open requires a single connect URL. Name one MCP, or use the aggregate connect flow.", 6, "usage");
328
- if (urls[0])
329
- openUrl(urls[0]);
330
- }
331
- const waitSeconds = value(args, "wait") ? Number(value(args, "wait")) : 0;
332
- if (!waitSeconds)
333
- return { json: managed, human: human.join("\n") };
334
- const targets = requested.length
335
- ? rows.filter((row) => row.status === "needs_your_signin").map((row) => String(row.app))
336
- : rows.filter((row) => row.status === "needs_your_signin").map((row) => String(row.app));
337
- if (!targets.length)
338
- return { json: managed, human: human.join("\n") };
339
- if (!bool(args, "json") && (!bool(args, "quiet") || !bool(args, "open")))
340
- runtime.stdout.write(`${human.join("\n")}\n`);
341
- const waitResult = await waitForConnections(gateway, targets, waitSeconds, runtime.signal);
342
- if (!waitResult.connected) {
343
- const note = typeof waitResult.note === "string" ? waitResult.note : "Timed out waiting for the MCP connection.";
344
- return failure(note, 1, "connection_timeout", { app: targets.length === 1 ? targets[0] : undefined });
345
- }
346
- managed = managePayload(await gateway.callTool("passport_manage_connections", { includeLinks: false }));
347
- return { json: managed, human: typeof waitResult.note === "string" ? waitResult.note : "Connection ready." };
348
- });
349
- }
350
- function findConnection(rows, requested) {
351
- const needle = requested.trim().toLowerCase();
352
- const row = rows.find((entry) => String(entry.app ?? "").toLowerCase() === needle || String(entry.name ?? "").toLowerCase() === needle);
353
- if (!row)
354
- return failure(`Unknown MCP "${requested}". Run passport status to see visible MCPs.`, 6, "unknown_app", {
355
- app: requested
356
- });
357
- return row;
358
- }
359
- function connectionUrls(managed, rows, explicitlyNamed) {
360
- const needSignin = rows.filter((row) => row.status === "needs_your_signin");
361
- if (!explicitlyNamed && needSignin.length >= 2 && managed.connectAllUrl)
362
- return [managed.connectAllUrl];
363
- return needSignin.map((row) => row.connectUrl).filter((url) => typeof url === "string");
364
- }
365
- function connectionLines(managed, rows, explicitlyNamed) {
366
- const urls = connectionUrls(managed, rows, explicitlyNamed);
367
- if (!explicitlyNamed && urls.length === 1 && rows.filter((row) => row.status === "needs_your_signin").length >= 2) {
368
- return [`Connect your MCPs: ${urls[0]}`];
369
- }
370
- const lines = [];
371
- for (const row of rows) {
372
- const name = String(row.name ?? row.app ?? "MCP");
373
- if (row.status === "needs_your_signin" && typeof row.connectUrl === "string")
374
- lines.push(`${name}: ${row.connectUrl}`);
375
- else if (row.status === "connected" || row.status === "org_managed")
376
- lines.push(`${name}: already connected`);
377
- else if (typeof row.action === "string")
378
- lines.push(`${name}: ${row.action}`);
379
- else
380
- lines.push(`${name}: ${String(row.status ?? "unknown")}`);
381
- }
382
- if (!lines.length || (!explicitlyNamed && !rows.some((row) => row.status === "needs_your_signin")))
383
- lines.push(managed.note || "Nothing needs connecting.");
384
- return lines;
385
- }
386
- async function waitForConnections(gateway, apps, seconds, signal) {
387
- const deadlineAt = Date.now() + seconds * 1000;
388
- let latest = { connected: false };
389
- do {
390
- const remaining = Math.max(1, Math.ceil((deadlineAt - Date.now()) / 1000));
391
- const chunk = Math.min(120, remaining);
392
- const result = requireSuccess(await gateway.callTool("passport_wait_for_connection", apps.length === 1 ? { app: apps[0], timeoutSeconds: chunk } : { apps, timeoutSeconds: chunk }, (chunk + 5) * 1000));
393
- const text = firstText(result);
394
- try {
395
- latest = JSON.parse(text);
396
- }
397
- catch {
398
- return failure("Passport returned an invalid connection wait payload.", 1, "invalid_server_response");
399
- }
400
- if (latest.connected === true || latest.status === "connected")
401
- return { ...latest, connected: true };
402
- if (latest.status === "needs_setup")
403
- return { ...latest, connected: false };
404
- if (Date.now() < deadlineAt)
405
- await sleep(Math.min(250, deadlineAt - Date.now()), signal);
406
- } while (Date.now() < deadlineAt);
407
- return { ...latest, connected: false };
408
- }
409
372
  async function resources(args, runtime) {
410
373
  if (value(args, "out") !== undefined && !value(args, "out"))
411
374
  return failure("--out cannot be empty.", 6, "usage");
@@ -522,6 +485,10 @@ async function dispatch(args, runtime) {
522
485
  return login(args, runtime);
523
486
  case "logout":
524
487
  return logout(args, runtime);
488
+ case "profiles":
489
+ return profilesResult(args);
490
+ case "use":
491
+ return useProfileResult(args, runtime.env);
525
492
  case "status":
526
493
  return status(args, runtime);
527
494
  case "doctor":
@@ -533,7 +500,7 @@ async function dispatch(args, runtime) {
533
500
  case "run":
534
501
  return run(args, runtime);
535
502
  case "connect":
536
- return connect(args, runtime);
503
+ return connect(args, runtime, withGateway);
537
504
  case "resources":
538
505
  return resources(args, runtime);
539
506
  case "prompts":
@@ -0,0 +1,5 @@
1
+ /** Every server-issued token is workspace-prefixed (`<wsId>~...`). Returns an
2
+ * empty string for environment-supplied or malformed tokens. */
3
+ export function workspaceOfToken(token) {
4
+ return token.match(/^(ws_[A-Za-z0-9][A-Za-z0-9_-]{0,124})~/)?.[1] ?? "";
5
+ }
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Keep in lockstep with bridge/package.json. The published bridge can run from
2
2
  // a compiled sidecar where package.json is not available at runtime.
3
- export const VERSION = "0.7.1";
3
+ export const VERSION = "0.8.0";
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "passport-bridge",
9
- "version": "0.7.1",
9
+ "version": "0.8.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/sdk": "1.30.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Passport CLI for governed terminal and CI agents, plus the local stdio-to-cloud MCP bridge.",
5
5
  "license": "MIT",
6
6
  "repository": {