@astrasyncai/verification-gateway 5.4.0 → 5.4.2

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 (133) hide show
  1. package/dist/adapter-interface/interface.d.mts +2 -3
  2. package/dist/adapter-interface/interface.d.ts +2 -3
  3. package/dist/adapters/express.d.mts +63 -4
  4. package/dist/adapters/express.d.ts +63 -4
  5. package/dist/adapters/express.js +9 -2
  6. package/dist/adapters/express.js.map +1 -1
  7. package/dist/adapters/express.mjs +9 -2
  8. package/dist/adapters/express.mjs.map +1 -1
  9. package/dist/adapters/mcp.d.mts +396 -4
  10. package/dist/adapters/mcp.d.ts +396 -4
  11. package/dist/adapters/mcp.js +9 -2
  12. package/dist/adapters/mcp.js.map +1 -1
  13. package/dist/adapters/mcp.mjs +9 -2
  14. package/dist/adapters/mcp.mjs.map +1 -1
  15. package/dist/adapters/nextjs.d.mts +22 -4
  16. package/dist/adapters/nextjs.d.ts +22 -4
  17. package/dist/adapters/nextjs.js +9 -2
  18. package/dist/adapters/nextjs.js.map +1 -1
  19. package/dist/adapters/nextjs.mjs +9 -2
  20. package/dist/adapters/nextjs.mjs.map +1 -1
  21. package/dist/adapters/sdk.d.mts +157 -3
  22. package/dist/adapters/sdk.d.ts +157 -3
  23. package/dist/adapters/sdk.js +35 -15
  24. package/dist/adapters/sdk.js.map +1 -1
  25. package/dist/adapters/sdk.mjs +35 -15
  26. package/dist/adapters/sdk.mjs.map +1 -1
  27. package/dist/agent/index.d.mts +224 -3
  28. package/dist/agent/index.d.ts +224 -3
  29. package/dist/agent/index.js +1 -1
  30. package/dist/agent/index.js.map +1 -1
  31. package/dist/agent/index.mjs +1 -1
  32. package/dist/agent/index.mjs.map +1 -1
  33. package/dist/bin/astrasync-claude-hook.js +9 -2
  34. package/dist/bin/astrasync-codex-hook.js +9 -2
  35. package/dist/bin/astrasync-guard.js +9 -2
  36. package/dist/bin/astrasync.js +9 -2
  37. package/dist/browser/background.js +9 -2
  38. package/dist/browser/background.js.map +1 -1
  39. package/dist/browser/background.mjs +9 -2
  40. package/dist/browser/background.mjs.map +1 -1
  41. package/dist/browser/browser-adapter.d.mts +1 -5
  42. package/dist/browser/browser-adapter.d.ts +1 -5
  43. package/dist/claude-code/claude-code-adapter.d.mts +1 -5
  44. package/dist/claude-code/claude-code-adapter.d.ts +1 -5
  45. package/dist/cli/index.d.mts +1 -5
  46. package/dist/cli/index.d.ts +1 -5
  47. package/dist/cli/index.js +1 -1
  48. package/dist/cli/index.js.map +1 -1
  49. package/dist/cli/index.mjs +1 -1
  50. package/dist/cli/index.mjs.map +1 -1
  51. package/dist/codex/index.d.mts +1 -5
  52. package/dist/codex/index.d.ts +1 -5
  53. package/dist/codex/index.js +9 -2
  54. package/dist/codex/index.js.map +1 -1
  55. package/dist/codex/index.mjs +9 -2
  56. package/dist/codex/index.mjs.map +1 -1
  57. package/dist/cursor/cursor-adapter.d.mts +1 -5
  58. package/dist/cursor/cursor-adapter.d.ts +1 -5
  59. package/dist/cursor/extension.d.mts +1 -5
  60. package/dist/cursor/extension.d.ts +1 -5
  61. package/dist/cursor/extension.js +9 -2
  62. package/dist/cursor/extension.js.map +1 -1
  63. package/dist/cursor/extension.mjs +9 -2
  64. package/dist/cursor/extension.mjs.map +1 -1
  65. package/dist/edge-config.d.mts +1 -1
  66. package/dist/edge-config.d.ts +1 -1
  67. package/dist/edge-config.js +1 -1
  68. package/dist/edge-config.js.map +1 -1
  69. package/dist/edge-config.mjs +1 -1
  70. package/dist/edge-config.mjs.map +1 -1
  71. package/dist/edge-core/index.d.mts +1 -1
  72. package/dist/edge-core/index.d.ts +1 -1
  73. package/dist/edge-core/index.js +9 -2
  74. package/dist/edge-core/index.js.map +1 -1
  75. package/dist/edge-core/index.mjs +9 -2
  76. package/dist/edge-core/index.mjs.map +1 -1
  77. package/dist/gateway/gateway.d.mts +2 -3
  78. package/dist/gateway/gateway.d.ts +2 -3
  79. package/dist/gateway/gateway.js +9 -2
  80. package/dist/gateway/gateway.js.map +1 -1
  81. package/dist/gateway/gateway.mjs +9 -2
  82. package/dist/gateway/gateway.mjs.map +1 -1
  83. package/dist/git-trigger/git-hooks.d.mts +253 -3
  84. package/dist/git-trigger/git-hooks.d.ts +253 -3
  85. package/dist/index.d.mts +4506 -42
  86. package/dist/index.d.ts +4506 -42
  87. package/dist/index.js +35 -15
  88. package/dist/index.js.map +1 -1
  89. package/dist/index.mjs +35 -15
  90. package/dist/index.mjs.map +1 -1
  91. package/dist/interface-q1WrMsB1.d.mts +365 -0
  92. package/dist/interface-q1WrMsB1.d.ts +365 -0
  93. package/dist/local-evaluator/evaluator.d.mts +2 -3
  94. package/dist/local-evaluator/evaluator.d.ts +2 -3
  95. package/dist/registration/index.js +1 -1
  96. package/dist/registration/index.js.map +1 -1
  97. package/dist/registration/index.mjs +1 -1
  98. package/dist/registration/index.mjs.map +1 -1
  99. package/dist/transport/index.d.mts +1324 -4
  100. package/dist/transport/index.d.ts +1324 -4
  101. package/dist/transport/index.js +1 -1
  102. package/dist/transport/index.js.map +1 -1
  103. package/dist/transport/index.mjs +1 -1
  104. package/dist/transport/index.mjs.map +1 -1
  105. package/dist/{types-DGh2akuh.d.ts → types-BRz2U0Pn.d.ts} +2 -2
  106. package/dist/{types-76TB0fxW.d.ts → types-BU04qAAR.d.mts} +59 -213
  107. package/dist/{types-CD1F9fmp.d.mts → types-BU04qAAR.d.ts} +59 -213
  108. package/dist/types-Bd2O3eX1.d.mts +769 -0
  109. package/dist/types-BfILnheI.d.mts +189 -0
  110. package/dist/types-BfILnheI.d.ts +189 -0
  111. package/dist/{types-z_RNjHWm.d.mts → types-CfBpm3w5.d.mts} +2 -2
  112. package/dist/types-DMChboN_.d.ts +769 -0
  113. package/dist/ui/index.d.mts +1 -2
  114. package/dist/ui/index.d.ts +1 -2
  115. package/dist/verify.d.mts +1 -1
  116. package/dist/verify.d.ts +1 -1
  117. package/dist/verify.js +9 -2
  118. package/dist/verify.js.map +1 -1
  119. package/dist/verify.mjs +9 -2
  120. package/dist/verify.mjs.map +1 -1
  121. package/package.json +1 -1
  122. package/dist/express-BIAT2pe0.d.mts +0 -69
  123. package/dist/express-D3Tf-b23.d.ts +0 -69
  124. package/dist/index-BVJkTyIF.d.mts +0 -248
  125. package/dist/index-By021oSN.d.mts +0 -1469
  126. package/dist/index-DaMXZabg.d.ts +0 -248
  127. package/dist/index-iJ9_DdLk.d.ts +0 -1469
  128. package/dist/mcp-BqfTDZLh.d.mts +0 -397
  129. package/dist/mcp-OrVOrH-s.d.ts +0 -397
  130. package/dist/nextjs-DGJXzWst.d.mts +0 -28
  131. package/dist/nextjs-xM-jdNrX.d.ts +0 -28
  132. package/dist/sdk-C1IOA5LE.d.ts +0 -173
  133. package/dist/sdk-C6_-6D-9.d.mts +0 -173
