@agent-deck/backend 1.11.7 → 1.11.9

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 (77) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/auth/client-grants.d.ts +109 -0
  3. package/dist/auth/client-grants.d.ts.map +1 -0
  4. package/dist/auth/client-grants.js +261 -0
  5. package/dist/auth/client-grants.js.map +1 -0
  6. package/dist/mcp-server.d.ts +124 -2
  7. package/dist/mcp-server.d.ts.map +1 -1
  8. package/dist/mcp-server.js +413 -12
  9. package/dist/mcp-server.js.map +1 -1
  10. package/dist/mcp-session-binding.d.ts +54 -0
  11. package/dist/mcp-session-binding.d.ts.map +1 -1
  12. package/dist/mcp-session-binding.js +81 -0
  13. package/dist/mcp-session-binding.js.map +1 -1
  14. package/dist/mcp-tools/register.d.ts.map +1 -1
  15. package/dist/mcp-tools/register.js +46 -0
  16. package/dist/mcp-tools/register.js.map +1 -1
  17. package/dist/models/database.d.ts +19 -8
  18. package/dist/models/database.d.ts.map +1 -1
  19. package/dist/models/database.js +65 -46
  20. package/dist/models/database.js.map +1 -1
  21. package/dist/routes/agent-grants.d.ts +9 -0
  22. package/dist/routes/agent-grants.d.ts.map +1 -0
  23. package/dist/routes/agent-grants.js +81 -0
  24. package/dist/routes/agent-grants.js.map +1 -0
  25. package/dist/routes/playbooks.d.ts.map +1 -1
  26. package/dist/routes/playbooks.js +9 -10
  27. package/dist/routes/playbooks.js.map +1 -1
  28. package/dist/routes/scope.d.ts.map +1 -1
  29. package/dist/routes/scope.js +4 -2
  30. package/dist/routes/scope.js.map +1 -1
  31. package/dist/routes/services.d.ts.map +1 -1
  32. package/dist/routes/services.js +6 -0
  33. package/dist/routes/services.js.map +1 -1
  34. package/dist/routes/trusted-session.d.ts.map +1 -1
  35. package/dist/routes/trusted-session.js +62 -1
  36. package/dist/routes/trusted-session.js.map +1 -1
  37. package/dist/routes/usage.d.ts +3 -1
  38. package/dist/routes/usage.d.ts.map +1 -1
  39. package/dist/routes/usage.js +20 -1
  40. package/dist/routes/usage.js.map +1 -1
  41. package/dist/scope/display.d.ts +1 -1
  42. package/dist/scope/display.d.ts.map +1 -1
  43. package/dist/scope/display.js +167 -6
  44. package/dist/scope/display.js.map +1 -1
  45. package/dist/scope/live-display-registry.d.ts +80 -3
  46. package/dist/scope/live-display-registry.d.ts.map +1 -1
  47. package/dist/scope/live-display-registry.js +132 -11
  48. package/dist/scope/live-display-registry.js.map +1 -1
  49. package/dist/server/cors-origins.d.ts +6 -0
  50. package/dist/server/cors-origins.d.ts.map +1 -0
  51. package/dist/server/cors-origins.js +103 -0
  52. package/dist/server/cors-origins.js.map +1 -0
  53. package/dist/server/index.d.ts.map +1 -1
  54. package/dist/server/index.js +11 -24
  55. package/dist/server/index.js.map +1 -1
  56. package/dist/trusted-session/route-policy-registry.d.ts.map +1 -1
  57. package/dist/trusted-session/route-policy-registry.js +3 -0
  58. package/dist/trusted-session/route-policy-registry.js.map +1 -1
  59. package/dist/trusted-session/store.d.ts +27 -0
  60. package/dist/trusted-session/store.d.ts.map +1 -1
  61. package/dist/trusted-session/store.js +34 -7
  62. package/dist/trusted-session/store.js.map +1 -1
  63. package/dist/vault/encrypted-file-secret-store.d.ts +61 -0
  64. package/dist/vault/encrypted-file-secret-store.d.ts.map +1 -0
  65. package/dist/vault/encrypted-file-secret-store.js +211 -0
  66. package/dist/vault/encrypted-file-secret-store.js.map +1 -0
  67. package/dist/vault/index.d.ts +1 -0
  68. package/dist/vault/index.d.ts.map +1 -1
  69. package/dist/vault/index.js +1 -0
  70. package/dist/vault/index.js.map +1 -1
  71. package/dist/vault/secret-store.d.ts.map +1 -1
  72. package/dist/vault/secret-store.js +14 -1
  73. package/dist/vault/secret-store.js.map +1 -1
  74. package/package.json +2 -2
  75. package/static-ui/assets/index-sENM6Awe.js +235 -0
  76. package/static-ui/index.html +1 -1
  77. package/static-ui/assets/index-DCImqPRz.js +0 -235
