@mastra/server 1.0.0-beta.19 → 1.0.0-beta.20

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 (110) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/dist/{chunk-MZXGNP3J.cjs → chunk-3PZVR6W3.cjs} +70 -106
  3. package/dist/chunk-3PZVR6W3.cjs.map +1 -0
  4. package/dist/{chunk-K73YS7YB.cjs → chunk-AQI6GLTN.cjs} +74 -74
  5. package/dist/{chunk-K73YS7YB.cjs.map → chunk-AQI6GLTN.cjs.map} +1 -1
  6. package/dist/{chunk-3XI22UQR.cjs → chunk-GWLR6K3H.cjs} +7 -3
  7. package/dist/chunk-GWLR6K3H.cjs.map +1 -0
  8. package/dist/{chunk-E646Y4FQ.js → chunk-H66LLFDL.js} +3 -3
  9. package/dist/chunk-H66LLFDL.js.map +1 -0
  10. package/dist/{chunk-7ZYZHQRF.cjs → chunk-IMPZBQ5U.cjs} +350 -216
  11. package/dist/chunk-IMPZBQ5U.cjs.map +1 -0
  12. package/dist/{chunk-MXJEVTGK.js → chunk-J6DCK7KG.js} +5 -11
  13. package/dist/chunk-J6DCK7KG.js.map +1 -0
  14. package/dist/{chunk-OCJ3BRZM.js → chunk-JQPDZZLI.js} +178 -51
  15. package/dist/chunk-JQPDZZLI.js.map +1 -0
  16. package/dist/{chunk-5ZYHM57F.cjs → chunk-KXYDJIKD.cjs} +177 -49
  17. package/dist/chunk-KXYDJIKD.cjs.map +1 -0
  18. package/dist/{chunk-SV4AUWGY.js → chunk-LOA7RQYO.js} +3 -3
  19. package/dist/{chunk-SV4AUWGY.js.map → chunk-LOA7RQYO.js.map} +1 -1
  20. package/dist/{chunk-AWK2DVRO.js → chunk-OKURLPIJ.js} +275 -138
  21. package/dist/chunk-OKURLPIJ.js.map +1 -0
  22. package/dist/{chunk-E4ZPLXZT.js → chunk-Q4BOUQ2O.js} +66 -100
  23. package/dist/chunk-Q4BOUQ2O.js.map +1 -0
  24. package/dist/{chunk-WBLT2HL3.js → chunk-QKXZF7YS.js} +7 -3
  25. package/dist/chunk-QKXZF7YS.js.map +1 -0
  26. package/dist/{chunk-BVIEHV3I.cjs → chunk-T3ZHTCEI.cjs} +2 -2
  27. package/dist/{chunk-BVIEHV3I.cjs.map → chunk-T3ZHTCEI.cjs.map} +1 -1
  28. package/dist/{chunk-BMLUV4BH.cjs → chunk-VX3VN7FN.cjs} +3 -3
  29. package/dist/chunk-VX3VN7FN.cjs.map +1 -0
  30. package/dist/{chunk-VYNS3ZKV.cjs → chunk-Y3VSCOCE.cjs} +7 -13
  31. package/dist/chunk-Y3VSCOCE.cjs.map +1 -0
  32. package/dist/{chunk-T2AYFHKB.js → chunk-ZRBZESWG.js} +2 -2
  33. package/dist/{chunk-T2AYFHKB.js.map → chunk-ZRBZESWG.js.map} +1 -1
  34. package/dist/{dist-AF7EUPXA.cjs → dist-7NTDEVLP.cjs} +28 -28
  35. package/dist/{dist-AF7EUPXA.cjs.map → dist-7NTDEVLP.cjs.map} +1 -1
  36. package/dist/{dist-4CMHRWC4.js → dist-B5GMANA6.js} +3 -3
  37. package/dist/{dist-4CMHRWC4.js.map → dist-B5GMANA6.js.map} +1 -1
  38. package/dist/dist-EDO7GEGI.js +3 -0
  39. package/dist/{dist-MEN73GGI.js.map → dist-EDO7GEGI.js.map} +1 -1
  40. package/dist/{dist-Q2ST4SUQ.cjs → dist-OF24ZMHH.cjs} +30 -30
  41. package/dist/{dist-Q2ST4SUQ.cjs.map → dist-OF24ZMHH.cjs.map} +1 -1
  42. package/dist/{dist-Y5SYUVLY.cjs → dist-P6YSNLL3.cjs} +20 -20
  43. package/dist/{dist-Y5SYUVLY.cjs.map → dist-P6YSNLL3.cjs.map} +1 -1
  44. package/dist/{dist-AEJONJSS.js → dist-SMBO5KVB.js} +3 -3
  45. package/dist/{dist-AEJONJSS.js.map → dist-SMBO5KVB.js.map} +1 -1
  46. package/dist/{dist-TE7XRSWH.js → dist-THPMW5QR.js} +3 -3
  47. package/dist/{dist-TE7XRSWH.js.map → dist-THPMW5QR.js.map} +1 -1
  48. package/dist/{dist-NVXXJWBO.cjs → dist-VZTG56X2.cjs} +26 -26
  49. package/dist/{dist-NVXXJWBO.cjs.map → dist-VZTG56X2.cjs.map} +1 -1
  50. package/dist/dist-ZLC23RVC.cjs +16 -0
  51. package/dist/{dist-2J26LQO2.cjs.map → dist-ZLC23RVC.cjs.map} +1 -1
  52. package/dist/{dist-VPYZNWNG.js → dist-ZOZ6MHJH.js} +3 -3
  53. package/dist/{dist-VPYZNWNG.js.map → dist-ZOZ6MHJH.js.map} +1 -1
  54. package/dist/docs/README.md +31 -0
  55. package/dist/docs/SKILL.md +32 -0
  56. package/dist/docs/SOURCE_MAP.json +6 -0
  57. package/dist/docs/server/01-custom-adapters.md +377 -0
  58. package/dist/docs/server/02-reference.md +828 -0
  59. package/dist/server/handlers/a2a.cjs +9 -9
  60. package/dist/server/handlers/a2a.js +1 -1
  61. package/dist/server/handlers/agent-builder.cjs +16 -28
  62. package/dist/server/handlers/agent-builder.d.ts +51 -85
  63. package/dist/server/handlers/agent-builder.d.ts.map +1 -1
  64. package/dist/server/handlers/agent-builder.js +1 -1
  65. package/dist/server/handlers/agents.cjs +24 -24
  66. package/dist/server/handlers/agents.d.ts.map +1 -1
  67. package/dist/server/handlers/agents.js +1 -1
  68. package/dist/server/handlers/memory.cjs +28 -24
  69. package/dist/server/handlers/memory.d.ts +114 -30
  70. package/dist/server/handlers/memory.d.ts.map +1 -1
  71. package/dist/server/handlers/memory.js +1 -1
  72. package/dist/server/handlers/observability.d.ts +17 -17
  73. package/dist/server/handlers/observability.d.ts.map +1 -1
  74. package/dist/server/handlers/workflows.cjs +24 -36
  75. package/dist/server/handlers/workflows.d.ts +61 -108
  76. package/dist/server/handlers/workflows.d.ts.map +1 -1
  77. package/dist/server/handlers/workflows.js +1 -1
  78. package/dist/server/handlers.cjs +10 -10
  79. package/dist/server/handlers.js +5 -5
  80. package/dist/server/schemas/agent-builder.d.ts +1 -1
  81. package/dist/server/schemas/agent-builder.d.ts.map +1 -1
  82. package/dist/server/schemas/memory.d.ts +161 -31
  83. package/dist/server/schemas/memory.d.ts.map +1 -1
  84. package/dist/server/schemas/workflows.d.ts +214 -34
  85. package/dist/server/schemas/workflows.d.ts.map +1 -1
  86. package/dist/server/server-adapter/index.cjs +102 -94
  87. package/dist/server/server-adapter/index.cjs.map +1 -1
  88. package/dist/server/server-adapter/index.d.ts +24 -6
  89. package/dist/server/server-adapter/index.d.ts.map +1 -1
  90. package/dist/server/server-adapter/index.js +20 -13
  91. package/dist/server/server-adapter/index.js.map +1 -1
  92. package/dist/server/server-adapter/routes/agent-builder.d.ts.map +1 -1
  93. package/dist/server/server-adapter/routes/memory.d.ts.map +1 -1
  94. package/dist/server/server-adapter/routes/workflows.d.ts.map +1 -1
  95. package/dist/server/utils.d.ts.map +1 -1
  96. package/package.json +10 -9
  97. package/dist/chunk-3XI22UQR.cjs.map +0 -1
  98. package/dist/chunk-5ZYHM57F.cjs.map +0 -1
  99. package/dist/chunk-7ZYZHQRF.cjs.map +0 -1
  100. package/dist/chunk-AWK2DVRO.js.map +0 -1
  101. package/dist/chunk-BMLUV4BH.cjs.map +0 -1
  102. package/dist/chunk-E4ZPLXZT.js.map +0 -1
  103. package/dist/chunk-E646Y4FQ.js.map +0 -1
  104. package/dist/chunk-MXJEVTGK.js.map +0 -1
  105. package/dist/chunk-MZXGNP3J.cjs.map +0 -1
  106. package/dist/chunk-OCJ3BRZM.js.map +0 -1
  107. package/dist/chunk-VYNS3ZKV.cjs.map +0 -1
  108. package/dist/chunk-WBLT2HL3.js.map +0 -1
  109. package/dist/dist-2J26LQO2.cjs +0 -16
  110. package/dist/dist-MEN73GGI.js +0 -3
