@lenne.tech/nest-server 12.9.3 → 12.10.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.
Files changed (150) hide show
  1. package/.claude/rules/configurable-features.md +4 -0
  2. package/.claude/rules/package-management.md +35 -6
  3. package/.claude/rules/role-system.md +12 -0
  4. package/.claude/rules/testing.md +4 -4
  5. package/CLAUDE.md +10 -1
  6. package/FRAMEWORK-API.md +2 -1
  7. package/dist/core/common/decorators/rest-user.decorator.js +4 -0
  8. package/dist/core/common/decorators/rest-user.decorator.js.map +1 -1
  9. package/dist/core/common/filters/http-exception-log.filter.js +3 -0
  10. package/dist/core/common/filters/http-exception-log.filter.js.map +1 -1
  11. package/dist/core/common/helpers/context.helper.js +9 -0
  12. package/dist/core/common/helpers/context.helper.js.map +1 -1
  13. package/dist/core/common/helpers/decorator.helper.js +4 -0
  14. package/dist/core/common/helpers/decorator.helper.js.map +1 -1
  15. package/dist/core/common/helpers/execution-context-request.helper.d.ts +14 -1
  16. package/dist/core/common/helpers/execution-context-request.helper.js +36 -0
  17. package/dist/core/common/helpers/execution-context-request.helper.js.map +1 -1
  18. package/dist/core/common/helpers/graphql-upload.helper.d.ts +8 -0
  19. package/dist/core/common/helpers/graphql-upload.helper.js +206 -0
  20. package/dist/core/common/helpers/graphql-upload.helper.js.map +1 -0
  21. package/dist/core/common/interceptors/translate-response.interceptor.js +4 -0
  22. package/dist/core/common/interceptors/translate-response.interceptor.js.map +1 -1
  23. package/dist/core/common/interfaces/server-options.interface.d.ts +11 -0
  24. package/dist/core/common/middleware/request-context.middleware.js +3 -0
  25. package/dist/core/common/middleware/request-context.middleware.js.map +1 -1
  26. package/dist/core/common/services/request-context.service.d.ts +2 -0
  27. package/dist/core/common/services/request-context.service.js +3 -0
  28. package/dist/core/common/services/request-context.service.js.map +1 -1
  29. package/dist/core/modules/ai/core-ai-mcp.controller.js +4 -2
  30. package/dist/core/modules/ai/core-ai-mcp.controller.js.map +1 -1
  31. package/dist/core/modules/ai/core-ai.constants.d.ts +1 -0
  32. package/dist/core/modules/ai/core-ai.constants.js +1 -0
  33. package/dist/core/modules/ai/core-ai.constants.js.map +1 -1
  34. package/dist/core/modules/ai/core-ai.module.js +2 -0
  35. package/dist/core/modules/ai/core-ai.module.js.map +1 -1
  36. package/dist/core/modules/ai/decorators/ai-agent-function.decorator.d.ts +8 -0
  37. package/dist/core/modules/ai/decorators/ai-agent-function.decorator.js +8 -0
  38. package/dist/core/modules/ai/decorators/ai-agent-function.decorator.js.map +1 -0
  39. package/dist/core/modules/ai/helpers/ai-verified-user.helper.d.ts +12 -0
  40. package/dist/core/modules/ai/helpers/ai-verified-user.helper.js +23 -0
  41. package/dist/core/modules/ai/helpers/ai-verified-user.helper.js.map +1 -0
  42. package/dist/core/modules/ai/index.d.ts +8 -0
  43. package/dist/core/modules/ai/index.js +8 -0
  44. package/dist/core/modules/ai/index.js.map +1 -1
  45. package/dist/core/modules/ai/interfaces/llm-provider.interface.d.ts +1 -0
  46. package/dist/core/modules/ai/models/core-ai-mcp-oauth.models.js +2 -0
  47. package/dist/core/modules/ai/models/core-ai-mcp-oauth.models.js.map +1 -1
  48. package/dist/core/modules/ai/providers/ai-egress.helper.d.ts +6 -0
  49. package/dist/core/modules/ai/providers/ai-egress.helper.js +58 -0
  50. package/dist/core/modules/ai/providers/ai-egress.helper.js.map +1 -0
  51. package/dist/core/modules/ai/providers/ai-sdk.packages.d.ts +16 -0
  52. package/dist/core/modules/ai/providers/ai-sdk.packages.js +99 -0
  53. package/dist/core/modules/ai/providers/ai-sdk.packages.js.map +1 -0
  54. package/dist/core/modules/ai/providers/ai-sdk.provider.d.ts +51 -0
  55. package/dist/core/modules/ai/providers/ai-sdk.provider.js +244 -0
  56. package/dist/core/modules/ai/providers/ai-sdk.provider.js.map +1 -0
  57. package/dist/core/modules/ai/providers/llm-provider.factory.d.ts +11 -1
  58. package/dist/core/modules/ai/providers/llm-provider.factory.js +44 -3
  59. package/dist/core/modules/ai/providers/llm-provider.factory.js.map +1 -1
  60. package/dist/core/modules/ai/providers/openai-compatible.provider.js +4 -21
  61. package/dist/core/modules/ai/providers/openai-compatible.provider.js.map +1 -1
  62. package/dist/core/modules/ai/services/core-ai-agent-function.bridge.d.ts +34 -0
  63. package/dist/core/modules/ai/services/core-ai-agent-function.bridge.js +130 -0
  64. package/dist/core/modules/ai/services/core-ai-agent-function.bridge.js.map +1 -0
  65. package/dist/core/modules/ai/services/core-ai-mcp-oauth.service.d.ts +28 -3
  66. package/dist/core/modules/ai/services/core-ai-mcp-oauth.service.js +141 -15
  67. package/dist/core/modules/ai/services/core-ai-mcp-oauth.service.js.map +1 -1
  68. package/dist/core/modules/ai/services/core-ai-mcp.service.js +2 -1
  69. package/dist/core/modules/ai/services/core-ai-mcp.service.js.map +1 -1
  70. package/dist/core/modules/ai/services/core-ai.service.js +2 -7
  71. package/dist/core/modules/ai/services/core-ai.service.js.map +1 -1
  72. package/dist/core/modules/ai/tools/ai-tool-result.helper.d.ts +2 -0
  73. package/dist/core/modules/ai/tools/ai-tool-result.helper.js +117 -0
  74. package/dist/core/modules/ai/tools/ai-tool-result.helper.js.map +1 -0
  75. package/dist/core/modules/ai/tools/ai-tool-schema.helper.d.ts +36 -0
  76. package/dist/core/modules/ai/tools/ai-tool-schema.helper.js +81 -0
  77. package/dist/core/modules/ai/tools/ai-tool-schema.helper.js.map +1 -0
  78. package/dist/core/modules/ai/tools/ai-tool.registry.js +2 -1
  79. package/dist/core/modules/ai/tools/ai-tool.registry.js.map +1 -1
  80. package/dist/core/modules/auth/guards/auth.guard.js +10 -2
  81. package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
  82. package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js +4 -1
  83. package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js.map +1 -1
  84. package/dist/core/modules/auth/guards/roles.guard.js +11 -1
  85. package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
  86. package/dist/core/modules/better-auth/better-auth-roles.guard.js +15 -1
  87. package/dist/core/modules/better-auth/better-auth-roles.guard.js.map +1 -1
  88. package/dist/core/modules/better-auth/better-auth.config.js +78 -0
  89. package/dist/core/modules/better-auth/better-auth.config.js.map +1 -1
  90. package/dist/core/modules/file/core-file.controller.js +8 -0
  91. package/dist/core/modules/file/core-file.controller.js.map +1 -1
  92. package/dist/core/modules/tenant/core-tenant.guard.js +9 -1
  93. package/dist/core/modules/tenant/core-tenant.guard.js.map +1 -1
  94. package/dist/core.module.js +2 -1
  95. package/dist/core.module.js.map +1 -1
  96. package/dist/index.d.ts +1 -0
  97. package/dist/index.js +1 -0
  98. package/dist/index.js.map +1 -1
  99. package/dist/types/graphql-upload.d.ts +34 -2
  100. package/docs/REQUEST-LIFECYCLE.md +46 -9
  101. package/docs/security-overrides.md +44 -10
  102. package/migration-guides/12.9.3-to-12.9.4.md +137 -0
  103. package/migration-guides/12.9.x-to-12.10.x.md +271 -0
  104. package/package.json +62 -37
  105. package/src/core/common/decorators/rest-user.decorator.ts +6 -0
  106. package/src/core/common/filters/http-exception-log.filter.ts +8 -0
  107. package/src/core/common/helpers/context.helper.ts +14 -0
  108. package/src/core/common/helpers/decorator.helper.ts +5 -0
  109. package/src/core/common/helpers/execution-context-request.helper.ts +97 -1
  110. package/src/core/common/helpers/graphql-upload.helper.ts +427 -0
  111. package/src/core/common/interceptors/translate-response.interceptor.ts +8 -0
  112. package/src/core/common/interfaces/server-options.interface.ts +98 -0
  113. package/src/core/common/middleware/request-context.middleware.ts +3 -0
  114. package/src/core/common/services/request-context.service.ts +11 -0
  115. package/src/core/modules/ai/INTEGRATION-CHECKLIST.md +16 -0
  116. package/src/core/modules/ai/README.md +101 -0
  117. package/src/core/modules/ai/core-ai-mcp.controller.ts +7 -2
  118. package/src/core/modules/ai/core-ai.constants.ts +4 -0
  119. package/src/core/modules/ai/core-ai.module.ts +3 -0
  120. package/src/core/modules/ai/decorators/ai-agent-function.decorator.ts +44 -0
  121. package/src/core/modules/ai/helpers/ai-verified-user.helper.ts +47 -0
  122. package/src/core/modules/ai/index.ts +8 -0
  123. package/src/core/modules/ai/interfaces/ai-tool.interface.ts +5 -1
  124. package/src/core/modules/ai/interfaces/llm-provider.interface.ts +6 -0
  125. package/src/core/modules/ai/models/core-ai-mcp-oauth.models.ts +4 -0
  126. package/src/core/modules/ai/providers/ai-egress.helper.ts +98 -0
  127. package/src/core/modules/ai/providers/ai-sdk.packages.ts +153 -0
  128. package/src/core/modules/ai/providers/ai-sdk.provider.ts +383 -0
  129. package/src/core/modules/ai/providers/llm-provider.factory.ts +93 -2
  130. package/src/core/modules/ai/providers/openai-compatible.provider.ts +5 -23
  131. package/src/core/modules/ai/services/core-ai-agent-function.bridge.ts +170 -0
  132. package/src/core/modules/ai/services/core-ai-mcp-oauth.service.ts +240 -20
  133. package/src/core/modules/ai/services/core-ai-mcp.service.ts +3 -1
  134. package/src/core/modules/ai/services/core-ai.service.ts +5 -7
  135. package/src/core/modules/ai/tools/ai-tool-result.helper.ts +153 -0
  136. package/src/core/modules/ai/tools/ai-tool-schema.helper.ts +134 -0
  137. package/src/core/modules/ai/tools/ai-tool.registry.ts +6 -1
  138. package/src/core/modules/auth/guards/auth.guard.ts +19 -2
  139. package/src/core/modules/auth/guards/legacy-auth-rate-limit.guard.ts +9 -2
  140. package/src/core/modules/auth/guards/roles.guard.ts +23 -1
  141. package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +11 -0
  142. package/src/core/modules/better-auth/README.md +204 -0
  143. package/src/core/modules/better-auth/better-auth-roles.guard.ts +29 -1
  144. package/src/core/modules/better-auth/better-auth.config.ts +138 -1
  145. package/src/core/modules/file/README.md +1 -0
  146. package/src/core/modules/file/core-file.controller.ts +17 -0
  147. package/src/core/modules/tenant/core-tenant.guard.ts +13 -1
  148. package/src/core.module.ts +5 -1
  149. package/src/index.ts +1 -0
  150. package/src/types/graphql-upload.d.ts +34 -2
