@mastra/nestjs 0.0.0-branches-as-default-20260512170712

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 (76) hide show
  1. package/CHANGELOG.md +239 -0
  2. package/LICENSE.md +30 -0
  3. package/README.md +324 -0
  4. package/dist/__tests__/test-helpers.d.ts +17 -0
  5. package/dist/__tests__/test-helpers.d.ts.map +1 -0
  6. package/dist/constants.d.ts +34 -0
  7. package/dist/constants.d.ts.map +1 -0
  8. package/dist/controllers/index.d.ts +3 -0
  9. package/dist/controllers/index.d.ts.map +1 -0
  10. package/dist/controllers/mastra.controller.d.ts +54 -0
  11. package/dist/controllers/mastra.controller.d.ts.map +1 -0
  12. package/dist/controllers/system.controller.d.ts +45 -0
  13. package/dist/controllers/system.controller.d.ts.map +1 -0
  14. package/dist/decorators/index.d.ts +3 -0
  15. package/dist/decorators/index.d.ts.map +1 -0
  16. package/dist/decorators/public.decorator.d.ts +17 -0
  17. package/dist/decorators/public.decorator.d.ts.map +1 -0
  18. package/dist/decorators/throttle.decorator.d.ts +34 -0
  19. package/dist/decorators/throttle.decorator.d.ts.map +1 -0
  20. package/dist/filters/index.d.ts +2 -0
  21. package/dist/filters/index.d.ts.map +1 -0
  22. package/dist/filters/mastra-exception.filter.d.ts +28 -0
  23. package/dist/filters/mastra-exception.filter.d.ts.map +1 -0
  24. package/dist/guards/index.d.ts +3 -0
  25. package/dist/guards/index.d.ts.map +1 -0
  26. package/dist/guards/mastra-auth.guard.d.ts +42 -0
  27. package/dist/guards/mastra-auth.guard.d.ts.map +1 -0
  28. package/dist/guards/mastra-route.guard.d.ts +23 -0
  29. package/dist/guards/mastra-route.guard.d.ts.map +1 -0
  30. package/dist/guards/mastra-throttle.guard.d.ts +53 -0
  31. package/dist/guards/mastra-throttle.guard.d.ts.map +1 -0
  32. package/dist/index.cjs +14305 -0
  33. package/dist/index.cjs.map +1 -0
  34. package/dist/index.d.ts +23 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +14291 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/interceptors/index.d.ts +3 -0
  39. package/dist/interceptors/index.d.ts.map +1 -0
  40. package/dist/interceptors/request-tracking.interceptor.d.ts +13 -0
  41. package/dist/interceptors/request-tracking.interceptor.d.ts.map +1 -0
  42. package/dist/interceptors/streaming.interceptor.d.ts +40 -0
  43. package/dist/interceptors/streaming.interceptor.d.ts.map +1 -0
  44. package/dist/interceptors/tracing.interceptor.d.ts +12 -0
  45. package/dist/interceptors/tracing.interceptor.d.ts.map +1 -0
  46. package/dist/mastra-server.adapter.d.ts +10 -0
  47. package/dist/mastra-server.adapter.d.ts.map +1 -0
  48. package/dist/mastra.module.d.ts +173 -0
  49. package/dist/mastra.module.d.ts.map +1 -0
  50. package/dist/mastra.service.d.ts +51 -0
  51. package/dist/mastra.service.d.ts.map +1 -0
  52. package/dist/middleware/body-limit.middleware.d.ts +24 -0
  53. package/dist/middleware/body-limit.middleware.d.ts.map +1 -0
  54. package/dist/middleware/index.d.ts +3 -0
  55. package/dist/middleware/index.d.ts.map +1 -0
  56. package/dist/middleware/json-body.middleware.d.ts +17 -0
  57. package/dist/middleware/json-body.middleware.d.ts.map +1 -0
  58. package/dist/services/auth.service.d.ts +34 -0
  59. package/dist/services/auth.service.d.ts.map +1 -0
  60. package/dist/services/index.d.ts +5 -0
  61. package/dist/services/index.d.ts.map +1 -0
  62. package/dist/services/request-context.service.d.ts +53 -0
  63. package/dist/services/request-context.service.d.ts.map +1 -0
  64. package/dist/services/route-handler.service.d.ts +78 -0
  65. package/dist/services/route-handler.service.d.ts.map +1 -0
  66. package/dist/services/shutdown.service.d.ts +54 -0
  67. package/dist/services/shutdown.service.d.ts.map +1 -0
  68. package/dist/utils/constants.d.ts +3 -0
  69. package/dist/utils/constants.d.ts.map +1 -0
  70. package/dist/utils/format.d.ts +5 -0
  71. package/dist/utils/format.d.ts.map +1 -0
  72. package/dist/utils/parse-multipart.d.ts +18 -0
  73. package/dist/utils/parse-multipart.d.ts.map +1 -0
  74. package/dist/utils/route-path.d.ts +6 -0
  75. package/dist/utils/route-path.d.ts.map +1 -0
  76. package/package.json +84 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,239 @@
