@strixgov/mcp-proxy 0.2.3 → 0.2.5

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +75 -25
  3. package/examples/controlled-launcher/README.md +33 -0
  4. package/examples/controlled-launcher/acceptance.mjs +337 -0
  5. package/examples/controlled-launcher/agent-client.mjs +18 -0
  6. package/examples/controlled-launcher/approval-relay.mjs +19 -0
  7. package/examples/controlled-launcher/approver.mjs +27 -0
  8. package/examples/controlled-launcher/authorizer.mjs +73 -0
  9. package/examples/controlled-launcher/bridge-client.mjs +8 -0
  10. package/examples/controlled-launcher/destination.mjs +18 -0
  11. package/examples/controlled-launcher/executor.mjs +74 -0
  12. package/examples/controlled-launcher/kernel-authority/acceptance.mjs +627 -0
  13. package/examples/controlled-launcher/kernel-authority/broker.mjs +83 -0
  14. package/examples/controlled-launcher/kernel-authority/derive.mjs +12 -0
  15. package/examples/controlled-launcher/kernel-authority/executor.mjs +105 -0
  16. package/examples/controlled-launcher/kernel-authority/reconcile.mjs +43 -0
  17. package/examples/controlled-launcher/kernel-authority/shim.mjs +38 -0
  18. package/examples/controlled-launcher/kernel-authority/signing-provider.mjs +137 -0
  19. package/examples/controlled-launcher/kernel-authority/strix-approver.mjs +73 -0
  20. package/examples/controlled-launcher/lib.mjs +63 -0
  21. package/examples/controlled-launcher/make-config.mjs +16 -0
  22. package/examples/controlled-launcher/proxy-host.mjs +19 -0
  23. package/examples/controlled-launcher/reconcile.mjs +30 -0
  24. package/examples/controlled-launcher/shim.mjs +32 -0
  25. package/examples/github-reference/README.md +34 -0
  26. package/examples/github-reference/acceptance.mjs +675 -0
  27. package/examples/github-reference/claims-matrix.md +34 -0
  28. package/examples/github-reference/demo-script.md +17 -0
  29. package/examples/github-reference/package-lock.json +1330 -0
  30. package/examples/github-reference/package.json +23 -0
  31. package/examples/github-reference/reuse-inventory.md +24 -0
  32. package/examples/synthetic-server/proxy-config.json +16 -0
  33. package/examples/synthetic-server/quickstart.mjs +98 -0
  34. package/examples/synthetic-server/server.mjs +54 -0
  35. package/package.json +6 -5
  36. package/test/package-contract.test.mjs +12 -0
  37. package/test/synthetic-quickstart.test.mjs +44 -0
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+ // Credential-holding destination executor (separate OS identity). Accepts ONLY:
3
+ // reads -> performed with its own credential (no token needed)
4
+ // create_branch -> requires a valid, exact-payload, single-use execution_authorization_v1 token
5
+ // Everything else is refused. It trusts neither the shim nor the proxy: the token is validated here with
6
+ // the published @strixgov/mcp-token-validator against the authorizer's JWKS.
7
+ // Write-ahead attempt accounting: STARTED is fsynced BEFORE the destination is called. A crash leaves STARTED
8
+ // with no outcome; on restart it is recorded UNKNOWN (never auto-retried) and reconciled by the observer.
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ import crypto from "node:crypto";
12
+ import { validateAuthorization } from "@strixgov/mcp-token-validator";
13
+ import { serve, payloadHash, appendDurable, burnOnce, signCanonical, jwkPublic } from "./lib.mjs";
14
+
15
+ const [sock, stateDir, authzJwksFile, destUrl, tenantId, environment] = process.argv.slice(2);
16
+ const credential = process.env.EXECUTOR_TOKEN; // delivered only to this process's environment
17
+ if (!credential) { console.error("executor: EXECUTOR_TOKEN missing"); process.exit(2); }
18
+ delete process.env.EXECUTOR_TOKEN;
19
+ fs.mkdirSync(path.join(stateDir, "nonces"), { recursive: true, mode: 0o755 });
20
+ const attemptsFile = path.join(stateDir, "attempts.jsonl");
21
+ const outcomesFile = path.join(stateDir, "outcomes.jsonl");
22
+ const keyFile = path.join(stateDir, "outcome-key.pem");
23
+ let priv;
24
+ if (fs.existsSync(keyFile)) priv = crypto.createPrivateKey(fs.readFileSync(keyFile));
25
+ else { const kp = crypto.generateKeyPairSync("ed25519"); fs.writeFileSync(keyFile, kp.privateKey.export({ format: "pem", type: "pkcs8" }), { mode: 0o400 }); priv = kp.privateKey; }
26
+ const OUT_KID = "executor-outcome-test-1";
27
+ fs.writeFileSync(path.join(stateDir, "outcome-jwks.json"), JSON.stringify({ keys: [jwkPublic(crypto.createPublicKey(priv), OUT_KID)] }, null, 2), { mode: 0o644 });
28
+
29
+ // Crash recovery: STARTED without a terminal record -> UNKNOWN (reconcile against the destination; never retried here).
30
+ const readJsonl = (f) => (fs.existsSync(f) ? fs.readFileSync(f, "utf8").trim().split("\n").filter(Boolean).map(JSON.parse) : []);
31
+ {
32
+ const done = new Set(readJsonl(outcomesFile).map((o) => o.attemptId));
33
+ for (const a of readJsonl(attemptsFile).filter((x) => x.state === "STARTED" && !done.has(x.attemptId))) {
34
+ appendDurable(attemptsFile, { attemptId: a.attemptId, state: "RECOVERED_UNKNOWN", at: new Date().toISOString(), note: "no outcome recorded before restart; reconcile against destination" });
35
+ writeOutcome({ attemptId: a.attemptId, authorizationId: a.authorizationId, payloadHash: a.payloadHash, status: "UNKNOWN", destinationStatus: null });
36
+ }
37
+ }
38
+
39
+ function writeOutcome(o) {
40
+ const payload = { schemaVersion: 1, outcomeId: "out_" + crypto.randomBytes(8).toString("hex"), ...o, at: new Date().toISOString() };
41
+ appendDurable(outcomesFile, { ...payload, signingKeyId: OUT_KID, signature: signCanonical(payload, priv) });
42
+ return payload;
43
+ }
44
+ const authzJwks = () => JSON.parse(fs.readFileSync(authzJwksFile, "utf8"));
45
+ const refuse = (error, detail) => ({ ok: false, error, ...(detail ? { detail } : {}) });
46
+ const result = (text, isError = false) => ({ ok: true, content: [{ type: "text", text }], ...(isError ? { isError } : {}) });
47
+ const dest = (method, url, body) => fetch(destUrl + url, { method, headers: { authorization: "Bearer " + credential }, body: body ? JSON.stringify(body) : undefined });
48
+
49
+ serve(sock, async (m) => {
50
+ const { tool, args = {}, token } = m;
51
+ if (tool === "get_file_contents" || tool === "list_branches") {
52
+ const r = await dest("GET", "/repos/synthetic/fixture/branches");
53
+ return result(JSON.stringify(await r.json()));
54
+ }
55
+ if (tool !== "create_branch") return refuse("TOOL_NOT_PERMITTED_BY_EXECUTOR", tool);
56
+ if (!token) return refuse("AUTHORIZATION_REQUIRED");
57
+ if (args.owner !== "synthetic" || args.repo !== "fixture") return refuse("SCOPE_REFUSED", "owner/repo outside declared estate");
58
+ const ph = payloadHash(args);
59
+ const v = await validateAuthorization(token, {
60
+ jwks: authzJwks(), expectedTenantId: tenantId, expectedEnvironment: environment, expectedActorClass: "agent",
61
+ burnNonce: async (n) => burnOnce(path.join(stateDir, "nonces"), n),
62
+ });
63
+ if (!v.ok) return refuse("AUTHORIZATION_INVALID", v.reason);
64
+ if (v.capabilityId !== "mcp.github.create_branch") return refuse("AUTHORIZATION_CAPABILITY_MISMATCH");
65
+ if (v.payloadHash !== ph) return refuse("AUTHORIZATION_PAYLOAD_MISMATCH"); // nonce already burned: a mismatched use consumes the token
66
+ const attemptId = "att_" + crypto.randomBytes(8).toString("hex");
67
+ appendDurable(attemptsFile, { attemptId, state: "STARTED", authorizationId: v.authorizationId, payloadHash: ph, tool, ref: "refs/heads/" + args.branch, at: new Date().toISOString() });
68
+ if (process.env.EXECUTOR_TEST_CRASH_AFTER_STARTED === "1") process.exit(99); // test hook: crash-recovery scenario
69
+ let status = null, st = "FAILED";
70
+ try { const r = await dest("POST", "/repos/synthetic/fixture/git/refs", { ref: "refs/heads/" + args.branch }); status = r.status; st = r.status === 201 ? "SUCCEEDED" : "REJECTED"; } catch { st = "UNKNOWN"; }
71
+ const o = writeOutcome({ attemptId, authorizationId: v.authorizationId, payloadHash: ph, status: st, destinationStatus: status });
72
+ appendDurable(attemptsFile, { attemptId, state: "COMPLETED_" + st, at: o.at });
73
+ return result(JSON.stringify({ status: st, destinationStatus: status, attemptId }), st !== "SUCCEEDED");
74
+ }, 0o660);