@happyvertical/smrt-app-mcp 0.68.0 → 0.70.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/AGENTS.md CHANGED
@@ -46,6 +46,12 @@ tool policy; `./sveltekit` owns the stateless Streamable HTTP transport.
46
46
  validates JWT access tokens and requires an application-owned principal mapper.
47
47
  - Mount `mountMcpRoute` as one modern `POST` endpoint. It creates a fresh
48
48
  protocol server per request, emits no session id, and refuses subscriptions.
49
+ `legacy: 'reject' | 'stateless'` (both mounts, SDK vocabulary, default
50
+ `'reject'` = `-32022`, mount-time only, #5109) opts 2025-era JSON-RPC clients
51
+ in; the SDK serves them from the SAME per-request factory and bound
52
+ principal, so every gate (auth, grant liveness, binder, scopes, policy,
53
+ confirm/approvals, audit) applies. Never add a parallel legacy dispatch path;
54
+ legacy gets stateless semantics (no sessions, `list_changed`, subscriptions).
49
55
  - `mountMcpAppRoute` (`src/defaults.ts` + `./sveltekit`) is the one-call app
50
56
  route: explicit `models` allow-list, required `requiredScopes`, principal from
51
57
  session locals (`principalFromSessionLocals`; absent `principalKind` denies
@@ -89,6 +95,13 @@ tool policy; `./sveltekit` owns the stateless Streamable HTTP transport.
89
95
  needs authentication, which the OAuth challenge requires. Agent principals
90
96
  (`kind: 'agent'`, #5086) pass the default policy only when `principalKinds`
91
97
  lists them.
98
+ - Scope narrowing (#5110): consent may grant fewer scopes than the resource
99
+ advertises, so `createMcpResourceAuth` needs only one advertised scope (none:
100
+ 403 `insufficient_scope`, `scope=` challenge; metadata unchanged). Per-tool
101
+ needs come from `toolScopes`/workflow `requiredScopes`; an unmapped tool
102
+ requires every advertised scope (fail closed, via the principal's
103
+ `unmappedToolScopes` stamped by the adapter), so map every tool for narrowed
104
+ tokens and keep `requiredScopes` `[]`. Tests: `narrowed-token.test.ts`.
92
105
  - `mountMcpToolsRoute`/`mountMcpCallRoute` share the modern route's
93
106
  `auth`/`bindPrincipal` sequence (`authenticateAndDispatch`): a bearer agent
94
107
  lists and calls with the same live-capped scopes on every route. `mountMcpRoute`
package/README.md CHANGED
@@ -67,9 +67,17 @@ export const POST = mountMcpAppRoute({
67
67
  or `resourcePolicy` is composed with this default and can only narrow it;
68
68
  for a wider policy, call `createMcpAppServer` and `mountMcpRoute` directly.
69
69
  Because the default is principal-aware, `tools/list` stays `private` even
70
- with a public-cache attestation. A scope applies uniformly to every
70
+ with a public-cache attestation. `requiredScopes` applies uniformly to every
71
71
  published tool, so a read scope such as `items.read` must be paired with
72
- `effects: ['read']` (below) unless the app adds per-operation policy.
72
+ `effects: ['read']` (below) unless the app adds per-operation policy. For
73
+ OAuth tokens that consent narrowed to a subset of the advertised scopes (#5110),
74
+ keep `requiredScopes: []` and map each tool with `toolScopes`: the resource
75
+ accepts a token carrying at least one advertised scope (none is 403
76
+ `insufficient_scope`) and each mapped tool needs only its own scopes. A tool
77
+ with no mapping requires every advertised scope (fail closed), so map them all.
78
+ Migration: an app that kept `requiredScopes` equal to all advertised scopes
79
+ now sees every tool 404 for narrowed tokens (it was 403 `insufficient_scope`);
80
+ switch to `requiredScopes: []` plus a complete `toolScopes` map.
73
81
  - **Effects** — `effects` (also on `createMcpAppServer`) limits the catalog to
74
82
  tools whose effect is listed: `'read'`, `'write'`, `'destructive'`, the
75
83
  WebMCP vocabulary. `mcpToolEffect` classifies with the existing read-only
@@ -435,8 +443,8 @@ import { mcpServer } from '$lib/server/mcp';
435
443
  export const POST = mountMcpRoute(mcpServer);
436
444
  ```
437
445
 
438
- `mountMcpRoute` is a modern-only, fetch-style Streamable HTTP endpoint. It
439
- serves `server/discover`, `tools/list`, and `tools/call` with the SDK's
446
+ `mountMcpRoute` is a modern-only (by default), fetch-style Streamable HTTP
447
+ endpoint. It serves `server/discover`, `tools/list`, and `tools/call` with the SDK's
440
448
  2026-07-28 envelope. It advertises the optional
441
449
  `io.modelcontextprotocol/tasks` extension only when an allowed object enables
442
450
  MCP tasks (`mcp: { tasks: [...] }`); task-aware clients can then call
@@ -449,6 +457,19 @@ ordered by name. Stock MCP clients send the required
449
457
  against the JSON-RPC body and returns the protocol `HeaderMismatch` error
450
458
  (`-32020`, HTTP 400) for a missing or mismatched header.
451
459
 
460
+ Legacy (2025-era) JSON-RPC clients, such as Paperclip, send an `initialize`
461
+ handshake or a request naming no protocol version. By default the route
462
+ answers those with `-32022` (Unsupported protocol version). Pass
463
+ `legacy: 'stateless'` to `mountMcpRoute` or `mountMcpAppRoute` to opt in
464
+ (default `'reject'`; the SDK's own vocabulary; mount-time only, never read from
465
+ a request). Each legacy request is served by a fresh protocol server from the
466
+ same per-request factory with the same authenticated, bound principal, so
467
+ OAuth challenge, per-call grant liveness, `bindPrincipal`, scopes, tool policy,
468
+ role-filtered `tools/list`, 404 for unknown or forbidden tools, `confirmTools`
469
+ and approvals, and audit all apply unchanged. Legacy clients get stateless
470
+ semantics: no sessions, no `list_changed`, no subscriptions. Modern requests
471
+ are served identically either way (#5109).
472
+
452
473
  `tools/list` emits the required cache metadata with a one-day, `private`
453
474
  default. Shared (`public`) caching is intentionally exceptional: set
454
475
  `toolListCache: { cacheScope: 'public', publicCatalog: true }` only for a
@@ -1,7 +1,7 @@
1
1
  import { ObjectRegistry, SmrtCollection, SmrtObject, field, smrt } from "@happyvertical/smrt-core";
2
2
  import { TenantScoped, tenantId, withSystemContext, withTenant } from "@happyvertical/smrt-tenancy";
3
3
  //#region src/__smrt-register__.ts
4
- ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-app-mcp","packageVersion":"0.68.0","objects":{"@happyvertical/smrt-app-mcp:McpCallAudit":{"name":"mcpcallaudit","className":"McpCallAudit","qualifiedName":"@happyvertical/smrt-app-mcp:McpCallAudit","collection":"mcpcallaudits","description":"One persisted MCP tool call. Stores identity, tool, tenant, outcome and argument KEY names only: never argument values or response bodies.","filePath":"src/audit-store.ts","packageName":"@happyvertical/smrt-app-mcp","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"principalId":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"principalKind":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"identityIssuer":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"identitySubject":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"identityClientId":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"tool":{"type":"text","_meta":{"__statedOptions":["required","requiredFor","default"],"required":true,"default":"","requiredFor":"identity"},"required":true,"default":""},"outcome":{"type":"text","_meta":{"__statedOptions":["required","default","enum"],"required":true,"default":"allowed"},"required":true,"default":"allowed","enum":["allowed","denied","error"]},"errorCode":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"argumentKeys":{"type":"json","_meta":{"__statedOptions":[]},"required":false},"occurredAt":{"type":"datetime","_meta":{"__statedOptions":["required"],"required":true},"required":true}},"methods":{},"decoratorConfig":{"tableName":"smrt_mcp_call_audits","api":false,"mcp":false,"cli":false,"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"McpCallAudit","collectionExportName":"McpCallAuditCollection","validationRules":[{"field":"tool","rule":"required","fieldType":"text"},{"field":"outcome","rule":"required","fieldType":"text"},{"field":"occurredAt","rule":"required","fieldType":"datetime"}],"schema":{"tableName":"smrt_mcp_call_audits","ddl":"CREATE TABLE IF NOT EXISTS \\"smrt_mcp_call_audits\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"principal_id\\" TEXT,\\n \\"principal_kind\\" TEXT,\\n \\"identity_issuer\\" TEXT,\\n \\"identity_subject\\" TEXT,\\n \\"identity_client_id\\" TEXT,\\n \\"tool\\" TEXT NOT NULL DEFAULT '',\\n \\"outcome\\" TEXT NOT NULL DEFAULT 'allowed',\\n \\"error_code\\" TEXT,\\n \\"argument_keys\\" JSON,\\n \\"occurred_at\\" TIMESTAMP NOT NULL\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"principal_id":{"type":"TEXT","notNull":false,"unique":false},"principal_kind":{"type":"TEXT","notNull":false,"unique":false},"identity_issuer":{"type":"TEXT","notNull":false,"unique":false},"identity_subject":{"type":"TEXT","notNull":false,"unique":false},"identity_client_id":{"type":"TEXT","notNull":false,"unique":false},"tool":{"type":"TEXT","notNull":true,"unique":false,"default":""},"outcome":{"type":"TEXT","notNull":true,"unique":false,"default":"allowed"},"error_code":{"type":"TEXT","notNull":false,"unique":false},"argument_keys":{"type":"JSON","notNull":false,"unique":false},"occurred_at":{"type":"TIMESTAMP","notNull":true,"unique":false}},"indexes":[{"name":"smrt_mcp_call_audits_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"smrt_mcp_call_audits_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"e0a722bb"},"importPath":"@happyvertical/smrt-app-mcp/audit-store"},"@happyvertical/smrt-app-mcp:McpCallAuditCollection":{"name":"mcpcallauditcollection","className":"McpCallAuditCollection","qualifiedName":"@happyvertical/smrt-app-mcp:McpCallAuditCollection","collection":"mcpcallaudits","description":"Tenant-aware persistence and queries for McpCallAudit.","filePath":"src/audit-store.ts","packageName":"@happyvertical/smrt-app-mcp","fields":{},"methods":{"append":{"name":"append","async":true,"parameters":[{"name":"record","type":"McpAuditRecord","optional":false}],"returnType":"Promise<McpCallAudit>","isStatic":false,"isPublic":true},"listAudits":{"name":"listAudits","async":true,"parameters":[{"name":"query","type":"any","optional":false,"typeUnresolved":true}],"returnType":"any","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"smrt_mcp_call_audits","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"McpCallAudit","exportName":"McpCallAuditCollection","collectionExportName":"McpCallAuditCollectionCollection","collectionOf":"@happyvertical/smrt-app-mcp:McpCallAudit","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"smrt_mcp_call_audits","ddl":"CREATE TABLE IF NOT EXISTS \\"smrt_mcp_call_audits\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"principal_id\\" TEXT,\\n \\"principal_kind\\" TEXT,\\n \\"identity_issuer\\" TEXT,\\n \\"identity_subject\\" TEXT,\\n \\"identity_client_id\\" TEXT,\\n \\"tool\\" TEXT NOT NULL DEFAULT '',\\n \\"outcome\\" TEXT NOT NULL DEFAULT 'allowed',\\n \\"error_code\\" TEXT,\\n \\"argument_keys\\" JSON,\\n \\"occurred_at\\" TIMESTAMP NOT NULL\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"principal_id":{"type":"TEXT","notNull":false,"unique":false},"principal_kind":{"type":"TEXT","notNull":false,"unique":false},"identity_issuer":{"type":"TEXT","notNull":false,"unique":false},"identity_subject":{"type":"TEXT","notNull":false,"unique":false},"identity_client_id":{"type":"TEXT","notNull":false,"unique":false},"tool":{"type":"TEXT","notNull":true,"unique":false,"default":""},"outcome":{"type":"TEXT","notNull":true,"unique":false,"default":"allowed"},"error_code":{"type":"TEXT","notNull":false,"unique":false},"argument_keys":{"type":"JSON","notNull":false,"unique":false},"occurred_at":{"type":"TIMESTAMP","notNull":true,"unique":false}},"indexes":[{"name":"smrt_mcp_call_audits_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"smrt_mcp_call_audits_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"e0a722bb"},"importPath":"@happyvertical/smrt-app-mcp/audit-store"}},"moduleType":"smrt","smrtDependencies":["@happyvertical/smrt-core","@happyvertical/smrt-jobs","@happyvertical/smrt-tenancy"],"stampsConstructors":true}`));
4
+ ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-app-mcp","packageVersion":"0.70.0","objects":{"@happyvertical/smrt-app-mcp:McpCallAudit":{"name":"mcpcallaudit","className":"McpCallAudit","qualifiedName":"@happyvertical/smrt-app-mcp:McpCallAudit","collection":"mcpcallaudits","description":"One persisted MCP tool call. Stores identity, tool, tenant, outcome and argument KEY names only: never argument values or response bodies.","filePath":"src/audit-store.ts","packageName":"@happyvertical/smrt-app-mcp","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"principalId":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"principalKind":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"identityIssuer":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"identitySubject":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"identityClientId":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"tool":{"type":"text","_meta":{"__statedOptions":["required","requiredFor","default"],"required":true,"default":"","requiredFor":"identity"},"required":true,"default":""},"outcome":{"type":"text","_meta":{"__statedOptions":["required","default","enum"],"required":true,"default":"allowed"},"required":true,"default":"allowed","enum":["allowed","denied","error"]},"errorCode":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"argumentKeys":{"type":"json","_meta":{"__statedOptions":[]},"required":false},"occurredAt":{"type":"datetime","_meta":{"__statedOptions":["required"],"required":true},"required":true}},"methods":{},"decoratorConfig":{"tableName":"smrt_mcp_call_audits","api":false,"mcp":false,"cli":false,"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"McpCallAudit","collectionExportName":"McpCallAuditCollection","validationRules":[{"field":"tool","rule":"required","fieldType":"text"},{"field":"outcome","rule":"required","fieldType":"text"},{"field":"occurredAt","rule":"required","fieldType":"datetime"}],"schema":{"tableName":"smrt_mcp_call_audits","ddl":"CREATE TABLE IF NOT EXISTS \\"smrt_mcp_call_audits\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"principal_id\\" TEXT,\\n \\"principal_kind\\" TEXT,\\n \\"identity_issuer\\" TEXT,\\n \\"identity_subject\\" TEXT,\\n \\"identity_client_id\\" TEXT,\\n \\"tool\\" TEXT NOT NULL DEFAULT '',\\n \\"outcome\\" TEXT NOT NULL DEFAULT 'allowed',\\n \\"error_code\\" TEXT,\\n \\"argument_keys\\" JSON,\\n \\"occurred_at\\" TIMESTAMP NOT NULL\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"principal_id":{"type":"TEXT","notNull":false,"unique":false},"principal_kind":{"type":"TEXT","notNull":false,"unique":false},"identity_issuer":{"type":"TEXT","notNull":false,"unique":false},"identity_subject":{"type":"TEXT","notNull":false,"unique":false},"identity_client_id":{"type":"TEXT","notNull":false,"unique":false},"tool":{"type":"TEXT","notNull":true,"unique":false,"default":""},"outcome":{"type":"TEXT","notNull":true,"unique":false,"default":"allowed"},"error_code":{"type":"TEXT","notNull":false,"unique":false},"argument_keys":{"type":"JSON","notNull":false,"unique":false},"occurred_at":{"type":"TIMESTAMP","notNull":true,"unique":false}},"indexes":[{"name":"smrt_mcp_call_audits_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"smrt_mcp_call_audits_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"e0a722bb"},"importPath":"@happyvertical/smrt-app-mcp/audit-store"},"@happyvertical/smrt-app-mcp:McpCallAuditCollection":{"name":"mcpcallauditcollection","className":"McpCallAuditCollection","qualifiedName":"@happyvertical/smrt-app-mcp:McpCallAuditCollection","collection":"mcpcallaudits","description":"Tenant-aware persistence and queries for McpCallAudit.","filePath":"src/audit-store.ts","packageName":"@happyvertical/smrt-app-mcp","fields":{},"methods":{"append":{"name":"append","async":true,"parameters":[{"name":"record","type":"McpAuditRecord","optional":false}],"returnType":"Promise<McpCallAudit>","isStatic":false,"isPublic":true},"listAudits":{"name":"listAudits","async":true,"parameters":[{"name":"query","type":"any","optional":false,"typeUnresolved":true}],"returnType":"any","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"smrt_mcp_call_audits","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"McpCallAudit","exportName":"McpCallAuditCollection","collectionExportName":"McpCallAuditCollectionCollection","collectionOf":"@happyvertical/smrt-app-mcp:McpCallAudit","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"smrt_mcp_call_audits","ddl":"CREATE TABLE IF NOT EXISTS \\"smrt_mcp_call_audits\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"principal_id\\" TEXT,\\n \\"principal_kind\\" TEXT,\\n \\"identity_issuer\\" TEXT,\\n \\"identity_subject\\" TEXT,\\n \\"identity_client_id\\" TEXT,\\n \\"tool\\" TEXT NOT NULL DEFAULT '',\\n \\"outcome\\" TEXT NOT NULL DEFAULT 'allowed',\\n \\"error_code\\" TEXT,\\n \\"argument_keys\\" JSON,\\n \\"occurred_at\\" TIMESTAMP NOT NULL\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"principal_id":{"type":"TEXT","notNull":false,"unique":false},"principal_kind":{"type":"TEXT","notNull":false,"unique":false},"identity_issuer":{"type":"TEXT","notNull":false,"unique":false},"identity_subject":{"type":"TEXT","notNull":false,"unique":false},"identity_client_id":{"type":"TEXT","notNull":false,"unique":false},"tool":{"type":"TEXT","notNull":true,"unique":false,"default":""},"outcome":{"type":"TEXT","notNull":true,"unique":false,"default":"allowed"},"error_code":{"type":"TEXT","notNull":false,"unique":false},"argument_keys":{"type":"JSON","notNull":false,"unique":false},"occurred_at":{"type":"TIMESTAMP","notNull":true,"unique":false}},"indexes":[{"name":"smrt_mcp_call_audits_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"smrt_mcp_call_audits_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"e0a722bb"},"importPath":"@happyvertical/smrt-app-mcp/audit-store"}},"moduleType":"smrt","smrtDependencies":["@happyvertical/smrt-core","@happyvertical/smrt-jobs","@happyvertical/smrt-tenancy"],"stampsConstructors":true}`));
5
5
  //#endregion
6
6
  //#region src/audit-store.ts
7
7
  var __defProp = Object.defineProperty;
@@ -1 +1 @@
1
- {"version":3,"file":"audit-store.js","names":[],"sources":["../src/__smrt-register__.ts","../src/audit-store.ts"],"sourcesContent":["// Generated by @happyvertical/smrt-core smrtPlugin at library build time.\n// The package manifest is inlined so self-registration cannot miss when a\n// downstream bundler relocates this module away from dist/manifest.json\n// (https://github.com/happyvertical/smrt/issues/1506,\n// https://github.com/happyvertical/smrt/issues/1507).\nimport { ObjectRegistry } from '@happyvertical/smrt-core';\n\nObjectRegistry.registerPackageManifest(JSON.parse(\"{\\\"version\\\":\\\"1.0.0\\\",\\\"timestamp\\\":0,\\\"packageName\\\":\\\"@happyvertical/smrt-app-mcp\\\",\\\"packageVersion\\\":\\\"0.68.0\\\",\\\"objects\\\":{\\\"@happyvertical/smrt-app-mcp:McpCallAudit\\\":{\\\"name\\\":\\\"mcpcallaudit\\\",\\\"className\\\":\\\"McpCallAudit\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-app-mcp:McpCallAudit\\\",\\\"collection\\\":\\\"mcpcallaudits\\\",\\\"description\\\":\\\"One persisted MCP tool call. Stores identity, tool, tenant, outcome and argument KEY names only: never argument values or response bodies.\\\",\\\"filePath\\\":\\\"src/audit-store.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-app-mcp\\\",\\\"fields\\\":{\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__tenancy\\\":{\\\"isTenantIdField\\\":true,\\\"autoFilter\\\":true,\\\"required\\\":false,\\\"autoPopulate\\\":true,\\\"nullable\\\":true,\\\"mode\\\":\\\"optional\\\",\\\"field\\\":\\\"tenantId\\\",\\\"allowSuperAdminBypass\\\":false},\\\"__statedOptions\\\":[\\\"sqlType\\\",\\\"nullable\\\",\\\"__tenancy\\\",\\\"required\\\"],\\\"sqlType\\\":\\\"UUID\\\",\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"principalId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"principalKind\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"identityIssuer\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"identitySubject\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"identityClientId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"tool\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"requiredFor\\\",\\\"default\\\"],\\\"required\\\":true,\\\"default\\\":\\\"\\\",\\\"requiredFor\\\":\\\"identity\\\"},\\\"required\\\":true,\\\"default\\\":\\\"\\\"},\\\"outcome\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"default\\\",\\\"enum\\\"],\\\"required\\\":true,\\\"default\\\":\\\"allowed\\\"},\\\"required\\\":true,\\\"default\\\":\\\"allowed\\\",\\\"enum\\\":[\\\"allowed\\\",\\\"denied\\\",\\\"error\\\"]},\\\"errorCode\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"argumentKeys\\\":{\\\"type\\\":\\\"json\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[]},\\\"required\\\":false},\\\"occurredAt\\\":{\\\"type\\\":\\\"datetime\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\"],\\\"required\\\":true},\\\"required\\\":true}},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"smrt_mcp_call_audits\\\",\\\"api\\\":false,\\\"mcp\\\":false,\\\"cli\\\":false,\\\"tenantScoped\\\":{\\\"mode\\\":\\\"optional\\\"},\\\"conflictColumns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"McpCallAudit\\\",\\\"collectionExportName\\\":\\\"McpCallAuditCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"tool\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"},{\\\"field\\\":\\\"outcome\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"},{\\\"field\\\":\\\"occurredAt\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"datetime\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"smrt_mcp_call_audits\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"smrt_mcp_call_audits\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID,\\\\n \\\\\\\"principal_id\\\\\\\" TEXT,\\\\n \\\\\\\"principal_kind\\\\\\\" TEXT,\\\\n \\\\\\\"identity_issuer\\\\\\\" TEXT,\\\\n \\\\\\\"identity_subject\\\\\\\" TEXT,\\\\n \\\\\\\"identity_client_id\\\\\\\" TEXT,\\\\n \\\\\\\"tool\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"outcome\\\\\\\" TEXT NOT NULL DEFAULT 'allowed',\\\\n \\\\\\\"error_code\\\\\\\" TEXT,\\\\n \\\\\\\"argument_keys\\\\\\\" JSON,\\\\n \\\\\\\"occurred_at\\\\\\\" TIMESTAMP NOT NULL\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"principal_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"principal_kind\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_issuer\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_subject\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_client_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"tool\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"\\\"},\\\"outcome\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"allowed\\\"},\\\"error_code\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"argument_keys\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"occurred_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"smrt_mcp_call_audits_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true,\\\"nullsNotDistinct\\\":true},{\\\"name\\\":\\\"smrt_mcp_call_audits_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"e0a722bb\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-app-mcp/audit-store\\\"},\\\"@happyvertical/smrt-app-mcp:McpCallAuditCollection\\\":{\\\"name\\\":\\\"mcpcallauditcollection\\\",\\\"className\\\":\\\"McpCallAuditCollection\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-app-mcp:McpCallAuditCollection\\\",\\\"collection\\\":\\\"mcpcallaudits\\\",\\\"description\\\":\\\"Tenant-aware persistence and queries for McpCallAudit.\\\",\\\"filePath\\\":\\\"src/audit-store.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-app-mcp\\\",\\\"fields\\\":{},\\\"methods\\\":{\\\"append\\\":{\\\"name\\\":\\\"append\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"record\\\",\\\"type\\\":\\\"McpAuditRecord\\\",\\\"optional\\\":false}],\\\"returnType\\\":\\\"Promise<McpCallAudit>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true},\\\"listAudits\\\":{\\\"name\\\":\\\"listAudits\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"query\\\",\\\"type\\\":\\\"any\\\",\\\"optional\\\":false,\\\"typeUnresolved\\\":true}],\\\"returnType\\\":\\\"any\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true}},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"smrt_mcp_call_audits\\\",\\\"api\\\":false,\\\"mcp\\\":false,\\\"cli\\\":false},\\\"extends\\\":\\\"SmrtCollection\\\",\\\"extendsTypeArg\\\":\\\"McpCallAudit\\\",\\\"exportName\\\":\\\"McpCallAuditCollection\\\",\\\"collectionExportName\\\":\\\"McpCallAuditCollectionCollection\\\",\\\"collectionOf\\\":\\\"@happyvertical/smrt-app-mcp:McpCallAudit\\\",\\\"inheritedExposure\\\":[\\\"api\\\",\\\"mcp\\\",\\\"cli\\\"],\\\"schema\\\":{\\\"tableName\\\":\\\"smrt_mcp_call_audits\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"smrt_mcp_call_audits\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID,\\\\n \\\\\\\"principal_id\\\\\\\" TEXT,\\\\n \\\\\\\"principal_kind\\\\\\\" TEXT,\\\\n \\\\\\\"identity_issuer\\\\\\\" TEXT,\\\\n \\\\\\\"identity_subject\\\\\\\" TEXT,\\\\n \\\\\\\"identity_client_id\\\\\\\" TEXT,\\\\n \\\\\\\"tool\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"outcome\\\\\\\" TEXT NOT NULL DEFAULT 'allowed',\\\\n \\\\\\\"error_code\\\\\\\" TEXT,\\\\n \\\\\\\"argument_keys\\\\\\\" JSON,\\\\n \\\\\\\"occurred_at\\\\\\\" TIMESTAMP NOT NULL\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"principal_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"principal_kind\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_issuer\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_subject\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_client_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"tool\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"\\\"},\\\"outcome\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"allowed\\\"},\\\"error_code\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"argument_keys\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"occurred_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"smrt_mcp_call_audits_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true,\\\"nullsNotDistinct\\\":true},{\\\"name\\\":\\\"smrt_mcp_call_audits_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"e0a722bb\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-app-mcp/audit-store\\\"}},\\\"moduleType\\\":\\\"smrt\\\",\\\"smrtDependencies\\\":[\\\"@happyvertical/smrt-core\\\",\\\"@happyvertical/smrt-jobs\\\",\\\"@happyvertical/smrt-tenancy\\\"],\\\"stampsConstructors\\\":true}\"));\n","// Self-register this package's manifest for consumers that import via this\n// subpath without the main entry (smrt#1132).\nimport './__smrt-register__.js';\n\nimport {\n field,\n SmrtCollection,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport {\n TenantScoped,\n tenantId,\n withSystemContext,\n withTenant,\n} from '@happyvertical/smrt-tenancy';\nimport type {\n McpAuditOutcome,\n McpAuditQuery,\n McpAuditRecord,\n McpAuditSink,\n} from './audit.js';\n\n/**\n * One persisted MCP tool call. Stores identity, tool, tenant, outcome and\n * argument KEY names only: never argument values or response bodies.\n */\n@smrt({\n tableName: 'smrt_mcp_call_audits',\n // Audit rows are read through `McpCallAuditCollection.listAudits`, which\n // requires an explicit tenant; no generated read surface (fail closed).\n api: false,\n mcp: false,\n cli: false,\n})\n@TenantScoped({ mode: 'optional' })\nexport class McpCallAudit extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-app-mcp\";\n /** The tenant the call ran for; `null` for a global/anonymous call. */\n @tenantId({ nullable: true })\n tenantId: string | null | undefined = undefined;\n\n /** The principal id (credential id); `null` for an anonymous call. */\n @field({ type: 'text', nullable: true })\n principalId: string | null = null;\n\n /** The principal kind (agent, owner, user, ...); `null` when unknown. */\n @field({ type: 'text', nullable: true })\n principalKind: string | null = null;\n\n @field({ type: 'text', nullable: true })\n identityIssuer: string | null = null;\n\n @field({ type: 'text', nullable: true })\n identitySubject: string | null = null;\n\n @field({ type: 'text', nullable: true })\n identityClientId: string | null = null;\n\n /**\n * The tool the call named. Required for identity: the record exists to say\n * which tool ran, and `listAudits` looks rows up by it.\n */\n @field({ type: 'text', required: true, requiredFor: 'identity', default: '' })\n tool = '';\n\n @field({ type: 'text', required: true, default: 'allowed' })\n outcome: McpAuditOutcome = 'allowed';\n\n @field({ type: 'text', nullable: true })\n errorCode: string | null = null;\n\n @field({ type: 'json' })\n argumentKeys: string[] = [];\n\n @field({ type: 'datetime', required: true })\n occurredAt: Date = new Date();\n}\n\nconst DEFAULT_LIMIT = 100;\nconst MAX_LIMIT = 500;\n\n/** Tenant-aware persistence and queries for {@link McpCallAudit}. */\nexport class McpCallAuditCollection extends SmrtCollection<McpCallAudit> {\n static readonly _itemClass = McpCallAudit;\n\n /** Persist one record under its own tenant (or the global scope). */\n async append(record: McpAuditRecord): Promise<McpCallAudit> {\n const write = () =>\n this.create({\n tenantId: record.tenantId,\n principalId: record.principalId,\n principalKind: record.principalKind,\n identityIssuer: record.identityIssuer ?? null,\n identitySubject: record.identitySubject ?? null,\n identityClientId: record.identityClientId ?? null,\n tool: record.tool,\n outcome: record.outcome,\n errorCode: record.errorCode ?? null,\n argumentKeys: [...record.argumentKeys],\n occurredAt: record.occurredAt,\n });\n return record.tenantId\n ? withTenant({ tenantId: record.tenantId }, write)\n : withSystemContext(write);\n }\n\n /**\n * Newest-first records for one tenant, optionally narrowed by principal,\n * tool or outcome. `tenantId` is mandatory: `null` lists global rows.\n */\n async listAudits(query: McpAuditQuery & { tenantId: string | null }) {\n if (query.tenantId === undefined) {\n throw new TypeError('listAudits requires an explicit tenantId.');\n }\n const limit = Math.min(\n Math.max(Math.trunc(query.limit ?? DEFAULT_LIMIT), 1),\n MAX_LIMIT,\n );\n const where: Record<string, unknown> = { tenantId: query.tenantId };\n if (query.principalId !== undefined) where.principalId = query.principalId;\n if (query.tool !== undefined) where.tool = query.tool;\n if (query.outcome !== undefined) where.outcome = query.outcome;\n const read = () => this.list({ where, orderBy: 'occurred_at DESC', limit });\n const rows = query.tenantId\n ? await withTenant({ tenantId: query.tenantId }, read)\n : await withSystemContext(read);\n return rows.map((row): McpAuditRecord & { id: string } => ({\n id: String(row.id),\n principalId: row.principalId ?? null,\n principalKind: row.principalKind ?? null,\n tool: row.tool,\n tenantId: row.tenantId ?? null,\n outcome: row.outcome,\n ...(row.errorCode ? { errorCode: row.errorCode } : {}),\n ...(row.identityIssuer ? { identityIssuer: row.identityIssuer } : {}),\n ...(row.identitySubject ? { identitySubject: row.identitySubject } : {}),\n ...(row.identityClientId\n ? { identityClientId: row.identityClientId }\n : {}),\n argumentKeys: Array.isArray(row.argumentKeys) ? row.argumentKeys : [],\n occurredAt: new Date(row.occurredAt),\n }));\n }\n}\n\n/** Options for {@link createSmrtMcpAuditStore}. */\nexport interface SmrtMcpAuditStoreOptions {\n /** SMRT options bag (`{ db }`), the same one `smrtOptions` supplies. */\n smrtOptions: () => Record<string, unknown>;\n}\n\n/**\n * The default persistent audit sink: a SMRT-model-backed, tenant-aware store.\n * Pass it as `auditSink` and read it back with `list`.\n */\nexport function createSmrtMcpAuditStore(\n options: SmrtMcpAuditStoreOptions,\n): McpAuditSink & {\n list(\n query: McpAuditQuery & { tenantId: string | null },\n ): ReturnType<McpCallAuditCollection['listAudits']>;\n} {\n // Resolved per operation: `smrtOptions()` may return request-scoped state\n // (e.g. a transaction-bound db under RLS) that must not outlive its request.\n const get = () =>\n McpCallAuditCollection.create(\n options.smrtOptions() as never,\n ) as Promise<McpCallAuditCollection>;\n return {\n async record(record) {\n await (await get()).append(record);\n },\n async list(query) {\n return (await get()).listAudits(query);\n },\n };\n}\n"],"mappings":";;;AAOA,eAAe,wBAAwB,KAAK,MAAM,g1QAAs5S,CAAC;;;;;;;;;;;;;;;;;;AC6Bl8S,IAAM,eAAN,cAA2B,WAAW;CAG3C,WAAsC,KAAA;CAItC,cAA6B;CAI7B,gBAA+B;CAG/B,iBAAgC;CAGhC,kBAAiC;CAGjC,mBAAkC;CAOlC,OAAO;CAGP,UAA2B;CAG3B,YAA2B;CAG3B,eAAyB,CAAC;CAG1B,6BAAmB,IAAI,KAAK;AAC9B;AAxC+C,cAAlC,cAAyC,mBAAkB,6BAAA;AAGtE,gBAAA,CADC,SAAS,EAAE,UAAU,KAAK,CAAC,CAAA,GAFjB,aAGX,WAAA,YAAA,CAAA;AAIA,gBAAA,CADC,MAAM;CAAE,MAAM;CAAQ,UAAU;AAAK,CAAC,CAAA,GAN5B,aAOX,WAAA,eAAA,CAAA;AAIA,gBAAA,CADC,MAAM;CAAE,MAAM;CAAQ,UAAU;AAAK,CAAC,CAAA,GAV5B,aAWX,WAAA,iBAAA,CAAA;AAGA,gBAAA,CADC,MAAM;CAAE,MAAM;CAAQ,UAAU;AAAK,CAAC,CAAA,GAb5B,aAcX,WAAA,kBAAA,CAAA;AAGA,gBAAA,CADC,MAAM;CAAE,MAA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,SAAS,wBACd,SAKA;CAGA,MAAM,YACJ,uBAAuB,OACrB,QAAQ,YAAY,CACtB;CACF,OAAO;EACL,MAAM,OAAO,QAAQ;GACnB,OAAO,MAAM,IAAI,EAAA,CAAG,OAAO,MAAM;EACnC;EACA,MAAM,KAAK,OAAO;GAChB,QAAQ,MAAM,IAAI,EAAA,CAAG,WAAW,KAAK;EACvC;CACF;AACF"}
1
+ {"version":3,"file":"audit-store.js","names":[],"sources":["../src/__smrt-register__.ts","../src/audit-store.ts"],"sourcesContent":["// Generated by @happyvertical/smrt-core smrtPlugin at library build time.\n// The package manifest is inlined so self-registration cannot miss when a\n// downstream bundler relocates this module away from dist/manifest.json\n// (https://github.com/happyvertical/smrt/issues/1506,\n// https://github.com/happyvertical/smrt/issues/1507).\nimport { ObjectRegistry } from '@happyvertical/smrt-core';\n\nObjectRegistry.registerPackageManifest(JSON.parse(\"{\\\"version\\\":\\\"1.0.0\\\",\\\"timestamp\\\":0,\\\"packageName\\\":\\\"@happyvertical/smrt-app-mcp\\\",\\\"packageVersion\\\":\\\"0.70.0\\\",\\\"objects\\\":{\\\"@happyvertical/smrt-app-mcp:McpCallAudit\\\":{\\\"name\\\":\\\"mcpcallaudit\\\",\\\"className\\\":\\\"McpCallAudit\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-app-mcp:McpCallAudit\\\",\\\"collection\\\":\\\"mcpcallaudits\\\",\\\"description\\\":\\\"One persisted MCP tool call. Stores identity, tool, tenant, outcome and argument KEY names only: never argument values or response bodies.\\\",\\\"filePath\\\":\\\"src/audit-store.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-app-mcp\\\",\\\"fields\\\":{\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__tenancy\\\":{\\\"isTenantIdField\\\":true,\\\"autoFilter\\\":true,\\\"required\\\":false,\\\"autoPopulate\\\":true,\\\"nullable\\\":true,\\\"mode\\\":\\\"optional\\\",\\\"field\\\":\\\"tenantId\\\",\\\"allowSuperAdminBypass\\\":false},\\\"__statedOptions\\\":[\\\"sqlType\\\",\\\"nullable\\\",\\\"__tenancy\\\",\\\"required\\\"],\\\"sqlType\\\":\\\"UUID\\\",\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"principalId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"principalKind\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"identityIssuer\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"identitySubject\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"identityClientId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"tool\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"requiredFor\\\",\\\"default\\\"],\\\"required\\\":true,\\\"default\\\":\\\"\\\",\\\"requiredFor\\\":\\\"identity\\\"},\\\"required\\\":true,\\\"default\\\":\\\"\\\"},\\\"outcome\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"default\\\",\\\"enum\\\"],\\\"required\\\":true,\\\"default\\\":\\\"allowed\\\"},\\\"required\\\":true,\\\"default\\\":\\\"allowed\\\",\\\"enum\\\":[\\\"allowed\\\",\\\"denied\\\",\\\"error\\\"]},\\\"errorCode\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"argumentKeys\\\":{\\\"type\\\":\\\"json\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[]},\\\"required\\\":false},\\\"occurredAt\\\":{\\\"type\\\":\\\"datetime\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\"],\\\"required\\\":true},\\\"required\\\":true}},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"smrt_mcp_call_audits\\\",\\\"api\\\":false,\\\"mcp\\\":false,\\\"cli\\\":false,\\\"tenantScoped\\\":{\\\"mode\\\":\\\"optional\\\"},\\\"conflictColumns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"McpCallAudit\\\",\\\"collectionExportName\\\":\\\"McpCallAuditCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"tool\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"},{\\\"field\\\":\\\"outcome\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"},{\\\"field\\\":\\\"occurredAt\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"datetime\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"smrt_mcp_call_audits\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"smrt_mcp_call_audits\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID,\\\\n \\\\\\\"principal_id\\\\\\\" TEXT,\\\\n \\\\\\\"principal_kind\\\\\\\" TEXT,\\\\n \\\\\\\"identity_issuer\\\\\\\" TEXT,\\\\n \\\\\\\"identity_subject\\\\\\\" TEXT,\\\\n \\\\\\\"identity_client_id\\\\\\\" TEXT,\\\\n \\\\\\\"tool\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"outcome\\\\\\\" TEXT NOT NULL DEFAULT 'allowed',\\\\n \\\\\\\"error_code\\\\\\\" TEXT,\\\\n \\\\\\\"argument_keys\\\\\\\" JSON,\\\\n \\\\\\\"occurred_at\\\\\\\" TIMESTAMP NOT NULL\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"principal_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"principal_kind\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_issuer\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_subject\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_client_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"tool\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"\\\"},\\\"outcome\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"allowed\\\"},\\\"error_code\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"argument_keys\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"occurred_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"smrt_mcp_call_audits_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true,\\\"nullsNotDistinct\\\":true},{\\\"name\\\":\\\"smrt_mcp_call_audits_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"e0a722bb\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-app-mcp/audit-store\\\"},\\\"@happyvertical/smrt-app-mcp:McpCallAuditCollection\\\":{\\\"name\\\":\\\"mcpcallauditcollection\\\",\\\"className\\\":\\\"McpCallAuditCollection\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-app-mcp:McpCallAuditCollection\\\",\\\"collection\\\":\\\"mcpcallaudits\\\",\\\"description\\\":\\\"Tenant-aware persistence and queries for McpCallAudit.\\\",\\\"filePath\\\":\\\"src/audit-store.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-app-mcp\\\",\\\"fields\\\":{},\\\"methods\\\":{\\\"append\\\":{\\\"name\\\":\\\"append\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"record\\\",\\\"type\\\":\\\"McpAuditRecord\\\",\\\"optional\\\":false}],\\\"returnType\\\":\\\"Promise<McpCallAudit>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true},\\\"listAudits\\\":{\\\"name\\\":\\\"listAudits\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"query\\\",\\\"type\\\":\\\"any\\\",\\\"optional\\\":false,\\\"typeUnresolved\\\":true}],\\\"returnType\\\":\\\"any\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true}},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"smrt_mcp_call_audits\\\",\\\"api\\\":false,\\\"mcp\\\":false,\\\"cli\\\":false},\\\"extends\\\":\\\"SmrtCollection\\\",\\\"extendsTypeArg\\\":\\\"McpCallAudit\\\",\\\"exportName\\\":\\\"McpCallAuditCollection\\\",\\\"collectionExportName\\\":\\\"McpCallAuditCollectionCollection\\\",\\\"collectionOf\\\":\\\"@happyvertical/smrt-app-mcp:McpCallAudit\\\",\\\"inheritedExposure\\\":[\\\"api\\\",\\\"mcp\\\",\\\"cli\\\"],\\\"schema\\\":{\\\"tableName\\\":\\\"smrt_mcp_call_audits\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"smrt_mcp_call_audits\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID,\\\\n \\\\\\\"principal_id\\\\\\\" TEXT,\\\\n \\\\\\\"principal_kind\\\\\\\" TEXT,\\\\n \\\\\\\"identity_issuer\\\\\\\" TEXT,\\\\n \\\\\\\"identity_subject\\\\\\\" TEXT,\\\\n \\\\\\\"identity_client_id\\\\\\\" TEXT,\\\\n \\\\\\\"tool\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"outcome\\\\\\\" TEXT NOT NULL DEFAULT 'allowed',\\\\n \\\\\\\"error_code\\\\\\\" TEXT,\\\\n \\\\\\\"argument_keys\\\\\\\" JSON,\\\\n \\\\\\\"occurred_at\\\\\\\" TIMESTAMP NOT NULL\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"principal_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"principal_kind\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_issuer\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_subject\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"identity_client_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"tool\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"\\\"},\\\"outcome\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false,\\\"default\\\":\\\"allowed\\\"},\\\"error_code\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"argument_keys\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"occurred_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"smrt_mcp_call_audits_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true,\\\"nullsNotDistinct\\\":true},{\\\"name\\\":\\\"smrt_mcp_call_audits_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"e0a722bb\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-app-mcp/audit-store\\\"}},\\\"moduleType\\\":\\\"smrt\\\",\\\"smrtDependencies\\\":[\\\"@happyvertical/smrt-core\\\",\\\"@happyvertical/smrt-jobs\\\",\\\"@happyvertical/smrt-tenancy\\\"],\\\"stampsConstructors\\\":true}\"));\n","// Self-register this package's manifest for consumers that import via this\n// subpath without the main entry (smrt#1132).\nimport './__smrt-register__.js';\n\nimport {\n field,\n SmrtCollection,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport {\n TenantScoped,\n tenantId,\n withSystemContext,\n withTenant,\n} from '@happyvertical/smrt-tenancy';\nimport type {\n McpAuditOutcome,\n McpAuditQuery,\n McpAuditRecord,\n McpAuditSink,\n} from './audit.js';\n\n/**\n * One persisted MCP tool call. Stores identity, tool, tenant, outcome and\n * argument KEY names only: never argument values or response bodies.\n */\n@smrt({\n tableName: 'smrt_mcp_call_audits',\n // Audit rows are read through `McpCallAuditCollection.listAudits`, which\n // requires an explicit tenant; no generated read surface (fail closed).\n api: false,\n mcp: false,\n cli: false,\n})\n@TenantScoped({ mode: 'optional' })\nexport class McpCallAudit extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-app-mcp\";\n /** The tenant the call ran for; `null` for a global/anonymous call. */\n @tenantId({ nullable: true })\n tenantId: string | null | undefined = undefined;\n\n /** The principal id (credential id); `null` for an anonymous call. */\n @field({ type: 'text', nullable: true })\n principalId: string | null = null;\n\n /** The principal kind (agent, owner, user, ...); `null` when unknown. */\n @field({ type: 'text', nullable: true })\n principalKind: string | null = null;\n\n @field({ type: 'text', nullable: true })\n identityIssuer: string | null = null;\n\n @field({ type: 'text', nullable: true })\n identitySubject: string | null = null;\n\n @field({ type: 'text', nullable: true })\n identityClientId: string | null = null;\n\n /**\n * The tool the call named. Required for identity: the record exists to say\n * which tool ran, and `listAudits` looks rows up by it.\n */\n @field({ type: 'text', required: true, requiredFor: 'identity', default: '' })\n tool = '';\n\n @field({ type: 'text', required: true, default: 'allowed' })\n outcome: McpAuditOutcome = 'allowed';\n\n @field({ type: 'text', nullable: true })\n errorCode: string | null = null;\n\n @field({ type: 'json' })\n argumentKeys: string[] = [];\n\n @field({ type: 'datetime', required: true })\n occurredAt: Date = new Date();\n}\n\nconst DEFAULT_LIMIT = 100;\nconst MAX_LIMIT = 500;\n\n/** Tenant-aware persistence and queries for {@link McpCallAudit}. */\nexport class McpCallAuditCollection extends SmrtCollection<McpCallAudit> {\n static readonly _itemClass = McpCallAudit;\n\n /** Persist one record under its own tenant (or the global scope). */\n async append(record: McpAuditRecord): Promise<McpCallAudit> {\n const write = () =>\n this.create({\n tenantId: record.tenantId,\n principalId: record.principalId,\n principalKind: record.principalKind,\n identityIssuer: record.identityIssuer ?? null,\n identitySubject: record.identitySubject ?? null,\n identityClientId: record.identityClientId ?? null,\n tool: record.tool,\n outcome: record.outcome,\n errorCode: record.errorCode ?? null,\n argumentKeys: [...record.argumentKeys],\n occurredAt: record.occurredAt,\n });\n return record.tenantId\n ? withTenant({ tenantId: record.tenantId }, write)\n : withSystemContext(write);\n }\n\n /**\n * Newest-first records for one tenant, optionally narrowed by principal,\n * tool or outcome. `tenantId` is mandatory: `null` lists global rows.\n */\n async listAudits(query: McpAuditQuery & { tenantId: string | null }) {\n if (query.tenantId === undefined) {\n throw new TypeError('listAudits requires an explicit tenantId.');\n }\n const limit = Math.min(\n Math.max(Math.trunc(query.limit ?? DEFAULT_LIMIT), 1),\n MAX_LIMIT,\n );\n const where: Record<string, unknown> = { tenantId: query.tenantId };\n if (query.principalId !== undefined) where.principalId = query.principalId;\n if (query.tool !== undefined) where.tool = query.tool;\n if (query.outcome !== undefined) where.outcome = query.outcome;\n const read = () => this.list({ where, orderBy: 'occurred_at DESC', limit });\n const rows = query.tenantId\n ? await withTenant({ tenantId: query.tenantId }, read)\n : await withSystemContext(read);\n return rows.map((row): McpAuditRecord & { id: string } => ({\n id: String(row.id),\n principalId: row.principalId ?? null,\n principalKind: row.principalKind ?? null,\n tool: row.tool,\n tenantId: row.tenantId ?? null,\n outcome: row.outcome,\n ...(row.errorCode ? { errorCode: row.errorCode } : {}),\n ...(row.identityIssuer ? { identityIssuer: row.identityIssuer } : {}),\n ...(row.identitySubject ? { identitySubject: row.identitySubject } : {}),\n ...(row.identityClientId\n ? { identityClientId: row.identityClientId }\n : {}),\n argumentKeys: Array.isArray(row.argumentKeys) ? row.argumentKeys : [],\n occurredAt: new Date(row.occurredAt),\n }));\n }\n}\n\n/** Options for {@link createSmrtMcpAuditStore}. */\nexport interface SmrtMcpAuditStoreOptions {\n /** SMRT options bag (`{ db }`), the same one `smrtOptions` supplies. */\n smrtOptions: () => Record<string, unknown>;\n}\n\n/**\n * The default persistent audit sink: a SMRT-model-backed, tenant-aware store.\n * Pass it as `auditSink` and read it back with `list`.\n */\nexport function createSmrtMcpAuditStore(\n options: SmrtMcpAuditStoreOptions,\n): McpAuditSink & {\n list(\n query: McpAuditQuery & { tenantId: string | null },\n ): ReturnType<McpCallAuditCollection['listAudits']>;\n} {\n // Resolved per operation: `smrtOptions()` may return request-scoped state\n // (e.g. a transaction-bound db under RLS) that must not outlive its request.\n const get = () =>\n McpCallAuditCollection.create(\n options.smrtOptions() as never,\n ) as Promise<McpCallAuditCollection>;\n return {\n async record(record) {\n await (await get()).append(record);\n },\n async list(query) {\n return (await get()).listAudits(query);\n },\n };\n}\n"],"mappings":";;;AAOA,eAAe,wBAAwB,KAAK,MAAM,g1QAAs5S,CAAC;;;;;;;;;;;;;;;;;;AC6Bl8S,IAAM,eAAN,cAA2B,WAAW;CAG3C,WAAsC,KAAA;CAItC,cAA6B;CAI7B,gBAA+B;CAG/B,iBAAgC;CAGhC,kBAAiC;CAGjC,mBAAkC;CAOlC,OAAO;CAGP,UAA2B;CAG3B,YAA2B;CAG3B,eAAyB,CAAC;CAG1B,6BAAmB,IAAI,KAAK;AAC9B;AAxC+C,cAAlC,cAAyC,mBAAkB,6BAAA;AAGtE,gBAAA,CADC,SAAS,EAAE,UAAU,KAAK,CAAC,CAAA,GAFjB,aAGX,WAAA,YAAA,CAAA;AAIA,gBAAA,CADC,MAAM;CAAE,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e,CAqEjB;AAED,uDAAuD;AACvD,MAAM,WAAW,4BAA4B;IAC3C;;;OAGG;IACH,OAAO,EAAE,oBAAoB,GAAG,CAAC,MAAM,oBAAoB,CAAC,CAAC;IAC7D;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;IAC9D;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,kEAAkE;IAClE,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IACnD,2BAA2B;IAC3B,UAAU,CAAC,EAAE,sBAAsB,CAAC,YAAY,CAAC,CAAC;IAClD,SAAS,CAAC,EAAE,sBAAsB,CAAC,WAAW,CAAC,CAAC;IAChD,aAAa,CAAC,EAAE,sBAAsB,CAAC,eAAe,CAAC,CAAC;CACzD;AAED,yEAAyE;AACzE,eAAO,MAAM,mBAAmB;;;;;EAK9B,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,4BAA4B,GACpC,MAAM,eAAe,GAAG,IAAI,CA0D9B;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,CA0LjB"}
package/dist/auth.js CHANGED
@@ -937,7 +937,7 @@ function createMcpResourceAuth(options) {
937
937
  if (!validString(payload.sub) || typeof payload.scope !== "string") return deny("invalid_token");
938
938
  const granted = payload.scope === "" ? [] : payload.scope.split(" ");
939
939
  if (granted.some((scope) => !scopePattern.test(scope))) return deny("invalid_token");
940
- if (scopes.some((scope) => !granted.includes(scope))) return deny("insufficient_scope");
940
+ if (scopes.length > 0 && !scopes.some((scope) => granted.includes(scope))) return deny("insufficient_scope");
941
941
  const fields = readOwnFields(await resolvePrincipal(Object.freeze({
942
942
  issuer,
943
943
  subject: payload.sub,
@@ -960,6 +960,7 @@ function createMcpResourceAuth(options) {
960
960
  kind: fields.kind,
961
961
  roles,
962
962
  scopes: [...granted],
963
+ ...scopes.length ? { unmappedToolScopes: [...scopes] } : {},
963
964
  tenantBinding: fields.tenantBinding ?? "direct-or-inherited"
964
965
  }, {
965
966
  issuer,