@@ -0,0 +1,109 @@
1
+ import type Database from 'better-sqlite3';
2
+ /**
3
+ * NOT-318: per-agent remote grants for the single-owner hosted appliance.
4
+ *
5
+ * Two boundaries live here:
6
+ *
7
+ * - `ClientPrincipal` — the unified authorization principal every MCP
8
+ * session resolves to. Loopback launcher sessions resolve to `local`
9
+ * (unconstrained, exactly as today); remote bearer sessions resolve to
10
+ * `grant` (constrained by the grant allowlist). Both flow through the
11
+ * same deck-scope check (`principalAllowsDeck`), so the deck header can
12
+ * never authorize beyond the principal.
13
+ * - `ClientGrantStore` — SQLite-backed grant metadata. V1 is one
14
+ * installation and one owner (`installationId` defaults to `'owner'`);
15
+ * the field exists so a future tenancy migration has something to
16
+ * partition on.
17
+ *
18
+ * Token format: `adg_<grantId>_<secret>` where `<secret>` carries 256
19
+ * bits of CSPRNG entropy (32 bytes, base64url). The id prefix is
20
+ * routing-only — it confers nothing by itself. The secret is shown once
21
+ * at issuance; only a versioned SHA-256 verifier is persisted (suitable
22
+ * for high-entropy tokens), compared in constant time.
23
+ */
24
+ export declare const GRANT_TOKEN_PREFIX = "adg";
25
+ /** Current verifier version. Bump when the hash construction changes. */
26
+ export declare const GRANT_VERIFIER_VERSION = "v1";
27
+ /** Single-installation owner principal for V1. */
28
+ export declare const OWNER_INSTALLATION_ID = "owner";
29
+ /** Unified authorization principal for one MCP session. */
30
+ export type ClientPrincipal = {
31
+ kind: 'local';
32
+ } | {
33
+ kind: 'grant';
34
+ grantId: string;
35
+ label: string;
36
+ defaultDeck: string;
37
+ allowedDecks: string[];
38
+ };
39
+ /** Persisted grant row (never carries the bearer secret). */
40
+ export type ClientGrant = {
41
+ id: string;
42
+ label: string;
43
+ verifierVersion: string;
44
+ defaultDeck: string;
45
+ allowedDecks: string[];
46
+ installationId: string;
47
+ createdAt: string;
48
+ expiresAt: string | null;
49
+ revokedAt: string | null;
50
+ lastUsedAt: string | null;
51
+ };
52
+ /** Owner-visible grant view: ids and labels only, never verifiers. */
53
+ export type ClientGrantPublic = Omit<ClientGrant, never>;
54
+ /** Result of issuing a grant — the only moment the secret exists. */
55
+ export type IssuedGrant = {
56
+ grant: ClientGrantPublic;
57
+ /** Full bearer value `adg_<id>_<secret>`. Display once, then drop. */
58
+ token: string;
59
+ };
60
+ export declare function parseGrantToken(token: string): {
61
+ grantId: string;
62
+ secret: string;
63
+ } | null;
64
+ /** True when the principal may serve `deckId`. Local sessions are unconstrained. */
65
+ export declare function principalAllowsDeck(principal: ClientPrincipal, deckId: string): boolean;
66
+ /**
67
+ * Resolve the effective deck for an authenticated grant: no requested deck
68
+ * applies the grant default; a requested deck must sit inside the allowlist
69
+ * (null = denied, never fall back — a forged header must not silently
70
+ * land on the default).
71
+ */
72
+ export declare function resolveGrantDeck(principal: Extract<ClientPrincipal, {
73
+ kind: 'grant';
74
+ }>, requestedDeckId?: string): string | null;
75
+ export type IssueGrantInput = {
76
+ label: string;
77
+ defaultDeck: string;
78
+ allowedDecks?: string[];
79
+ expiresAt?: string | null;
80
+ installationId?: string;
81
+ };
82
+ export declare class ClientGrantStore {
83
+ private readonly db;
84
+ private readonly installationId;
85
+ constructor(db: Database.Database, installationId?: string);
86
+ private ensureTables;
87
+ /**
88
+ * Issue a grant and its bearer secret. The returned token is the only
89
+ * copy of the secret — persist nothing but the versioned verifier.
90
+ */
91
+ issueGrant(input: IssueGrantInput): IssuedGrant;
92
+ getGrant(id: string): ClientGrantPublic | null;
93
+ listGrants(): ClientGrantPublic[];
94
+ /**
95
+ * Authenticate a bearer token. Returns the grant principal on success,
96
+ * null for every failure mode (unknown id, secret mismatch, expired,
97
+ * revoked) — callers map all of them to one uniform 401 with no oracle.
98
+ * Touches `last_used_at` on success only.
99
+ */
100
+ authenticateToken(token: string): Extract<ClientPrincipal, {
101
+ kind: 'grant';
102
+ }> | null;
103
+ /**
104
+ * Revoke a grant. There is no un-revoke: a re-issued grant for the same
105
+ * agent is a new id with a new secret. Returns false when unknown.
106
+ */
107
+ revokeGrant(id: string): boolean;
108
+ }
109
+ //# sourceMappingURL=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 Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientGrantStore = exports.OWNER_INSTALLATION_ID = exports.GRANT_VERIFIER_VERSION = exports.GRANT_TOKEN_PREFIX = void 0;
4
+ exports.parseGrantToken = parseGrantToken;
5
+ exports.principalAllowsDeck = principalAllowsDeck;
6
+ exports.resolveGrantDeck = resolveGrantDeck;
7
+ const node_crypto_1 = require("node:crypto");
8
+ /**
9
+ * NOT-318: per-agent remote grants for the single-owner hosted appliance.
10
+ *
11
+ * Two boundaries live here:
12
+ *
13
+ * - `ClientPrincipal` — the unified authorization principal every MCP
14
+ * session resolves to. Loopback launcher sessions resolve to `local`
15
+ * (unconstrained, exactly as today); remote bearer sessions resolve to
16
+ * `grant` (constrained by the grant allowlist). Both flow through the
17
+ * same deck-scope check (`principalAllowsDeck`), so the deck header can
18
+ * never authorize beyond the principal.
19
+ * - `ClientGrantStore` — SQLite-backed grant metadata. V1 is one
20
+ * installation and one owner (`installationId` defaults to `'owner'`);
21
+ * the field exists so a future tenancy migration has something to
22
+ * partition on.
23
+ *
24
+ * Token format: `adg_<grantId>_<secret>` where `<secret>` carries 256
25
+ * bits of CSPRNG entropy (32 bytes, base64url). The id prefix is
26
+ * routing-only — it confers nothing by itself. The secret is shown once
27
+ * at issuance; only a versioned SHA-256 verifier is persisted (suitable
28
+ * for high-entropy tokens), compared in constant time.
29
+ */
30
+ exports.GRANT_TOKEN_PREFIX = 'adg';
31
+ /** Current verifier version. Bump when the hash construction changes. */
32
+ exports.GRANT_VERIFIER_VERSION = 'v1';
33
+ /** Single-installation owner principal for V1. */
34
+ exports.OWNER_INSTALLATION_ID = 'owner';
35
+ function nowIso() {
36
+ return new Date().toISOString();
37
+ }
38
+ function hashSecret(secret) {
39
+ return (0, node_crypto_1.createHash)('sha256').update(secret, 'utf8').digest('hex');
40
+ }
41
+ /**
42
+ * Parse `adg_<grantId>_<secret>`. Returns null for anything else —
43
+ * malformed input is indistinguishable from an unknown grant upstream.
44
+ *
45
+ * The split is anchored on the grant-id shape (`ag_<uuid>`), not on a
46
+ * bare `_`: issued secrets are base64url and may themselves contain `_`,
47
+ * so first- or last-underscore splitting misroutes roughly half of all
48
+ * tokens. `issueGrant` is the only id minter, so the shape is closed.
49
+ */
50
+ const GRANT_TOKEN_PATTERN = /^adg_(ag_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})_(\S+)$/;
51
+ function parseGrantToken(token) {
52
+ if (typeof token !== 'string') {
53
+ return null;
54
+ }
55
+ const match = GRANT_TOKEN_PATTERN.exec(token.trim());
56
+ if (!match) {
57
+ return null;
58
+ }
59
+ return { grantId: match[1], secret: match[2] };
60
+ }
61
+ /** True when the principal may serve `deckId`. Local sessions are unconstrained. */
62
+ function principalAllowsDeck(principal, deckId) {
63
+ if (principal.kind === 'local') {
64
+ return true;
65
+ }
66
+ return principal.allowedDecks.includes(deckId);
67
+ }
68
+ /**
69
+ * Resolve the effective deck for an authenticated grant: no requested deck
70
+ * applies the grant default; a requested deck must sit inside the allowlist
71
+ * (null = denied, never fall back — a forged header must not silently
72
+ * land on the default).
73
+ */
74
+ function resolveGrantDeck(principal, requestedDeckId) {
75
+ const requested = requestedDeckId?.trim();
76
+ if (!requested) {
77
+ return principal.defaultDeck;
78
+ }
79
+ return principal.allowedDecks.includes(requested) ? requested : null;
80
+ }
81
+ class ClientGrantStore {
82
+ db;
83
+ installationId;
84
+ constructor(db, installationId = exports.OWNER_INSTALLATION_ID) {
85
+ this.db = db;
86
+ this.installationId = installationId;
87
+ this.ensureTables();
88
+ }
89
+ ensureTables() {
90
+ this.db.exec(`
91
+ CREATE TABLE IF NOT EXISTS agent_grants (
92
+ id TEXT PRIMARY KEY,
93
+ label TEXT NOT NULL,
94
+ verifier_version TEXT NOT NULL,
95
+ secret_hash TEXT NOT NULL,
96
+ default_deck TEXT NOT NULL,
97
+ allowed_decks TEXT NOT NULL,
98
+ installation_id TEXT NOT NULL,
99
+ created_at TEXT NOT NULL,
100
+ expires_at TEXT,
101
+ revoked_at TEXT,
102
+ last_used_at TEXT
103
+ );
104
+ CREATE INDEX IF NOT EXISTS agent_grants_installation_idx
105
+ ON agent_grants (installation_id);
106
+ `);
107
+ }
108
+ /**
109
+ * Issue a grant and its bearer secret. The returned token is the only
110
+ * copy of the secret — persist nothing but the versioned verifier.
111
+ */
112
+ issueGrant(input) {
113
+ const label = input.label?.trim();
114
+ if (!label) {
115
+ throw new Error('label required');
116
+ }
117
+ const defaultDeck = input.defaultDeck?.trim();
118
+ if (!defaultDeck) {
119
+ throw new Error('defaultDeck required');
120
+ }
121
+ const allowed = [...new Set((input.allowedDecks ?? [defaultDeck]).map((d) => d.trim()).filter(Boolean))];
122
+ if (!allowed.includes(defaultDeck)) {
123
+ allowed.push(defaultDeck);
124
+ }
125
+ if (input.expiresAt !== undefined && input.expiresAt !== null) {
126
+ const ms = Date.parse(input.expiresAt);
127
+ if (!Number.isFinite(ms)) {
128
+ throw new Error('expiresAt must be an ISO timestamp');
129
+ }
130
+ }
131
+ const id = `ag_${(0, node_crypto_1.randomUUID)()}`;
132
+ const secret = (0, node_crypto_1.randomBytes)(32).toString('base64url');
133
+ const createdAt = nowIso();
134
+ this.db
135
+ .prepare(`INSERT INTO agent_grants
136
+ (id, label, verifier_version, secret_hash, default_deck, allowed_decks,
137
+ installation_id, created_at, expires_at, revoked_at, last_used_at)
138
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL)`)
139
+ .run(id, label, exports.GRANT_VERIFIER_VERSION, hashSecret(secret), defaultDeck, JSON.stringify(allowed), input.installationId ?? this.installationId, createdAt, input.expiresAt ?? null);
140
+ return {
141
+ grant: this.getGrant(id),
142
+ token: `${exports.GRANT_TOKEN_PREFIX}_${id}_${secret}`,
143
+ };
144
+ }
145
+ getGrant(id) {
146
+ const row = this.db
147
+ .prepare(`SELECT id, label, verifier_version, secret_hash, default_deck, allowed_decks,
148
+ installation_id, created_at, expires_at, revoked_at, last_used_at
149
+ FROM agent_grants WHERE id = ?`)
150
+ .get(id);
151
+ return row ? toPublicGrant(row) : null;
152
+ }
153
+ listGrants() {
154
+ const rows = this.db
155
+ .prepare(`SELECT id, label, verifier_version, secret_hash, default_deck, allowed_decks,
156
+ installation_id, created_at, expires_at, revoked_at, last_used_at
157
+ FROM agent_grants ORDER BY created_at ASC`)
158
+ .all();
159
+ return rows.map(toPublicGrant);
160
+ }
161
+ /**
162
+ * Authenticate a bearer token. Returns the grant principal on success,
163
+ * null for every failure mode (unknown id, secret mismatch, expired,
164
+ * revoked) — callers map all of them to one uniform 401 with no oracle.
165
+ * Touches `last_used_at` on success only.
166
+ */
167
+ authenticateToken(token) {
168
+ const parsed = parseGrantToken(token);
169
+ if (!parsed) {
170
+ // Same-cost dummy comparison so malformed input is not measurably
171
+ // cheaper than a secret mismatch.
172
+ dummyCompare();
173
+ return null;
174
+ }
175
+ const row = this.db
176
+ .prepare(`SELECT id, label, verifier_version, secret_hash, default_deck, allowed_decks,
177
+ installation_id, created_at, expires_at, revoked_at, last_used_at
178
+ FROM agent_grants WHERE id = ?`)
179
+ .get(parsed.grantId);
180
+ if (!row) {
181
+ dummyCompare();
182
+ return null;
183
+ }
184
+ if (!verifierMatches(parsed.secret, row.secret_hash)) {
185
+ return null;
186
+ }
187
+ if (row.revoked_at) {
188
+ return null;
189
+ }
190
+ if (row.expires_at && Date.parse(row.expires_at) <= Date.now()) {
191
+ return null;
192
+ }
193
+ this.db
194
+ .prepare(`UPDATE agent_grants SET last_used_at = ? WHERE id = ?`)
195
+ .run(nowIso(), row.id);
196
+ return {
197
+ kind: 'grant',
198
+ grantId: row.id,
199
+ label: row.label,
200
+ defaultDeck: row.default_deck,
201
+ allowedDecks: parseAllowedDecks(row.allowed_decks),
202
+ };
203
+ }
204
+ /**
205
+ * Revoke a grant. There is no un-revoke: a re-issued grant for the same
206
+ * agent is a new id with a new secret. Returns false when unknown.
207
+ */
208
+ revokeGrant(id) {
209
+ const result = this.db
210
+ .prepare(`UPDATE agent_grants SET revoked_at = ? WHERE id = ? AND revoked_at IS NULL`)
211
+ .run(nowIso(), id);
212
+ return result.changes > 0;
213
+ }
214
+ }
215
+ exports.ClientGrantStore = ClientGrantStore;
216
+ function toPublicGrant(row) {
217
+ return {
218
+ id: row.id,
219
+ label: row.label,
220
+ verifierVersion: row.verifier_version,
221
+ defaultDeck: row.default_deck,
222
+ allowedDecks: parseAllowedDecks(row.allowed_decks),
223
+ installationId: row.installation_id,
224
+ createdAt: row.created_at,
225
+ expiresAt: row.expires_at,
226
+ revokedAt: row.revoked_at,
227
+ lastUsedAt: row.last_used_at,
228
+ };
229
+ }
230
+ function parseAllowedDecks(raw) {
231
+ try {
232
+ const parsed = JSON.parse(raw);
233
+ return Array.isArray(parsed) ? parsed.filter((d) => typeof d === 'string') : [];
234
+ }
235
+ catch {
236
+ return [];
237
+ }
238
+ }
239
+ /** Constant-time comparison of the presented secret against the stored verifier. */
240
+ function verifierMatches(secret, storedHex) {
241
+ let presented;
242
+ let stored;
243
+ try {
244
+ presented = Buffer.from(hashSecret(secret), 'hex');
245
+ stored = Buffer.from(storedHex, 'hex');
246
+ }
247
+ catch {
248
+ return false;
249
+ }
250
+ if (presented.length !== stored.length) {
251
+ return false;
252
+ }
253
+ return (0, node_crypto_1.timingSafeEqual)(presented, stored);
254
+ }
255
+ /** Burn comparable time when there is nothing to compare against (unknown id / malformed). */
256
+ function dummyCompare() {
257
+ const a = Buffer.from(hashSecret('agent-deck-grant-dummy'), 'hex');
258
+ const b = Buffer.from(hashSecret('agent-deck-grant-dummy-other'), 'hex');
259
+ (0, node_crypto_1.timingSafeEqual)(a, b);
260
+ }
261
+ //# sourceMappingURL=client-grants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-grants.js","sourceRoot":"","sources":["../../src/auth/client-grants.ts"],"names":[],"mappings":";;;AAqGA,0CASC;AAGD,kDAKC;AAQD,4CASC;AAvID,6CAAmF;AAInF;;;;;;;;;;;;;;;;;;;;;G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AAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;QACnD,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAA,6BAAe,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED,8FAA8F;AAC9F,SAAS,YAAY;IACnB,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,wBAAwB,CAAC,EAAE,KAAK,CAAC,CAAC;IACnE,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,8BAA8B,CAAC,EAAE,KAAK,CAAC,CAAC;IACzE,IAAA,6BAAe,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACxB,CAAC"}
@@ -1,5 +1,35 @@
1
1
  import express from 'express';