@@ -1,4 +1,396 @@
1
- import 'express';
2
- import '../types-76TB0fxW.js';
3
- export { M as MCP_VERIFIED_HOP_HEADER, b as McpMiddlewareOptions, P as ParsedMcpRequest, T as ToolGate, c as ToolGateConfig, d as createMcpMiddleware, i as isVerifiedHopValidFor, m as mcpDefaultEnforced, e as mcpToPdlss, p as parseMcpJsonRpc, f as parseVerifiedHop, s as serializeVerifiedHop } from '../mcp-OrVOrH-s.js';
4
- import '../metadata-capture.js';
1
+ import { Request, Response, RequestHandler } from 'express';
2
+ import { d as VerificationResult, G as GatewayConfig } from '../types-BU04qAAR.js';
3
+
4
+ /**
5
+ * X-Astra-Verified-Hop — cross-hop verify-access dedupe marker.
6
+ *
7
+ * Header carrying upstream verify-access proof so an inner-hop endpoint can
8
+ * dedupe (skip verify-access when the same ASTRA-id was already verified a
9
+ * few ms earlier). Emitted by the MCP adapter toward tool fetches and by the
10
+ * edge gateway toward the origin at authenticate/authorize depth. Value
11
+ * format:
12
+ *
13
+ * {astraId};{sessionId};{checkedAt-ms}
14
+ *
15
+ * Receivers MUST validate that `checkedAt` is recent (≤ 60s window
16
+ * recommended) and that `astraId` matches the agent identity claimed on the
17
+ * inner hop. The header alone is NOT proof-of-identity — it's an UNSIGNED
18
+ * dedupe advisory: trust it (`trustVerifiedHop`) only where every network
19
+ * path to the inner hop crosses a stripping gateway or an equivalent trusted
20
+ * boundary, exactly like the unsigned X-AstraSync-* attestation headers.
21
+ * Pair with the existing X-Astra-Id auth.
22
+ */
23
+ declare const MCP_VERIFIED_HOP_HEADER = "X-Astra-Verified-Hop";
24
+ interface VerifiedHopMarker {
25
+ astraId: string;
26
+ sessionId?: string;
27
+ checkedAt: number;
28
+ }
29
+ declare function serializeVerifiedHop(marker: VerifiedHopMarker): string;
30
+ declare function parseVerifiedHop(value: string | undefined | null): VerifiedHopMarker | null;
31
+ /**
32
+ * Returns true when `marker.astraId` matches the inner-hop's claimed
33
+ * ASTRA-id AND the marker is recent enough. Inner-hop middleware uses this
34
+ * to skip a duplicate verify-access call.
35
+ */
36
+ declare function isVerifiedHopValidFor(marker: VerifiedHopMarker | null, expectedAstraId: string, opts?: {
37
+ maxAgeMs?: number;
38
+ now?: number;
39
+ }): boolean;
40
+
41
+ /**
42
+ * MCP server-side helpers — companion to `transport/mcp.ts` (which handles the
43
+ * agent-side `_meta.astrasync` block).
44
+ *
45
+ * Surfaces a body-aware policy hook the existing `createMiddleware` couldn't
46
+ * provide — MCP traffic is JSON-RPC over a single endpoint (`/mcp`), so the
47
+ * default route-pattern gating is too coarse: every request looks the same
48
+ * URL-wise, but `initialize` is low-risk handshake while `tools/call` of a
49
+ * payment tool is high-risk. Cohort-3 beta merchants flagged this 🟡 in the
50
+ * v2.9.5 round.
51
+ *
52
+ * What lives here:
53
+ * - `parseMcpJsonRpc(body)` — peels JSON-RPC method + tool name + agent
54
+ * id without committing to a particular MCP
55
+ * server framework.
56
+ * - `mcpToPdlss(parsed)` — canonical mapping JSON-RPC method → PDLSS
57
+ * purpose / action / resource. Doc-stable
58
+ * so audits can correlate.
59
+ * - `mcpDefaultEnforced(parsed)` — whether a method is enforced by default
60
+ * so a single MCP middleware can split
61
+ * `initialize` / `tools/list` (pass-through)
62
+ * from `tools/call` (enforced).
63
+ * - `MCP_VERIFIED_HOP_HEADER` — header convention for the dedupe pattern
64
+ * when an MCP tool calls an inner REST hop.
65
+ * - `serialize/parseVerifiedHop` helpers.
66
+ *
67
+ * The Express MCP adapter is in `adapters/mcp.ts` and consumes these.
68
+ */
69
+
70
+ /**
71
+ * Output of `parseMcpJsonRpc`. Self-describing so the middleware doesn't have
72
+ * to re-introspect the body to figure out gating.
73
+ */
74
+ interface ParsedMcpRequest {
75
+ /** JSON-RPC method (e.g. `tools/call`, `initialize`, `tools/list`). */
76
+ method: string;
77
+ /** Set when method === 'tools/call'; the tool name from `params.name`. */
78
+ toolName?: string;
79
+ /** Initialize-specific protocolVersion handshake info, when present. */
80
+ protocolVersion?: string;
81
+ /**
82
+ * Agent id read from the body, in priority order:
83
+ * 1. `params._meta.astrasync.agentId` (the canonical SDK location, see
84
+ * `transport/mcp.ts → setMcpMeta`)
85
+ * 2. `params.arguments.agent_id` (legacy / hand-written tool callers)
86
+ * Header-supplied id (X-Astra-Id) is read separately by the adapter and
87
+ * compared to this for the mismatch check.
88
+ */
89
+ agentIdFromBody?: string;
90
+ /**
91
+ * Purpose extracted from the MCP body
92
+ * with the symmetric precedence chain. Sourced from `_meta.astrasync.purpose`
93
+ * (canonical SDK location) OR `params.arguments.purpose` (legacy /
94
+ * conventional callers). The discriminator is on `purposeSourceFromBody`.
95
+ * Adapter combines this with the `X-Astra-Purpose` header (header wins)
96
+ * before mapping; final fallback at `mcpToPdlss` is `undefined`.
97
+ */
98
+ purposeFromBody?: string;
99
+ /** Which body location resolved `purposeFromBody`. */
100
+ purposeSourceFromBody?: 'meta' | 'tool_argument';
101
+ /**
102
+ * Action extracted from the MCP body with the same
103
+ * symmetric chain as purpose. Sourced from `_meta.astrasync.action`
104
+ * (canonical) OR `params.arguments.action` (legacy). Adapter combines
105
+ * with the `X-Astra-Action` header (header wins) before mapping; final
106
+ * fallback at `mcpToPdlss` is the transport-layer default
107
+ * (`tools/call:<toolname>` or just `<method>`).
108
+ */
109
+ actionFromBody?: string;
110
+ /** Which body location resolved `actionFromBody`. */
111
+ actionSourceFromBody?: 'meta' | 'tool_argument';
112
+ /** True for handshake methods that must succeed before any tool call. */
113
+ isInitialize: boolean;
114
+ /** True for `tools/call`. */
115
+ isToolCall: boolean;
116
+ /** True for low-risk introspection (`tools/list`, `prompts/list`, etc.). */
117
+ isIntrospection: boolean;
118
+ }
119
+ /**
120
+ * Peel the JSON-RPC envelope. Returns `null` if the body isn't a JSON-RPC
121
+ * request (callers can short-circuit with a 400 or treat as untyped traffic).
122
+ *
123
+ * Accepts both single-request and notification shapes. Batch requests are
124
+ * NOT supported here — the verify-access contract is single-agent-per-call;
125
+ * a batch body should be split before policy gating.
126
+ */
127
+ declare function parseMcpJsonRpc(body: unknown): ParsedMcpRequest | null;
128
+ /**
129
+ * PDLSS mapping for an MCP request. The platform's PDLSS taxonomy is
130
+ * `purpose / action / resource`; for MCP traffic the audit-useful dimensions
131
+ * are the JSON-RPC method and (for `tools/call`) the tool name.
132
+ *
133
+ * v2.5.0 rules:
134
+ * - `resource` defaults to the HTTP request path (e.g. `/mcp`). Per-tool
135
+ * overrides via `toolGates` config let merchants map tools to specific
136
+ * backend resources (e.g. `/api/catalog`).
137
+ * - `purpose` defaults to `undefined` (backend evaluator applies
138
+ * skip-when-undefined). Per-tool overrides via `toolGates` config let
139
+ * merchants declare the semantic purpose each tool fulfils.
140
+ * - `action` comes only from declarations (toolGate config, header, or
141
+ * body). For `tools/call` with none declared it is `undefined` —
142
+ * evaluation is purpose-only, because a raw tool name is a transport
143
+ * token, not a PDLSS action, and sending it as one guarantees an
144
+ * action-policy mismatch. For other JSON-RPC methods the method string
145
+ * is used.
146
+ */
147
+ interface McpPdlssMapping {
148
+ purpose: string | undefined;
149
+ /**
150
+ * `undefined` when a `tools/call` request declared no action anywhere —
151
+ * the verify-access call then evaluates purpose-only. Tool names never
152
+ * travel as PDLSS actions.
153
+ */
154
+ action: string | undefined;
155
+ resource: string;
156
+ purposeSource: 'header' | 'meta' | 'tool_argument' | 'tool_gate' | undefined;
157
+ actionSource: 'header' | 'meta' | 'tool_argument' | 'tool_gate' | 'transport_layer' | undefined;
158
+ }
159
+ /**
160
+ * v2.5.0 — PDLSS field derivation for MCP requests.
161
+ *
162
+ * Purpose precedence:
163
+ * - If `toolGate.purpose` is provided, it is authoritative (header/body ignored).
164
+ * - Otherwise: header → body `_meta` → body `arguments` → `undefined`.
165
+ *
166
+ * Resource precedence:
167
+ * - `toolGate.resource` if provided, else `requestPath`.
168
+ *
169
+ * Action precedence (3.1.0 — toolGate override added for
170
+ * symmetry with purpose; 4.1.0 — the bare-tool-name fallback for
171
+ * `tools/call` was removed):
172
+ * - `toolGate.action` authoritative → header → body `_meta` → body
173
+ * `arguments` → then: `undefined` for `tools/call` (purpose-only
174
+ * evaluation — tool names are transport tokens, never PDLSS actions),
175
+ * or the JSON-RPC method string for other methods (transport_layer).
176
+ *
177
+ * @param requestPath The HTTP request path (e.g. '/mcp'). Required.
178
+ * @param toolGate Resolved per-tool config from `toolGates`, if present.
179
+ */
180
+ declare function mcpToPdlss(parsed: ParsedMcpRequest, requestPath: string, headerPurpose?: string, headerAction?: string, toolGate?: {
181
+ purpose?: string;
182
+ action?: string;
183
+ resource?: string;
184
+ }): McpPdlssMapping;
185
+ /**
186
+ * Whether a method is enforced (calls verify-access + gates on the server
187
+ * decision) by default. The MCP middleware uses this to split low-risk
188
+ * handshake / introspection traffic (pass-through) from high-risk tool
189
+ * execution (enforced). Per-tool / per-method overrides win over this default.
190
+ *
191
+ * - `initialize` / `notifications/initialized` → false (handshake must work for unregistered probes)
192
+ * - `tools/list` / `prompts/list` / `resources/list` → false (introspection is public-surface)
193
+ * - `ping` → false
194
+ * - `resources/read` → true
195
+ * - `tools/call` → true (default — overridable per-tool)
196
+ * - everything else → true (least-privilege fallback)
197
+ */
198
+ declare function mcpDefaultEnforced(parsed: ParsedMcpRequest): boolean;
199
+
200
+ /**
201
+ * AstraSync Universal Verification Gateway — MCP middleware
202
+ *
203
+ * Express-shaped middleware tailored to the JSON-RPC body of an MCP
204
+ * (Model Context Protocol) endpoint. Closes the cohort-3 gaps the default
205
+ * `createMiddleware` couldn't:
206
+ *
207
+ * (a) **Body-aware gating**. All MCP traffic targets the same `/mcp` URL.
208
+ * The default route-pattern matcher can't tell `initialize` (low risk)
209
+ * from `tools/call start_checkout` (high risk). This middleware peels
210
+ * the JSON-RPC body and applies a per-method risk tier.
211
+ *
212
+ * (b) **PDLSS mapping**. Derives purpose, action, and resource from
213
+ * `toolGates` config and request context. See `transport/mcp-server.ts`
214
+ * `mcpToPdlss()` for the exact mapping.
215
+ *
216
+ * (c) **Inner-hop dedupe**. Outbound responses set
217
+ * `X-Astra-Verified-Hop` so a downstream REST endpoint that the tool
218
+ * calls can skip a duplicate verify-access. The receiving REST
219
+ * middleware checks `parseVerifiedHop` and skips when valid.
220
+ *
221
+ * (d) **Header-vs-body identity precedence**. Reads ASTRA-id from
222
+ * `X-Astra-Id` first, body second. If both are present and disagree,
223
+ * returns a structured 400 by default (configurable). Pre-fix,
224
+ * integrators had to re-discover this on their own.
225
+ *
226
+ * Usage:
227
+ *
228
+ * ```typescript
229
+ * import express from 'express';
230
+ * import { createMcpMiddleware } from '@astrasyncai/verification-gateway/mcp';
231
+ *
232
+ * const app = express();
233
+ * app.use(express.json());
234
+ *
235
+ * app.post(
236
+ * '/mcp',
237
+ * createMcpMiddleware({
238
+ * apiBaseUrl: 'https://astrasync.ai/api',
239
+ * apiKey: process.env.ASTRASYNC_API_KEY,
240
+ * // Per-tool gates — `tools/call` is enforced by default; introspection /
241
+ * // handshake pass through. A gated tool needs a PDLSS purpose (and ideally
242
+ * // an action). Set a tool/method to `'observe'` to pass it through
243
+ * // unenforced (still evaluated when `evaluateAlwaysIfCredentialed`).
244
+ * toolGates: {
245
+ * browse_catalog: { purpose: 'shopping', action: 'shopping.search' },
246
+ * start_checkout: { purpose: 'shopping', action: 'shopping.purchase' },
247
+ * health_check: 'observe',
248
+ * },
249
+ * }),
250
+ * yourMcpServerHandler,
251
+ * );
252
+ * ```
253
+ */
254
+
255
+ declare global {
256
+ namespace Express {
257
+ interface Request {
258
+ mcpRequest?: ParsedMcpRequest;
259
+ agentVerification?: VerificationResult;
260
+ }
261
+ }
262
+ }
263
+ /**
264
+ * Extended per-tool gate with optional PDLSS purpose + action + resource
265
+ * overrides.
266
+ *
267
+ * When `purpose` is set, it is authoritative for that tool — the agent's
268
+ * `X-Astra-Purpose` header is ignored. This lets the merchant declare what
269
+ * semantic purpose each tool fulfils rather than trusting agent self-declaration.
270
+ *
271
+ * When `action` is set (symmetric with `purpose`), it is
272
+ * authoritative over `X-Astra-Action` / body declarations, letting the
273
+ * merchant pin a dotted-verb action (e.g. `shopping.search`) for a tool
274
+ * whose callers would otherwise leave the action undeclared (purpose-only
275
+ * evaluation — raw tool names never travel as PDLSS actions).
276
+ *
277
+ * When `resource` is set, it overrides the default (`req.path`) for that
278
+ * tool's verify-access call — e.g. mapping `list_products` to `/api/catalog`.
279
+ */
280
+ interface ToolGateConfig {
281
+ purpose?: string;
282
+ action?: string;
283
+ resource?: string;
284
+ }
285
+ /**
286
+ * A tool/method gate is either a {@link ToolGateConfig} (enforced — calls
287
+ * verify-access and gates on the server decision, using the declared PDLSS
288
+ * purpose/action) or the literal `'observe'` (passed through unenforced;
289
+ * still evaluated when `evaluateAlwaysIfCredentialed` is set). SDK 5.0.0
290
+ * removed the access-level band, so a gate no longer carries a tier — its
291
+ * only decision is enforce vs observe.
292
+ */
293
+ type ToolGate = ToolGateConfig | 'observe';
294
+ interface McpMiddlewareOptions extends GatewayConfig {
295
+ /**
296
+ * Per-tool gating for `tools/call` invocations. Tools not listed are
297
+ * enforced by default (`tools/call` calls verify-access and gates on the
298
+ * server decision).
299
+ *
300
+ * A gated tool declares its PDLSS `purpose` (required: the backend rejects
301
+ * gated calls with no resolvable purpose) and ideally a dotted-verb
302
+ * `action`:
303
+ * ```typescript
304
+ * toolGates: {
305
+ * list_products: { purpose: 'shopping',
306
+ * action: 'shopping.search',
307
+ * resource: '/api/catalog' },
308
+ * start_checkout: { purpose: 'shopping',
309
+ * action: 'shopping.purchase',
310
+ * resource: '/api/checkout/*' },
311
+ * health_check: 'observe', // pass through unenforced
312
+ * }
313
+ * ```
314
+ *
315
+ * Set a tool to `'observe'` to pass it through without enforcement (it is
316
+ * still evaluated for the audit trail when `evaluateAlwaysIfCredentialed`
317
+ * is set). A gated object form with no resolvable purpose fails fast with a
318
+ * `PDLSS_PURPOSE_REQUIRED` 400 (the SDK never sends the raw tool name as
319
+ * the PDLSS action).
320
+ *
321
+ * The action axis for non-tools/call MCP methods (`tools/list`,
322
+ * `resources/list`, `prompts/list`, etc.) is the literal JSON-RPC method
323
+ * name (e.g. `'tools/list'`). Merchants gating MCP traffic by action should
324
+ * declare per-tool gates in `toolGates`, not endpoint-level `allowedActions`
325
+ * — the latter applies to REST-style action values, not MCP method strings.
326
+ */
327
+ toolGates?: Record<string, ToolGate>;
328
+ /**
329
+ * Per-method override. By default introspection / handshake methods
330
+ * (`tools/list`, `initialize`, `ping`, …) pass through and `tools/call` is
331
+ * enforced; declare a method here to enforce it (object form, with a PDLSS
332
+ * purpose) or set it to `'observe'` to pass it through. Matches by exact
333
+ * JSON-RPC method string.
334
+ */
335
+ methodGates?: Record<string, ToolGate>;
336
+ /**
337
+ * What to do when the agent id supplied in the X-Astra-Id header
338
+ * disagrees with the agent id in the JSON-RPC body
339
+ * (`params._meta.astrasync.agentId` or `params.arguments.agent_id`).
340
+ *
341
+ * - `'reject'` (default) — return 400 `AGENT_ID_MISMATCH`. Safest.
342
+ * - `'prefer-header'` — log + verify against the header value. Keeps
343
+ * bodies that were authored before X-Astra-Id was the canonical
344
+ * identity slot working.
345
+ * - `'prefer-body'` — log + verify against the body value. Useful in
346
+ * reverse-proxy setups that strip auth headers.
347
+ */
348
+ onAgentIdMismatch?: 'reject' | 'prefer-header' | 'prefer-body';
349
+ /** Skip verification + dedupe entirely. For testing. */
350
+ skip?: boolean;
351
+ /** Custom denied handler. Defaults to a structured JSON-RPC error response. */
352
+ onDenied?: (result: VerificationResult, req: Request, res: Response) => void;
353
+ /**
354
+ * If `true`, trust an inbound `X-Astra-Verified-Hop` header to skip
355
+ * verify-access when it carries a recent marker for the resolved agent.
356
+ *
357
+ * **DEFAULT FLIPPED TO `false` in SDK 2.4.13.** The marker
358
+ * is plaintext semicolon-delimited with no HMAC, so any client that sets
359
+ * the header (with the right format + fresh timestamp + matching ASTRA-id)
360
+ * skipped verify-access entirely. The per-process verify-access result
361
+ * cache already dedupes legitimate repeat calls — this optimization
362
+ * provided no additional savings, only a bypass surface.
363
+ *
364
+ * Set this to `true` ONLY if you control every upstream MCP hop that sets
365
+ * the header AND you trust the network path between hops (mTLS, internal
366
+ * VPC, etc.). For most installs, leave at the safe default.
367
+ *
368
+ * A future SDK release will either remove this option entirely OR add
369
+ * HMAC signing to the marker.
370
+ */
371
+ trustVerifiedHop?: boolean;
372
+ /** Window for accepting an upstream verified-hop marker. Default 60_000ms. */
373
+ verifiedHopMaxAgeMs?: number;
374
+ /**
375
+ * Automatically record grant/deny decisions for every MCP call. Default
376
+ * `true` — matches the express adapter.
377
+ */
378
+ recordDecisions?: boolean;
379
+ /** Forward runtime challenge (default `true`). */
380
+ enableRuntimeChallenge?: boolean;
381
+ /**
382
+ * Posture when the MCP middleware itself throws an internal error.
383
+ * Default `'open'` for backward compatibility in SDK 2.4.13. Shadow logs
384
+ * record what WOULD be denied with `failOnError: 'closed'` so merchants
385
+ * can grep correlationId for impact analysis during the observation
386
+ * window. Default flips to `'closed'` in a follow-up release.
387
+ */
388
+ failOnError?: 'open' | 'closed';
389
+ }
390
+ /**
391
+ * Create the MCP middleware. Attach AFTER `express.json()` — the body must
392
+ * already be a parsed object.
393
+ */
394
+ declare function createMcpMiddleware(options: McpMiddlewareOptions): RequestHandler;
395
+
396
+ export { MCP_VERIFIED_HOP_HEADER, type McpMiddlewareOptions, type ParsedMcpRequest, type ToolGate, type ToolGateConfig, createMcpMiddleware, isVerifiedHopValidFor, mcpDefaultEnforced, mcpToPdlss, parseMcpJsonRpc, parseVerifiedHop, serializeVerifiedHop };
@@ -32,7 +32,7 @@ __export(mcp_exports, {
32
32
  module.exports = __toCommonJS(mcp_exports);
33
33
 
34
34
  // src/version.ts
35
- var SDK_VERSION = "5.4.0";
35
+ var SDK_VERSION = "5.4.1";
36
36
 
37
37
  // src/http.ts
38
38
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -221,7 +221,14 @@ function getCacheKey(request, counterpartyId) {
221
221
  request.callerMetadata?.sourceIp || "",
222
222
  request.callerMetadata?.userAgent || "",
223
223
  request.callerMetadata?.forwardedFor || "",
224
- request.callerMetadata?.agentCardUrl || ""
224
+ request.callerMetadata?.agentCardUrl || "",
225
+ // UAT2 Bug B (5.4.1): the commerce phase and cart identity DO affect the
226
+ // backend verdict — the confirm leg is the ONLY leg that may execute
227
+ // first-party settlement. Without these, a confirm within the cache TTL of
228
+ // its start_checkout quote was served the cached quote-leg grant (no
229
+ // settlementOutcome) and never reached the backend. Same F-A1-07 bug class.
230
+ request.commercePhase || "",
231
+ request.checkoutSessionId || ""
225
232
  ].join("|");
226
233
  }
227
234
  function getCachedResult(request, counterpartyId) {