@@ -0,0 +1,137 @@
1
+ # Migration Guide: 12.9.3 → 12.9.4
2
+
3
+ ## Overview
4
+
5
+ | Category | Details |
6
+ |---|---|
7
+ | **Breaking Changes** | None in nest-server. NestJS 12.5.0, which `pnpm run update` installs, adds startup errors for configurations it used to ignore (§2) |
8
+ | **New Features** | None |
9
+ | **Bugfixes** | Every S3 download the client aborted mid-transfer logged `ERROR File download failed: aborted` with a stack trace (§1) |
10
+ | **Security** | NestJS 12.5.0 closes three high advisories of the Express stack (process crashes; §2). `ws` GHSA-37g9-w4hg-h9qr (high, unauthenticated memory-exhaustion DoS through the GraphQL WebSocket) — add one override to your `pnpm-workspace.yaml` (§3) |
11
+ | **Migration Effort** | `pnpm run update`, one override (§3), a test run against NestJS 12.5.0 (§2) |
12
+
13
+ ## Quick Migration
14
+
15
+ ```bash
16
+ pnpm add @lenne.tech/nest-server@12.9.4
17
+ pnpm run update # nest-server-starter based projects
18
+ # add the ws override from §3 to pnpm-workspace.yaml, then: pnpm install
19
+ pnpm run build
20
+ pnpm test
21
+ ```
22
+
23
+ **Vendor mode**: run `/lt-dev:backend:update-nest-server-core` as usual.
24
+
25
+ ## 1. No ERROR for downloads the client aborts
26
+
27
+ A client that leaves while an S3 download is still streaming is normal traffic, and with 12.9.3 a frequent one: a video
28
+ player aborts the running range on every seek. Each of them logged
29
+
30
+ ```
31
+ ERROR [CoreFileController] File download failed: aborted
32
+ Error: aborted
33
+ at Socket.socketCloseListener (node:_http_client:…)
34
+ ```
35
+
36
+ through the framework's download routes and every project route that delivers with `pipeFileToResponse()` — under the
37
+ load in which the `S3 socket pool exhausted:` line has to stand out.
38
+
39
+ The cause is an order of listeners. `downloadAbortSignal(res)` is created before the rights check (the client may leave
40
+ while it runs), so its listeners come first. On the event that reports the client gone it aborts the S3 request, and the
41
+ SDK fails the body with `aborted` inside that same dispatch, before `pipeFileToResponse()` has seen the client leave.
42
+ It shows through a Nest route, whose GET request is not read to its end, so the request's `close` reports the abort.
43
+
44
+ Since 12.9.4 `pipeFileToResponse()` reads a stream error while the client is gone (`isResponseGone(res)`, or one of its
45
+ own client-gone signals) as the end of an aborted download: nothing is sent, one debug line is logged, the socket was
46
+ already released. A store error while the client is still connected is an ERROR as before.
47
+
48
+ Nothing to change in a project. A route that delivers with its own code instead of `pipeFileToResponse()` should switch
49
+ to it (see the 12.8.9 guide).
50
+
51
+ ## 2. Dependencies: NestJS 12.5.0
52
+
53
+ 12.9.4 declares NestJS 12.5.0. `pnpm run update` raises these pins of a nest-server-starter based project:
54
+
55
+ | Package | From | To |
56
+ |---|---|---|
57
+ | `@nestjs/common`, `@nestjs/core`, `@nestjs/platform-express` | 12.4.2 | 12.5.0 |
58
+ | `@nestjs/graphql` | 14.2.0 | 14.2.1 |
59
+ | `@nestjs/schedule` | 12.0.3 | 12.0.4 |
60
+ | `@nestjs/swagger` | 12.1.1 | 12.1.2 |
61
+ | `@nestjs/cli` (dev) | 12.0.12 | 12.0.13 |
62
+ | `@nestjs/testing` (dev) | 12.4.2 | 12.5.0 |
63
+ | `oxlint-tsgolint` (dev) | 7.0.2006 | 7.0.2007 |
64
+ | `vite` (dev) | 8.3.7 | 8.3.8 |
65
+
66
+ Update `@nestjs/core` and the platform package together: the adapter passes new route-matching options to the core.
67
+
68
+ **Why now: NestJS 12.5.0 is a security release.** Its advisories of 2026-11-12 include three high ones for an
69
+ application on Express, all fixed only in 12.5.0:
70
+
71
+ | Advisory | Package | What |
72
+ |---|---|---|
73
+ | [GHSA-q223-fc7f-xg75](https://github.com/nestjs/nest/security/advisories/GHSA-q223-fc7f-xg75) | `@nestjs/core` 12.4.x | Process crash when a handler returns a stream that fails before it is read |
74
+ | [GHSA-c8fr-c7pf-58pf](https://github.com/nestjs/nest/security/advisories/GHSA-c8fr-c7pf-58pf) | `@nestjs/platform-express` < 12.5.0 | Process crash via a multipart request with many fields |
75
+ | [GHSA-jgpx-8x6j-fcpf](https://github.com/nestjs/nest/security/advisories/GHSA-jgpx-8x6j-fcpf) | `@nestjs/common` < 12.5.0 | Process crash via many files validated at once by `ParseFilePipe` |
76
+
77
+ They were not in GitHub's global advisory database on 2026-11-14, so `pnpm audit` does not report them yet. A project
78
+ that pins `@nestjs/*` itself below 12.5.0 stays affected whatever nest-server version it runs.
79
+
80
+ NestJS 12.5.0 changes behaviour that a REST / GraphQL application on Express can meet (full list in its
81
+ [release notes](https://github.com/nestjs/nest/releases/tag/v12.5.0)):
82
+
83
+ - **New startup errors.** A guard, interceptor or pipe that cannot run (an abstract class as token, a class given as
84
+ the `useValue` of `APP_GUARD`) and an invalid `forRoutes()` / `exclude()` entry now stop the application at startup.
85
+ They did nothing before, so the fix is to correct or remove the entry — boot the application once after the update.
86
+ - Middleware passed to `forRoutes()` is now also mounted on routes excluded from the global prefix.
87
+ - Multipart requests are capped at 1000 parts by default (`limits.parts` raises it), which also caps a `maxCount` above 1000.
88
+ - A `SyntaxError` / `URIError` without a status thrown by an `app.use()` middleware answers 500 instead of 400.
89
+ - An `@Optional()` dependency that exists but fails to build now fails its consumer instead of arriving as `undefined`.
90
+ - A limit given as `NaN` (`Number(process.env.UNSET)`) now gets its default instead of switching the limit off.
91
+
92
+ `@apollo/server` stays at 5.5.1. 5.5.2 caps `@graphql-tools/utils` below 12.0.2 for Node 20 installs and thereby brings
93
+ back GHSA-c4qx-w738-7hr3 (high); this framework requires Node >= 22.15, so 5.5.2 adds nothing. Do not raise it in a
94
+ project either.
95
+
96
+ **better-auth** is your project's own pin; nest-server 12.9.4 is tested with 1.7.23 and its peer range is unchanged.
97
+ If you raise it past 1.7.21, two changes from better-auth apply: a throw from `sendVerificationEmail` no longer rejects
98
+ a sign-up (it is logged, the sign-up succeeds — the user stays unverified and can request the mail again), and the
99
+ MongoDB adapter builds indexes for fields marked `unique` / `index` at startup — one that fails (duplicate e-mail
100
+ addresses, a conflicting index) has to be fixed before the application starts cleanly.
101
+
102
+ ## 3. Security: one override for `ws`
103
+
104
+ [GHSA-37g9-w4hg-h9qr](https://github.com/websockets/ws/security/advisories/GHSA-37g9-w4hg-h9qr) (high): a client floods
105
+ ping frames without reading the replies, the server buffers the automatic pongs, and the process runs out of memory. It
106
+ needs no authentication, and every application with GraphQL subscriptions accepts the WebSocket. Patched in `ws`
107
+ 8.23.0. The GraphQL WebSocket server runs on the `ws` copy of `@nestjs/graphql`, which 14.2.1 — the newest release —
108
+ exact-pins at 8.22.1. nest-server's own `overrides:` do not reach your install (`docs/security-overrides.md`), so put the
109
+ entry into your project's `pnpm-workspace.yaml` and run `pnpm install`. A nest-server-starter based project already has
110
+ an 8.x entry, `'ws@>=8.0.0 <8.22.1': 8.22.1`: **replace** it, do not only raise its target — its key does not match
111
+ the exact `8.22.1` that `@nestjs/graphql` requests, so the vulnerable copy would stay. Its 7.x entry
112
+ `'ws@>=7.0.0 <7.5.13': 7.5.13` is a pre-emptive floor for projects that add `subscriptions-transport-ws`; 7.5.13 is
113
+ covered by the same advisory (patched 7.5.14), so raise it to `'ws@>=7.0.0 <7.5.14': '7.5.14'` as well.
114
+
115
+ ```yaml
116
+ overrides:
117
+ # GHSA-37g9-w4hg-h9qr (high): @nestjs/graphql 14.2.1 exact-pins ws 8.22.1. Keep the target in lockstep with the
118
+ # ws version @lenne.tech/nest-server declares (8.23.0 since 12.9.4). Remove once @nestjs/graphql pins ws >= 8.23.0.
119
+ 'ws@>=8.0.0 <8.23.0': '8.23.0'
120
+ ```
121
+
122
+ `pnpm why ws` must then show a single `ws@8.23.0`. Until GitHub's global advisory database lists the advisory,
123
+ `pnpm audit` does not report the vulnerable version — a green audit does not mean the project is not affected. A
124
+ vendor-mode project adds the same entry.
125
+
126
+ ## Troubleshooting
127
+
128
+ | Symptom | Cause | Fix |
129
+ |---|---|---|
130
+ | `ERROR [CoreFileController] File download failed: aborted` with `socketCloseListener` in the stack, one per aborted download | 12.8.9 – 12.9.3 on S3 | Update to 12.9.4 |
131
+ | The application stops at startup after the update, naming a guard, interceptor, pipe or a `forRoutes()` / `exclude()` entry | NestJS 12.5.0 refuses what 12.4 ignored (§2) | Correct or remove the entry; it never took effect |
132
+ | `pnpm why ws` lists `ws@8.22.1` under `@nestjs/graphql` | The override from §3 is missing, or the old `<8.22.1` key was kept with only its target raised | Use exactly `'ws@>=8.0.0 <8.23.0': '8.23.0'`, `pnpm install` |
133
+
134
+ ## Module Documentation
135
+
136
+ - `src/core/modules/file/README.md` — "Error responses"
137
+ - `docs/security-overrides.md` — "Status since 12.9.4", "The fix"
@@ -0,0 +1,271 @@
1
+ # Migration Guide: 12.9.x → 12.10.x
2
+
3
+ > **This minor contains breaking changes** (see "Breaking Changes"): secret fields no longer reach the model, the client
4
+ > or an MCP client through an AI tool result; a failed OAuth sign-in without its own error URL lands on the app's login
5
+ > page instead of Better-Auth's error page; a `socialProviders.<name>.scope` that is neither a string nor a list is
6
+ > ignored. The MAJOR digit follows NestJS, so a breaking change ships as a minor here — read this guide before updating.
7
+
8
+ ## Overview
9
+
10
+ | Category | Details |
11
+ |----------|---------|
12
+ | **Breaking Changes** | (1) Failed OAuth sign-ins without their own error URL, and `GET /iam/error`, now land on `<appUrl>/auth/login?error=<code>` (`betterAuth.errorUrl`, `false` restores Better-Auth's page). (2) A `socialProviders.<name>.scope` that is neither a string nor a list is ignored with an error at boot. (3) AI tool results lose every secret field (`password`, `verificationToken`, `passwordResetToken`, `passwordResetTokenExpiresAt`, `refreshTokens`, `tempTokens`, `apiKeyEncrypted`, `security.secretFields`, each also as its SQL column) — in the chat loop, in `actions[].result` and in `/ai/mcp` `tools/call` |
13
+ | **Security fixes** | GraphQL multipart uploads: one anonymous request to `/graphql` could crash the process (graphql-upload GHSA-5vm7-vc2x-p3w2, high), and duplicate file fields leaked temporary files (GHSA-qwwm-252j-9whw, medium) — fixed by the framework's own parser, no action needed (see "Security: GraphQL multipart uploads"). MCP OAuth tokens are bound to their resource (RFC 8707). With `@nestjs/ai` or `@nestjs/mcp` installed, the framework's global guards decided agent function / MCP tool calls on the tool ARGUMENTS (`switchToHttp()` is index 0 there): `{ "user": { "roles": ["admin"] } }` in a model's tool call was the authenticated caller. Now the request the call runs in decides; a request-less caller is anonymous |
14
+ | **New Features** | Social provider options reach Better-Auth (`tenantId`, `scope`, `prompt`, `mapProfileToUser`, …), `scope` from an environment variable, `betterAuth.errorUrl`; AI SDK transport (`providerType: 'nestjs-ai'`, `LlmProviderFactory.registerAiSdkModel()`), `@AgentFunction()` methods as AI tools (`ai.agentFunctions`, `@AiAgentFunction()`), Standard Schema tool parameters, `CoreAiMcpOAuthService.createMcpTokenVerifier()` for a `@nestjs/mcp` endpoint, `RequestContext.getRequest()`, `LlmCompletionOptions.abortSignal` |
15
+ | **Bugfixes** | `HttpExceptionLogFilter` no longer throws on non-HTTP transports (the model read "Internal server error" for every refusal of an agent function) |
16
+ | **Migration Effort** | ~5 minutes: check that the app has `/auth/login` (or set `betterAuth.errorUrl`), and that no AI tool returns a secret-named field on purpose |
17
+
18
+ ## Quick Migration
19
+
20
+ ```bash
21
+ pnpm add @lenne.tech/nest-server@12.10.x
22
+ pnpm run update # only if you use the starter's update script
23
+ pnpm run build
24
+ pnpm test
25
+ ```
26
+
27
+ No new dependency is required. `ai`, `@nestjs/ai` and `@nestjs/resilience` are new **optional** peers — install them
28
+ only for the integrations below.
29
+
30
+ ## Security: GraphQL multipart uploads (graphql-upload GHSA-5vm7-vc2x-p3w2, GHSA-qwwm-252j-9whw)
31
+
32
+ **No action needed** unless the project registers `graphqlUploadExpress()` itself (below).
33
+
34
+ `CoreModule` registers graphql-upload's `graphqlUploadExpress()` for `/graphql`, in front of every guard. Up to 12.9.x
35
+ it ran graphql-upload's own `processRequest`, which accepted any object path in the multipart `map` field:
36
+
37
+ - **GHSA-5vm7-vc2x-p3w2 (high):** a path into an upload placed by an earlier entry replaced one of its methods. A
38
+ request with `map={"1":["variables.file"],"2":["variables.file.reject"]}` and no file fields made the parser throw
39
+ `TypeError: upload.reject is not a function` outside any request — an uncaught exception, on which the process
40
+ exits (`installProcessDiagnostics()` exits 1, as Node does without it). **One anonymous request took the server
41
+ down.** A path with a `__proto__` key let a client-supplied object pass the `GraphQLUpload` scalar's check.
42
+ - **GHSA-qwwm-252j-9whw (medium):** a second file field with the name of an already resolved upload created another
43
+ temporary file and dropped the reference to the first, which was never deleted — temporary files and file
44
+ descriptors leaked per request.
45
+
46
+ graphql-upload fixed both in 18.0.2, which requires graphql 17; this framework runs graphql 16. 12.10.0 therefore
47
+ ships `processGraphQlUploadRequest` (`common/helpers/graphql-upload.helper.ts`): graphql-upload 17.1.0's parser with
48
+ both upstream fixes, and `CoreModule` passes it to `graphqlUploadExpress()`. Such a `map` path is answered with 400
49
+ "Invalid object path", a duplicate file field is ignored. graphql-upload stays at 17.1.0 for its scalar and middleware.
50
+
51
+ **A project that registers `graphqlUploadExpress()` itself** (its own route, its own limits) passes the framework's
52
+ parser — graphql-upload's default is the vulnerable one:
53
+
54
+ ```typescript
55
+ import { processGraphQlUploadRequest } from '@lenne.tech/nest-server';
56
+ import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
57
+
58
+ consumer
59
+ .apply(graphqlUploadExpress({ maxFiles: 10, maxFileSize: 10_000_000, processRequest: processGraphQlUploadRequest }))
60
+ .forRoutes('graphql');
61
+ ```
62
+
63
+ Find such registrations with `grep -rn "graphqlUploadExpress(" src/`. A project that calls graphql-upload's
64
+ `processRequest` directly switches to `processGraphQlUploadRequest` (same signature and options).
65
+
66
+ **Behaviour change:** a GraphQL variable literally named `__proto__` that receives a file is refused with 400 (input
67
+ object fields cannot use that name; names starting with `__` are reserved).
68
+
69
+ ## What's New in 12.10.x
70
+
71
+ ### 0. Social sign-in: provider options and the error page (Better-Auth)
72
+
73
+ - **Provider options reach Better-Auth.** Until 12.9.4 `buildSocialProviders()` handed a provider only `clientId`,
74
+ `clientSecret` and `disableSignUp`; `tenantId`, `scope` and every other option were dropped without a word (a Microsoft
75
+ sign-in ran against `common` with Better-Auth's default scopes). Every option on `betterAuth.socialProviders.<name>`
76
+ except `enabled` is now passed on; the computed `clientId` / `clientSecret` / `disableSignUp` are written last, so a
77
+ string `disableSignUp` from `NEST_SERVER_CONFIG` still cannot open a closed registration.
78
+ - **`scope` from an environment variable works.** `NSC__…__SCOPE=openid,profile,email` is split on commas or spaces.
79
+ - **`betterAuth.errorUrl`** (`string | false`, default `<appUrl>/auth/login`; a path is resolved against the app URL)
80
+ becomes Better-Auth's `onAPIError.errorURL`. `options.onAPIError` is merged; its own `errorURL` wins.
81
+
82
+ ```typescript
83
+ betterAuth: {
84
+ errorUrl: '/auth/login', // default; false keeps Better-Auth's page on the API host
85
+ socialProviders: {
86
+ microsoft: { clientId, clientSecret, tenantId: '<tenant-id>', scope: 'openid,profile,email' },
87
+ },
88
+ },
89
+ ```
90
+
91
+ A login page maps the `error` query code to its own text and never renders `error_description` — anyone can set it
92
+ through a link to `/iam/error`. Details: [Better-Auth README](../src/core/modules/better-auth/README.md), "Social
93
+ providers".
94
+
95
+ ### 1. Global guards on `@nestjs/ai` and `@nestjs/mcp` calls
96
+
97
+ `@nestjs/ai` (`@AgentFunction()`) and `@nestjs/mcp` (`@Tool()`, `@Resource()`, `@Prompt()`) run every global guard,
98
+ interceptor and filter around their methods with the context types `'ai'` / `'mcp'`. The framework now resolves the
99
+ request of such a call from the call object (`caller.request`, `McpContext.request`):
100
+
101
+ - `@Roles()` on an agent function or MCP tool is decided against the request's user exactly as over HTTP, tenant
102
+ header included.
103
+ - A **request-less** caller — `caller: { user, scopes }` (a queue job), a durable run, MCP over stdio — is
104
+ **anonymous**: public methods run, every other one is refused with 401. To run a role-gated agent function from a job,
105
+ authenticate there and pass a request (`caller: { request }`).
106
+ - `@Restricted` and secret-field filtering apply to the result for the request's user.
107
+
108
+ Nothing to do unless you relied on the old behaviour (which read the tool arguments).
109
+
110
+ ### 2. AI SDK transport
111
+
112
+ ```typescript
113
+ // A model of @nestjs/ai's AiModule.forRoot({ models }): create a connection with
114
+ // providerType 'nestjs-ai', model 'default' (the registered name), baseUrl 'nestjs-ai:default'.
115
+
116
+ // Or any AI SDK provider for database-managed connections:
117
+ await llmProviderFactory.registerAiSdkModel('anthropic', (connection, { fetch }) =>
118
+ createAnthropic({ apiKey: connection.apiKey, fetch })(connection.model),
119
+ );
120
+ ```
121
+
122
+ Requires `ai` (`>=7.0.0 <8`); `nestjs-ai` additionally `@nestjs/ai` (`>=0.0.2 <0.0.3`) and `@nestjs/resilience`
123
+ (`>=0.0.3 <0.0.4`). Outside these ranges the call / boot fails with `AiSdkPackageError` naming the range. Hand the
124
+ provider the `fetch` from the builder context, or `ai.allowedBaseUrlHosts` does not cover it.
125
+
126
+ ### 3. Agent functions as AI tools
127
+
128
+ ```typescript
129
+ // config.env.ts
130
+ ai: { agentFunctions: true }, // or { include: ['cancel_booking'] } / { exclude: [...] }
131
+
132
+ // on the method
133
+ @AgentFunction({ name: 'cancel_booking', description: 'Cancel a booking', inputSchema: z.object({ id: z.string() }) })
134
+ @AiAgentFunction({ destructive: true })
135
+ @Roles(RoleEnum.S_USER)
136
+ cancel({ id }: { id: string }) { ... }
137
+ ```
138
+
139
+ The AI module's gates run first (role filter, policies and grants, `authorize()`, confirmation, plan mode, budgets),
140
+ then `@nestjs/ai`'s pipeline with the run's HTTP request. Roles default to the method's `@Roles()`, else `S_USER`.
141
+
142
+ ### 4. Standard Schema tool parameters
143
+
144
+ ```typescript
145
+ readonly parameters = z.object({ id: z.string() }) as any; // Zod 4.2+, ArkType, Valibot via toStandardJsonSchema()
146
+ ```
147
+
148
+ The registry stores the JSON Schema and validates the arguments before `authorize()` and `execute()`.
149
+
150
+ ### 5. A `@nestjs/mcp` endpoint with the framework's MCP OAuth server
151
+
152
+ `CoreAiMcpOAuthService.createMcpTokenVerifier({ resource })` returns a verifier for `McpModule`'s `auth.verifier`
153
+ (module README → "Your own `@nestjs/mcp` endpoint").
154
+
155
+ ### 6. MCP OAuth tokens are bound to their resource (RFC 8707)
156
+
157
+ The authorization server honours `resource` at `/authorize` and `/token` (code and refresh grant) and binds it into the
158
+ code, the refresh token and the access token (`aud`). `/ai/mcp` accepts only tokens for itself, a
159
+ `createMcpTokenVerifier()` only tokens for its `resource`; an unknown `resource` is `invalid_target`. Nothing changes for
160
+ today's clients: one that names no `resource` gets a token for `/ai/mcp`, and tokens and refresh tokens issued before
161
+ 12.10.0 stay valid at `/ai/mcp` (a refresh binds them to it). **SQL projects:** the tables of the MCP OAuth codes and refresh
162
+ tokens (collections `aiMcpOAuthCodes` / `aiMcpOAuthRefreshTokens` on MongoDB) gain a nullable `resource` column, which the boot adds as the owner role (`ownerUrl`);
163
+ without an owner connection add it with a migration.
164
+
165
+ ### 7. Dependencies
166
+
167
+ 12.10.0 declares NestJS 12.5.1. `pnpm run update` raises these pins where a nest-server-starter based project already
168
+ declares them:
169
+
170
+ | Package | From | To |
171
+ |---|---|---|
172
+ | `@nestjs/common`, `@nestjs/core`, `@nestjs/platform-express`, `@nestjs/testing` | 12.5.0 | 12.5.1 |
173
+ | `@nestjs/terminus` | 12.1.0 | 12.2.0 |
174
+ | `graphql-subscriptions` | 3.0.0 | 3.1.0 |
175
+ | `js-sha256` | 1.0.0 | 1.1.0 |
176
+ | `nodemailer` | 10.5.0 | 10.6.0 |
177
+ | `mongoose` (MongoDB projects) | 9.12.1 | 9.12.2 |
178
+
179
+ Where declared, also the optional peers `bullmq` 6.7.7, `@aws-sdk/*` 3.1171.0 and `ai` 7.0.176, and `vitest` /
180
+ `@vitest/coverage-v8` 5.1.1. `js-sha256` 1.1.0 now hashes multi-byte typed arrays (`Uint16Array`, `Float32Array`, …) by
181
+ their bytes, as Node's `crypto` does; string input — what the framework hashes — gives the same digests as before.
182
+
183
+ New direct `dependencies` for the multipart parser (see "Security: GraphQL multipart uploads"): `busboy` 1.6.0,
184
+ `fs-capacitor` 8.0.0, `http-errors` 2.0.1 and `object-path` 0.11.8 — the versions graphql-upload 17.1.0 already
185
+ installed, so an npm-mode project gets no new package. A vendor-mode project declares them (the core imports them
186
+ directly).
187
+
188
+ ## Breaking Changes
189
+
190
+ ### Failed OAuth sign-ins land on the app's login page
191
+
192
+ **Before:** a failed OAuth sign-in without an error URL of its own (state expired after ten minutes, missing or tampered;
193
+ a flow started without `errorCallbackURL`) and every `GET /iam/error` showed Better-Auth's English error page on the API
194
+ host.
195
+
196
+ **After:** they land on `<appUrl>/auth/login?error=<code>`.
197
+
198
+ **Action:** make sure the app has an `/auth/login` route that reads `error`, or set `betterAuth.errorUrl` to another
199
+ page (an absolute URL or a path). A project that customized Better-Auth's page
200
+ (`options.onAPIError.customizeDefaultErrorPage`) sets `betterAuth.errorUrl: false`. An explicit
201
+ `options.onAPIError.errorURL` still wins.
202
+
203
+ ### A `scope` that is neither a string nor a list is ignored
204
+
205
+ **Before:** an object (indexed `NSC__…__SCOPE__0` variables) made every `/iam/sign-in/social` throw a `TypeError`.
206
+
207
+ **After:** it is dropped with one error at boot, and the provider asks for its default scopes — with
208
+ `disableDefaultScope: true` for none, which the provider refuses.
209
+
210
+ **Action:** write one comma-separated `NSC__…__SCOPE` variable.
211
+
212
+ ### Secret fields leave AI tool results
213
+
214
+ **Before:** `CoreAiService.sanitizeResult()` ran `securityCheck()` on model instances only, and `/ai/mcp` sent
215
+ `JSON.stringify(result)`. A tool returning a lean document or a plain object handed its secret fields to the model, to
216
+ `actions[].result` and to the MCP client.
217
+
218
+ **After:** both paths use `sanitizeToolResultForModel()`: `securityCheck(user)` on every model instance at any depth —
219
+ also inside the `{ success, data }` wrapper, which `/ai/mcp` never looked into — then every field named in
220
+ `security.secretFields` or the framework defaults (also as SQL column, `password_reset_token`) is removed, at any depth.
221
+ A Mongoose document is replaced by its stripped `toJSON()`; a class instance becomes a plain copy of its own enumerable
222
+ fields (what `JSON.stringify` read anyway). An MCP OAuth user now carries `hasRole()` (string or array, as Better-Auth
223
+ users do) and `_authenticatedViaBetterAuth`, so a `securityCheck()` calling `user.hasRole()` works on that path.
224
+
225
+ **Action:** if a tool returns a field with such a name ON PURPOSE (it should not — the model and the client read it),
226
+ rename it. Over `/ai/mcp`, a result now loses what its models' `securityCheck()` hides from the caller, as it already did
227
+ in the chat. An override of `sanitizeResult()` keeps working.
228
+
229
+ ## Compatibility Notes
230
+
231
+ | Pattern | Status |
232
+ |---------|--------|
233
+ | `LlmProviderFactory` subclass with its own constructor | Compatible — the new `ModuleRef` parameter is optional |
234
+ | Builder registered under `'nestjs-ai'` by the project | Compatible — `registerBuilder()` replaces the built-in one |
235
+ | Override of `OpenAiCompatibleProvider.resolveAllowedBaseUrlHosts()` / `normaliseHostEntry()` | Compatible — same contract; the default bodies now delegate to `ai-egress.helper` |
236
+ | `/ai/mcp` and the MCP OAuth server | Unchanged — still `@modelcontextprotocol/sdk` 1.x (see below) |
237
+ | Projects without `ai` / `@nestjs/ai` / `@nestjs/mcp` | Unchanged — nothing new is loaded |
238
+ | Vendor mode | The core names `ai`, `@nestjs/ai` and `@nestjs/resilience` in literal `import()` calls: the project declares them (the lt CLI adds them) |
239
+ | Vendor mode, GraphQL uploads | The core imports `busboy`, `fs-capacitor`, `http-errors` and `object-path` itself (`common/helpers/graphql-upload.helper.ts`): add them to `dependencies` at the versions in §7 — a pnpm project does not see graphql-upload's own copies |
240
+ | `graphqlUploadExpress()` registered by the project | Pass `processRequest: processGraphQlUploadRequest` (see "Security: GraphQL multipart uploads") |
241
+
242
+ **Why `/ai/mcp` stays on MCP SDK v1:** `@modelcontextprotocol/server` 2.x ships no OAuth authorization-server router
243
+ (only resource-server helpers), and `@nestjs/mcp` serves every request statelessly — no sessions, no server-initiated
244
+ elicitation for 2025 clients, which the clients in use today need for the confirmation of destructive tools. A migration
245
+ that keeps every current behaviour is a release of its own.
246
+
247
+ ## Troubleshooting
248
+
249
+ | Symptom | Cause | Fix |
250
+ |---------|-------|-----|
251
+ | `AiSdkPackageError: @nestjs/ai@0.0.3 is installed, but … tested with >=0.0.2 <0.0.3` | an untested 0.x release | install a version in the range, or update `@lenne.tech/nest-server` |
252
+ | `ai.agentFunctions is set, but the application imports no AiModule.forRoot()` | the bridge needs `@nestjs/ai`'s module | import `AiModule.forRoot({ models })` or remove `ai.agentFunctions` |
253
+ | An agent function is missing from the tools | it requires `scopes` | remove `scopes`, gate it with `@Roles()` |
254
+ | A role-gated agent function answers 401 from a queue job | request-less callers are anonymous | authenticate in the job and pass `caller: { request }` |
255
+ | A `@nestjs/mcp` tool answers 401 with an MCP OAuth token | the verifier refused it (expired, `ai.mcp.roles`, unknown user) | check `ai.mcp.roles`; obtain a new token |
256
+ | A file upload answers 400 `Invalid object path for the ‘map’ multipart field …` | the `map` names a path into another upload or with a `__proto__` key | send each file at its own variable path (`variables.files.0`, `variables.files.1`) |
257
+ | Vendor mode: `Cannot find package 'busboy'` (or `fs-capacitor`, `http-errors`, `object-path`) at start | the core imports them since 12.10.0 | add them to `dependencies` (§7) |
258
+
259
+ ## Module Documentation
260
+
261
+ - [Better-Auth README](../src/core/modules/better-auth/README.md) — "Social providers", OAuth error URL
262
+ - [Better-Auth INTEGRATION-CHECKLIST](../src/core/modules/better-auth/INTEGRATION-CHECKLIST.md) — "Social provider with its own options"
263
+ - [AI module README](../src/core/modules/ai/README.md) — "NestJS AI and the AI SDK", "Your own `@nestjs/mcp` endpoint"
264
+ - [AI INTEGRATION-CHECKLIST](../src/core/modules/ai/INTEGRATION-CHECKLIST.md) — "NestJS AI / AI SDK"
265
+ - [Request lifecycle](../docs/REQUEST-LIFECYCLE.md) — "Agent function and MCP calls"
266
+
267
+ ## References
268
+
269
+ - `@nestjs/ai`: https://www.npmjs.com/package/@nestjs/ai
270
+ - `@nestjs/mcp`: https://www.npmjs.com/package/@nestjs/mcp
271
+ - AI SDK: https://ai-sdk.dev
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "12.9.3",
3
+ "version": "12.10.0",
4
4
  "type": "module",
5
5
  "description": "Server framework in TypeScript on top of NestJS: GraphQL and REST APIs on MongoDB, PostgreSQL, MySQL or MariaDB, with authentication, field-level permissions, multi-tenancy, offline sync and an AI assistant.",
6
6
  "keywords": [
@@ -100,26 +100,27 @@
100
100
  "node": ">= 22.15",
101
101
  "pnpm": "^11.0.0"
102
102
  },
103
- "packageManager": "pnpm@11.28.10+sha512.672216f06e15c109b85471d49d3fbed17e6f03ead258df08c2bf5b4a5c33321ebfbf59476bce81325efada16ace0ac78548fd0bfcd7a51369e939182a3dd50e4",
103
+ "packageManager": "pnpm@11.28.13+sha512.d5caa9cdcd6067ac2902f9f44daa00b1288a73babf1e98f4f375b3a7583b1894b4d49f7527da8f5e1530198bb10e03adba321a1f015429dc2946ce8a7a9a8c65",
104
104
  "dependencies": {
105
105
  "@apollo/server": "5.5.1",
106
106
  "@as-integrations/express5": "1.1.2",
107
107
  "@getbrevo/brevo": "6.2.0",
108
108
  "@modelcontextprotocol/sdk": "1.32.2",
109
- "@nestjs/apollo": "14.2.0",
110
- "@nestjs/common": "12.4.2",
111
- "@nestjs/core": "12.4.2",
112
- "@nestjs/graphql": "14.2.0",
113
- "@nestjs/jwt": "12.0.4",
114
- "@nestjs/passport": "12.0.1",
115
- "@nestjs/platform-express": "12.4.2",
116
- "@nestjs/schedule": "12.0.3",
117
- "@nestjs/swagger": "12.1.1",
118
- "@nestjs/terminus": "12.1.0",
109
+ "@nestjs/apollo": "14.2.1",
110
+ "@nestjs/common": "12.5.1",
111
+ "@nestjs/core": "12.5.1",
112
+ "@nestjs/graphql": "14.2.1",
113
+ "@nestjs/jwt": "12.0.5",
114
+ "@nestjs/passport": "12.0.2",
115
+ "@nestjs/platform-express": "12.5.1",
116
+ "@nestjs/schedule": "12.0.4",
117
+ "@nestjs/swagger": "12.1.2",
118
+ "@nestjs/terminus": "12.2.0",
119
119
  "@tus/file-store": "2.1.2",
120
120
  "@tus/server": "2.4.7",
121
121
  "@types/supertest": "7.2.1",
122
122
  "bcrypt": "6.0.0",
123
+ "busboy": "1.6.0",
123
124
  "class-transformer": "0.5.1",
124
125
  "class-validator": "0.15.1",
125
126
  "compression": "1.8.2",
@@ -128,18 +129,21 @@
128
129
  "dotenv": "18.0.10",
129
130
  "ejs": "7.0.2",
130
131
  "express": "5.3.0",
131
- "graphql": "16.14.2",
132
+ "fs-capacitor": "8.0.0",
133
+ "graphql": "16.15.0",
132
134
  "graphql-query-complexity": "2.0.0",
133
- "graphql-subscriptions": "3.0.0",
135
+ "graphql-subscriptions": "3.1.0",
134
136
  "graphql-upload": "17.1.0",
135
137
  "graphql-ws": "6.4.1",
138
+ "http-errors": "2.0.1",
136
139
  "jose": "6.2.17",
137
- "js-sha256": "1.0.0",
140
+ "js-sha256": "1.1.0",
138
141
  "json-to-graphql-query": "2.3.0",
139
142
  "lodash": "4.18.1",
140
143
  "multer": "2.5.0",
141
144
  "node-mailjet": "6.0.11",
142
- "nodemailer": "10.4.1",
145
+ "nodemailer": "10.6.0",
146
+ "object-path": "0.11.8",
143
147
  "passport": "0.7.0",
144
148
  "passport-jwt": "4.0.1",
145
149
  "reflect-metadata": "0.2.2",
@@ -148,7 +152,7 @@
148
152
  "supertest": "7.3.2",
149
153
  "ts-morph": "28.0.0",
150
154
  "undici": "7.30.2",
151
- "ws": "8.22.1",
155
+ "ws": "8.23.0",
152
156
  "yuml-diagram": "1.2.0"
153
157
  },
154
158
  "peerDependencies": {
@@ -157,9 +161,12 @@
157
161
  "@aws-sdk/s3-request-presigner": ">=3.1045.0 <4",
158
162
  "@better-auth/core": ">=1.7.16 <1.8.0",
159
163
  "@better-auth/passkey": ">=1.7.16 <1.8.0",
164
+ "@nestjs/ai": ">=0.0.2 <0.0.3",
160
165
  "@nestjs/mongoose": ">=12.0.0 <13",
166
+ "@nestjs/resilience": ">=0.0.3 <0.0.4",
161
167
  "@swc/core": ">=1.10.0 <2",
162
168
  "@tus/s3-store": ">=2.0.5 <3",
169
+ "ai": ">=7.0.0 <8",
163
170
  "better-auth": ">=1.7.16 <1.8.0",
164
171
  "bullmq": ">=5.16.0 <7",
165
172
  "drizzle-orm": "1.0.0-rc.5",
@@ -187,15 +194,24 @@
187
194
  "@better-auth/passkey": {
188
195
  "optional": false
189
196
  },
197
+ "@nestjs/ai": {
198
+ "optional": true
199
+ },
190
200
  "@nestjs/mongoose": {
191
201
  "optional": true
192
202
  },
203
+ "@nestjs/resilience": {
204
+ "optional": true
205
+ },
193
206
  "@swc/core": {
194
207
  "optional": true
195
208
  },
196
209
  "@tus/s3-store": {
197
210
  "optional": true
198
211
  },
212
+ "ai": {
213
+ "optional": true
214
+ },
199
215
  "better-auth": {
200
216
  "optional": false
201
217
  },
@@ -228,54 +244,63 @@
228
244
  }
229
245
  },
230
246
  "devDependencies": {
231
- "@aws-sdk/client-s3": "3.1165.0",
232
- "@aws-sdk/lib-storage": "3.1165.0",
233
- "@aws-sdk/s3-request-presigner": "3.1165.0",
234
- "@better-auth/core": "1.7.19",
235
- "@better-auth/passkey": "1.7.19",
247
+ "@aws-sdk/client-s3": "3.1171.0",
248
+ "@aws-sdk/lib-storage": "3.1171.0",
249
+ "@aws-sdk/s3-request-presigner": "3.1171.0",
250
+ "@better-auth/core": "1.7.23",
251
+ "@better-auth/passkey": "1.7.23",
236
252
  "@compodoc/compodoc": "2.0.0",
237
- "@nestjs/cli": "12.0.12",
253
+ "@modelcontextprotocol/server": "2.4.0",
254
+ "@nestjs/ai": "0.0.2",
255
+ "@nestjs/cli": "12.0.13",
256
+ "@nestjs/mcp": "0.0.4",
238
257
  "@nestjs/mongoose": "12.0.1",
258
+ "@nestjs/resilience": "0.0.3",
239
259
  "@nestjs/schematics": "12.0.13",
240
- "@nestjs/testing": "12.4.2",
260
+ "@nestjs/testing": "12.5.1",
241
261
  "@swc/cli": "0.8.2",
242
262
  "@swc/core": "1.16.22",
243
263
  "@tus/s3-store": "2.1.0",
264
+ "@types/busboy": "1.5.5",
244
265
  "@types/compression": "1.8.1",
245
266
  "@types/cookie-parser": "1.4.10",
246
267
  "@types/ejs": "3.1.5",
247
268
  "@types/express": "5.0.6",
269
+ "@types/http-errors": "2.0.5",
248
270
  "@types/lodash": "4.17.27",
249
271
  "@types/multer": "2.3.0",
250
272
  "@types/node": "26.6.6",
273
+ "@types/object-path": "0.11.4",
251
274
  "@types/passport": "1.0.17",
252
275
  "@types/pg": "8.23.1",
253
- "@vitest/coverage-v8": "5.1.0",
254
- "better-auth": "1.7.19",
255
- "bullmq": "6.7.2",
276
+ "@vitest/coverage-v8": "5.1.1",
277
+ "ai": "7.0.176",
278
+ "better-auth": "1.7.23",
279
+ "bullmq": "6.7.7",
256
280
  "cross-env": "10.1.0",
257
281
  "drizzle-orm": "1.0.0-rc.5",
258
282
  "ioredis": "6.0.0",
259
- "kysely": "0.29.8",
283
+ "kysely": "0.29.9",
260
284
  "mongodb": "7.8.0",
261
- "mongoose": "9.12.1",
285
+ "mongoose": "9.12.2",
262
286
  "mysql2": "3.24.6",
263
287
  "nodemon": "3.1.14",
264
288
  "otpauth": "9.6.0",
265
- "oxfmt": "0.78.0",
266
- "oxlint": "1.93.0",
267
- "oxlint-tsgolint": "7.0.2006",
289
+ "oxfmt": "0.79.0",
290
+ "oxlint": "1.94.0",
291
+ "oxlint-tsgolint": "7.0.2007",
268
292
  "pg": "8.23.1",
269
- "playwright-core": "1.65.0",
293
+ "playwright-core": "1.65.1",
270
294
  "rimraf": "6.1.4",
271
- "smtp-server": "3.21.3",
295
+ "smtp-server": "3.21.6",
272
296
  "tsx": "4.23.15",
273
297
  "tus-js-client": "4.3.1",
274
- "typeorm": "1.1.2",
298
+ "typeorm": "1.1.3",
275
299
  "typescript": "6.0.3",
276
300
  "unplugin-swc": "2.0.0",
277
- "vite": "8.3.7",
278
- "vitest": "5.1.0"
301
+ "vite": "8.3.8",
302
+ "vitest": "5.1.1",
303
+ "zod": "4.6.7"
279
304
  },
280
305
  "main": "dist/index.js",
281
306
  "types": "dist/index.d.ts",
@@ -1,9 +1,15 @@
1
1
  import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2
2
 
3
+ import { isAgentCallContext, resolveAgentCallRequest } from '../helpers/execution-context-request.helper.js';
4
+
3
5
  /**
4
6
  * User decorator for REST request
5
7
  */
6
8
  export const RESTUser = createParamDecorator((data: unknown, ctx: ExecutionContext) => {
9
+ // An agent function / MCP call: the request's user, never one in the call's arguments (nestjs-ai plan §1)
10
+ if (isAgentCallContext(ctx)) {
11
+ return resolveAgentCallRequest(ctx)?.user;
12
+ }
7
13
  const request = ctx.switchToHttp().getRequest();
8
14
  return request.user;
9
15
  });
@@ -37,6 +37,14 @@ export class HttpExceptionLogFilter implements ExceptionFilter {
37
37
  return exception;
38
38
  }
39
39
 
40
+ // Any transport without an HTTP response of its own — an agent function call (`'ai'`) or an MCP call (`'mcp'`),
41
+ // whose second argument is the CALL, not a response (nestjs-ai plan §1). Returning nothing hands the exception
42
+ // back to the caller's handler, which tells the model or MCP client its message. Writing to `switchToHttp()`
43
+ // there threw a TypeError instead, and the model read "Internal server error" for every 401 / 403 / 404.
44
+ if (type !== 'http') {
45
+ return undefined;
46
+ }
47
+
40
48
  // REST
41
49
  const ctx = host.switchToHttp();
42
50
  const res = ctx.getResponse<Response>();