passport-bridge 0.5.0 → 0.6.1
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/LICENSE +21 -0
- package/README.md +273 -0
- package/dist/bridge.js +53 -5
- package/dist/cli.js +30 -1
- package/dist/cliArgs.js +159 -0
- package/dist/cliClient.js +162 -0
- package/dist/cliProtocol.js +4 -0
- package/dist/completion.js +132 -0
- package/dist/credentials.js +90 -35
- package/dist/doctor.js +208 -0
- package/dist/passport.js +939 -0
- package/dist/version.js +3 -0
- package/package.json +20 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ramish Syed
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# Passport CLI and bridge
|
|
2
|
+
|
|
3
|
+
`passport-bridge` connects MCP clients to a Passport workspace without putting a long-lived token in the client configuration. The same package also installs `passport`, a polished command-line client for terminal agents, scripts, and CI.
|
|
4
|
+
|
|
5
|
+
Both binaries use the Passport gateway. Member-authenticated CLI calls share tool access, client selection, guardrails, approvals, and activity logging with native MCP clients. Non-interactive agent keys still use their assigned pass, client selection, guardrails, middleware, and audit trail, but do not raise a member's interactive approval prompt.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --global passport-bridge
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Node.js 20 or newer is required.
|
|
14
|
+
|
|
15
|
+
## Passport CLI
|
|
16
|
+
|
|
17
|
+
Sign in once, then search and run the tools your workspace permits:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
passport login --cloud https://passport.example.com --workspace ws_example
|
|
21
|
+
passport status
|
|
22
|
+
passport search "open issues"
|
|
23
|
+
passport describe github_search_issues
|
|
24
|
+
passport run github_search_issues '{"query":"SSO"}'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`passport help [command]` documents every option. `passport help` and `passport version` work without a profile or network connection.
|
|
28
|
+
|
|
29
|
+
Remote Passport servers must use HTTPS. Plain HTTP is accepted only for local
|
|
30
|
+
development on `localhost`, `127.0.0.0/8`, or `::1`. Self-hosted deployments
|
|
31
|
+
should terminate HTTPS before using interactive profiles or agent keys.
|
|
32
|
+
|
|
33
|
+
Passport CLI 0.6.1 requires gateway MCP serverInfo `passport` version 0.5.0 or
|
|
34
|
+
newer and the exact four-tool governed CLI protocol. Older servers fail clearly
|
|
35
|
+
before the CLI makes a tool call.
|
|
36
|
+
|
|
37
|
+
### Commands
|
|
38
|
+
|
|
39
|
+
| Command | Purpose |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `login` | Complete device sign-in and save a rotating CLI credential. |
|
|
42
|
+
| `logout` | Revoke the credential and remove its local profile. |
|
|
43
|
+
| `status` | Show the workspace, member, client, and visible MCP connection states. |
|
|
44
|
+
| `doctor` | Check runtime, credential-store safety, configuration, reachability, authentication, and CLI protocol compatibility. |
|
|
45
|
+
| `search [query]` | Search permitted tool definitions. An empty query lists the complete catalog. |
|
|
46
|
+
| `describe <tool>` | Print one exact definition and its full parameter schema. |
|
|
47
|
+
| `run <tool> [json]` | Run a tool through Passport governance. |
|
|
48
|
+
| `connect [app...]` | Show secure member connection links and optionally wait for completion. |
|
|
49
|
+
| `resources [uri]` | List or read MCP resources. |
|
|
50
|
+
| `prompts [name]` | List or get MCP prompts. |
|
|
51
|
+
| `completion <shell>` | Generate completion for Bash, Zsh, or Fish without a profile or network. |
|
|
52
|
+
| `help [command]` | Show general or command-specific help. |
|
|
53
|
+
| `version` | Show the package version and locally resolvable profile context. |
|
|
54
|
+
|
|
55
|
+
Every command accepts `--profile <name>`, `--json`, `--timeout <seconds>`, `--quiet`, and `--caller <id>` where applicable.
|
|
56
|
+
|
|
57
|
+
### Diagnostics
|
|
58
|
+
|
|
59
|
+
Run diagnostics before opening a support ticket or promoting a CLI release:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
passport doctor --profile cli@ws_example
|
|
63
|
+
passport doctor --profile cli@ws_example --json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`doctor` checks Node.js, the credential file's shape/ownership/mode, auth
|
|
67
|
+
configuration, HTTPS policy, `/healthz`, the authenticated MCP handshake,
|
|
68
|
+
serverInfo compatibility, and the exact four-tool CLI protocol. It never prints
|
|
69
|
+
credential values, response bodies, member identity, or all stored profile
|
|
70
|
+
names. A failed required check returns exit 1 while still emitting the complete
|
|
71
|
+
diagnostic report; configuration errors include a concrete fix.
|
|
72
|
+
|
|
73
|
+
### Shell completion
|
|
74
|
+
|
|
75
|
+
Completion is generated locally and performs no profile or network lookup:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
# Bash
|
|
79
|
+
mkdir -p ~/.local/share/bash-completion/completions
|
|
80
|
+
passport completion bash > ~/.local/share/bash-completion/completions/passport
|
|
81
|
+
|
|
82
|
+
# Zsh (ensure ~/.zfunc is in fpath before compinit)
|
|
83
|
+
mkdir -p ~/.zfunc
|
|
84
|
+
passport completion zsh > ~/.zfunc/_passport
|
|
85
|
+
|
|
86
|
+
# Fish
|
|
87
|
+
mkdir -p ~/.config/fish/completions
|
|
88
|
+
passport completion fish > ~/.config/fish/completions/passport.fish
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Tool arguments
|
|
92
|
+
|
|
93
|
+
Pass a JSON object positionally:
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
passport run github_search_issues '{"query":"SSO","limit":10}'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Read the object from stdin:
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
printf '%s' '{"query":"SSO"}' | passport run github_search_issues --args -
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or build it without shell JSON escaping:
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
passport run github_search_issues --set query=SSO --set-json limit=10
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
These forms are mutually exclusive. `--set` produces strings and `--set-json` accepts any valid JSON value.
|
|
112
|
+
|
|
113
|
+
### Approvals and connections
|
|
114
|
+
|
|
115
|
+
An approval-required call exits immediately with code 4 and its approval ID. `--wait <seconds>` retries only after a definite structured `approval_pending` response:
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
passport run github_create_issue '{"title":"Customer report"}' --wait 90
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The CLI never retries a call after a network failure or timeout because the execution outcome may be unknown.
|
|
122
|
+
|
|
123
|
+
For an MCP that needs member sign-in:
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
passport connect github --open --wait 120
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Without app names, `connect` uses one aggregate link when several visible MCPs need sign-in. Agent-key principals receive status and member guidance but cannot mint browser links.
|
|
130
|
+
|
|
131
|
+
### Resources and prompts
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
passport resources
|
|
135
|
+
passport resources passport+github://welcome
|
|
136
|
+
passport resources passport+github://image --out image.png
|
|
137
|
+
|
|
138
|
+
passport prompts
|
|
139
|
+
passport prompts github_summarize --set note=welcome
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Human mode writes text content to stdout. Binary or other non-text content requires `--out <file>` or `--json`.
|
|
143
|
+
|
|
144
|
+
## Output contract
|
|
145
|
+
|
|
146
|
+
With `--json`, stdout contains exactly one JSON value and no progress text. Hints and warnings use stderr. The success value for each command is:
|
|
147
|
+
|
|
148
|
+
| Command | JSON value |
|
|
149
|
+
| --- | --- |
|
|
150
|
+
| `login` | `{profile, endpoint, client, surface}` |
|
|
151
|
+
| `logout` | `{profile, removed, revoked}` |
|
|
152
|
+
| `status` | `{workspace, member, endpoint, auth, profile?, client, mcps}` |
|
|
153
|
+
| `doctor` | `{version,ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}` (also emitted when checks fail). |
|
|
154
|
+
| `search` | The gateway search payload, including `results` or `catalog` and `note`. |
|
|
155
|
+
| `describe` | One tool definition. |
|
|
156
|
+
| `run` | The complete governed MCP tool result, preserving every content block and upstream `structuredContent`. |
|
|
157
|
+
| `connect` | The gateway connection payload, including `connections` and optional `connectAllUrl`. |
|
|
158
|
+
| `resources` | The MCP list or read result. |
|
|
159
|
+
| `prompts` | The MCP list or get result. |
|
|
160
|
+
| `completion` | `{shell,script}`. Human mode emits the raw completion script. |
|
|
161
|
+
| `help` | `{command, help}` |
|
|
162
|
+
| `version` | `{version, endpoint?, profile?}` |
|
|
163
|
+
|
|
164
|
+
JSON errors have a stable shape:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{"error":"...","cause":"blocked","exitCode":5,"app":"github"}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
`approvalId` and `app` are included when supplied by the gateway.
|
|
171
|
+
|
|
172
|
+
| Exit | Meaning |
|
|
173
|
+
| ---: | --- |
|
|
174
|
+
| 0 | Success |
|
|
175
|
+
| 1 | Network, timeout, server, or unsupported-content error |
|
|
176
|
+
| 2 | Missing, expired, or revoked authentication |
|
|
177
|
+
| 3 | The MCP needs member sign-in |
|
|
178
|
+
| 4 | Approval is pending |
|
|
179
|
+
| 5 | Policy, guardrail, selection, or approval denial |
|
|
180
|
+
| 6 | Invalid usage or unknown tool/app |
|
|
181
|
+
|
|
182
|
+
## Profiles
|
|
183
|
+
|
|
184
|
+
Credentials are named slots in one file, `~/.passport/credentials.json`, with mode `0600`. Set `PASSPORT_HOME` to change its directory. Profile resolution is:
|
|
185
|
+
|
|
186
|
+
1. `--profile <name>`
|
|
187
|
+
2. `PASSPORT_PROFILE`
|
|
188
|
+
3. the sole stored profile
|
|
189
|
+
|
|
190
|
+
If several profiles exist, select one explicitly. The credential store is shared with `passport-bridge` and refresh exchanges are coordinated across processes.
|
|
191
|
+
|
|
192
|
+
Profile names are 1-80 letters, numbers, dots, underscores, `@` signs, or hyphens, and must start with a letter or number. Credential updates are atomically replaced at mode `0600`, including when several profiles rotate concurrently.
|
|
193
|
+
|
|
194
|
+
`logout` always removes the local slot. If Passport cannot be reached to confirm server-side revocation, it prints a warning so the user knows the remote credential could not be revoked.
|
|
195
|
+
|
|
196
|
+
Use a distinct policy identity for a particular agent while keeping the CLI protocol:
|
|
197
|
+
|
|
198
|
+
```sh
|
|
199
|
+
passport login \
|
|
200
|
+
--cloud https://passport.example.com \
|
|
201
|
+
--workspace ws_example \
|
|
202
|
+
--client claude-code \
|
|
203
|
+
--profile claude-code@ws_example
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The credential surface remains `cli`; `claude-code` is the separate client identity used for policy, selection, devices, and activity attribution.
|
|
207
|
+
|
|
208
|
+
## Caller attribution
|
|
209
|
+
|
|
210
|
+
`--caller <id>` adds cooperative activity detail for the agent behind the CLI call. Values use lowercase letters, numbers, and hyphens, up to 24 characters. The CLI otherwise detects Claude Code, Codex, OpenCode, Cursor, or Gemini CLI from their environment markers.
|
|
211
|
+
|
|
212
|
+
Caller attribution is self-reported, not an attested identity. The gateway only accepts it from a CLI-surface credential or a CLI agent-key request.
|
|
213
|
+
|
|
214
|
+
## Headless and CI authentication
|
|
215
|
+
|
|
216
|
+
Supply an existing Passport agent key from the job's secret manager:
|
|
217
|
+
|
|
218
|
+
```sh
|
|
219
|
+
export PASSPORT_ENDPOINT=https://passport.example.com/mcp
|
|
220
|
+
export PASSPORT_AGENT_KEY="$CI_PASSPORT_AGENT_KEY"
|
|
221
|
+
passport search "deployment status" --json
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Environment authentication wins over stored profiles, persists nothing, and sends the agent key directly to the gateway. Do not combine it with `--profile`. `PASSPORT_PROFILE` is only for stored interactive credentials.
|
|
225
|
+
|
|
226
|
+
Agent keys are deliberately non-interactive. Their assigned pass, app selection,
|
|
227
|
+
guardrails, middleware, and audit trail still apply, but action-time member
|
|
228
|
+
approval prompts do not. Use a member profile for work that must pause for a
|
|
229
|
+
human's one-off approval.
|
|
230
|
+
|
|
231
|
+
## Package verification and updates
|
|
232
|
+
|
|
233
|
+
Maintainers can build the exact npm tarball, validate its required files, and
|
|
234
|
+
write a SHA-256 sidecar without registry credentials:
|
|
235
|
+
|
|
236
|
+
```sh
|
|
237
|
+
npm run pack:verified
|
|
238
|
+
sha256sum -c passport-bridge-<version>.tgz.sha256
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The command also reports npm's SHA-1 shasum and SHA-512 integrity value for
|
|
242
|
+
release notes or an external artifact manifest. The package declares public
|
|
243
|
+
access and points support/source inquiries at Passport's public release repo.
|
|
244
|
+
|
|
245
|
+
The CLI deliberately performs no background registry request, telemetry, or
|
|
246
|
+
automatic self-update. Check explicitly with `npm view passport-bridge version`
|
|
247
|
+
and upgrade with `npm install --global passport-bridge@latest`. npm provenance
|
|
248
|
+
attestation is intentionally deferred until publication moves to a trusted
|
|
249
|
+
OIDC publisher; local/manual publishing cannot produce a trustworthy
|
|
250
|
+
attestation. Platform signing is not applicable to these JavaScript npm bins.
|
|
251
|
+
|
|
252
|
+
## MCP stdio bridge
|
|
253
|
+
|
|
254
|
+
Create a bridge profile:
|
|
255
|
+
|
|
256
|
+
```sh
|
|
257
|
+
passport-bridge login \
|
|
258
|
+
--cloud https://passport.example.com \
|
|
259
|
+
--workspace ws_example \
|
|
260
|
+
--client cursor \
|
|
261
|
+
--profile cursor@ws_example
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Configure the MCP client to launch:
|
|
265
|
+
|
|
266
|
+
```sh
|
|
267
|
+
passport-bridge serve --profile cursor@ws_example
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
The bridge exchanges its file-backed refresh credential for short-lived access tokens, persists rotations, coordinates concurrent processes, and forwards tools, resources, prompts, cancellation, progress, and tool-list changes over stdio. `passport-bridge status` checks stored bridge profiles, and `passport-bridge logout --profile <name>` revokes one.
|
|
271
|
+
|
|
272
|
+
Run `passport-bridge --help` for the complete bridge command surface or
|
|
273
|
+
`passport-bridge --version` to print the installed package version.
|
package/dist/bridge.js
CHANGED
|
@@ -5,9 +5,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
5
5
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
6
6
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
7
7
|
import { ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListResourceTemplatesRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
-
|
|
9
|
-
// and self-contained, so it can't read package.json at runtime to learn this.
|
|
10
|
-
const VERSION = "0.5.0";
|
|
8
|
+
import { VERSION } from "./version.js";
|
|
11
9
|
/** Everything but the MCP protocol goes to stderr — stdout is the transport. */
|
|
12
10
|
export function log(...args) {
|
|
13
11
|
process.stderr.write(`[passport-bridge] ${args.join(" ")}\n`);
|
|
@@ -20,6 +18,22 @@ function safeHostname() {
|
|
|
20
18
|
return "unknown";
|
|
21
19
|
}
|
|
22
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The workspace a Passport token belongs to. Every token the server mints is
|
|
23
|
+
* workspace-prefixed (`<wsId>~...`, see server store.mintToken), so the tenant
|
|
24
|
+
* is recoverable from the string itself. Returns "" for an env-supplied or
|
|
25
|
+
* malformed token with no recognizable prefix.
|
|
26
|
+
*/
|
|
27
|
+
export function workspaceOfToken(token) {
|
|
28
|
+
return token.match(/^(ws_[A-Za-z0-9]+)~/)?.[1] ?? "";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Shown to the AI client (and logged) when the bridge refuses to switch tenants:
|
|
32
|
+
* the on-disk credential now belongs to a DIFFERENT workspace than this process
|
|
33
|
+
* started serving. We fail closed rather than silently attribute activity to the
|
|
34
|
+
* wrong workspace.
|
|
35
|
+
*/
|
|
36
|
+
export const TENANT_FLIP_MESSAGE = "This machine's Passport credential now belongs to a different workspace. Reconnect this client from the Passport app.";
|
|
23
37
|
/**
|
|
24
38
|
* Holds the long-lived refresh token and mints short-lived access tokens
|
|
25
39
|
* from the cloud, transparently refreshing on expiry or a 401.
|
|
@@ -28,11 +42,18 @@ export class TokenManager {
|
|
|
28
42
|
endpoint;
|
|
29
43
|
onRotate;
|
|
30
44
|
coordinate;
|
|
45
|
+
requestTimeoutMs;
|
|
46
|
+
requestSignal;
|
|
31
47
|
origin;
|
|
32
48
|
refreshToken;
|
|
33
49
|
access;
|
|
34
50
|
expiresAt = 0;
|
|
35
51
|
inflight;
|
|
52
|
+
/** The workspace this process started serving, read from its initial refresh
|
|
53
|
+
* token. The tenant-flip guard refuses to adopt an on-disk credential whose
|
|
54
|
+
* workspace differs from this. */
|
|
55
|
+
homeWorkspace;
|
|
56
|
+
tenantFlipLogged = false;
|
|
36
57
|
/**
|
|
37
58
|
* @param onRotate persist a rotated refresh token. When provided, the bridge
|
|
38
59
|
* opts into single-use refresh-token rotation; without it (e.g. an env-only
|
|
@@ -43,12 +64,15 @@ export class TokenManager {
|
|
|
43
64
|
* them, a sibling process's rotation makes our in-memory token a replay —
|
|
44
65
|
* which the server treats as theft and answers by revoking the family.
|
|
45
66
|
*/
|
|
46
|
-
constructor(endpoint, refreshToken, onRotate, coordinate) {
|
|
67
|
+
constructor(endpoint, refreshToken, onRotate, coordinate, requestTimeoutMs, requestSignal) {
|
|
47
68
|
this.endpoint = endpoint;
|
|
48
69
|
this.onRotate = onRotate;
|
|
49
70
|
this.coordinate = coordinate;
|
|
71
|
+
this.requestTimeoutMs = requestTimeoutMs;
|
|
72
|
+
this.requestSignal = requestSignal;
|
|
50
73
|
this.origin = new URL(endpoint).origin;
|
|
51
74
|
this.refreshToken = refreshToken;
|
|
75
|
+
this.homeWorkspace = workspaceOfToken(refreshToken);
|
|
52
76
|
}
|
|
53
77
|
async accessToken(force = false) {
|
|
54
78
|
if (!force && this.access && Date.now() < this.expiresAt - 60_000)
|
|
@@ -73,11 +97,32 @@ export class TokenManager {
|
|
|
73
97
|
// Adopt a sibling's rotation before burning anything: the on-disk token is
|
|
74
98
|
// the live one; ours may already be a would-be replay.
|
|
75
99
|
const disk = this.coordinate?.reload();
|
|
76
|
-
if (disk && disk !== this.refreshToken)
|
|
100
|
+
if (disk && disk !== this.refreshToken) {
|
|
101
|
+
const diskWorkspace = workspaceOfToken(disk);
|
|
102
|
+
// TENANT-FLIP GUARD (defense in depth — per-workspace slots make this
|
|
103
|
+
// rare). The on-disk credential in this slot now belongs to a DIFFERENT
|
|
104
|
+
// workspace than the one this process started serving. Refuse to adopt
|
|
105
|
+
// it: never silently switch tenants mid-session. We keep serving on the
|
|
106
|
+
// current cached access token until it expires; this exchange fails
|
|
107
|
+
// closed with an MCP-visible error rather than routing to the wrong
|
|
108
|
+
// workspace. Log once to stderr.
|
|
109
|
+
if (diskWorkspace && this.homeWorkspace && diskWorkspace !== this.homeWorkspace) {
|
|
110
|
+
if (!this.tenantFlipLogged) {
|
|
111
|
+
this.tenantFlipLogged = true;
|
|
112
|
+
log(`refusing to adopt an on-disk credential for ${diskWorkspace}; this bridge serves ${this.homeWorkspace}.`, "Reconnect this client from the Passport app.");
|
|
113
|
+
}
|
|
114
|
+
throw new Error(TENANT_FLIP_MESSAGE);
|
|
115
|
+
}
|
|
77
116
|
this.refreshToken = disk;
|
|
117
|
+
}
|
|
118
|
+
const exchangeSignals = [
|
|
119
|
+
...(this.requestSignal ? [this.requestSignal] : []),
|
|
120
|
+
...(this.requestTimeoutMs ? [AbortSignal.timeout(this.requestTimeoutMs)] : [])
|
|
121
|
+
];
|
|
78
122
|
const res = await fetch(`${this.origin}/api/token`, {
|
|
79
123
|
method: "POST",
|
|
80
124
|
headers: { "content-type": "application/json" },
|
|
125
|
+
...(exchangeSignals.length ? { signal: exchangeSignals.length === 1 ? exchangeSignals[0] : AbortSignal.any(exchangeSignals) } : {}),
|
|
81
126
|
// Report host + version so the device shows up in the admin inventory.
|
|
82
127
|
// rotate:false when we can't persist the new credential.
|
|
83
128
|
body: JSON.stringify({ refreshToken: this.refreshToken, host: safeHostname(), version: VERSION, rotate: Boolean(this.onRotate) })
|
|
@@ -103,6 +148,9 @@ export class TokenManager {
|
|
|
103
148
|
const apply = (token) => {
|
|
104
149
|
const headers = new Headers(init?.headers);
|
|
105
150
|
headers.set("authorization", `Bearer ${token}`);
|
|
151
|
+
// The SDK owns per-MCP-request deadlines via init.signal. The constructor
|
|
152
|
+
// timeout only bounds refresh exchange; applying it here would truncate an
|
|
153
|
+
// explicit `passport connect --wait 120` request at the default 30s.
|
|
106
154
|
return { ...init, headers };
|
|
107
155
|
};
|
|
108
156
|
let res = await fetch(input, apply(await this.accessToken()));
|
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { getProfile, writeProfile, removeProfile, readCreds, credsPath, withProfileLock } from "./credentials.js";
|
|
4
4
|
import { TokenManager, runBridge, log } from "./bridge.js";
|
|
5
|
+
import { VERSION } from "./version.js";
|
|
5
6
|
/**
|
|
6
7
|
* passport-bridge — the local tier.
|
|
7
8
|
*
|
|
@@ -20,6 +21,10 @@ function arg(flag, fallback = "") {
|
|
|
20
21
|
}
|
|
21
22
|
async function main() {
|
|
22
23
|
const command = process.argv[2] ?? "serve";
|
|
24
|
+
if (process.argv.includes("--help") || process.argv.includes("-h") || command === "help")
|
|
25
|
+
return help();
|
|
26
|
+
if (command === "--version" || command === "-V" || command === "version")
|
|
27
|
+
return version();
|
|
23
28
|
if (command === "serve")
|
|
24
29
|
return serve();
|
|
25
30
|
if (command === "login")
|
|
@@ -28,9 +33,33 @@ async function main() {
|
|
|
28
33
|
return logout();
|
|
29
34
|
if (command === "status")
|
|
30
35
|
return status();
|
|
31
|
-
process.stderr.write(`Unknown command: ${command}\
|
|
36
|
+
process.stderr.write(`Unknown command: ${command}\nRun \`passport-bridge --help\` for usage.\n`);
|
|
32
37
|
process.exit(1);
|
|
33
38
|
}
|
|
39
|
+
function help() {
|
|
40
|
+
process.stdout.write(`Passport bridge ${VERSION}
|
|
41
|
+
|
|
42
|
+
Usage: passport-bridge [command] [options]
|
|
43
|
+
|
|
44
|
+
Commands:
|
|
45
|
+
serve Connect an MCP client using a saved profile (default)
|
|
46
|
+
login Sign in and save a rotating bridge credential
|
|
47
|
+
status Check saved bridge profiles
|
|
48
|
+
logout Revoke and remove a saved profile
|
|
49
|
+
|
|
50
|
+
Options:
|
|
51
|
+
--profile <name> Use a named profile (default: default)
|
|
52
|
+
--cloud <url> Passport URL for login
|
|
53
|
+
--workspace <id> Workspace for login
|
|
54
|
+
--client <name> AI client identity for login
|
|
55
|
+
--target <target> Credential target for login
|
|
56
|
+
-h, --help Show this help
|
|
57
|
+
-V, --version Show the package version
|
|
58
|
+
`);
|
|
59
|
+
}
|
|
60
|
+
function version() {
|
|
61
|
+
process.stdout.write(`${VERSION}\n`);
|
|
62
|
+
}
|
|
34
63
|
async function serve() {
|
|
35
64
|
const profile = arg("--profile", "default");
|
|
36
65
|
let endpoint = process.env.PASSPORT_ENDPOINT ?? "";
|
package/dist/cliArgs.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
export const COMMANDS = [
|
|
2
|
+
"login",
|
|
3
|
+
"logout",
|
|
4
|
+
"status",
|
|
5
|
+
"doctor",
|
|
6
|
+
"search",
|
|
7
|
+
"describe",
|
|
8
|
+
"run",
|
|
9
|
+
"connect",
|
|
10
|
+
"resources",
|
|
11
|
+
"prompts",
|
|
12
|
+
"completion",
|
|
13
|
+
"help",
|
|
14
|
+
"version"
|
|
15
|
+
];
|
|
16
|
+
const FLAGS = {
|
|
17
|
+
profile: { kind: "value" },
|
|
18
|
+
json: { kind: "boolean" },
|
|
19
|
+
timeout: { kind: "value" },
|
|
20
|
+
quiet: { kind: "boolean" },
|
|
21
|
+
caller: { kind: "value" },
|
|
22
|
+
help: { kind: "boolean" },
|
|
23
|
+
cloud: { kind: "value", commands: ["login"] },
|
|
24
|
+
workspace: { kind: "value", commands: ["login"] },
|
|
25
|
+
client: { kind: "value", commands: ["login"] },
|
|
26
|
+
app: { kind: "value", commands: ["search"] },
|
|
27
|
+
args: { kind: "value", commands: ["run"] },
|
|
28
|
+
set: { kind: "repeat", commands: ["run", "prompts"] },
|
|
29
|
+
"set-json": { kind: "repeat", commands: ["run"] },
|
|
30
|
+
wait: { kind: "value", commands: ["run", "connect"] },
|
|
31
|
+
alias: { kind: "value", commands: ["connect"] },
|
|
32
|
+
open: { kind: "boolean", commands: ["connect"] },
|
|
33
|
+
out: { kind: "value", commands: ["resources", "prompts"] }
|
|
34
|
+
};
|
|
35
|
+
export class ArgError extends Error {
|
|
36
|
+
}
|
|
37
|
+
function knownCommand(value) {
|
|
38
|
+
return COMMANDS.includes(value);
|
|
39
|
+
}
|
|
40
|
+
function flagParts(raw) {
|
|
41
|
+
const body = raw.slice(2);
|
|
42
|
+
const equals = body.indexOf("=");
|
|
43
|
+
return equals < 0 ? { name: body } : { name: body.slice(0, equals), inline: body.slice(equals + 1) };
|
|
44
|
+
}
|
|
45
|
+
/** Parse without dependencies. Long options can appear before or after the verb. */
|
|
46
|
+
export function parseArgs(argv) {
|
|
47
|
+
let command;
|
|
48
|
+
const positionals = [];
|
|
49
|
+
const values = {};
|
|
50
|
+
const repeats = {};
|
|
51
|
+
const booleans = new Set();
|
|
52
|
+
let positionalOnly = false;
|
|
53
|
+
for (let i = 0; i < argv.length; i++) {
|
|
54
|
+
let raw = argv[i];
|
|
55
|
+
if (!positionalOnly && raw === "--") {
|
|
56
|
+
positionalOnly = true;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (!positionalOnly && (raw === "-h" || raw === "-V")) {
|
|
60
|
+
raw = raw === "-h" ? "--help" : "--version";
|
|
61
|
+
}
|
|
62
|
+
if (!positionalOnly && raw.startsWith("--")) {
|
|
63
|
+
if (raw === "--version") {
|
|
64
|
+
if (command)
|
|
65
|
+
throw new ArgError("--version must be used without another command.");
|
|
66
|
+
command = "version";
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const { name, inline } = flagParts(raw);
|
|
70
|
+
const spec = FLAGS[name];
|
|
71
|
+
if (!spec)
|
|
72
|
+
throw new ArgError(`Unknown option: --${name}`);
|
|
73
|
+
if (spec.kind === "boolean") {
|
|
74
|
+
if (inline !== undefined)
|
|
75
|
+
throw new ArgError(`--${name} does not take a value.`);
|
|
76
|
+
if (booleans.has(name))
|
|
77
|
+
throw new ArgError(`--${name} may only be passed once.`);
|
|
78
|
+
booleans.add(name);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const value = inline !== undefined ? inline : argv[++i];
|
|
82
|
+
if (value === undefined)
|
|
83
|
+
throw new ArgError(`--${name} requires a value.`);
|
|
84
|
+
if (spec.kind === "repeat") {
|
|
85
|
+
(repeats[name] ??= []).push(value);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (Object.hasOwn(values, name))
|
|
89
|
+
throw new ArgError(`--${name} may only be passed once.`);
|
|
90
|
+
values[name] = value;
|
|
91
|
+
}
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (!positionalOnly && raw.startsWith("-") && raw !== "-")
|
|
95
|
+
throw new ArgError(`Unknown option: ${raw}`);
|
|
96
|
+
if (!command) {
|
|
97
|
+
if (!knownCommand(raw))
|
|
98
|
+
throw new ArgError(`Unknown command: ${raw}`);
|
|
99
|
+
command = raw;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
positionals.push(raw);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
command ??= "help";
|
|
106
|
+
if (booleans.has("help") && command !== "help") {
|
|
107
|
+
positionals.splice(0, positionals.length, command);
|
|
108
|
+
command = "help";
|
|
109
|
+
booleans.delete("help");
|
|
110
|
+
}
|
|
111
|
+
for (const name of [...Object.keys(values), ...Object.keys(repeats), ...booleans]) {
|
|
112
|
+
const allowed = FLAGS[name]?.commands;
|
|
113
|
+
if (allowed && !allowed.includes(command))
|
|
114
|
+
throw new ArgError(`--${name} is not valid with ${command}.`);
|
|
115
|
+
}
|
|
116
|
+
validateShape(command, positionals);
|
|
117
|
+
validateNumbers(values);
|
|
118
|
+
return { command, positionals, values, repeats, booleans };
|
|
119
|
+
}
|
|
120
|
+
function validateShape(command, positionals) {
|
|
121
|
+
const max = {
|
|
122
|
+
login: 0,
|
|
123
|
+
logout: 0,
|
|
124
|
+
status: 0,
|
|
125
|
+
doctor: 0,
|
|
126
|
+
describe: 1,
|
|
127
|
+
run: 2,
|
|
128
|
+
resources: 1,
|
|
129
|
+
prompts: 1,
|
|
130
|
+
completion: 1,
|
|
131
|
+
help: 1,
|
|
132
|
+
version: 0
|
|
133
|
+
};
|
|
134
|
+
const minimum = { describe: 1, run: 1, completion: 1 };
|
|
135
|
+
if (positionals.length < (minimum[command] ?? 0)) {
|
|
136
|
+
throw new ArgError(`${command} requires ${command === "run" ? "a tool name" : command === "completion" ? "bash, zsh, or fish" : "a name"}.`);
|
|
137
|
+
}
|
|
138
|
+
const cap = max[command];
|
|
139
|
+
if (cap !== undefined && positionals.length > cap)
|
|
140
|
+
throw new ArgError(`Too many arguments for ${command}.`);
|
|
141
|
+
}
|
|
142
|
+
function validateNumbers(values) {
|
|
143
|
+
for (const name of ["timeout", "wait"]) {
|
|
144
|
+
if (!Object.hasOwn(values, name))
|
|
145
|
+
continue;
|
|
146
|
+
const parsed = Number(values[name]);
|
|
147
|
+
if (!Number.isFinite(parsed) || parsed <= 0)
|
|
148
|
+
throw new ArgError(`--${name} must be a positive number of seconds.`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export function bool(args, name) {
|
|
152
|
+
return args.booleans.has(name);
|
|
153
|
+
}
|
|
154
|
+
export function value(args, name) {
|
|
155
|
+
return args.values[name];
|
|
156
|
+
}
|
|
157
|
+
export function repeated(args, name) {
|
|
158
|
+
return args.repeats[name] ?? [];
|
|
159
|
+
}
|