2
+ import { ClientGrantStore } from './auth/client-grants';
2
3
  import { McpToolProfile } from './mcp-tools/profile';
4
+ /**
5
+ * NOT-318: hosted-mode flag. When `AGENT_DECK_MCP_REQUIRE_BEARER=1`, every
6
+ * `/mcp` request requires a valid per-agent grant secret, regardless of
7
+ * peer address. Peer-address detection is explicitly rejected as the
8
+ * trigger (TLS-terminating proxies forward internet traffic over
9
+ * loopback), and `X-Forwarded-*` headers are never trusted for auth.
10
+ * The local launcher never sets this flag, so loopback sessions stay
11
+ * bearer-free with zero config change.
12
+ */
13
+ export declare const MCP_REQUIRE_BEARER_ENV_VAR = "AGENT_DECK_MCP_REQUIRE_BEARER";
14
+ export declare function isBearerGrantRequired(raw?: string | undefined): boolean;
15
+ /**
16
+ * NOT-309: keep-alive touch cadence for idle-but-connected MCP sessions.
17
+ * Every MCP tool call already bumps `lastActivityAt` (debounced POST touch),
18
+ * but a session with an open transport and no tool calls sends no HTTP POSTs
19
+ * (the SSE stream is a GET), so without a keep-alive it would expire out of
20
+ * the live-display registry while still connected. Override via
21
+ * `AGENT_DECK_MCP_LIVE_TOUCH_KEEPALIVE_MS` (`0` disables); the default is
22
+ * also clamped under a third of the stale bound so a shortened
23
+ * `LIVE_DISPLAY_STALE_MS` never outruns it.
24
+ *
25
+ * Both processes must see the same `LIVE_DISPLAY_STALE_MS`: the MCP server
26
+ * runs separately (mcp-index) and resolves the bound from its own
27
+ * environment, so shortening it only on the backend leaves the keep-alive
28
+ * at 5 minutes and idle sessions expire. Export it for both processes.
29
+ */
30
+ export declare const DEFAULT_LIVE_TOUCH_KEEPALIVE_MS: number;
31
+ export declare const LIVE_TOUCH_KEEPALIVE_ENV_VAR = "AGENT_DECK_MCP_LIVE_TOUCH_KEEPALIVE_MS";
32
+ export declare function resolveLiveTouchKeepAliveMs(raw: string | undefined, staleMs: number): number;
3
33
  export declare class AgentDeckMCPServer {
4
34
  /** Cap on remembered stale session ids — the tally is diagnostics, not a ledger. */
5
35
  private static readonly STALE_SESSION_SAMPLE_LIMIT;
@@ -17,6 +47,8 @@ export declare class AgentDeckMCPServer {
17
47
  /** Session badge from the backend registry (POST /api/scope/live-display response). */
18
48
  private badgeBySession;
19
49
  private lastTouchAtMs;
50
+ /** NOT-309: keep-alive timer proving idle-but-connected sessions still live. */
51
+ private liveTouchKeepAliveTimer;
20
52
  /** In-flight live-display unregisters so `stop()` can drain them before closing. */
21
53
  private unregisterTasks;
22
54
  /** Changes on every process start — how a client detects it outlived the server. */
@@ -36,7 +68,27 @@ export declare class AgentDeckMCPServer {
36
68
  private staleSessionLastAt;
37
69
  private staleSessionLastId;
38
70
  private get server();
39
- constructor(port?: number, backendUrl?: string, toolProfile?: McpToolProfile, host?: string);
71
+ /** Injected grant store (tests). `undefined` means "resolve lazily". */
72
+ private grantStoreOverride;
73
+ /** Lazily opened grant store for hosted mode (shared backend database file). */
74
+ private grantStoreCache;
75
+ constructor(port?: number, backendUrl?: string, toolProfile?: McpToolProfile, host?: string, options?: {
76
+ grantStore?: ClientGrantStore | null;
77
+ });
78
+ /**
79
+ * NOT-318: grant metadata store. An injected store (tests) wins; otherwise
80
+ * the shared backend database file is opened lazily — only when a bearer
81
+ * is presented or hosted mode requires one, so loopback-only processes
82
+ * and existing tests never touch the database file.
83
+ */
84
+ private getGrantStore;
85
+ /**
86
+ * NOT-318: authenticate one bearer token to a grant principal. Every
87
+ * failure mode (missing store, malformed, unknown id, secret mismatch,
88
+ * expired, revoked) returns null — the caller answers one uniform 401
89
+ * with no oracle. Touches `lastUsedAt`; never logs or returns the secret.
90
+ */
91
+ private authenticateGrant;
40
92
  /** Actual listening port (resolves OS-assigned `port: 0` after `start()`). */
41
93
  getPort(): number;
42
94
  /**
@@ -48,11 +100,32 @@ export declare class AgentDeckMCPServer {
48
100
  private buildBindingPayload;
49
101
  private registerLiveDisplay;
50
102
  private static readonly TOUCH_DEBOUNCE_MS;
51
- /** Fire-and-forget lastActivityAt bump; only for sessions the registry knows. */
103
+ /**
104
+ * Fire-and-forget lastActivityAt bump; only for sessions this process
105
+ * registered (badge-holding). `force` bypasses the per-request debounce —
106
+ * the keep-alive already runs on a minutes-long cadence, so debouncing it
107
+ * would only delay proof of life.
108
+ *
109
+ * NOT-309 repair round 2: when the backend reports `found: false` the
110
+ * entry was swept while this transport stayed open (host sleep longer
111
+ * than the stale bound, then a status-line read on wake). Re-register so
112
+ * the live session returns to the status line without a reconnect. An
113
+ * explicit `found === false` is required — older backends answer `{}` and
114
+ * must not trigger a re-register storm.
115
+ */
52
116
  private touchLiveDisplay;
53
117
  private static readonly UNREGISTER_TIMEOUT_MS;
54
118
  /** Override via AGENT_DECK_MCP_UNREGISTER_TIMEOUT_MS (tests use a short value). */
55
119
  private static unregisterTimeoutMs;
120
+ /**
121
+ * NOT-309: keep the registry fresh for sessions with an open transport but
122
+ * no tool calls. Only badge-holding (registered) sessions are touched; the
123
+ * backend ignores touches for sessions it never saw, so unassigned or
124
+ * half-initialized sessions are harmless no-ops by construction.
125
+ */
126
+ private touchAllLiveDisplays;
127
+ private startLiveDisplayKeepAlive;
128
+ private stopLiveDisplayKeepAlive;
56
129
  private unregisterLiveDisplay;
57
130
  private callBackendAPI;
58
131
  private getBoundDeckId;
@@ -93,6 +166,40 @@ export declare class AgentDeckMCPServer {
93
166
  private rememberClosedSession;
94
167
  private refreshRuntimeSession;
95
168
  private sendDeckRequired;
169
+ /**
170
+ * NOT-318: the single 401 envelope for every credential failure on a
171
+ * hosted endpoint (missing / malformed / invalid / expired / revoked).
172
+ * Byte-identical every time — including the constant `WWW-Authenticate:
173
+ * Bearer` challenge — so probers learn nothing, and generic HTTP
174
+ * clients stay well-behaved. Never carries grant state or deck detail.
175
+ */
176
+ private sendGrantRequired;
177
+ /**
178
+ * NOT-318: authenticated but outside the grant allowlist. Only reachable
179
+ * post-auth, so it oracles the allowlist solely to the already-
180
+ * authenticated owner. Transport kept.
181
+ */
182
+ private sendOutOfScope;
183
+ /**
184
+ * NOT-318: bind a fresh MCP session to an authenticated grant principal.
185
+ * Mirrors `authenticateLaunchDeck` (workspace + correlation handling) but
186
+ * resolves through the grant: the deck was already constrained by
187
+ * `resolveGrantDeck`, and the owning grant id is linked on the runtime
188
+ * session so deck-switch creation/approval enforces the same allowlist.
189
+ */
190
+ private authenticateGrantDeck;
191
+ /**
192
+ * NOT-318: revalidate a grant-bound session on every follow-up request.
193
+ * The grant (not a cached decision) is re-resolved per request, so
194
+ * revocation and expiry fail the *next* request closed — no grace
195
+ * window, strictly inside the 60s bound. The deck header is
196
+ * request-only: a header outside the allowlist is denied with 403 and
197
+ * the binding is left untouched; a header for another allowed deck is
198
+ * ignored (deck changes go through human-approved switch_deck, which
199
+ * re-checks the same allowlist). Transport kept on every denial so a
200
+ * correct credential on the next attempt can succeed.
201
+ */
202
+ private requireGrantFollowUp;
96
203
  private authenticateLaunchDeck;
97
204
  private disconnectTrustedSession;
98
205
  /**
@@ -104,7 +211,22 @@ export declare class AgentDeckMCPServer {
104
211
  */
105
212
  private requireFollowUpDeckHeader;
106
213
  private sendLaunchDeckInvalid;
214
+ /**
215
+ * NOT-318: initialize with a bearer grant. Authenticates before
216
+ * advertising any `mcp-session-id`: failure answers the uniform 401
217
+ * with no transport or session record created. Success binds the fresh
218
+ * session to the grant-constrained deck (absent header → default;
219
+ * out-of-grant header → 403, no session).
220
+ */
221
+ private handleGrantInitialize;
107
222
  private handleMcpPost;
223
+ /**
224
+ * Shared transport handshake tail: create the per-session MCP server,
225
+ * connect the streamable transport, and register the live session. Runs
226
+ * only after the session is authenticated and bound (launch, grant, or
227
+ * unassigned) — never before.
228
+ */
229
+ private establishTransportSession;
108
230
  private handleMcpSessionRequest;
109
231
  start(): Promise<express.Application>;
110
232
  stop(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAWA,OAAO,OAA8B,MAAM,SAAS,CAAC;AAgBrD,OAAO,EAAE,cAAc,EAAyB,MAAM,qBAAqB,CAAC;AAuD5E,qBAAa,kBAAkB;IAC7B,oFAAoF;IACpF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,0BAA0B,CAAO;IAEzD,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,GAAG,CAAsB;IACjC,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAiB;IACpC,OAAO,CAAC,QAAQ,CAAiC;IACjD,mFAAmF;IACnF,OAAO,CAAC,wBAAwB,CAAwB;IACxD,mFAAmF;IACnF,OAAO,CAAC,cAAc,CAAyB;IAC/C,uFAAuF;IACvF,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,aAAa,CAA6B;IAClD,oFAAoF;IACpF,OAAO,CAAC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