1
+ # @mastra/nestjs
2
+
3
+ ## 0.0.0-branches-as-default-20260512170712
4
+
5
+ ### Patch Changes
6
+
7
+ - Improved Studio agent serialization by making Studio mode and auth-related request context server-controlled across adapters. Playground requests now identify Studio traffic consistently, body and query request context cannot set reserved server values, and Studio placeholder fallback is limited to instruction rendering while serialized models, workspace, skills, tools, and default options use the real request context. ([#16152](https://github.com/mastra-ai/mastra/pull/16152))
8
+
9
+ - Fixed peer dependency ranges so packages that use the Mastra server require a compatible Mastra core version. ([#16208](https://github.com/mastra-ai/mastra/pull/16208))
10
+
11
+ - Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`7ad5585`](https://github.com/mastra-ai/mastra/commit/7ad55856406f1de398dc713f6a9eaa78b2784bb6), [`ac47842`](https://github.com/mastra-ai/mastra/commit/ac478427aa7a5f5fdaed633a911218689b438c60), [`d1fdbd0`](https://github.com/mastra-ai/mastra/commit/d1fdbd012add5623cb7e6b7f882b605ab358bbb4), [`210ea7a`](https://github.com/mastra-ai/mastra/commit/210ea7af559791b73a44fc9c12179908aaa3183f), [`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`bae019e`](https://github.com/mastra-ai/mastra/commit/bae019ecb6694da96909f7ec7b9eb3a0a33aa887), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`37c0dc5`](https://github.com/mastra-ai/mastra/commit/37c0dc5697d343db98628bf867bf71ce6deec6d7), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`7d57eeb`](https://github.com/mastra-ai/mastra/commit/7d57eeb8ad67c2e93c39d8fddb697aa11d677dbb), [`83218c8`](https://github.com/mastra-ai/mastra/commit/83218c88b37773c9424fbe733b37be556e55e94d), [`aefd33b`](https://github.com/mastra-ai/mastra/commit/aefd33b09f7e192639535df2a36129f40d05c046), [`ef6b584`](https://github.com/mastra-ai/mastra/commit/ef6b5847ac33c0a7e80af3a86e8801e2933dd3ee), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`d91ebe2`](https://github.com/mastra-ai/mastra/commit/d91ebe28ee065d8f2ed6df741c3c07f58d359529), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`33f5061`](https://github.com/mastra-ai/mastra/commit/33f5061cd1c0335020c3faae61ce96de822854fa), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`265ec9f`](https://github.com/mastra-ai/mastra/commit/265ec9f887b5c81255c873a76ff7796f16e4f99b), [`ce01024`](https://github.com/mastra-ai/mastra/commit/ce010242eee9bdfc09e4c26725b9d37998679a8d), [`6ce80bf`](https://github.com/mastra-ai/mastra/commit/6ce80bf4872a891e0bddf8b80561a80584efb14b), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`9268531`](https://github.com/mastra-ai/mastra/commit/9268531e7ec4be98beeba3b3ae8be0a7ea380662), [`13ead79`](https://github.com/mastra-ai/mastra/commit/13ead79149486b88144db7e11e6ff551caef5be1), [`dccd8f1`](https://github.com/mastra-ai/mastra/commit/dccd8f1f8b8f1ad203b77556207e5529567c616d), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`4dd900d`](https://github.com/mastra-ai/mastra/commit/4dd900d75dfe9be89f8c15188b368a8622aa1e18), [`b560d6f`](https://github.com/mastra-ai/mastra/commit/b560d6f88b9b904b15c10f75c949eb145bc27684), [`99869ec`](https://github.com/mastra-ai/mastra/commit/99869ecb1f2aa6dfcc44fa4e843e5ee0344efa64), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`4ff5bdf`](https://github.com/mastra-ai/mastra/commit/4ff5bdfe170cba6dfb5260c6af0f4ba668430772), [`284b0d7`](https://github.com/mastra-ai/mastra/commit/284b0d78d0edb306413447e5268007491006937c), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`bbcd93c`](https://github.com/mastra-ai/mastra/commit/bbcd93cf7d8aa1007d6d84bfd033b8015c912087), [`8373ff4`](https://github.com/mastra-ai/mastra/commit/8373ff46745d77af79f183c4470f80fa2727a6b2), [`0461546`](https://github.com/mastra-ai/mastra/commit/0461546755951706ca81bc24d1d31013d9d70a6d), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a), [`308bd07`](https://github.com/mastra-ai/mastra/commit/308bd074f35cef0c75d82fc1eb19382fe04ecf6f), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`36b3bbf`](https://github.com/mastra-ai/mastra/commit/36b3bbf5a8d59f7e23d47e29340e76c681b4929c), [`d86f031`](https://github.com/mastra-ai/mastra/commit/d86f031eb6b0b2570145afafea664e59bf688962), [`b275631`](https://github.com/mastra-ai/mastra/commit/b275631dc10541a482b2e2d4a3e3cfa843bd5fa1), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`bd36d8e`](https://github.com/mastra-ai/mastra/commit/bd36d8eb6de8c9a0310352649dbd4b06703c2299), [`11c1528`](https://github.com/mastra-ai/mastra/commit/11c152848c5d0ef227184853b5040f5b41ee7b1e), [`284b0d7`](https://github.com/mastra-ai/mastra/commit/284b0d78d0edb306413447e5268007491006937c), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`8ac9141`](https://github.com/mastra-ai/mastra/commit/8ac9141439caa8fdd674944c4d84f29b3c730296), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066), [`5688881`](https://github.com/mastra-ai/mastra/commit/5688881669c7ed157f31ac77f6fc5f8d95ceea32)]:
12
+ - @mastra/core@0.0.0-branches-as-default-20260512170712
13
+ - @mastra/server@0.0.0-branches-as-default-20260512170712
14
+
15
+ ## 0.1.3-alpha.12
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [[`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a)]:
20
+ - @mastra/core@1.33.0-alpha.12
21
+ - @mastra/server@1.33.0-alpha.12
22
+
23
+ ## 0.1.3-alpha.11
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [[`37c0dc5`](https://github.com/mastra-ai/mastra/commit/37c0dc5697d343db98628bf867bf71ce6deec6d7), [`ef6b584`](https://github.com/mastra-ai/mastra/commit/ef6b5847ac33c0a7e80af3a86e8801e2933dd3ee), [`4dd900d`](https://github.com/mastra-ai/mastra/commit/4dd900d75dfe9be89f8c15188b368a8622aa1e18), [`4ff5bdf`](https://github.com/mastra-ai/mastra/commit/4ff5bdfe170cba6dfb5260c6af0f4ba668430772), [`bbcd93c`](https://github.com/mastra-ai/mastra/commit/bbcd93cf7d8aa1007d6d84bfd033b8015c912087), [`308bd07`](https://github.com/mastra-ai/mastra/commit/308bd074f35cef0c75d82fc1eb19382fe04ecf6f)]:
28
+ - @mastra/core@1.33.0-alpha.11
29
+ - @mastra/server@1.33.0-alpha.11
30
+
31
+ ## 0.1.3-alpha.10
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies [[`7ad5585`](https://github.com/mastra-ai/mastra/commit/7ad55856406f1de398dc713f6a9eaa78b2784bb6), [`210ea7a`](https://github.com/mastra-ai/mastra/commit/210ea7af559791b73a44fc9c12179908aaa3183f), [`83218c8`](https://github.com/mastra-ai/mastra/commit/83218c88b37773c9424fbe733b37be556e55e94d), [`265ec9f`](https://github.com/mastra-ai/mastra/commit/265ec9f887b5c81255c873a76ff7796f16e4f99b), [`6ce80bf`](https://github.com/mastra-ai/mastra/commit/6ce80bf4872a891e0bddf8b80561a80584efb14b), [`9268531`](https://github.com/mastra-ai/mastra/commit/9268531e7ec4be98beeba3b3ae8be0a7ea380662), [`13ead79`](https://github.com/mastra-ai/mastra/commit/13ead79149486b88144db7e11e6ff551caef5be1), [`bd36d8e`](https://github.com/mastra-ai/mastra/commit/bd36d8eb6de8c9a0310352649dbd4b06703c2299), [`8ac9141`](https://github.com/mastra-ai/mastra/commit/8ac9141439caa8fdd674944c4d84f29b3c730296)]:
36
+ - @mastra/core@1.33.0-alpha.10
37
+ - @mastra/server@1.33.0-alpha.10
38
+
39
+ ## 0.1.3-alpha.9
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies [[`5688881`](https://github.com/mastra-ai/mastra/commit/5688881669c7ed157f31ac77f6fc5f8d95ceea32)]:
44
+ - @mastra/core@1.33.0-alpha.9
45
+ - @mastra/server@1.33.0-alpha.9
46
+
47
+ ## 0.1.3-alpha.8
48
+
49
+ ### Patch Changes
50
+
51
+ - Updated dependencies [[`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4)]:
52
+ - @mastra/core@1.33.0-alpha.8
53
+ - @mastra/server@1.33.0-alpha.8
54
+
55
+ ## 0.1.3-alpha.7
56
+
57
+ ### Patch Changes
58
+
59
+ - Improved Studio agent serialization by making Studio mode and auth-related request context server-controlled across adapters. Playground requests now identify Studio traffic consistently, body and query request context cannot set reserved server values, and Studio placeholder fallback is limited to instruction rendering while serialized models, workspace, skills, tools, and default options use the real request context. ([#16152](https://github.com/mastra-ai/mastra/pull/16152))
60
+
61
+ - Updated dependencies [[`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`7d57eeb`](https://github.com/mastra-ai/mastra/commit/7d57eeb8ad67c2e93c39d8fddb697aa11d677dbb), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`284b0d7`](https://github.com/mastra-ai/mastra/commit/284b0d78d0edb306413447e5268007491006937c), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`284b0d7`](https://github.com/mastra-ai/mastra/commit/284b0d78d0edb306413447e5268007491006937c), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066)]:
62
+ - @mastra/core@1.33.0-alpha.7
63
+ - @mastra/server@1.33.0-alpha.7
64
+
65
+ ## 0.1.3-alpha.6
66
+
67
+ ### Patch Changes
68
+
69
+ - Updated dependencies [[`b560d6f`](https://github.com/mastra-ai/mastra/commit/b560d6f88b9b904b15c10f75c949eb145bc27684), [`36b3bbf`](https://github.com/mastra-ai/mastra/commit/36b3bbf5a8d59f7e23d47e29340e76c681b4929c), [`b275631`](https://github.com/mastra-ai/mastra/commit/b275631dc10541a482b2e2d4a3e3cfa843bd5fa1)]:
70
+ - @mastra/core@1.33.0-alpha.6
71
+ - @mastra/server@1.33.0-alpha.6
72
+
73
+ ## 0.1.3-alpha.5
74
+
75
+ ### Patch Changes
76
+
77
+ - Updated dependencies [[`bae019e`](https://github.com/mastra-ai/mastra/commit/bae019ecb6694da96909f7ec7b9eb3a0a33aa887), [`33f5061`](https://github.com/mastra-ai/mastra/commit/33f5061cd1c0335020c3faae61ce96de822854fa), [`99869ec`](https://github.com/mastra-ai/mastra/commit/99869ecb1f2aa6dfcc44fa4e843e5ee0344efa64), [`d86f031`](https://github.com/mastra-ai/mastra/commit/d86f031eb6b0b2570145afafea664e59bf688962)]:
78
+ - @mastra/core@1.33.0-alpha.5
79
+ - @mastra/server@1.33.0-alpha.5
80
+
81
+ ## 0.1.3-alpha.4
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a)]:
86
+ - @mastra/core@1.33.0-alpha.4
87
+ - @mastra/server@1.33.0-alpha.4
88
+
89
+ ## 0.1.3-alpha.3
90
+
91
+ ### Patch Changes
92
+
93
+ - Updated dependencies [[`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`0461546`](https://github.com/mastra-ai/mastra/commit/0461546755951706ca81bc24d1d31013d9d70a6d)]:
94
+ - @mastra/core@1.33.0-alpha.3
95
+ - @mastra/server@1.33.0-alpha.3
96
+
97
+ ## 0.1.3-alpha.2
98
+
99
+ ### Patch Changes
100
+
101
+ - Updated dependencies [[`d1fdbd0`](https://github.com/mastra-ai/mastra/commit/d1fdbd012add5623cb7e6b7f882b605ab358bbb4), [`d91ebe2`](https://github.com/mastra-ai/mastra/commit/d91ebe28ee065d8f2ed6df741c3c07f58d359529)]:
102
+ - @mastra/core@1.33.0-alpha.2
103
+ - @mastra/server@1.33.0-alpha.2
104
+
105
+ ## 0.1.3-alpha.1
106
+
107
+ ### Patch Changes
108
+
109
+ - Updated dependencies [[`dccd8f1`](https://github.com/mastra-ai/mastra/commit/dccd8f1f8b8f1ad203b77556207e5529567c616d)]:
110
+ - @mastra/core@1.33.0-alpha.1
111
+ - @mastra/server@1.33.0-alpha.1
112
+
113
+ ## 0.1.3-alpha.0
114
+
115
+ ### Patch Changes
116
+
117
+ - Fixed peer dependency ranges so packages that use the Mastra server require a compatible Mastra core version. ([#16208](https://github.com/mastra-ai/mastra/pull/16208))
118
+
119
+ - Updated dependencies [[`ac47842`](https://github.com/mastra-ai/mastra/commit/ac478427aa7a5f5fdaed633a911218689b438c60), [`aefd33b`](https://github.com/mastra-ai/mastra/commit/aefd33b09f7e192639535df2a36129f40d05c046)]:
120
+ - @mastra/core@1.33.0-alpha.0
121
+ - @mastra/server@1.33.0-alpha.0
122
+
123
+ ## 0.1.2
124
+
125
+ ### Patch Changes
126
+
127
+ - Updated dependencies [[`cc0469d`](https://github.com/mastra-ai/mastra/commit/cc0469d671d6f7a426013e4425f9501da6fa45f2), [`ddc0174`](https://github.com/mastra-ai/mastra/commit/ddc0174da0f39008e178c02194a2eaeab0829b15)]:
128
+ - @mastra/core@1.32.1
129
+ - @mastra/server@1.32.1
130
+
131
+ ## 0.1.2-alpha.0
132
+
133
+ ### Patch Changes
134
+
135
+ - Updated dependencies [[`cc0469d`](https://github.com/mastra-ai/mastra/commit/cc0469d671d6f7a426013e4425f9501da6fa45f2), [`ddc0174`](https://github.com/mastra-ai/mastra/commit/ddc0174da0f39008e178c02194a2eaeab0829b15)]:
136
+ - @mastra/core@1.32.1-alpha.0
137
+ - @mastra/server@1.32.1-alpha.0
138
+
139
+ ## 0.1.1
140
+
141
+ ### Patch Changes
142
+
143
+ - Updated dependencies [[`6dcd65f`](https://github.com/mastra-ai/mastra/commit/6dcd65f2a34069e6dc43ba35f1d11119b9b40bef), [`86c0298`](https://github.com/mastra-ai/mastra/commit/86c0298e647306423c842f9d5ac827bd616bd13d), [`fb0719a`](https://github.com/mastra-ai/mastra/commit/fb0719aef8072132efbcdca740e265f5f2b98a99), [`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`ca28c23`](https://github.com/mastra-ai/mastra/commit/ca28c232a2f18801a6cf20fe053479237b4d4fb0), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`7fce309`](https://github.com/mastra-ai/mastra/commit/7fce30912b14170bfc41f0ac736cca0f39fe0cd4), [`cd96779`](https://github.com/mastra-ai/mastra/commit/cd9677937f113b2856dc8b9f3d4bdabcee58bb2e), [`1d64a76`](https://github.com/mastra-ai/mastra/commit/1d64a765861a0772ea187bab76e5ed37bf82d042), [`1c2dda8`](https://github.com/mastra-ai/mastra/commit/1c2dda805fbfccc0abf55d4cb20cc34402dc3f0c), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`7997c2e`](https://github.com/mastra-ai/mastra/commit/7997c2e55ddd121562a4098cd8d2b89c68433bf1), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`39162cb`](https://github.com/mastra-ai/mastra/commit/39162cb952c0053fdd4ed7217ec7802a2027b19d), [`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`a0d9b6d`](https://github.com/mastra-ai/mastra/commit/a0d9b6d6b810aeaa9e177a0dcc99a4402e609634), [`e97ccb9`](https://github.com/mastra-ai/mastra/commit/e97ccb900f8b7a390ce82c9f8eb8d6eb2c5e3777), [`f5afe62`](https://github.com/mastra-ai/mastra/commit/f5afe62beff3ae69148a35e55fe5375168897829), [`c5daf48`](https://github.com/mastra-ai/mastra/commit/c5daf48556e98c46ae06caf00f92c249912007e9), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`cd96779`](https://github.com/mastra-ai/mastra/commit/cd9677937f113b2856dc8b9f3d4bdabcee58bb2e), [`b0c7022`](https://github.com/mastra-ai/mastra/commit/b0c70224f80dad7c0cdbfb22cbff22e0f75c064f), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d), [`86c0298`](https://github.com/mastra-ai/mastra/commit/86c0298e647306423c842f9d5ac827bd616bd13d)]:
144
+ - @mastra/core@1.32.0
145
+ - @mastra/server@1.32.0
146
+
147
+ ## 0.1.1-alpha.4
148
+
149
+ ### Patch Changes
150
+
151
+ - Updated dependencies [[`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`1d64a76`](https://github.com/mastra-ai/mastra/commit/1d64a765861a0772ea187bab76e5ed37bf82d042), [`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`a0d9b6d`](https://github.com/mastra-ai/mastra/commit/a0d9b6d6b810aeaa9e177a0dcc99a4402e609634)]:
152
+ - @mastra/core@1.32.0-alpha.4
153
+ - @mastra/server@1.32.0-alpha.4
154
+
155
+ ## 0.1.1-alpha.3
156
+
157
+ ### Patch Changes
158
+
159
+ - Updated dependencies [[`fb0719a`](https://github.com/mastra-ai/mastra/commit/fb0719aef8072132efbcdca740e265f5f2b98a99), [`ca28c23`](https://github.com/mastra-ai/mastra/commit/ca28c232a2f18801a6cf20fe053479237b4d4fb0), [`39162cb`](https://github.com/mastra-ai/mastra/commit/39162cb952c0053fdd4ed7217ec7802a2027b19d)]:
160
+ - @mastra/server@1.32.0-alpha.3
161
+ - @mastra/core@1.32.0-alpha.3
162
+
163
+ ## 0.1.1-alpha.2
164
+
165
+ ### Patch Changes
166
+
167
+ - Updated dependencies [[`86c0298`](https://github.com/mastra-ai/mastra/commit/86c0298e647306423c842f9d5ac827bd616bd13d), [`7fce309`](https://github.com/mastra-ai/mastra/commit/7fce30912b14170bfc41f0ac736cca0f39fe0cd4), [`cd96779`](https://github.com/mastra-ai/mastra/commit/cd9677937f113b2856dc8b9f3d4bdabcee58bb2e), [`7997c2e`](https://github.com/mastra-ai/mastra/commit/7997c2e55ddd121562a4098cd8d2b89c68433bf1), [`e97ccb9`](https://github.com/mastra-ai/mastra/commit/e97ccb900f8b7a390ce82c9f8eb8d6eb2c5e3777), [`f5afe62`](https://github.com/mastra-ai/mastra/commit/f5afe62beff3ae69148a35e55fe5375168897829), [`c5daf48`](https://github.com/mastra-ai/mastra/commit/c5daf48556e98c46ae06caf00f92c249912007e9), [`cd96779`](https://github.com/mastra-ai/mastra/commit/cd9677937f113b2856dc8b9f3d4bdabcee58bb2e), [`86c0298`](https://github.com/mastra-ai/mastra/commit/86c0298e647306423c842f9d5ac827bd616bd13d)]:
168
+ - @mastra/core@1.32.0-alpha.2
169
+ - @mastra/server@1.32.0-alpha.2
170
+
171
+ ## 0.1.1-alpha.1
172
+
173
+ ### Patch Changes
174
+
175
+ - Updated dependencies [[`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d)]:
176
+ - @mastra/core@1.32.0-alpha.1
177
+ - @mastra/server@1.32.0-alpha.1
178
+
179
+ ## 0.1.1-alpha.0
180
+
181
+ ### Patch Changes
182
+
183
+ - Updated dependencies [[`6dcd65f`](https://github.com/mastra-ai/mastra/commit/6dcd65f2a34069e6dc43ba35f1d11119b9b40bef), [`1c2dda8`](https://github.com/mastra-ai/mastra/commit/1c2dda805fbfccc0abf55d4cb20cc34402dc3f0c)]:
184
+ - @mastra/core@1.31.1-alpha.0
185
+ - @mastra/server@1.31.1-alpha.0
186
+
187
+ ## 0.1.0
188
+
189
+ ### Minor Changes
190
+
191
+ - Add NestJS server adapter (`@mastra/nestjs`) for running Mastra with NestJS Express applications. Provides native module registration, DI-based service injection, rate limiting, graceful shutdown, streaming, and MCP transport support. ([#12751](https://github.com/mastra-ai/mastra/pull/12751))
192
+
193
+ ```typescript
194
+ import { Module } from '@nestjs/common';
195
+ import { MastraModule } from '@mastra/nestjs';
196
+ import { mastra } from './mastra';
197
+
198
+ @Module({
199
+ imports: [MastraModule.register({ mastra })],
200
+ })
201
+ export class AppModule {}
202
+ ```
203
+
204
+ ### Patch Changes
205
+
206
+ - Updated dependencies [[`1723e09`](https://github.com/mastra-ai/mastra/commit/1723e099829892419ddbfe49287acfeac2522724), [`629f9e9`](https://github.com/mastra-ai/mastra/commit/629f9e9a7e56aa8f129515a3923c5813298790c7), [`25168fb`](https://github.com/mastra-ai/mastra/commit/25168fb9c1de9db7f8171df4f58ceb842c53aa29), [`ab34b5a`](https://github.com/mastra-ai/mastra/commit/ab34b5a2191b8e4353df1dbf7b9155e7d6628d79), [`5fb6c2a`](https://github.com/mastra-ai/mastra/commit/5fb6c2a95c1843cc231704b91354311fc1f34a71), [`2b0f355`](https://github.com/mastra-ai/mastra/commit/2b0f3553be3e9e5524da539a66e5cf82668440a4), [`f0d3c1a`](https://github.com/mastra-ai/mastra/commit/f0d3c1a9a2b283abc322d363f4f87e04e16837cf), [`394f0cf`](https://github.com/mastra-ai/mastra/commit/394f0cfc31e6b4d801219fdef2e9cc69e5bc8682), [`b2deb29`](https://github.com/mastra-ai/mastra/commit/b2deb29412b300c868655b5840463614fbb7962d), [`66644be`](https://github.com/mastra-ai/mastra/commit/66644beac1aa560f0e417956ff007c89341dc382), [`7dfea5e`](https://github.com/mastra-ai/mastra/commit/7dfea5eff7774eeeccd55ceb655392d70886206b), [`e109607`](https://github.com/mastra-ai/mastra/commit/e10960749251e34d46b480a20648c490fd30381b), [`310b953`](https://github.com/mastra-ai/mastra/commit/310b95345f302dcd5ba3ed862bdc96f059d44122), [`c600d54`](https://github.com/mastra-ai/mastra/commit/c600d5427277f44bc246b4daf70f77605ff1265c), [`3d7f709`](https://github.com/mastra-ai/mastra/commit/3d7f709b615e588050bb6283c4ee5cfe2978cbde), [`48a42f1`](https://github.com/mastra-ai/mastra/commit/48a42f114a4006a95e0b7a1b5ad1a24815a175c2), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006), [`2c83efc`](https://github.com/mastra-ai/mastra/commit/2c83efc4482b3efe50830e3b8b4ba9a8d219edff), [`43f0e1d`](https://github.com/mastra-ai/mastra/commit/43f0e1d5d5a74ba6fc746f2ad89ebe0c64777a7d), [`da0b9e2`](https://github.com/mastra-ai/mastra/commit/da0b9e2ba7ecc560213b426d6c097fe63946086e), [`282a10c`](https://github.com/mastra-ai/mastra/commit/282a10c9446e9922afe80e10e3770481c8ac8a28), [`04151c7`](https://github.com/mastra-ai/mastra/commit/04151c7dcea934b4fe9076708a23fac161195414), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006)]:
207
+ - @mastra/core@1.31.0
208
+ - @mastra/server@1.31.0
209
+
210
+ ## 0.1.0-alpha.1
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies [[`f0d3c1a`](https://github.com/mastra-ai/mastra/commit/f0d3c1a9a2b283abc322d363f4f87e04e16837cf)]:
215
+ - @mastra/server@1.31.0-alpha.5
216
+ - @mastra/core@1.31.0-alpha.5
217
+
218
+ ## 0.1.0-alpha.0
219
+
220
+ ### Minor Changes
221
+
222
+ - Add NestJS server adapter (`@mastra/nestjs`) for running Mastra with NestJS Express applications. Provides native module registration, DI-based service injection, rate limiting, graceful shutdown, streaming, and MCP transport support. ([#12751](https://github.com/mastra-ai/mastra/pull/12751))
223
+
224
+ ```typescript
225
+ import { Module } from '@nestjs/common';
226
+ import { MastraModule } from '@mastra/nestjs';
227
+ import { mastra } from './mastra';
228
+
229
+ @Module({
230
+ imports: [MastraModule.register({ mastra })],
231
+ })
232
+ export class AppModule {}
233
+ ```
234
+
235
+ ### Patch Changes
236
+
237
+ - Updated dependencies [[`c600d54`](https://github.com/mastra-ai/mastra/commit/c600d5427277f44bc246b4daf70f77605ff1265c), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006), [`04151c7`](https://github.com/mastra-ai/mastra/commit/04151c7dcea934b4fe9076708a23fac161195414), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006)]:
238
+ - @mastra/server@1.31.0-alpha.4
239
+ - @mastra/core@1.31.0-alpha.4
package/LICENSE.md ADDED
@@ -0,0 +1,30 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
16
+ # Apache License 2.0
17
+
18
+ Copyright (c) 2025 Kepler Software, Inc.
19
+
20
+ Licensed under the Apache License, Version 2.0 (the "License");
21
+ you may not use this file except in compliance with the License.
22
+ You may obtain a copy of the License at
23
+
24
+ http://www.apache.org/licenses/LICENSE-2.0
25
+
26
+ Unless required by applicable law or agreed to in writing, software
27
+ distributed under the License is distributed on an "AS IS" BASIS,
28
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ See the License for the specific language governing permissions and
30
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,324 @@
1
+ # @mastra/nestjs
2
+
3
+ NestJS server adapter for [Mastra](https://mastra.ai). Use it to expose agents, workflows, tools, MCP, and streaming endpoints through NestJS with native guards, interceptors, and DI.
4
+
5
+ This package supports NestJS running on the Express adapter only. If your app uses Fastify, `MastraModule` now fails fast during bootstrap with a clear error instead of partially initializing.
6
+
7
+ ## Features
8
+
9
+ - **NestJS-native integration** via modules, DI, guards, interceptors, and filters
10
+ - **Rate limiting** enabled by default (opt-out)
11
+ - **Graceful shutdown** with in-flight request tracking and optional SSE notifications
12
+ - **Streaming** for AI responses with optional redaction and SSE heartbeats
13
+ - **MCP transport** (HTTP + SSE) exposed under the API prefix
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @mastra/nestjs @mastra/core
19
+ # or
20
+ pnpm add @mastra/nestjs @mastra/core
21
+ # or
22
+ yarn add @mastra/nestjs @mastra/core
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ // app.module.ts
29
+ import { Module } from '@nestjs/common';
30
+ import { MastraModule } from '@mastra/nestjs';
31
+ import { Mastra } from '@mastra/core/mastra';
32
+ import { z } from 'zod';
33
+ import { createTool } from '@mastra/core/tools';
34
+
35
+ /** Simple tool used by the demo agent. */
36
+ const pingTool = createTool({
37
+ id: 'ping',
38
+ description: 'Returns a pong response',
39
+ inputSchema: z.object({ message: z.string() }),
40
+ execute: async ({ message }) => ({ ok: true, message }),
41
+ });
42
+
43
+ /** Minimal Mastra instance for NestJS integration. */
44
+ const mastra = new Mastra({
45
+ tools: { ping: pingTool },
46
+ agents: {
47
+ greeter: {
48
+ name: 'greeter',
49
+ description: 'Greets the user and can call tools.',
50
+ model: 'openai/gpt-4o-mini',
51
+ tools: ['ping'],
52
+ },
53
+ },
54
+ });
55
+
56
+ @Module({
57
+ imports: [MastraModule.register({ mastra })],
58
+ })
59
+ export class AppModule {}
60
+ ```
61
+
62
+ ```typescript
63
+ // main.ts
64
+ import { NestFactory } from '@nestjs/core';
65
+ import { AppModule } from './app.module';
66
+
67
+ async function bootstrap() {
68
+ const app = await NestFactory.create(AppModule);
69
+ await app.listen(3000);
70
+ }
71
+
72
+ bootstrap();
73
+ ```
74
+
75
+ With the default prefix (`/api`), Mastra routes mount under `http://localhost:3000/api`.
76
+
77
+ ## Async Module Registration
78
+
79
+ Use async registration when the Mastra config depends on runtime services (e.g., `ConfigService`).
80
+
81
+ ```typescript
82
+ import { Module } from '@nestjs/common';
83
+ import { ConfigModule, ConfigService } from '@nestjs/config';
84
+ import { MastraModule } from '@mastra/nestjs';
85
+ import { Mastra } from '@mastra/core/mastra';
86
+
87
+ @Module({
88
+ imports: [
89
+ ConfigModule.forRoot(),
90
+ MastraModule.registerAsync({
91
+ imports: [ConfigModule],
92
+ useFactory: (config: ConfigService) => ({
93
+ mastra: new Mastra({
94
+ agents: {
95
+ greeter: {
96
+ name: 'greeter',
97
+ description: 'Greets users with a short response.',
98
+ model: config.get('MASTRA_MODEL', 'openai/gpt-4o-mini'),
99
+ },
100
+ },
101
+ }),
102
+ prefix: config.get('MASTRA_PREFIX', '/api'),
103
+ }),
104
+ inject: [ConfigService],
105
+ }),
106
+ ],
107
+ })
108
+ export class AppModule {}
109
+ ```
110
+
111
+ ## Injecting Mastra in Services
112
+
113
+ Use `MASTRA` for direct access or `MastraService` for helper methods.
114
+
115
+ ```typescript
116
+ import { Injectable, Inject } from '@nestjs/common';
117
+ import { MASTRA, MastraService } from '@mastra/nestjs';
118
+ import type { Mastra } from '@mastra/core/mastra';
119
+
120
+ @Injectable()
121
+ export class AgentService {
122
+ constructor(@Inject(MASTRA) private readonly mastra: Mastra) {}
123
+
124
+ async greet() {
125
+ const agent = this.mastra.getAgent('greeter');
126
+ return agent.generate({
127
+ messages: [{ role: 'user', content: 'Hello from NestJS' }],
128
+ });
129
+ }
130
+ }
131
+
132
+ @Injectable()
133
+ export class WorkflowService {
134
+ constructor(private readonly mastraService: MastraService) {}
135
+
136
+ async runWorkflow(workflowId: string, inputData: Record<string, unknown>) {
137
+ const workflow = this.mastraService.getWorkflow(workflowId);
138
+ return workflow.start({ inputData });
139
+ }
140
+ }
141
+ ```
142
+
143
+ ## Request Context (GET + POST)
144
+
145
+ Pass request context via query string or JSON body. The adapter accepts JSON or base64-encoded JSON.
146
+
147
+ ```bash
148
+ curl "http://localhost:3000/api/agents/greeter/generate?requestContext=%7B%22userId%22%3A%22123%22%7D"
149
+ ```
150
+
151
+ ```bash
152
+ curl -X POST "http://localhost:3000/api/agents/greeter/generate" \
153
+ -H "Content-Type: application/json" \
154
+ -d '{"messages":[{"role":"user","content":"hi"}],"requestContext":{"userId":"123"}}'
155
+ ```
156
+
157
+ ## Rate Limiting
158
+
159
+ Rate limiting is on by default. Disable it or customize limits:
160
+
161
+ ```typescript
162
+ MastraModule.register({
163
+ mastra,
164
+ rateLimitOptions: {
165
+ enabled: true,
166
+ defaultLimit: 200,
167
+ generateLimit: 20,
168
+ windowMs: 60_000,
169
+ },
170
+ });
171
+ ```
172
+
173
+ ## Mastra Auth Compatibility
174
+
175
+ Mastra's built-in token auth is disabled by default because most NestJS apps already have their own auth layer. When enabled, bearer tokens from the `Authorization` header are the default credential source.
176
+
177
+ Query-string `?apiKey=` auth is available only as an explicit backward-compatibility option:
178
+
179
+ ```typescript
180
+ MastraModule.register({
181
+ mastra,
182
+ auth: {
183
+ enabled: true,
184
+ allowQueryApiKey: true,
185
+ },
186
+ });
187
+ ```
188
+
189
+ ## Streaming Options
190
+
191
+ ```typescript
192
+ MastraModule.register({
193
+ mastra,
194
+ streamOptions: {
195
+ redact: true,
196
+ heartbeatMs: 20_000,
197
+ },
198
+ });
199
+ ```
200
+
201
+ ## MCP Transport (HTTP + SSE)
202
+
203
+ MCP endpoints are exposed under the API prefix:
204
+
205
+ - `POST /api/mcp/:serverId/mcp`
206
+ - `GET /api/mcp/:serverId/sse`
207
+ - `POST /api/mcp/:serverId/messages`
208
+
209
+ ## Health Endpoints
210
+
211
+ These are always at the root (not under the prefix):
212
+
213
+ - `GET /health`
214
+ - `GET /ready`
215
+ - `GET /info`
216
+
217
+ ## Decorators
218
+
219
+ Skip auth or rate limiting on specific controller routes:
220
+
221
+ ```typescript
222
+ import { Controller, Get, Post } from '@nestjs/common';
223
+ import { Public, SkipThrottle, MastraThrottle } from '@mastra/nestjs';
224
+
225
+ @Controller('custom')
226
+ export class CustomController {
227
+ @Get('public')
228
+ @Public()
229
+ publicRoute() {}
230
+
231
+ @Get('unlimited')
232
+ @SkipThrottle()
233
+ unlimitedRoute() {}
234
+
235
+ @Post('custom-limit')
236
+ @MastraThrottle({ limit: 5, windowMs: 60_000 })
237
+ customLimitRoute() {}
238
+ }
239
+ ```
240
+
241
+ ## Configuration Options
242
+
243
+ | Option | Type | Default | Description |
244
+ | ----------------------------------- | --------------------------------------------------- | -------------------- | ------------------------------------------- |
245
+ | `mastra` | `Mastra` | required | The Mastra instance |
246
+ | `prefix` | `string` | `/api` | Route prefix |
247
+ | `rateLimitOptions` | `object` | enabled | Rate limiting configuration |
248
+ | `rateLimitOptions.enabled` | `boolean` | `true` | Enable/disable rate limiting |
249
+ | `rateLimitOptions.defaultLimit` | `number` | `100` | Requests per window |
250
+ | `rateLimitOptions.generateLimit` | `number` | `10` | Stricter limit for `/generate` |
251
+ | `rateLimitOptions.windowMs` | `number` | `60000` | Window size in ms |
252
+ | `shutdownOptions` | `object` | - | Graceful shutdown configuration |
253
+ | `shutdownOptions.timeoutMs` | `number` | `30000` | Max wait time for in-flight requests |
254
+ | `shutdownOptions.notifyClients` | `boolean` | `true` | Send shutdown event to SSE clients |
255
+ | `bodyLimitOptions` | `object` | - | Request body size limits |
256
+ | `bodyLimitOptions.maxSize` | `number` | `10MB` | Max JSON body size |
257
+ | `bodyLimitOptions.maxFileSize` | `number` | - | Max multipart file size (no limit if unset) |
258
+ | `bodyLimitOptions.allowedMimeTypes` | `string[]` | - | Allowed upload MIME types |
259
+ | `streamOptions` | `{ redact?: boolean; heartbeatMs?: number }` | - | Streaming config |
260
+ | `tracingOptions` | `{ enabled?: boolean; serviceName?: string }` | - | OpenTelemetry tracing |
261
+ | `customRouteAuthConfig` | `Map<string, boolean>` | - | Per-route auth overrides |
262
+ | `mcpOptions` | `object` | - | MCP transport options |
263
+ | `mcpOptions.serverless` | `boolean` | `false` | Stateless MCP HTTP mode |
264
+ | `mcpOptions.sessionIdGenerator` | `() => string` | - | Custom MCP session IDs |
265
+ | `auth` | `{ enabled?: boolean; allowQueryApiKey?: boolean }` | `{ enabled: false }` | Enable Mastra's built-in token auth |
266
+
267
+ ## Requirements
268
+
269
+ - Node.js >= 22.13.0
270
+ - NestJS with Express adapter (`@nestjs/platform-express`)
271
+ - Express 4.x or 5.x
272
+
273
+ **Note:** This adapter supports NestJS with Express only. Fastify is not supported in v1, and `MastraModule` throws during bootstrap if another Nest HTTP adapter is in use.
274
+
275
+ ## API Reference
276
+
277
+ ### `MastraModule.register(options)`
278
+
279
+ Register Mastra with NestJS DI.
280
+
281
+ ### `MastraModule.registerAsync(options)`
282
+
283
+ Async registration supporting `useFactory`, `useClass`, and `useExisting`.
284
+
285
+ ### `MastraService`
286
+
287
+ ```typescript
288
+ class MastraService {
289
+ getMastra(): Mastra;
290
+ getOptions(): MastraModuleOptions;
291
+ getAgent(agentId: string): Agent;
292
+ getWorkflow(workflowId: string): Workflow;
293
+ isShuttingDown: boolean;
294
+ }
295
+ ```
296
+
297
+ ### `MASTRA`
298
+
299
+ Injection token for the Mastra instance.
300
+
301
+ ## Exported Components
302
+
303
+ ```typescript
304
+ import {
305
+ MastraAuthGuard,
306
+ MastraThrottleGuard,
307
+ StreamingInterceptor,
308
+ RequestTrackingInterceptor,
309
+ MastraExceptionFilter,
310
+ RouteHandlerService,
311
+ RequestContextService,
312
+ ShutdownService,
313
+ } from '@mastra/nestjs';
314
+ ```
315
+
316
+ ## Related Packages
317
+
318
+ - [@mastra/core](https://www.npmjs.com/package/@mastra/core)
319
+ - [@mastra/express](https://www.npmjs.com/package/@mastra/express)
320
+ - [@mastra/hono](https://www.npmjs.com/package/@mastra/hono)
321
+
322
+ ## License
323
+
324
+ Apache-2.0
@@ -0,0 +1,17 @@
1
+ import type { Readable } from 'node:stream';
2
+ import type { Application } from 'express';
3
+ export type MockHttpRequest = {
4
+ method: string;
5
+ path: string;
6
+ headers?: Record<string, string>;
7
+ body?: unknown;
8
+ rawBody?: string | Buffer;
9
+ };
10
+ export type MockHttpResponse = {
11
+ status: number;
12
+ headers: Record<string, string>;
13
+ body: unknown;
14
+ stream?: Readable;
15
+ };
16
+ export declare function executeExpressRequest(app: Application, req: MockHttpRequest): Promise<MockHttpResponse>;
17
+ //# sourceMappingURL=test-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../../src/__tests__/test-helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAC;AAWF,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqI7G"}