passcontrol 0.1.1 → 0.2.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 +42 -141
- package/bin/passcontrol.mjs +123 -16
- package/cli/mcp/README.md +54 -0
- package/cli/mcp/gateway.mjs +158 -0
- package/cli/mcp/integration.mjs +96 -0
- package/cli/mcp/server.mjs +114 -0
- package/cli/sidecar.mjs +11 -44
- package/cli/visa-client.mjs +74 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# PassControl
|
|
2
2
|
|
|
3
|
-
**An identity & credential gateway for AI agents.** Stop pasting your OpenAI
|
|
4
|
-
|
|
3
|
+
**An identity & credential gateway for AI agents.** Stop pasting your OpenAI/Anthropic keys
|
|
4
|
+
into agent runtimes. Give each agent a cryptographic **passport**; it signs a challenge to
|
|
5
5
|
mint a short-lived **work-visa**; the gateway injects your *real* provider key from a vault
|
|
6
6
|
and proxies the call — so the agent never holds the key. You get per-agent budgets, scopes,
|
|
7
7
|
an instant kill switch, and a per-agent audit trail.
|
|
@@ -14,42 +14,8 @@ self-host it, or use the managed version when it's available.
|
|
|
14
14
|
> first, and see [Security](#security) for responsible disclosure. We'd rather you know than
|
|
15
15
|
> find out.
|
|
16
16
|
|
|
17
|
-
**New here? Start with the [Getting Started tutorial](./TUTORIAL.md)** — clone to a real
|
|
18
|
-
governed agent in ~15 minutes.
|
|
19
|
-
|
|
20
17
|
---
|
|
21
18
|
|
|
22
|
-
## The `passcontrol` CLI
|
|
23
|
-
|
|
24
|
-
PassControl pairs the browser-based **Control Tower** (where you add a provider key and issue a
|
|
25
|
-
passport) with a terminal **CLI** (where you configure agents, make governed calls, run a
|
|
26
|
-
sidecar, inspect spend/logs, and control a fleet).
|
|
27
|
-
|
|
28
|
-
## Install
|
|
29
|
-
|
|
30
|
-
**Fastest — install the CLI globally:**
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npm install -g passcontrol
|
|
34
|
-
passcontrol setup # offers to fetch the local stack, then boots it and opens the dashboard
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
The published package is just the CLI (a few files, no provider keys). `passcontrol setup`
|
|
38
|
-
detects it's installed globally and offers to clone the self-hostable stack (Supabase + Redis +
|
|
39
|
-
dashboard) into `~/passcontrol`, install its dependencies, and start it — so a single command
|
|
40
|
-
takes you from nothing to a running Control Tower. Override the location with `--app-dir <path>`
|
|
41
|
-
or the `PASSCONTROL_APP_ROOT` environment variable, and pass `--yes` for non-interactive setups.
|
|
42
|
-
|
|
43
|
-
**From a source checkout** (if you'd rather clone yourself), run the CLI with `npm run cli -- <command>`.
|
|
44
|
-
The short `passcontrol <command>` form also works inside a clone after `npm link`:
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
git clone https://github.com/Vertias3u/PassControl.git
|
|
48
|
-
cd PassControl && npm install
|
|
49
|
-
npm run cli -- --help # every command
|
|
50
|
-
npm run cli -- setup # boots the local stack from this checkout
|
|
51
|
-
```
|
|
52
|
-
|
|
53
19
|
## Why
|
|
54
20
|
A raw provider key handed to an autonomous agent leaks (logs, repos, prompts), never rotates,
|
|
55
21
|
has no per-agent spend cap, no off-switch, and no record of *which* agent did *what*.
|
|
@@ -60,27 +26,23 @@ PassControl removes the key from the agent entirely and puts a governed gateway
|
|
|
60
26
|
2. **Work-visa** — the agent signs a challenge (timestamp + single-use nonce) → mints a
|
|
61
27
|
short-lived (5 min) HS256 token carrying its identity, scope, and budget.
|
|
62
28
|
3. **Inject & proxy** — a request arrives with a visa; the gateway verifies it → checks the
|
|
63
|
-
kill switch → checks scope
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
switch (platform / tenant / per-agent), and an append-only audit log of every call.
|
|
29
|
+
kill switch → checks scope → reserves budget → pulls your provider key from Supabase Vault
|
|
30
|
+
→ injects it → forwards to the provider and streams back. The agent never sees the key.
|
|
31
|
+
4. **Govern** — per-agent token/cost budgets (enforced), layered kill switch
|
|
32
|
+
(platform / tenant / per-agent), and an append-only audit log of every call.
|
|
68
33
|
|
|
69
34
|
## Features
|
|
70
35
|
- 🔑 Agents never hold your provider key (BYOK; key stays in the vault, injected in-flight)
|
|
71
36
|
- 🪪 Per-agent cryptographic identity (Ed25519), short-lived revocable visas
|
|
72
|
-
- 💸 Enforced per-agent
|
|
73
|
-
-
|
|
74
|
-
chat-scoped agent can't reach files, fine-tuning, batches, responses, embeddings, etc.
|
|
75
|
-
with your key
|
|
76
|
-
- ⛔ Layered, per-tenant kill switch + per-agent suspend — revoke a running agent mid-task
|
|
37
|
+
- 💸 Enforced per-agent token/cost budgets (reserved pre-flight, reconciled after)
|
|
38
|
+
- ⛔ Layered, per-tenant kill switch + per-agent suspend
|
|
77
39
|
- 📒 Per-agent / per-passport audit trail (append-only; direct `UPDATE` / `DELETE` /
|
|
78
40
|
`TRUNCATE` rejected by the database)
|
|
79
|
-
- 🧰 Drop-in
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
41
|
+
- 🧰 Drop-in: point your existing OpenAI/Anthropic/OpenAI-compatible SDK at the gateway
|
|
42
|
+
(OpenAI, Anthropic, Groq, Mistral, Together, DeepSeek)
|
|
43
|
+
- 🔌 MCP server: expose governed `chat` / `list_models` tools to Claude Desktop, Cursor &
|
|
44
|
+
Claude Code — same scope, budget, and kill switch (`passcontrol mcp`)
|
|
45
|
+
- 🖥️ Control Tower dashboard + a developer control-plane API + TOTP MFA
|
|
84
46
|
|
|
85
47
|
## Quickstart (self-host)
|
|
86
48
|
Stack: **Next.js** (App Router, edge routes) · **Supabase** (Postgres + Vault + Auth) ·
|
|
@@ -90,24 +52,18 @@ services are required — the kill switch is Redis-backed.
|
|
|
90
52
|
### Local (Docker) quickstart
|
|
91
53
|
For the fastest local run, use the bundled Docker stack. It starts Supabase locally
|
|
92
54
|
(Postgres + Vault + Auth), Redis-over-REST, applies migrations inside the DB container, and
|
|
93
|
-
seeds a confirmed dev user. Prereqs: Docker Desktop
|
|
94
|
-
|
|
55
|
+
seeds a confirmed dev user. Prereqs: Docker Desktop and the Supabase CLI. No host `psql`
|
|
56
|
+
is required.
|
|
95
57
|
|
|
96
58
|
```bash
|
|
97
|
-
git clone https://github.com
|
|
59
|
+
git clone https://github.com/<you>/passcontrol && cd passcontrol
|
|
98
60
|
npm install
|
|
99
|
-
npm run
|
|
61
|
+
npm run dev:stack # starts Supabase + Redis locally, migrates, seeds a dev user
|
|
62
|
+
npm run dev:docker # runs the app against the local stack (loads .env.docker)
|
|
100
63
|
```
|
|
101
64
|
|
|
102
|
-
Use
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
```bash
|
|
106
|
-
npm run cli -- setup --no-open --port-offset 100
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
This offsets the local Supabase and Redis-over-REST ports together (for example, API `54421`
|
|
110
|
-
and database `54422`). The dashboard still uses the configured gateway port, which defaults to 3000.
|
|
65
|
+
> Use **`npm run dev:docker`**, not `npm run dev`, for the local stack — plain `npm run
|
|
66
|
+
> dev` loads `.env.local` (your hosted Supabase), not the Docker stack's `.env.docker`.
|
|
111
67
|
|
|
112
68
|
Open `http://localhost:3000` and log in with:
|
|
113
69
|
|
|
@@ -116,36 +72,13 @@ dev@passcontrol.local
|
|
|
116
72
|
passcontrol-dev
|
|
117
73
|
```
|
|
118
74
|
|
|
119
|
-
|
|
120
|
-
> `scripts/seed.mjs`. It is a convenience for local development — **never deploy it or reuse
|
|
121
|
-
> these credentials** in a hosted/production instance. Real deployments create accounts
|
|
122
|
-
> through normal signup (gated by `INVITE_CODE`); no default credentials ship.
|
|
123
|
-
|
|
124
|
-
Then add a **non-critical** provider key in the Control Tower, issue a passport, and copy the
|
|
125
|
-
one-time `PASSPORT_ID` / `PASSPORT_SECRET` values. In the second terminal, run:
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
npm run cli -- init # gateway + passport + provider/model → .passcontrol
|
|
129
|
-
npm run cli -- doctor --deep # verifies the configuration and mints a visa
|
|
130
|
-
npm run cli -- call "Say hello in 3 words"
|
|
131
|
-
npm run cli -- spend # confirms governed spend
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
You should see a streamed response in the terminal and an `ok` row in the dashboard Audit Log.
|
|
135
|
-
That is the complete governed loop: passport → visa → vault key injection → proxied call → audit.
|
|
136
|
-
|
|
137
|
-
To expose the short form locally, run this once from the repository root:
|
|
75
|
+
Then add a provider key in the Control Tower, issue a passport, and run:
|
|
138
76
|
|
|
139
77
|
```bash
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
passcontrol status
|
|
78
|
+
PASSPORT_ID=<passport_id> PASSPORT_SECRET=<passport_secret> \
|
|
79
|
+
node examples/chat-agent.mjs "Say hello in 3 words"
|
|
143
80
|
```
|
|
144
81
|
|
|
145
|
-
Use `passcontrol start`, `passcontrol stop`, and `passcontrol restart` to manage only a dashboard
|
|
146
|
-
process started by the CLI. Use `passcontrol local-logs --follow` for its output.
|
|
147
|
-
`passcontrol reset --local --confirm RESET` destroys and recreates local data—use it only for a clean slate.
|
|
148
|
-
|
|
149
82
|
The final agent call uses your real Anthropic/OpenAI key from the local Vault, so start
|
|
150
83
|
with a non-critical key.
|
|
151
84
|
|
|
@@ -156,7 +89,7 @@ with a non-critical key.
|
|
|
156
89
|
> Supabase stack), not a plain Postgres database.
|
|
157
90
|
|
|
158
91
|
```bash
|
|
159
|
-
git clone https://github.com
|
|
92
|
+
git clone https://github.com/<you>/passcontrol && cd passcontrol
|
|
160
93
|
npm install
|
|
161
94
|
cp .env.example .env.local # fill in Supabase / Upstash / secrets
|
|
162
95
|
DATABASE_URL='postgresql://…' npm run migrate # applies db/migrations/*.sql in order, once each
|
|
@@ -172,32 +105,6 @@ drift and flushes last-seen. On Vercel it's wired via `vercel.json`. Self-hostin
|
|
|
172
105
|
yourself (system `cron`, a GitHub Action, etc.) every few minutes — it's a correction layer,
|
|
173
106
|
not the hot path, so an occasional missed run is harmless.
|
|
174
107
|
|
|
175
|
-
## CLI command center
|
|
176
|
-
|
|
177
|
-
The CLI is the terminal operator interface. `npm run cli -- …` works from a clone; replace it
|
|
178
|
-
with `passcontrol …` after `npm link`.
|
|
179
|
-
|
|
180
|
-
| Need | Command |
|
|
181
|
-
|---|---|
|
|
182
|
-
| See config, gateway status, and suggested next steps | `npm run cli -- status` |
|
|
183
|
-
| Check local setup / mint a test visa | `npm run cli -- doctor --deep` |
|
|
184
|
-
| Make a governed model call | `npm run cli -- call "Summarize this"` |
|
|
185
|
-
| Start a bridge for an existing agent | `npm run cli -- sidecar` |
|
|
186
|
-
| Print settings for OpenHands, Aider, Cline, Continue, or LiteLLM | `npm run cli -- env openhands` |
|
|
187
|
-
| List or create agents | `npm run cli -- agent list` · `npm run cli -- agent create billing-bot` |
|
|
188
|
-
| Suspend, resume, or revoke an agent | `npm run cli -- agent suspend <id>` |
|
|
189
|
-
| Inspect spend, logs, and audit history | `npm run cli -- spend` · `npm run cli -- logs` · `npm run cli -- audit` |
|
|
190
|
-
| Arm or release the tenant kill switch | `npm run cli -- kill on` · `npm run cli -- kill off` |
|
|
191
|
-
| Open the Control Tower | `npm run cli -- open` |
|
|
192
|
-
| Prepare or repair local services | `npm run cli -- setup` · `npm run cli -- doctor --fix` |
|
|
193
|
-
| Manage the local dashboard | `npm run cli -- start` · `npm run cli -- stop` · `npm run cli -- restart` |
|
|
194
|
-
| Follow local dashboard logs | `npm run cli -- local-logs --follow` |
|
|
195
|
-
| Preview/write an Aider config | `npm run cli -- configure aider` · `npm run cli -- configure aider --write` |
|
|
196
|
-
|
|
197
|
-
The CLI reads environment variables first, then a project-local `.passcontrol`, then
|
|
198
|
-
`~/.config/passcontrol/config`. `.passcontrol` contains a passport secret, is gitignored, and
|
|
199
|
-
is written with owner-only permissions—never commit or share it.
|
|
200
|
-
|
|
201
108
|
## Using it from an agent
|
|
202
109
|
The client SDK hides the visa dance — point your provider SDK at the gateway:
|
|
203
110
|
|
|
@@ -212,22 +119,6 @@ const openai = new OpenAI(pc.clientOptions("openai")); // baseURL + auth wired;
|
|
|
212
119
|
The SDK is vendored in this repo under `./sdk`; it is not a separately published npm package
|
|
213
120
|
yet.
|
|
214
121
|
|
|
215
|
-
**Using an agent you don't control (OpenHands, Aider, Cline, Continue…)?** They expect a
|
|
216
|
-
static API key, but a visa expires in minutes. Run the **visa sidecar** — a local proxy that
|
|
217
|
-
mints/refreshes the visa for you — and point the agent at it like any other endpoint:
|
|
218
|
-
|
|
219
|
-
```bash
|
|
220
|
-
npm run cli -- sidecar # http://127.0.0.1:8788
|
|
221
|
-
npm run cli -- env openhands
|
|
222
|
-
# then set the agent's base URL to http://127.0.0.1:8788/api/v1/anthropic (or /openai),
|
|
223
|
-
# API key = anything. The agent never holds a real key or a long-lived token.
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
Presets are available for `openhands`, `aider`, `cline`, `continue`, and `litellm`.
|
|
227
|
-
If a client defaults to OpenAI `/responses` (notably Continue for some o-series/gpt-5
|
|
228
|
-
configs), disable that mode and force `/chat/completions`; PassControl intentionally proxies
|
|
229
|
-
only chat/messages and model-listing endpoints.
|
|
230
|
-
|
|
231
122
|
Manage the fleet programmatically with the control-plane SDK + API key:
|
|
232
123
|
|
|
233
124
|
```ts
|
|
@@ -237,18 +128,28 @@ await cp.agents.list();
|
|
|
237
128
|
await cp.killSwitch.set(true);
|
|
238
129
|
```
|
|
239
130
|
|
|
240
|
-
|
|
131
|
+
Full API reference: [`openapi.yaml`](./openapi.yaml) and [`DOCUMENTATION.md`](./DOCUMENTATION.md).
|
|
132
|
+
Runnable example agents in [`examples/`](./examples).
|
|
133
|
+
|
|
134
|
+
## Use it from Claude Desktop, Cursor, or Claude Code (MCP)
|
|
135
|
+
`passcontrol mcp` runs a local [MCP](https://modelcontextprotocol.io) server that exposes two
|
|
136
|
+
tools — `chat` and `list_models` — to any MCP client. Every `chat` goes through the gateway,
|
|
137
|
+
so the provider key stays server-side and the passport's scope, budget, and kill switch all
|
|
138
|
+
apply. The client sees the model's response, never your key.
|
|
139
|
+
|
|
140
|
+
Set it up once. Your passport lives in a single trusted local file; the client config never
|
|
141
|
+
holds a secret:
|
|
241
142
|
|
|
242
143
|
```bash
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
npm run cli -- audit --limit 20
|
|
247
|
-
npm run cli -- kill on
|
|
144
|
+
passcontrol init --global # store the passport once (~/.config/passcontrol)
|
|
145
|
+
passcontrol configure claude-desktop --write # merge a secret-free MCP entry into the client
|
|
146
|
+
# then restart Claude Desktop
|
|
248
147
|
```
|
|
249
148
|
|
|
250
|
-
|
|
251
|
-
|
|
149
|
+
Swap `claude-desktop` for `cursor`, or for Claude Code run the printed
|
|
150
|
+
`claude mcp add --scope user passcontrol -- passcontrol mcp`. Ask the client to use the `chat`
|
|
151
|
+
tool and the call is governed end-to-end — arm the kill switch and the next tool call is
|
|
152
|
+
refused. Run `passcontrol env claude-desktop` to preview the config without writing it.
|
|
252
153
|
|
|
253
154
|
## Limitations
|
|
254
155
|
- A work-visa is a bearer token and is reusable until it expires (≤5 minutes). Keep it out
|
package/bin/passcontrol.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
CONFIG_FILE,
|
|
12
12
|
OPENAI_SHAPE_PROVIDERS,
|
|
13
13
|
PROVIDERS,
|
|
14
|
+
assertConfigLoaded,
|
|
14
15
|
config,
|
|
15
16
|
configPathLabel,
|
|
16
17
|
defaultModelForProvider,
|
|
@@ -25,12 +26,28 @@ import {
|
|
|
25
26
|
step,
|
|
26
27
|
writeConfigFile,
|
|
27
28
|
} from "../cli/config.mjs";
|
|
29
|
+
import {
|
|
30
|
+
CLAUDE_CODE_ADD_COMMAND,
|
|
31
|
+
isMcpIntegration,
|
|
32
|
+
mcpClientConfigPath,
|
|
33
|
+
mcpServerEntry,
|
|
34
|
+
mcpServersDocument,
|
|
35
|
+
writeMcpClientConfig,
|
|
36
|
+
} from "../cli/mcp/integration.mjs";
|
|
28
37
|
import { startSidecar } from "../cli/sidecar.mjs";
|
|
29
38
|
|
|
30
39
|
const b64url = (bytes) =>
|
|
31
40
|
Buffer.from(bytes).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
32
41
|
const fromB64url = (s) => new Uint8Array(Buffer.from(s.replace(/-/g, "+").replace(/_/g, "/"), "base64"));
|
|
33
|
-
const
|
|
42
|
+
const CLI_ENTRY = fileURLToPath(import.meta.url);
|
|
43
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(CLI_ENTRY), "..");
|
|
44
|
+
const CLI_VERSION = (() => {
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf8")).version ?? "0.0.0";
|
|
47
|
+
} catch {
|
|
48
|
+
return "0.0.0";
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
34
51
|
const DASHBOARD_STATE_FILE = "local-dashboard.json";
|
|
35
52
|
const APP_STATE_FILE = "app.json";
|
|
36
53
|
const PUBLIC_REPO_URL = "https://github.com/Vertias3u/PassControl.git";
|
|
@@ -99,8 +116,11 @@ Usage:
|
|
|
99
116
|
clone the app (if needed), start local services, open the dashboard
|
|
100
117
|
${cmd} call "hi" mint a visa and call a model
|
|
101
118
|
${cmd} sidecar [--port 8788] start the local agent bridge
|
|
119
|
+
${cmd} mcp start the local stdio MCP server
|
|
102
120
|
${cmd} env [openhands] print sidecar settings for agents
|
|
103
|
-
${cmd}
|
|
121
|
+
${cmd} env claude-desktop|cursor|claude-code
|
|
122
|
+
print secret-free MCP client settings
|
|
123
|
+
${cmd} configure <integration> [--write] [--force]
|
|
104
124
|
preview or create a supported integration config
|
|
105
125
|
${cmd} agent list list agents
|
|
106
126
|
${cmd} agent create <name> create an agent passport
|
|
@@ -974,17 +994,25 @@ async function logsCommand(opts) {
|
|
|
974
994
|
})
|
|
975
995
|
);
|
|
976
996
|
console.table(
|
|
977
|
-
rows.map((row) =>
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
997
|
+
rows.map((row) => {
|
|
998
|
+
const input = typeof row.input_tokens === "number" && Number.isFinite(row.input_tokens)
|
|
999
|
+
? row.input_tokens
|
|
1000
|
+
: null;
|
|
1001
|
+
const output = typeof row.output_tokens === "number" && Number.isFinite(row.output_tokens)
|
|
1002
|
+
? row.output_tokens
|
|
1003
|
+
: null;
|
|
1004
|
+
return {
|
|
1005
|
+
at: row.created_at,
|
|
1006
|
+
agent: row.agent_id,
|
|
1007
|
+
provider: row.provider,
|
|
1008
|
+
model: row.model,
|
|
1009
|
+
status: row.status,
|
|
1010
|
+
in: input ?? "-",
|
|
1011
|
+
out: output ?? "-",
|
|
1012
|
+
total: input === null && output === null ? "-" : (input ?? 0) + (output ?? 0),
|
|
1013
|
+
usd: usd(row.cost_microcents),
|
|
1014
|
+
};
|
|
1015
|
+
})
|
|
988
1016
|
);
|
|
989
1017
|
}
|
|
990
1018
|
|
|
@@ -1018,6 +1046,12 @@ async function sidecarCommand(rest, opts) {
|
|
|
1018
1046
|
}
|
|
1019
1047
|
}
|
|
1020
1048
|
|
|
1049
|
+
async function mcpCommand() {
|
|
1050
|
+
const { passportId, passportSecret } = requirePassport(config);
|
|
1051
|
+
const { startMcpServer } = await import("../cli/mcp/server.mjs");
|
|
1052
|
+
await startMcpServer({ gateway: config.gateway, passportId, passportSecret });
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1021
1055
|
function sidecarBaseUrl(opts = {}) {
|
|
1022
1056
|
const provider = String(opts.provider || config.provider);
|
|
1023
1057
|
assertProvider(provider);
|
|
@@ -1041,8 +1075,42 @@ function printExports(values) {
|
|
|
1041
1075
|
}
|
|
1042
1076
|
}
|
|
1043
1077
|
|
|
1078
|
+
function requireGlobalMcpPassport() {
|
|
1079
|
+
assertConfigLoaded();
|
|
1080
|
+
const globalSource = config.sources.find((source) => source.type === "global");
|
|
1081
|
+
const passportId = String(globalSource?.values?.PASSPORT_ID ?? "").trim();
|
|
1082
|
+
const passportSecret = String(globalSource?.values?.PASSPORT_SECRET ?? "").trim();
|
|
1083
|
+
if (!passportId || !passportSecret) {
|
|
1084
|
+
throw new Error(
|
|
1085
|
+
"MCP client setup requires a passport in the global PassControl config. Run `passcontrol init --global` first."
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
function passControlMcpEntry() {
|
|
1091
|
+
return mcpServerEntry({ cliPath: CLI_ENTRY });
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function printMcpPreset(integration) {
|
|
1095
|
+
requireGlobalMcpPassport();
|
|
1096
|
+
if (integration === "claude-code") {
|
|
1097
|
+
console.log("# Add PassControl to Claude Code:");
|
|
1098
|
+
console.log(CLAUDE_CODE_ADD_COMMAND);
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
const label = integration === "cursor" ? "Cursor" : "Claude Desktop";
|
|
1103
|
+
console.log(`# ${label} mcpServers config:`);
|
|
1104
|
+
console.log(JSON.stringify(mcpServersDocument(passControlMcpEntry()), null, 2));
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1044
1107
|
function printAgentPreset(name = "generic", opts = {}) {
|
|
1045
1108
|
const preset = name.toLowerCase();
|
|
1109
|
+
if (isMcpIntegration(preset)) {
|
|
1110
|
+
printMcpPreset(preset);
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1046
1114
|
const { provider, model, apiKey, baseUrl } = sidecarBaseUrl(opts);
|
|
1047
1115
|
const modelWithProvider = `${provider}/${model}`;
|
|
1048
1116
|
const sidecarStart = opts.port ? cliCommand(`sidecar --port ${opts.port}`) : cliCommand("sidecar");
|
|
@@ -1089,7 +1157,9 @@ function printAgentPreset(name = "generic", opts = {}) {
|
|
|
1089
1157
|
]);
|
|
1090
1158
|
break;
|
|
1091
1159
|
default:
|
|
1092
|
-
throw new Error(
|
|
1160
|
+
throw new Error(
|
|
1161
|
+
"Usage: passcontrol env [generic|openhands|litellm|aider|cline|continue|claude-desktop|cursor|claude-code]"
|
|
1162
|
+
);
|
|
1093
1163
|
}
|
|
1094
1164
|
}
|
|
1095
1165
|
|
|
@@ -1105,9 +1175,43 @@ function aiderConfig(opts = {}) {
|
|
|
1105
1175
|
].join("\n");
|
|
1106
1176
|
}
|
|
1107
1177
|
|
|
1178
|
+
function configureMcpClient(integration, opts = {}) {
|
|
1179
|
+
requireGlobalMcpPassport();
|
|
1180
|
+
if (integration === "claude-code") {
|
|
1181
|
+
console.log("Claude Code manages MCP servers through its CLI. Run:");
|
|
1182
|
+
console.log(CLAUDE_CODE_ADD_COMMAND);
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
const target = mcpClientConfigPath(integration);
|
|
1187
|
+
const entry = passControlMcpEntry();
|
|
1188
|
+
const preview = JSON.stringify(mcpServersDocument(entry), null, 2);
|
|
1189
|
+
console.log(`Preview: ${target}\n\n${preview}`);
|
|
1190
|
+
if (!opts.write) {
|
|
1191
|
+
step("Dry run only. Re-run with `--write` to merge this entry.");
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
const result = writeMcpClientConfig({ target, entry, force: Boolean(opts.force) });
|
|
1196
|
+
if (!result.changed) {
|
|
1197
|
+
ok(`${target} already contains this PassControl MCP entry`);
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
if (result.backupPath) step(`backed up ${result.backupPath}`);
|
|
1201
|
+
ok(`wrote ${target}`);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1108
1204
|
async function configureCommand(rest, opts = {}) {
|
|
1109
1205
|
const integration = String(rest[0] ?? "").toLowerCase();
|
|
1110
|
-
if (!integration)
|
|
1206
|
+
if (!integration) {
|
|
1207
|
+
throw new Error(
|
|
1208
|
+
"Usage: passcontrol configure <aider|cline|continue|openhands|claude-desktop|cursor|claude-code> [--write] [--force]"
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
1211
|
+
if (isMcpIntegration(integration)) {
|
|
1212
|
+
configureMcpClient(integration, opts);
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1111
1215
|
if (integration !== "aider") {
|
|
1112
1216
|
if (opts.write) throw new Error(`${integration} configuration is UI- or project-schema-specific; no file was written. Use the preview below.`);
|
|
1113
1217
|
printAgentPreset(integration, opts);
|
|
@@ -1217,7 +1321,7 @@ async function main() {
|
|
|
1217
1321
|
return;
|
|
1218
1322
|
}
|
|
1219
1323
|
if (opts.version || command === "version") {
|
|
1220
|
-
console.log(
|
|
1324
|
+
console.log(`passcontrol ${CLI_VERSION}`);
|
|
1221
1325
|
return;
|
|
1222
1326
|
}
|
|
1223
1327
|
|
|
@@ -1256,6 +1360,9 @@ async function main() {
|
|
|
1256
1360
|
case "sidecar":
|
|
1257
1361
|
await sidecarCommand(commandRest, opts);
|
|
1258
1362
|
break;
|
|
1363
|
+
case "mcp":
|
|
1364
|
+
await mcpCommand();
|
|
1365
|
+
break;
|
|
1259
1366
|
case "env":
|
|
1260
1367
|
printAgentPreset(commandRest[0] || "generic", opts);
|
|
1261
1368
|
break;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# PassControl MCP server
|
|
2
|
+
|
|
3
|
+
`passcontrol mcp` starts a local stdio MCP server with `chat` and `list_models`.
|
|
4
|
+
It reads the same environment, nearest `.passcontrol`, and global
|
|
5
|
+
`~/.config/passcontrol/config` sources as the rest of the CLI. MCP client setup requires a
|
|
6
|
+
passport in the global profile so clients can launch from any working directory without
|
|
7
|
+
embedding a secret:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
passcontrol init --global
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The client receives neither the provider key nor the short-lived work visa. The
|
|
14
|
+
server mints the visa locally and sends every model call through the configured
|
|
15
|
+
PassControl gateway.
|
|
16
|
+
|
|
17
|
+
## Claude Desktop
|
|
18
|
+
|
|
19
|
+
Preview or merge the entry into Claude Desktop's real per-OS config path:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
passcontrol env claude-desktop
|
|
23
|
+
passcontrol configure claude-desktop --write
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Cursor
|
|
27
|
+
|
|
28
|
+
Preview or merge `mcpServers.passcontrol` into `~/.cursor/mcp.json`:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
passcontrol env cursor
|
|
32
|
+
passcontrol configure cursor --write
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Claude Code
|
|
36
|
+
|
|
37
|
+
Claude Code manages this setting through its CLI. Either command below prints the exact
|
|
38
|
+
`claude mcp add` command to run:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
passcontrol env claude-code
|
|
42
|
+
passcontrol configure claude-code
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The equivalent private, user-scoped command is:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
claude mcp add --scope user passcontrol -- passcontrol mcp
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Desktop/Cursor entries use absolute Node and `bin/passcontrol.mjs` paths because GUI clients
|
|
52
|
+
may not inherit shell `PATH`. Existing `mcpServers` entries are preserved, an existing file is
|
|
53
|
+
backed up to `.bak`, and a different PassControl entry requires `--force`. No generated client
|
|
54
|
+
config contains a passport secret or provider key.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { decodeJwt } from "jose";
|
|
2
|
+
import { OPENAI_SHAPE_PROVIDERS, formatProxyError } from "../config.mjs";
|
|
3
|
+
import { createVisaClient } from "../visa-client.mjs";
|
|
4
|
+
|
|
5
|
+
const DEFAULT_ANTHROPIC_MAX_TOKENS = 1024;
|
|
6
|
+
|
|
7
|
+
const trimSlash = (value) => String(value ?? "").replace(/\/+$/, "");
|
|
8
|
+
|
|
9
|
+
function requestFor({ provider, model, messages, max_tokens, temperature }) {
|
|
10
|
+
if (provider === "anthropic") {
|
|
11
|
+
const system = messages
|
|
12
|
+
.filter((message) => message.role === "system")
|
|
13
|
+
.map((message) => message.content)
|
|
14
|
+
.join("\n\n");
|
|
15
|
+
const providerMessages = messages.filter((message) => message.role !== "system");
|
|
16
|
+
if (providerMessages.length === 0) {
|
|
17
|
+
throw new Error("Anthropic chat requires at least one user or assistant message.");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
path: "v1/messages",
|
|
22
|
+
body: {
|
|
23
|
+
model,
|
|
24
|
+
max_tokens: max_tokens ?? DEFAULT_ANTHROPIC_MAX_TOKENS,
|
|
25
|
+
messages: providerMessages,
|
|
26
|
+
...(system ? { system } : {}),
|
|
27
|
+
...(temperature === undefined ? {} : { temperature }),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (OPENAI_SHAPE_PROVIDERS.has(provider)) {
|
|
33
|
+
return {
|
|
34
|
+
path: "chat/completions",
|
|
35
|
+
body: {
|
|
36
|
+
model,
|
|
37
|
+
messages,
|
|
38
|
+
...(max_tokens === undefined ? {} : { max_tokens }),
|
|
39
|
+
...(temperature === undefined ? {} : { temperature }),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw new Error(`Provider ${provider} is not supported by PassControl MCP.`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function extractAssistantText(provider, data) {
|
|
48
|
+
if (provider === "anthropic") {
|
|
49
|
+
const text = Array.isArray(data?.content)
|
|
50
|
+
? data.content
|
|
51
|
+
.filter((part) => part?.type === "text" && typeof part.text === "string")
|
|
52
|
+
.map((part) => part.text)
|
|
53
|
+
.join("")
|
|
54
|
+
: "";
|
|
55
|
+
if (text) return text;
|
|
56
|
+
} else {
|
|
57
|
+
const content = data?.choices?.[0]?.message?.content;
|
|
58
|
+
if (typeof content === "string" && content) return content;
|
|
59
|
+
if (Array.isArray(content)) {
|
|
60
|
+
const text = content
|
|
61
|
+
.map((part) => (typeof part === "string" ? part : typeof part?.text === "string" ? part.text : ""))
|
|
62
|
+
.join("");
|
|
63
|
+
if (text) return text;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
throw new Error(`${provider} returned no assistant text.`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function proxyError(status, body) {
|
|
71
|
+
if (status === 401) {
|
|
72
|
+
const detail = String(body ?? "").trim();
|
|
73
|
+
return `Gateway rejected the work visa with 401: ${detail}. Check the passport and gateway, then retry.`;
|
|
74
|
+
}
|
|
75
|
+
return formatProxyError(status, body);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function usageFrom(data) {
|
|
79
|
+
return data?.usage && typeof data.usage === "object" && !Array.isArray(data.usage)
|
|
80
|
+
? data.usage
|
|
81
|
+
: undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function modelsFromVisa(visa) {
|
|
85
|
+
let payload;
|
|
86
|
+
try {
|
|
87
|
+
payload = decodeJwt(visa);
|
|
88
|
+
} catch {
|
|
89
|
+
throw new Error("Gateway returned a work visa with an unreadable scope.");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!Array.isArray(payload.scope)) {
|
|
93
|
+
throw new Error("Gateway work visa did not contain a model scope.");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return payload.scope.flatMap((entry) => {
|
|
97
|
+
if (!entry || typeof entry.provider !== "string" || !Array.isArray(entry.models)) return [];
|
|
98
|
+
return entry.models
|
|
99
|
+
.filter((model) => typeof model === "string")
|
|
100
|
+
.map((model) => ({ provider: entry.provider, model }));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function createGatewayClient({
|
|
105
|
+
gateway,
|
|
106
|
+
passportId,
|
|
107
|
+
passportSecret,
|
|
108
|
+
fetch: fetchImpl = globalThis.fetch,
|
|
109
|
+
now = () => Date.now(),
|
|
110
|
+
randomUUID = () => globalThis.crypto.randomUUID(),
|
|
111
|
+
refreshSkewSeconds = 30,
|
|
112
|
+
}) {
|
|
113
|
+
const baseUrl = trimSlash(gateway);
|
|
114
|
+
const visas = createVisaClient({
|
|
115
|
+
gateway: baseUrl,
|
|
116
|
+
passportId,
|
|
117
|
+
passportSecret,
|
|
118
|
+
fetch: fetchImpl,
|
|
119
|
+
now,
|
|
120
|
+
randomUUID,
|
|
121
|
+
refreshSkewSeconds,
|
|
122
|
+
missingVisaMessage: "Challenge returned no visa.",
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
async function proxyChat(input, visa) {
|
|
126
|
+
const { path, body } = requestFor(input);
|
|
127
|
+
return fetchImpl(`${baseUrl}/api/v1/${input.provider}/${path}`, {
|
|
128
|
+
method: "POST",
|
|
129
|
+
headers: {
|
|
130
|
+
"content-type": "application/json",
|
|
131
|
+
authorization: `Bearer ${visa}`,
|
|
132
|
+
},
|
|
133
|
+
body: JSON.stringify(body),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
async chat(input) {
|
|
139
|
+
const response = await visas.fetchWithVisa((visa) => proxyChat(input, visa));
|
|
140
|
+
if (!response.ok) throw new Error(proxyError(response.status, await response.text()));
|
|
141
|
+
|
|
142
|
+
let data;
|
|
143
|
+
try {
|
|
144
|
+
data = await response.json();
|
|
145
|
+
} catch {
|
|
146
|
+
throw new Error(`Gateway returned a non-JSON ${input.provider} response.`);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
text: extractAssistantText(input.provider, data),
|
|
150
|
+
usage: usageFrom(data),
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
async listModels() {
|
|
155
|
+
return modelsFromVisa(await visas.getVisa());
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
|
|
6
|
+
export const MCP_INTEGRATIONS = new Set(["claude-desktop", "cursor", "claude-code"]);
|
|
7
|
+
export const CLAUDE_CODE_ADD_COMMAND =
|
|
8
|
+
"claude mcp add --scope user passcontrol -- passcontrol mcp";
|
|
9
|
+
|
|
10
|
+
export function isMcpIntegration(name) {
|
|
11
|
+
return MCP_INTEGRATIONS.has(name);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function mcpServerEntry({ cliPath, nodePath = process.execPath }) {
|
|
15
|
+
return {
|
|
16
|
+
command: path.resolve(nodePath),
|
|
17
|
+
args: [path.resolve(cliPath), "mcp"],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function mcpServersDocument(entry) {
|
|
22
|
+
return { mcpServers: { passcontrol: entry } };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function mcpClientConfigPath(
|
|
26
|
+
integration,
|
|
27
|
+
{ platform = process.platform, home = os.homedir(), env = process.env } = {}
|
|
28
|
+
) {
|
|
29
|
+
if (integration === "cursor") return path.join(home, ".cursor", "mcp.json");
|
|
30
|
+
if (integration !== "claude-desktop") return null;
|
|
31
|
+
|
|
32
|
+
if (platform === "darwin") {
|
|
33
|
+
return path.join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
34
|
+
}
|
|
35
|
+
if (platform === "win32") {
|
|
36
|
+
const appData = env.APPDATA || path.join(home, "AppData", "Roaming");
|
|
37
|
+
return path.join(appData, "Claude", "claude_desktop_config.json");
|
|
38
|
+
}
|
|
39
|
+
const configHome = env.XDG_CONFIG_HOME || path.join(home, ".config");
|
|
40
|
+
return path.join(configHome, "Claude", "claude_desktop_config.json");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function readConfigObject(target) {
|
|
44
|
+
if (!fs.existsSync(target)) return { exists: false, value: {} };
|
|
45
|
+
|
|
46
|
+
let value;
|
|
47
|
+
try {
|
|
48
|
+
value = JSON.parse(fs.readFileSync(target, "utf8"));
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new Error(`Cannot parse ${target}: ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
53
|
+
throw new Error(`${target} must contain a JSON object.`);
|
|
54
|
+
}
|
|
55
|
+
if (
|
|
56
|
+
value.mcpServers !== undefined &&
|
|
57
|
+
(!value.mcpServers || typeof value.mcpServers !== "object" || Array.isArray(value.mcpServers))
|
|
58
|
+
) {
|
|
59
|
+
throw new Error(`${target} has an invalid mcpServers value; expected a JSON object.`);
|
|
60
|
+
}
|
|
61
|
+
return { exists: true, value };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function writeMcpClientConfig({ target, entry, force = false }) {
|
|
65
|
+
const { exists, value } = readConfigObject(target);
|
|
66
|
+
const mcpServers = value.mcpServers ?? {};
|
|
67
|
+
const hasPassControl = Object.prototype.hasOwnProperty.call(mcpServers, "passcontrol");
|
|
68
|
+
if (hasPassControl && !isDeepStrictEqual(mcpServers.passcontrol, entry) && !force) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`${target} already has a different mcpServers.passcontrol entry; re-run with --force to replace only that entry.`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (hasPassControl && isDeepStrictEqual(mcpServers.passcontrol, entry)) {
|
|
74
|
+
return { changed: false, backupPath: null };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const merged = {
|
|
78
|
+
...value,
|
|
79
|
+
mcpServers: {
|
|
80
|
+
...mcpServers,
|
|
81
|
+
passcontrol: entry,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
85
|
+
|
|
86
|
+
let backupPath = null;
|
|
87
|
+
if (exists) {
|
|
88
|
+
backupPath = `${target}.bak`;
|
|
89
|
+
fs.copyFileSync(target, backupPath);
|
|
90
|
+
fs.chmodSync(backupPath, 0o600);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fs.writeFileSync(target, `${JSON.stringify(merged, null, 2)}\n`, { mode: 0o600 });
|
|
94
|
+
fs.chmodSync(target, 0o600);
|
|
95
|
+
return { changed: true, backupPath };
|
|
96
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
import { PROVIDERS } from "../config.mjs";
|
|
5
|
+
import { createGatewayClient } from "./gateway.mjs";
|
|
6
|
+
|
|
7
|
+
const messageSchema = z.object({
|
|
8
|
+
role: z.enum(["system", "user", "assistant"]),
|
|
9
|
+
content: z.string().min(1),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const usageSchema = z.record(z.string(), z.unknown());
|
|
13
|
+
const modelSchema = z.object({
|
|
14
|
+
provider: z.string(),
|
|
15
|
+
model: z.string(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function toolError(error) {
|
|
19
|
+
return {
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
text: error instanceof Error ? error.message : String(error),
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
isError: true,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createMcpServer(options) {
|
|
31
|
+
const gateway = createGatewayClient(options);
|
|
32
|
+
const server = new McpServer(
|
|
33
|
+
{ name: "passcontrol", version: "0.2.0" },
|
|
34
|
+
{
|
|
35
|
+
instructions:
|
|
36
|
+
"Use chat for governed model calls through PassControl. Every chat call is subject to the configured passport's scope, budget, and kill switches.",
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
server.registerTool(
|
|
41
|
+
"chat",
|
|
42
|
+
{
|
|
43
|
+
title: "Governed model chat",
|
|
44
|
+
description:
|
|
45
|
+
"Call a supported model through the PassControl gateway. The provider key stays in the gateway; passport scope, budget, and kill switches apply.",
|
|
46
|
+
inputSchema: {
|
|
47
|
+
provider: z.enum(PROVIDERS),
|
|
48
|
+
model: z.string().min(1),
|
|
49
|
+
messages: z.array(messageSchema).min(1),
|
|
50
|
+
max_tokens: z.number().int().positive().optional(),
|
|
51
|
+
temperature: z.number().min(0).max(2).optional(),
|
|
52
|
+
},
|
|
53
|
+
outputSchema: {
|
|
54
|
+
text: z.string(),
|
|
55
|
+
usage: usageSchema.optional(),
|
|
56
|
+
},
|
|
57
|
+
annotations: {
|
|
58
|
+
destructiveHint: false,
|
|
59
|
+
idempotentHint: false,
|
|
60
|
+
openWorldHint: true,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
async (input) => {
|
|
64
|
+
try {
|
|
65
|
+
const result = await gateway.chat(input);
|
|
66
|
+
const structuredContent = {
|
|
67
|
+
text: result.text,
|
|
68
|
+
...(result.usage ? { usage: result.usage } : {}),
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
content: [{ type: "text", text: result.text }],
|
|
72
|
+
structuredContent,
|
|
73
|
+
};
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return toolError(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
server.registerTool(
|
|
81
|
+
"list_models",
|
|
82
|
+
{
|
|
83
|
+
title: "List scoped models",
|
|
84
|
+
description:
|
|
85
|
+
"List provider/model patterns in the gateway-issued scope for the configured passport.",
|
|
86
|
+
outputSchema: { models: z.array(modelSchema) },
|
|
87
|
+
annotations: {
|
|
88
|
+
readOnlyHint: true,
|
|
89
|
+
destructiveHint: false,
|
|
90
|
+
idempotentHint: true,
|
|
91
|
+
openWorldHint: false,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
async () => {
|
|
95
|
+
try {
|
|
96
|
+
const structuredContent = { models: await gateway.listModels() };
|
|
97
|
+
return {
|
|
98
|
+
content: [{ type: "text", text: JSON.stringify(structuredContent, null, 2) }],
|
|
99
|
+
structuredContent,
|
|
100
|
+
};
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return toolError(error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return server;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function startMcpServer(options) {
|
|
111
|
+
const server = createMcpServer(options);
|
|
112
|
+
await server.connect(new StdioServerTransport());
|
|
113
|
+
return server;
|
|
114
|
+
}
|
package/cli/sidecar.mjs
CHANGED
|
@@ -1,48 +1,19 @@
|
|
|
1
1
|
import http from "node:http";
|
|
2
2
|
import { Readable } from "node:stream";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const b64url = (bytes) =>
|
|
7
|
-
Buffer.from(bytes).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
8
|
-
const fromB64url = (s) => new Uint8Array(Buffer.from(s.replace(/-/g, "+").replace(/_/g, "/"), "base64"));
|
|
3
|
+
import { fail, ok, step } from "./config.mjs";
|
|
4
|
+
import { createVisaClient } from "./visa-client.mjs";
|
|
9
5
|
|
|
10
6
|
const STRIP_REQ = new Set(["authorization", "x-api-key", "host", "content-length", "accept-encoding", "connection"]);
|
|
11
7
|
const STRIP_RES = new Set(["content-encoding", "content-length", "transfer-encoding", "connection"]);
|
|
12
8
|
|
|
13
9
|
export function createSidecar({ gateway, passportId, passportSecret, port = 8788, host = "127.0.0.1", refreshSkewSeconds = 30 }) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const signature = b64url(ed25519.sign(fromB64url(payload), fromB64url(passportSecret)));
|
|
22
|
-
const res = await fetch(`${gateway}/api/auth/challenge`, {
|
|
23
|
-
method: "POST",
|
|
24
|
-
headers: { "content-type": "application/json" },
|
|
25
|
-
body: JSON.stringify({ payload, signature }),
|
|
26
|
-
});
|
|
27
|
-
if (!res.ok) throw new Error(formatChallengeError(res.status, await res.text()));
|
|
28
|
-
const { visa, expires_in } = await res.json();
|
|
29
|
-
if (!visa) throw new Error("challenge returned no visa");
|
|
30
|
-
return { token: visa, expiresAt: Date.now() + (expires_in ?? 300) * 1000 };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function getVisa() {
|
|
34
|
-
if (cached && Date.now() < cached.expiresAt - skewMs) return cached.token;
|
|
35
|
-
if (inflight) return inflight;
|
|
36
|
-
inflight = mint()
|
|
37
|
-
.then((v) => {
|
|
38
|
-
cached = v;
|
|
39
|
-
return v.token;
|
|
40
|
-
})
|
|
41
|
-
.finally(() => {
|
|
42
|
-
inflight = null;
|
|
43
|
-
});
|
|
44
|
-
return inflight;
|
|
45
|
-
}
|
|
10
|
+
const visas = createVisaClient({
|
|
11
|
+
gateway,
|
|
12
|
+
passportId,
|
|
13
|
+
passportSecret,
|
|
14
|
+
refreshSkewSeconds,
|
|
15
|
+
missingVisaMessage: "challenge returned no visa",
|
|
16
|
+
});
|
|
46
17
|
|
|
47
18
|
function readBody(req) {
|
|
48
19
|
return new Promise((resolve, reject) => {
|
|
@@ -76,11 +47,7 @@ export function createSidecar({ gateway, passportId, passportSecret, port = 8788
|
|
|
76
47
|
const server = http.createServer(async (req, res) => {
|
|
77
48
|
try {
|
|
78
49
|
const body = await readBody(req);
|
|
79
|
-
|
|
80
|
-
if (upstream.status === 401) {
|
|
81
|
-
cached = null;
|
|
82
|
-
upstream = await fetchUpstream(req, body, await getVisa());
|
|
83
|
-
}
|
|
50
|
+
const upstream = await visas.fetchWithVisa((visa) => fetchUpstream(req, body, visa));
|
|
84
51
|
writeResponse(res, upstream);
|
|
85
52
|
} catch (e) {
|
|
86
53
|
if (!res.headersSent) {
|
|
@@ -92,7 +59,7 @@ export function createSidecar({ gateway, passportId, passportSecret, port = 8788
|
|
|
92
59
|
}
|
|
93
60
|
});
|
|
94
61
|
|
|
95
|
-
return { server, getVisa };
|
|
62
|
+
return { server, getVisa: visas.getVisa };
|
|
96
63
|
}
|
|
97
64
|
|
|
98
65
|
export function startSidecar(opts) {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ed25519 } from "@noble/curves/ed25519";
|
|
2
|
+
import { formatChallengeError } from "./config.mjs";
|
|
3
|
+
|
|
4
|
+
const b64url = (bytes) =>
|
|
5
|
+
Buffer.from(bytes).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
6
|
+
const fromB64url = (value) =>
|
|
7
|
+
new Uint8Array(Buffer.from(value.replace(/-/g, "+").replace(/_/g, "/"), "base64"));
|
|
8
|
+
|
|
9
|
+
export function createVisaClient({
|
|
10
|
+
gateway,
|
|
11
|
+
passportId,
|
|
12
|
+
passportSecret,
|
|
13
|
+
fetch: fetchImpl = (...args) => globalThis.fetch(...args),
|
|
14
|
+
now = () => Date.now(),
|
|
15
|
+
randomUUID = () => globalThis.crypto.randomUUID(),
|
|
16
|
+
refreshSkewSeconds = 30,
|
|
17
|
+
missingVisaMessage = "Challenge returned no visa.",
|
|
18
|
+
}) {
|
|
19
|
+
const skewMs = Math.max(0, Number(refreshSkewSeconds) * 1000);
|
|
20
|
+
let cached = null;
|
|
21
|
+
let inflight = null;
|
|
22
|
+
|
|
23
|
+
async function mint() {
|
|
24
|
+
const payloadObject = { passport_id: passportId, ts: now(), nonce: randomUUID() };
|
|
25
|
+
const payload = b64url(new TextEncoder().encode(JSON.stringify(payloadObject)));
|
|
26
|
+
const signature = b64url(ed25519.sign(fromB64url(payload), fromB64url(passportSecret)));
|
|
27
|
+
const response = await fetchImpl(`${gateway}/api/auth/challenge`, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: { "content-type": "application/json" },
|
|
30
|
+
body: JSON.stringify({ payload, signature }),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw new Error(formatChallengeError(response.status, await response.text()));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const data = await response.json();
|
|
38
|
+
if (!data.visa) throw new Error(missingVisaMessage);
|
|
39
|
+
return {
|
|
40
|
+
token: data.visa,
|
|
41
|
+
expiresAt: now() + (data.expires_in ?? 300) * 1000,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function getVisa() {
|
|
46
|
+
if (cached && now() < cached.expiresAt - skewMs) return cached.token;
|
|
47
|
+
if (inflight) return inflight;
|
|
48
|
+
|
|
49
|
+
inflight = mint()
|
|
50
|
+
.then((visa) => {
|
|
51
|
+
cached = visa;
|
|
52
|
+
return visa.token;
|
|
53
|
+
})
|
|
54
|
+
.finally(() => {
|
|
55
|
+
inflight = null;
|
|
56
|
+
});
|
|
57
|
+
return inflight;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function invalidate() {
|
|
61
|
+
cached = null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function fetchWithVisa(request) {
|
|
65
|
+
let response = await request(await getVisa());
|
|
66
|
+
if (response.status === 401) {
|
|
67
|
+
invalidate();
|
|
68
|
+
response = await request(await getVisa());
|
|
69
|
+
}
|
|
70
|
+
return response;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return { getVisa, invalidate, fetchWithVisa };
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passcontrol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Secure Agent Control Plane & Passport Vault — identity-aware reverse proxy for AI agent credentials.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"homepage": "https://github.com/Vertias3u/PassControl#readme",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"files": [
|
|
33
33
|
"bin",
|
|
34
34
|
"cli",
|
|
35
|
+
"!cli/**/__tests__",
|
|
35
36
|
"LICENSE",
|
|
36
37
|
"README.md"
|
|
37
38
|
],
|
|
@@ -57,6 +58,7 @@
|
|
|
57
58
|
},
|
|
58
59
|
"dependencies": {
|
|
59
60
|
"@base-ui/react": "^1.5.0",
|
|
61
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
60
62
|
"@noble/curves": "^1.6.0",
|
|
61
63
|
"@noble/hashes": "^1.5.0",
|
|
62
64
|
"@sentry/nextjs": "^10.64.0",
|
|
@@ -73,7 +75,8 @@
|
|
|
73
75
|
"react-dom": "^18.3.1",
|
|
74
76
|
"shadcn": "^4.11.0",
|
|
75
77
|
"tailwind-merge": "^3.6.0",
|
|
76
|
-
"tw-animate-css": "^1.4.0"
|
|
78
|
+
"tw-animate-css": "^1.4.0",
|
|
79
|
+
"zod": "^3.25.76"
|
|
77
80
|
},
|
|
78
81
|
"devDependencies": {
|
|
79
82
|
"@tailwindcss/postcss": "^4.3.1",
|