@@ -0,0 +1,828 @@
1
+ # Server API Reference
2
+
3
+ > API reference for server - 3 entries
4
+
5
+
6
+ ---
7
+
8
+ ## Reference: MastraServer
9
+
10
+ > API reference for the MastraServer abstract class used to create server adapters.
11
+
12
+ The `MastraServer` abstract class is the base for all server adapters. Extend this class to create adapters for frameworks other than Hono or Express.
13
+
14
+ ## Import
15
+
16
+ ```typescript
17
+ import { MastraServer } from '@mastra/server/server-adapter';
18
+ ```
19
+
20
+ ## Type parameters
21
+
22
+ ```typescript
23
+ MastraServer<TApp, TRequest, TResponse>
24
+ ```
25
+
26
+ | Parameter | Description |
27
+ |-----------|-------------|
28
+ | `TApp` | Framework app type (e.g., `Hono`, `Application`) |
29
+ | `TRequest` | Framework request type |
30
+ | `TResponse` | Framework response/context type |
31
+
32
+ ## Constructor
33
+
34
+ ```typescript
35
+ constructor(options: MastraServerOptions<TApp>)
36
+ ```
37
+
38
+ ### Options
39
+
40
+ ## Abstract methods
41
+
42
+ These methods must be implemented by adapters:
43
+
44
+ ### registerContextMiddleware()
45
+
46
+ Attach Mastra context to every request.
47
+
48
+ ```typescript
49
+ abstract registerContextMiddleware(): void
50
+ ```
51
+
52
+ **Context to attach:**
53
+ - `mastra` - Mastra instance
54
+ - `requestContext` - Request-scoped context
55
+ - `tools` - Available tools
56
+ - `abortSignal` - Request cancellation signal
57
+
58
+ ### registerAuthMiddleware()
59
+
60
+ Register authentication and authorization middleware.
61
+
62
+ ```typescript
63
+ abstract registerAuthMiddleware(): void
64
+ ```
65
+
66
+ ### registerRoute()
67
+
68
+ Register a single route with the framework.
69
+
70
+ ```typescript
71
+ abstract registerRoute(
72
+ app: TApp,
73
+ route: ServerRoute,
74
+ options: { prefix?: string }
75
+ ): Promise<void>
76
+ ```
77
+
78
+ ### getParams()
79
+
80
+ Extract parameters from the request.
81
+
82
+ ```typescript
83
+ abstract getParams(
84
+ route: ServerRoute,
85
+ request: TRequest
86
+ ): Promise<{
87
+ urlParams: Record<string, string>;
88
+ queryParams: Record<string, string>;
89
+ body: unknown;
90
+ }>
91
+ ```
92
+
93
+ ### sendResponse()
94
+
95
+ Send response based on route type.
96
+
97
+ ```typescript
98
+ abstract sendResponse(
99
+ route: ServerRoute,
100
+ response: TResponse,
101
+ result: unknown
102
+ ): Promise<unknown>
103
+ ```
104
+
105
+ ### stream()
106
+
107
+ Handle streaming responses.
108
+
109
+ ```typescript
110
+ abstract stream(
111
+ route: ServerRoute,
112
+ response: TResponse,
113
+ result: unknown
114
+ ): Promise<unknown>
115
+ ```
116
+
117
+ ## Instance methods
118
+
119
+ ### init()
120
+
121
+ Initialize the server by registering all middleware and routes.
122
+
123
+ ```typescript
124
+ async init(): Promise<void>
125
+ ```
126
+
127
+ Calls in order:
128
+ 1. `registerContextMiddleware()`
129
+ 2. `registerAuthMiddleware()`
130
+ 3. `registerRoutes()`
131
+
132
+ ### registerRoutes()
133
+
134
+ Register all Mastra routes.
135
+
136
+ ```typescript
137
+ async registerRoutes(): Promise<void>
138
+ ```
139
+
140
+ ### getApp()
141
+
142
+ Get the framework app instance.
143
+
144
+ ```typescript
145
+ getApp<T = TApp>(): T
146
+ ```
147
+
148
+ ### parsePathParams()
149
+
150
+ Validate path parameters with the route's Zod schema.
151
+
152
+ ```typescript
153
+ async parsePathParams(
154
+ route: ServerRoute,
155
+ params: Record<string, string>
156
+ ): Promise<Record<string, unknown>>
157
+ ```
158
+
159
+ ### parseQueryParams()
160
+
161
+ Validate query parameters with the route's Zod schema.
162
+
163
+ ```typescript
164
+ async parseQueryParams(
165
+ route: ServerRoute,
166
+ params: Record<string, string>
167
+ ): Promise<Record<string, unknown>>
168
+ ```
169
+
170
+ ### parseBody()
171
+
172
+ Validate request body with the route's Zod schema.
173
+
174
+ ```typescript
175
+ async parseBody(
176
+ route: ServerRoute,
177
+ body: unknown
178
+ ): Promise<unknown>
179
+ ```
180
+
181
+ ### registerOpenAPIRoute()
182
+
183
+ Register an endpoint that serves the OpenAPI specification.
184
+
185
+ ```typescript
186
+ async registerOpenAPIRoute(
187
+ app: TApp,
188
+ config: OpenAPIConfig,
189
+ options: { prefix?: string }
190
+ ): Promise<void>
191
+ ```
192
+
193
+ ## Protected methods
194
+
195
+ ### mergeRequestContext()
196
+
197
+ Merge request context from multiple sources (query params and body).
198
+
199
+ ```typescript
200
+ protected mergeRequestContext(options: {
201
+ paramsRequestContext?: Record<string, any>;
202
+ bodyRequestContext?: Record<string, any>;
203
+ }): RequestContext
204
+ ```
205
+
206
+ ## Types
207
+
208
+ ### BodyLimitOptions
209
+
210
+ ```typescript
211
+ interface BodyLimitOptions {
212
+ maxSize: number;
213
+ onError: (error: unknown) => unknown;
214
+ }
215
+ ```
216
+
217
+ ### StreamOptions
218
+
219
+ ```typescript
220
+ interface StreamOptions {
221
+ redact?: boolean;
222
+ }
223
+ ```
224
+
225
+ ## Example
226
+
227
+ ```typescript
228
+ import { MastraServer, ServerRoute } from '@mastra/server/server-adapter';
229
+ import type { Mastra } from '@mastra/core';
230
+
231
+ export class MyServer extends MastraServer<MyApp, MyRequest, MyResponse> {
232
+ registerContextMiddleware(): void {
233
+ this.app.use('*', (req, res, next) => {
234
+ res.locals.mastra = this.mastra;
235
+ next();
236
+ });
237
+ }
238
+
239
+ registerAuthMiddleware(): void {
240
+ const auth = this.mastra.getServer()?.auth;
241
+ if (!auth) return;
242
+ // Implement auth
243
+ }
244
+
245
+ async registerRoute(app, route, { prefix }) {
246
+ // Implement route registration
247
+ }
248
+
249
+ async getParams(route, request) {
250
+ return {
251
+ urlParams: request.params,
252
+ queryParams: request.query,
253
+ body: request.body,
254
+ };
255
+ }
256
+
257
+ async sendResponse(route, response, result) {
258
+ return response.json(result);
259
+ }
260
+
261
+ async stream(route, response, result) {
262
+ // Implement streaming
263
+ }
264
+ }
265
+ ```
266
+
267
+ ## Related
268
+
269
+ - [Server Adapters](https://mastra.ai/docs/v1/server/server-adapters) - Using adapters
270
+ - [Custom Adapters](https://mastra.ai/docs/v1/server/custom-adapters) - Creating custom adapters
271
+ - [createRoute()](https://mastra.ai/reference/v1/server/create-route) - Creating custom routes
272
+
273
+ ---
274
+
275
+ ## Reference: createRoute()
276
+
277
+ > API reference for createRoute() function used to define type-safe routes with validation and OpenAPI generation.
278
+
279
+ The `createRoute()` function creates type-safe routes with Zod validation. When an `openapiPath` is configured on the server adapter, it generates OpenAPI schema entries from the supplied Zod schemas.
280
+
281
+ ## Import
282
+
283
+ ```typescript
284
+ import { createRoute } from '@mastra/server/server-adapter';
285
+ ```
286
+
287
+ ## Signature
288
+
289
+ ```typescript
290
+ function createRoute<TPath, TQuery, TBody, TResponse, TResponseType>(
291
+ config: RouteConfig<TPath, TQuery, TBody, TResponse, TResponseType>
292
+ ): ServerRoute
293
+ ```
294
+
295
+ ## Parameters
296
+
297
+ ## Handler parameters
298
+
299
+ The handler receives validated parameters plus runtime context:
300
+
301
+ ```typescript
302
+ handler: async (params) => {
303
+ // From schemas (typed from Zod)
304
+ params.id; // From pathParamSchema
305
+ params.filter; // From queryParamSchema
306
+ params.name; // From bodySchema
307
+
308
+ // Runtime context (always available)
309
+ params.mastra; // Mastra instance
310
+ params.requestContext; // Request-scoped context
311
+ params.tools; // Available tools
312
+ params.abortSignal; // Request cancellation signal
313
+ params.taskStore; // A2A task storage
314
+ }
315
+ ```
316
+
317
+ ## Return value
318
+
319
+ Returns a `ServerRoute` object that can be registered with an adapter.
320
+
321
+ ## Examples
322
+
323
+ ### GET route with path params
324
+
325
+ ```typescript
326
+ import { createRoute } from '@mastra/server/server-adapter';
327
+ import { z } from 'zod';
328
+
329
+ const getAgent = createRoute({
330
+ method: 'GET',
331
+ path: '/api/agents/:agentId',
332
+ responseType: 'json',
333
+ pathParamSchema: z.object({
334
+ agentId: z.string(),
335
+ }),
336
+ responseSchema: z.object({
337
+ name: z.string(),
338
+ description: z.string().optional(),
339
+ }),
340
+ summary: 'Get agent by ID',
341
+ tags: ['Agents'],
342
+ handler: async ({ agentId, mastra }) => {
343
+ return mastra.getAgent(agentId);
344
+ },
345
+ });
346
+ ```
347
+
348
+ ### POST route with body
349
+
350
+ ```typescript
351
+ const createItem = createRoute({
352
+ method: 'POST',
353
+ path: '/api/items',
354
+ responseType: 'json',
355
+ bodySchema: z.object({
356
+ name: z.string(),
357
+ value: z.number(),
358
+ }),
359
+ responseSchema: z.object({
360
+ id: z.string(),
361
+ name: z.string(),
362
+ value: z.number(),
363
+ }),
364
+ handler: async ({ name, value, mastra }) => {
365
+ // name and value are typed from bodySchema
366
+ return { id: 'new-id', name, value };
367
+ },
368
+ });
369
+ ```
370
+
371
+ ### Query params with coercion
372
+
373
+ ```typescript
374
+ const listItems = createRoute({
375
+ method: 'GET',
376
+ path: '/api/items',
377
+ responseType: 'json',
378
+ queryParamSchema: z.object({
379
+ page: z.coerce.number().default(0),
380
+ limit: z.coerce.number().default(50),
381
+ enabled: z.coerce.boolean().optional(),
382
+ }),
383
+ handler: async ({ page, limit, enabled, mastra }) => {
384
+ // page, limit, enabled are typed and coerced
385
+ return { items: [], page, limit };
386
+ },
387
+ });
388
+ ```
389
+
390
+ ### Streaming route
391
+
392
+ ```typescript
393
+ const streamAgent = createRoute({
394
+ method: 'POST',
395
+ path: '/api/agents/:agentId/stream',
396
+ responseType: 'stream',
397
+ streamFormat: 'sse',
398
+ pathParamSchema: z.object({
399
+ agentId: z.string(),
400
+ }),
401
+ bodySchema: z.object({
402
+ messages: z.array(z.any()),
403
+ }),
404
+ handler: async ({ agentId, messages, mastra, abortSignal }) => {
405
+ const agent = mastra.getAgent(agentId);
406
+ return agent.stream({ messages, abortSignal });
407
+ },
408
+ });
409
+ ```
410
+
411
+ ### Custom body size limit
412
+
413
+ ```typescript
414
+ const uploadRoute = createRoute({
415
+ method: 'POST',
416
+ path: '/api/upload',
417
+ responseType: 'json',
418
+ maxBodySize: 50 * 1024 * 1024, // 50MB
419
+ bodySchema: z.object({
420
+ file: z.string(),
421
+ }),
422
+ handler: async ({ file }) => {
423
+ return { uploaded: true };
424
+ },
425
+ });
426
+ ```
427
+
428
+ ## Schema patterns
429
+
430
+ ### Passthrough for extensibility
431
+
432
+ ```typescript
433
+ const bodySchema = z.object({
434
+ required: z.string(),
435
+ }).passthrough(); // Allow unknown fields
436
+ ```
437
+
438
+ ### Date coercion
439
+
440
+ ```typescript
441
+ const querySchema = z.object({
442
+ fromDate: z.coerce.date().optional(),
443
+ toDate: z.coerce.date().optional(),
444
+ });
445
+ ```
446
+
447
+ ### Union types
448
+
449
+ ```typescript
450
+ const bodySchema = z.object({
451
+ messages: z.union([
452
+ z.array(z.any()),
453
+ z.string(),
454
+ ]),
455
+ });
456
+ ```
457
+
458
+ ## Error handling
459
+
460
+ Throw an error with a `status` property to return specific HTTP status codes from handlers. If using Hono, you can use `HTTPException` from `hono/http-exception`:
461
+
462
+ ```typescript
463
+ import { createRoute } from '@mastra/server/server-adapter';
464
+ import { HTTPException } from 'hono/http-exception';
465
+
466
+ const getAgent = createRoute({
467
+ method: 'GET',
468
+ path: '/api/agents/:agentId',
469
+ responseType: 'json',
470
+ pathParamSchema: z.object({ agentId: z.string() }),
471
+ handler: async ({ agentId, mastra }) => {
472
+ const agent = mastra.getAgent(agentId);
473
+ if (!agent) {
474
+ throw new HTTPException(404, { message: `Agent '${agentId}' not found` });
475
+ }
476
+ return agent;
477
+ },
478
+ });
479
+ ```
480
+
481
+ For Express or framework-agnostic code, throw an error with a `status` property:
482
+
483
+ ```typescript
484
+ class HttpError extends Error {
485
+ constructor(public status: number, message: string) {
486
+ super(message);
487
+ }
488
+ }
489
+
490
+ // In handler:
491
+ throw new HttpError(404, `Agent '${agentId}' not found`);
492
+ ```
493
+
494
+ Common status codes:
495
+
496
+ | Code | Meaning |
497
+ |------|---------|
498
+ | 400 | Bad Request |
499
+ | 401 | Unauthorized |
500
+ | 403 | Forbidden |
501
+ | 404 | Not Found |
502
+ | 500 | Internal Server Error |
503
+
504
+ ## Related
505
+
506
+ - [Server Routes](https://mastra.ai/reference/v1/server/routes) - Default Mastra routes
507
+ - [MastraServer](https://mastra.ai/reference/v1/server/mastra-server) - Server adapter class
508
+ - [Server Adapters](https://mastra.ai/docs/v1/server/server-adapters) - Using adapters
509
+
510
+ ---
511
+
512
+ ## Reference: Server Routes
513
+
514
+ > API reference for HTTP routes registered by Mastra server adapters.
515
+
516
+ Server adapters register these routes when you call `server.init()`. All routes are prefixed with the `prefix` option if configured.
517
+
518
+ ## Agents
519
+
520
+ | Method | Path | Description |
521
+ |--------|------|-------------|
522
+ | `GET` | `/api/agents` | List all agents |
523
+ | `GET` | `/api/agents/:agentId` | Get agent by ID |
524
+ | `POST` | `/api/agents/:agentId/generate` | Generate agent response |
525
+ | `POST` | `/api/agents/:agentId/stream` | Stream agent response |
526
+ | `GET` | `/api/agents/:agentId/tools` | List agent tools |
527
+ | `POST` | `/api/agents/:agentId/tools/:toolId/execute` | Execute agent tool |
528
+
529
+ ### Generate request body
530
+
531
+ ```typescript
532
+ {
533
+ messages: CoreMessage[] | string; // Required
534
+ instructions?: string; // System instructions
535
+ system?: string; // System prompt
536
+ context?: CoreMessage[]; // Additional context
537
+ memory?: { key: string } | boolean; // Memory config
538
+ resourceId?: string; // Resource identifier
539
+ threadId?: string; // Thread identifier
540
+ runId?: string; // Run identifier
541
+ maxSteps?: number; // Max tool steps
542
+ activeTools?: string[]; // Tools to enable
543
+ toolChoice?: ToolChoice; // Tool selection mode
544
+ requestContext?: Record<string, unknown>; // Request context
545
+ output?: ZodSchema; // Structured output schema
546
+ }
547
+ ```
548
+
549
+ ### Generate response
550
+
551
+ ```typescript
552
+ {
553
+ text: string;
554
+ toolCalls?: ToolCall[];
555
+ finishReason: string;
556
+ usage?: {
557
+ promptTokens: number;
558
+ completionTokens: number;
559
+ };
560
+ }
561
+ ```
562
+
563
+ ## Workflows
564
+
565
+ | Method | Path | Description |
566
+ |--------|------|-------------|
567
+ | `GET` | `/api/workflows` | List all workflows |
568
+ | `GET` | `/api/workflows/:workflowId` | Get workflow by ID |
569
+ | `POST` | `/api/workflows/:workflowId/create-run` | Create a new workflow run |
570
+ | `POST` | `/api/workflows/:workflowId/start-async` | Start workflow and await result |
571
+ | `POST` | `/api/workflows/:workflowId/stream` | Stream workflow execution |
572
+ | `POST` | `/api/workflows/:workflowId/resume` | Resume suspended workflow |
573
+ | `POST` | `/api/workflows/:workflowId/resume-async` | Resume asynchronously |
574
+ | `GET` | `/api/workflows/:workflowId/runs` | List workflow runs |
575
+ | `GET` | `/api/workflows/:workflowId/runs/:runId` | Get specific run |
576
+
577
+ ### Create run request body
578
+
579
+ ```typescript
580
+ {
581
+ resourceId?: string; // Associate run with a resource (e.g., user ID)
582
+ disableScorers?: boolean; // Disable scorers for this run
583
+ }
584
+ ```
585
+
586
+ ### Start-async request body
587
+
588
+ ```typescript
589
+ {
590
+ resourceId?: string; // Associate run with a resource (e.g., user ID)
591
+ inputData?: unknown;
592
+ initialState?: unknown;
593
+ requestContext?: Record<string, unknown>;
594
+ tracingOptions?: {
595
+ spanName?: string;
596
+ attributes?: Record<string, unknown>;
597
+ };
598
+ }
599
+ ```
600
+
601
+ ### Stream workflow request body
602
+
603
+ ```typescript
604
+ {
605
+ resourceId?: string; // Associate run with a resource (e.g., user ID)
606
+ inputData?: unknown;
607
+ initialState?: unknown;
608
+ requestContext?: Record<string, unknown>;
609
+ closeOnSuspend?: boolean;
610
+ }
611
+ ```
612
+
613
+ ### Resume request body
614
+
615
+ ```typescript
616
+ {
617
+ step?: string | string[];
618
+ resumeData?: unknown;
619
+ requestContext?: Record<string, unknown>;
620
+ }
621
+ ```
622
+
623
+ ## Tools
624
+
625
+ | Method | Path | Description |
626
+ |--------|------|-------------|
627
+ | `GET` | `/api/tools` | List all tools |
628
+ | `GET` | `/api/tools/:toolId` | Get tool by ID |
629
+ | `POST` | `/api/tools/:toolId/execute` | Execute tool |
630
+
631
+ ### Execute tool request body
632
+
633
+ ```typescript
634
+ {
635
+ data: unknown; // Tool input data
636
+ requestContext?: Record<string, unknown>;
637
+ }
638
+ ```
639
+
640
+ ## Memory
641
+
642
+ | Method | Path | Description |
643
+ |--------|------|-------------|
644
+ | `GET` | `/api/memory/threads` | List threads |
645
+ | `GET` | `/api/memory/threads/:threadId` | Get thread |
646
+ | `POST` | `/api/memory/threads` | Create thread |
647
+ | `DELETE` | `/api/memory/threads/:threadId` | Delete thread |
648
+ | `POST` | `/api/memory/threads/:threadId/clone` | Clone thread |
649
+ | `GET` | `/api/memory/threads/:threadId/messages` | Get thread messages |
650
+ | `POST` | `/api/memory/threads/:threadId/messages` | Add message |
651
+
652
+ ### Create thread request body
653
+
654
+ ```typescript
655
+ {
656
+ resourceId: string;
657
+ title?: string;
658
+ metadata?: Record<string, unknown>;
659
+ }
660
+ ```
661
+
662
+ ### Clone thread request body
663
+
664
+ ```typescript
665
+ {
666
+ newThreadId?: string; // Custom ID for cloned thread
667
+ resourceId?: string; // Override resource ID
668
+ title?: string; // Custom title for clone
669
+ metadata?: Record<string, unknown>; // Additional metadata
670
+ options?: {
671
+ messageLimit?: number; // Max messages to clone
672
+ messageFilter?: {
673
+ startDate?: Date; // Clone messages after this date
674
+ endDate?: Date; // Clone messages before this date
675
+ messageIds?: string[]; // Clone specific messages
676
+ };
677
+ };
678
+ }
679
+ ```
680
+
681
+ ### Clone thread response
682
+
683
+ ```typescript
684
+ {
685
+ thread: {
686
+ id: string;
687
+ resourceId: string;
688
+ title: string;
689
+ createdAt: Date;
690
+ updatedAt: Date;
691
+ metadata: {
692
+ clone: {
693
+ sourceThreadId: string;
694
+ clonedAt: Date;
695
+ lastMessageId?: string;
696
+ };
697
+ // ... other metadata
698
+ };
699
+ };
700
+ clonedMessages: MastraDBMessage[];
701
+ }
702
+ ```
703
+
704
+ ## Vectors
705
+
706
+ | Method | Path | Description |
707
+ |--------|------|-------------|
708
+ | `POST` | `/api/vectors/:vectorName/upsert` | Upsert vectors |
709
+ | `POST` | `/api/vectors/:vectorName/query` | Query vectors |
710
+ | `POST` | `/api/vectors/:vectorName/delete` | Delete vectors |
711
+
712
+ ### Upsert request body
713
+
714
+ ```typescript
715
+ {
716
+ vectors: Array<{
717
+ id: string;
718
+ values: number[];
719
+ metadata?: Record<string, unknown>;
720
+ }>;
721
+ }
722
+ ```
723
+
724
+ ### Query request body
725
+
726
+ ```typescript
727
+ {
728
+ vector: number[];
729
+ topK?: number;
730
+ filter?: Record<string, unknown>;
731
+ includeMetadata?: boolean;
732
+ }
733
+ ```
734
+
735
+ ## MCP
736
+
737
+ | Method | Path | Description |
738
+ |--------|------|-------------|
739
+ | `GET` | `/api/mcp/servers` | List MCP servers |
740
+ | `GET` | `/api/mcp/servers/:serverId/tools` | List server tools |
741
+ | `POST` | `/api/mcp/:serverId` | MCP HTTP transport |
742
+ | `GET` | `/api/mcp/:serverId/sse` | MCP SSE transport |
743
+
744
+ ## Logs
745
+
746
+ | Method | Path | Description |
747
+ |--------|------|-------------|
748
+ | `GET` | `/api/logs` | List logs |
749
+ | `GET` | `/api/logs/:runId` | Get logs by run ID |
750
+
751
+ ### Query parameters
752
+
753
+ ```typescript
754
+ {
755
+ page?: number;
756
+ perPage?: number;
757
+ transportId?: string;
758
+ }
759
+ ```
760
+
761
+ ## Telemetry
762
+
763
+ | Method | Path | Description |
764
+ |--------|------|-------------|
765
+ | `GET` | `/api/telemetry/traces` | List traces |
766
+ | `GET` | `/api/telemetry/traces/:traceId` | Get trace |
767
+ | `GET` | `/api/telemetry/traces/:traceId/spans` | Get trace spans |
768
+
769
+ ## Common query parameters
770
+
771
+ ### Pagination
772
+
773
+ Most list endpoints support:
774
+
775
+ ```typescript
776
+ {
777
+ page?: number; // Page number (0-indexed)
778
+ perPage?: number; // Items per page (default: 10)
779
+ }
780
+ ```
781
+
782
+ Or offset-based:
783
+
784
+ ```typescript
785
+ {
786
+ offset?: number; // Skip N items
787
+ limit?: number; // Max items (default: 50)
788
+ }
789
+ ```
790
+
791
+ ### Filtering
792
+
793
+ Workflow runs support:
794
+
795
+ ```typescript
796
+ {
797
+ fromDate?: string; // ISO date string
798
+ toDate?: string; // ISO date string
799
+ status?: string; // Run status filter
800
+ resourceId?: string; // Filter by resource
801
+ }
802
+ ```
803
+
804
+ ## Error responses
805
+
806
+ All routes return errors in this format:
807
+
808
+ ```typescript
809
+ {
810
+ error: string; // Error message
811
+ details?: unknown; // Additional details
812
+ }
813
+ ```
814
+
815
+ Common status codes:
816
+
817
+ | Code | Meaning |
818
+ |------|---------|
819
+ | 400 | Bad Request - Invalid parameters |
820
+ | 401 | Unauthorized - Missing/invalid auth |
821
+ | 403 | Forbidden - Insufficient permissions |
822
+ | 404 | Not Found - Resource doesn't exist |
823
+ | 500 | Internal Server Error |
824
+
825
+ ## Related
826
+
827
+ - [createRoute()](https://mastra.ai/reference/v1/server/create-route) - Creating custom routes
828
+ - [Server Adapters](https://mastra.ai/docs/v1/server/server-adapters) - Using adapters