@mastra/mcp-docs-server 1.0.0-beta.7 → 1.0.0-beta.9

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 (63) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +1 -15
  2. package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +1 -7
  3. package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +1 -55
  4. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +12 -12
  5. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +48 -48
  6. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +17 -17
  7. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +17 -17
  8. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +18 -18
  9. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +17 -17
  10. package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fconvex.md +16 -0
  12. package/.docs/organized/changelogs/%40mastra%2Fcore.md +78 -78
  13. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +18 -18
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +23 -23
  15. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +17 -17
  16. package/.docs/organized/changelogs/%40mastra%2Flance.md +17 -17
  17. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +65 -65
  18. package/.docs/organized/changelogs/%40mastra%2Floggers.md +29 -29
  19. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +16 -16
  20. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +12 -12
  21. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +10 -10
  22. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +17 -17
  23. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +17 -17
  24. package/.docs/organized/changelogs/%40mastra%2Fpg.md +69 -69
  25. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +31 -31
  26. package/.docs/organized/changelogs/%40mastra%2Freact.md +14 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fserver.md +56 -56
  28. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +17 -17
  29. package/.docs/organized/changelogs/create-mastra.md +13 -13
  30. package/.docs/organized/changelogs/mastra.md +21 -21
  31. package/.docs/organized/code-examples/mcp-server-adapters.md +1 -2
  32. package/.docs/organized/code-examples/processors-with-ai-sdk.md +14 -0
  33. package/.docs/organized/code-examples/server-app-access.md +1 -1
  34. package/.docs/organized/code-examples/server-hono-adapter.md +1 -1
  35. package/.docs/raw/getting-started/studio.mdx +4 -2
  36. package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +161 -0
  37. package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +381 -431
  38. package/.docs/raw/guides/getting-started/quickstart.mdx +11 -0
  39. package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +3 -3
  40. package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +31 -0
  41. package/.docs/raw/reference/ai-sdk/chat-route.mdx +127 -0
  42. package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +117 -0
  43. package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +64 -0
  44. package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +116 -0
  45. package/.docs/raw/reference/ai-sdk/network-route.mdx +99 -0
  46. package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +289 -0
  47. package/.docs/raw/reference/ai-sdk/workflow-route.mdx +110 -0
  48. package/.docs/raw/reference/client-js/agents.mdx +251 -67
  49. package/.docs/raw/reference/client-js/mastra-client.mdx +2 -2
  50. package/.docs/raw/reference/client-js/memory.mdx +4 -1
  51. package/.docs/raw/reference/core/getMemory.mdx +73 -0
  52. package/.docs/raw/reference/core/getStoredAgentById.mdx +183 -0
  53. package/.docs/raw/reference/core/listMemory.mdx +70 -0
  54. package/.docs/raw/reference/core/listStoredAgents.mdx +151 -0
  55. package/.docs/raw/reference/core/mastra-class.mdx +8 -0
  56. package/.docs/raw/reference/server/express-adapter.mdx +52 -0
  57. package/.docs/raw/reference/server/hono-adapter.mdx +54 -0
  58. package/.docs/raw/server-db/custom-api-routes.mdx +5 -5
  59. package/.docs/raw/server-db/server-adapters.mdx +94 -91
  60. package/.docs/raw/streaming/tool-streaming.mdx +10 -14
  61. package/.docs/raw/workflows/workflow-state.mdx +4 -5
  62. package/CHANGELOG.md +15 -0
  63. package/package.json +4 -4
@@ -0,0 +1,70 @@
1
+ ---
2
+ title: "Reference: Mastra.listMemory() | Core"
3
+ description: "Documentation for the `Mastra.listMemory()` method in Mastra, which returns all registered memory instances."
4
+ ---
5
+
6
+ # Mastra.listMemory()
7
+
8
+ The `.listMemory()` method returns all memory instances registered with the Mastra instance.
9
+
10
+ ## Usage example
11
+
12
+ ```typescript copy
13
+ const memoryInstances = mastra.listMemory();
14
+
15
+ for (const [key, memory] of Object.entries(memoryInstances)) {
16
+ console.log(`Memory "${key}": ${memory.id}`);
17
+ }
18
+ ```
19
+
20
+ ## Parameters
21
+
22
+ This method takes no parameters.
23
+
24
+ ## Returns
25
+
26
+ <PropertiesTable
27
+ content={[
28
+ {
29
+ name: "memory",
30
+ type: "Record<string, MastraMemory>",
31
+ description:
32
+ "An object containing all registered memory instances, keyed by their registry keys.",
33
+ },
34
+ ]}
35
+ />
36
+
37
+ ## Example: Checking Registered Memory
38
+
39
+ ```typescript copy
40
+ import { Mastra } from "@mastra/core";
41
+ import { Memory } from "@mastra/memory";
42
+ import { LibSQLStore } from "@mastra/libsql";
43
+
44
+ const conversationMemory = new Memory({
45
+ id: "conversation-memory",
46
+ storage: new LibSQLStore({ url: ":memory:" }),
47
+ });
48
+
49
+ const analyticsMemory = new Memory({
50
+ id: "analytics-memory",
51
+ storage: new LibSQLStore({ url: ":memory:" }),
52
+ });
53
+
54
+ const mastra = new Mastra({
55
+ memory: {
56
+ conversationMemory,
57
+ analyticsMemory,
58
+ },
59
+ });
60
+
61
+ // List all registered memory instances
62
+ const allMemory = mastra.listMemory();
63
+ console.log(Object.keys(allMemory)); // ["conversationMemory", "analyticsMemory"]
64
+ ```
65
+
66
+ ## Related
67
+
68
+ - [Mastra.getMemory()](/reference/v1/core/getMemory)
69
+ - [Memory overview](/docs/v1/memory/overview)
70
+ - [Agent Memory](/docs/v1/agents/agent-memory)
@@ -0,0 +1,151 @@
1
+ ---
2
+ title: "Reference: Mastra.listStoredAgents() | Core"
3
+ description: "Documentation for the `Mastra.listStoredAgents()` method in Mastra, which retrieves a paginated list of agents from storage."
4
+ ---
5
+
6
+ # Mastra.listStoredAgents()
7
+
8
+ The `.listStoredAgents()` method retrieves a paginated list of agent configurations from storage. By default, it returns executable `Agent` instances, but can also return raw storage data.
9
+
10
+ ## Usage example
11
+
12
+ ```typescript copy
13
+ // Get Agent instances from storage
14
+ const { agents, total, hasMore } = await mastra.listStoredAgents();
15
+
16
+ for (const agent of agents) {
17
+ console.log(agent.id, agent.name);
18
+ // Each agent is ready to use
19
+ // const response = await agent.generate({ messages: "Hello!" });
20
+ }
21
+ ```
22
+
23
+ ```typescript copy
24
+ // Get paginated results with raw storage data
25
+ const result = await mastra.listStoredAgents({
26
+ page: 0,
27
+ perPage: 10,
28
+ raw: true,
29
+ });
30
+
31
+ console.log(`Showing ${result.agents.length} of ${result.total} agents`);
32
+ console.log(`Has more: ${result.hasMore}`);
33
+
34
+ for (const config of result.agents) {
35
+ console.log(config.id, config.name, config.createdAt);
36
+ }
37
+ ```
38
+
39
+ ## Parameters
40
+
41
+ <PropertiesTable
42
+ content={[
43
+ {
44
+ name: "args",
45
+ type: "object",
46
+ description:
47
+ "Optional configuration object for pagination and output format.",
48
+ isOptional: true,
49
+ },
50
+ ]}
51
+ />
52
+
53
+ ### Args Options
54
+
55
+ <PropertiesTable
56
+ content={[
57
+ {
58
+ name: "page",
59
+ type: "number",
60
+ description: "Zero-indexed page number for pagination.",
61
+ isOptional: true,
62
+ defaultValue: "0",
63
+ },
64
+ {
65
+ name: "perPage",
66
+ type: "number | false",
67
+ description:
68
+ "Number of items per page. Set to `false` to fetch all records without pagination.",
69
+ isOptional: true,
70
+ defaultValue: "100",
71
+ },
72
+ {
73
+ name: "raw",
74
+ type: "boolean",
75
+ description:
76
+ "When `true`, returns raw `StorageAgentType` objects instead of `Agent` instances.",
77
+ isOptional: true,
78
+ defaultValue: "false",
79
+ },
80
+ ]}
81
+ />
82
+
83
+ ## Returns
84
+
85
+ <PropertiesTable
86
+ content={[
87
+ {
88
+ name: "agents",
89
+ type: "Agent[] | StorageAgentType[]",
90
+ description:
91
+ "Array of `Agent` instances by default, or `StorageAgentType` objects when `raw: true`.",
92
+ },
93
+ {
94
+ name: "total",
95
+ type: "number",
96
+ description: "Total number of stored agents across all pages.",
97
+ },
98
+ {
99
+ name: "page",
100
+ type: "number",
101
+ description: "Current page number (zero-indexed).",
102
+ },
103
+ {
104
+ name: "perPage",
105
+ type: "number | false",
106
+ description: "Number of items per page, or `false` if fetching all.",
107
+ },
108
+ {
109
+ name: "hasMore",
110
+ type: "boolean",
111
+ description: "Whether there are more pages available.",
112
+ },
113
+ ]}
114
+ />
115
+
116
+ ## Primitive Resolution
117
+
118
+ When creating `Agent` instances (default behavior), each stored agent's configuration is resolved against registered primitives:
119
+
120
+ - **Tools**: Resolved from `tools` registered in Mastra config
121
+ - **Workflows**: Resolved from `workflows` registered in Mastra config
122
+ - **Sub-agents**: Resolved from `agents` registered in Mastra config
123
+ - **Memory**: Resolved from `memory` registered in Mastra config
124
+ - **Scorers**: Resolved from `scorers` registered in Mastra config
125
+
126
+ If a referenced primitive is not found, a warning is logged but the agent is still created.
127
+
128
+ ## Example: Iterating Through All Stored Agents
129
+
130
+ ```typescript copy
131
+ async function getAllStoredAgents(mastra: Mastra) {
132
+ const allAgents: Agent[] = [];
133
+ let page = 0;
134
+ let hasMore = true;
135
+
136
+ while (hasMore) {
137
+ const result = await mastra.listStoredAgents({ page, perPage: 50 });
138
+ allAgents.push(...result.agents);
139
+ hasMore = result.hasMore;
140
+ page++;
141
+ }
142
+
143
+ return allAgents;
144
+ }
145
+ ```
146
+
147
+ ## Related
148
+
149
+ - [Mastra.getStoredAgentById()](/reference/v1/core/getStoredAgentById)
150
+ - [Storage overview](/docs/v1/server-db/storage)
151
+ - [Agents overview](/docs/v1/agents/overview)
@@ -148,5 +148,13 @@ export const mastra = new Mastra({
148
148
  isOptional: true,
149
149
  defaultValue: "{}",
150
150
  },
151
+ {
152
+ name: "memory",
153
+ type: "Record<string, MastraMemory>",
154
+ description:
155
+ "Memory instances to register. These can be referenced by stored agents and resolved at runtime. Structured as a key-value pair, with keys being the registry key and values being memory instances.",
156
+ isOptional: true,
157
+ defaultValue: "{}",
158
+ },
151
159
  ]}
152
160
  />
@@ -5,6 +5,7 @@ description: "API reference for the @mastra/express server adapter."
5
5
 
6
6
  import Steps from "@site/src/components/Steps";
7
7
  import StepItem from "@site/src/components/StepItem";
8
+ import PropertiesTable from "@site/src/components/PropertiesTable";
8
9
 
9
10
  # Express Adapter
10
11
 
@@ -87,6 +88,57 @@ await server.init();
87
88
  app.listen(4111);
88
89
  ```
89
90
 
91
+ ## Constructor parameters
92
+
93
+ <PropertiesTable
94
+ content={[
95
+ {
96
+ name: "app",
97
+ type: "Application",
98
+ description: "Express app instance",
99
+ isOptional: false,
100
+ },
101
+ {
102
+ name: "mastra",
103
+ type: "Mastra",
104
+ description: "Mastra instance",
105
+ isOptional: false,
106
+ },
107
+ {
108
+ name: "prefix",
109
+ type: "string",
110
+ description: "Route path prefix (e.g., `/api/v2`)",
111
+ isOptional: true,
112
+ defaultValue: "''",
113
+ },
114
+ {
115
+ name: "openapiPath",
116
+ type: "string",
117
+ description: "Path to serve OpenAPI spec (e.g., `/openapi.json`)",
118
+ isOptional: true,
119
+ },
120
+ {
121
+ name: "bodyLimitOptions",
122
+ type: "{ maxSize: number, onError: (err) => unknown }",
123
+ description: "Request body size limits",
124
+ isOptional: true,
125
+ },
126
+ {
127
+ name: "streamOptions",
128
+ type: "{ redact?: boolean }",
129
+ description: "Stream redaction config. When true, redacts sensitive data from streams.",
130
+ isOptional: true,
131
+ defaultValue: "{ redact: true }",
132
+ },
133
+ {
134
+ name: "customRouteAuthConfig",
135
+ type: "Map<string, boolean>",
136
+ description: "Per-route auth overrides. Keys are `METHOD:PATH` (e.g., `GET:/api/health`). Value `false` makes route public, `true` requires auth.",
137
+ isOptional: true,
138
+ },
139
+ ]}
140
+ />
141
+
90
142
  ## Differences from Hono
91
143
 
92
144
  | Aspect | Express | Hono |
@@ -5,6 +5,7 @@ description: "API reference for the @mastra/hono server adapter."
5
5
 
6
6
  import Steps from "@site/src/components/Steps";
7
7
  import StepItem from "@site/src/components/StepItem";
8
+ import PropertiesTable from "@site/src/components/PropertiesTable";
8
9
 
9
10
  # Hono Adapter
10
11
 
@@ -77,6 +78,59 @@ await server.init();
77
78
  export default app;
78
79
  ```
79
80
 
81
+
82
+ ## Constructor parameters
83
+
84
+ <PropertiesTable
85
+ content={[
86
+ {
87
+ name: "app",
88
+ type: "Hono",
89
+ description: "Hono app instance",
90
+ isOptional: false,
91
+ },
92
+ {
93
+ name: "mastra",
94
+ type: "Mastra",
95
+ description: "Mastra instance",
96
+ isOptional: false,
97
+ },
98
+ {
99
+ name: "prefix",
100
+ type: "string",
101
+ description: "Route path prefix (e.g., `/api/v2`)",
102
+ isOptional: true,
103
+ defaultValue: "''",
104
+ },
105
+ {
106
+ name: "openapiPath",
107
+ type: "string",
108
+ description: "Path to serve OpenAPI spec (e.g., `/openapi.json`)",
109
+ isOptional: true,
110
+ },
111
+ {
112
+ name: "bodyLimitOptions",
113
+ type: "{ maxSize: number, onError: (err) => unknown }",
114
+ description: "Request body size limits",
115
+ isOptional: true,
116
+ },
117
+ {
118
+ name: "streamOptions",
119
+ type: "{ redact?: boolean }",
120
+ description: "Stream redaction config. When true, redacts sensitive data from streams.",
121
+ isOptional: true,
122
+ defaultValue: "{ redact: true }",
123
+ },
124
+ {
125
+ name: "customRouteAuthConfig",
126
+ type: "Map<string, boolean>",
127
+ description: "Per-route auth overrides. Keys are `METHOD:PATH` (e.g., `GET:/api/health`). Value `false` makes route public, `true` requires auth.",
128
+ isOptional: true,
129
+ },
130
+ ]}
131
+ />
132
+
133
+
80
134
  ## Adding custom routes
81
135
 
82
136
  Add routes directly to the Hono app:
@@ -5,11 +5,11 @@ description: "Expose additional HTTP endpoints from your Mastra server."
5
5
 
6
6
  # Custom API Routes
7
7
 
8
- By default Mastra automatically exposes registered agents and workflows via the server. For additional behavior you can define your own HTTP routes.
8
+ By default, Mastra automatically exposes registered agents and workflows via its server. For additional behavior you can define your own HTTP routes.
9
9
 
10
- Routes are provided with a helper `registerApiRoute` from `@mastra/core/server`. Routes can live in the same file as the `Mastra` instance but separating them helps keep configuration concise.
10
+ Routes are provided with a helper `registerApiRoute()` from `@mastra/core/server`. Routes can live in the same file as the `Mastra` instance but separating them helps keep configuration concise.
11
11
 
12
- ```typescript title="src/mastra/index.ts" copy showLineNumbers
12
+ ```typescript title="src/mastra/index.ts" copy
13
13
  import { Mastra } from "@mastra/core";
14
14
  import { registerApiRoute } from "@mastra/core/server";
15
15
 
@@ -39,9 +39,9 @@ curl http://localhost:4111/my-custom-route
39
39
 
40
40
  Each route's handler receives the Hono `Context`. Within the handler you can access the `Mastra` instance to fetch or call agents and workflows.
41
41
 
42
- To add route-specific middleware pass a `middleware` array when calling `registerApiRoute`.
42
+ To add route-specific middleware pass a `middleware` array when calling `registerApiRoute()`.
43
43
 
44
- ```typescript title="src/mastra/index.ts" copy showLineNumbers
44
+ ```typescript title="src/mastra/index.ts" copy
45
45
  import { Mastra } from "@mastra/core";
46
46
  import { registerApiRoute } from "@mastra/core/server";
47
47
 
@@ -3,20 +3,16 @@ title: "Server Adapters | Server & DB"
3
3
  description: "Manually configure a Mastra server using Hono or Express adapters."
4
4
  ---
5
5
 
6
- import PropertiesTable from "@site/src/components/PropertiesTable";
7
6
  import Tabs from "@theme/Tabs";
8
7
  import TabItem from "@theme/TabItem";
9
8
 
10
9
  # Server Adapters
11
10
 
12
- Server adapters let you run Mastra with your own HTTP server instead of using `mastra build`. While `mastra build` generates a standalone server for you, adapters give you full control over the server setup, letting you integrate Mastra into any Node.js application.
11
+ Server adapters let you run Mastra with your own HTTP server instead of the Hono server generated by `mastra build`. They provide more control over the server setup, including custom middleware ordering, authentication, logging, and deployment configuration, while still letting you integrate Mastra into any Node.js application without changing how agents or workflows execute.
13
12
 
14
- Use adapters when you need to:
13
+ ## When to use server adapters
15
14
 
16
- - **Integrate Mastra into an existing application** - Add Mastra endpoints to an Express or Hono app you already have running
17
- - **Control middleware ordering** - Insert your own middleware before or after Mastra's authentication and routing
18
- - **Deploy to platforms requiring specific server setup** - Some platforms like Cloudflare Workers or custom Docker setups need direct access to the server instance
19
- - **Use Express instead of Hono** - `mastra build` uses Hono internally, but you may prefer Express for its ecosystem or team familiarity
15
+ Use server adapters when you want Mastra’s endpoints added automatically to an existing application, when you need direct access to the server instance for custom configuration, or when your team prefers using Express instead of the Hono server created by `mastra build`.
20
16
 
21
17
  :::info
22
18
 
@@ -26,81 +22,85 @@ For simple deployments without custom server requirements, use `mastra build` in
26
22
 
27
23
  ## Available adapters
28
24
 
29
- - **[@mastra/hono](/reference/v1/server/hono-adapter)** - Hono framework adapter
30
- - **[@mastra/express](/reference/v1/server/express-adapter)** - Express framework adapter
31
-
32
- ## Basic setup
33
-
34
- Both adapters follow the same pattern. The adapter wraps your framework's app instance and registers Mastra's routes and middleware onto it.
35
-
36
- 1. **Create your framework's app instance** - Initialize Hono or Express as you normally would
37
- 2. **Create a `MastraServer`** - Pass your app and Mastra instance to the adapter
38
- 3. **Call `init()`** - This registers context middleware, authentication, and all API routes
39
-
40
- After `init()`, your app has all the Mastra endpoints (`/api/agents`, `/api/workflows`, etc.) and you can add your own routes before or after.
41
-
42
- See the [Hono Adapter](/reference/v1/server/hono-adapter) or [Express Adapter](/reference/v1/server/express-adapter) docs for framework-specific setup and code examples.
43
-
44
- ## Constructor options
45
-
46
- Both adapters accept the same options:
47
-
48
- <PropertiesTable
49
- content={[
50
- {
51
- name: "app",
52
- type: "Hono | Application",
53
- description: "Framework app instance",
54
- isOptional: false,
55
- },
56
- {
57
- name: "mastra",
58
- type: "Mastra",
59
- description: "Mastra instance",
60
- isOptional: false,
61
- },
62
- {
63
- name: "prefix",
64
- type: "string",
65
- description: "Route path prefix (e.g., `/api/v2`)",
66
- isOptional: true,
67
- defaultValue: "''",
68
- },
69
- {
70
- name: "openapiPath",
71
- type: "string",
72
- description: "Path to serve OpenAPI spec (e.g., `/openapi.json`)",
73
- isOptional: true,
74
- },
75
- {
76
- name: "bodyLimitOptions",
77
- type: "{ maxSize: number, onError: (err) => unknown }",
78
- description: "Request body size limits",
79
- isOptional: true,
80
- },
81
- {
82
- name: "streamOptions",
83
- type: "{ redact?: boolean }",
84
- description: "Stream redaction config. When true, redacts sensitive data from streams.",
85
- isOptional: true,
86
- defaultValue: "{ redact: true }",
87
- },
88
- {
89
- name: "customRouteAuthConfig",
90
- type: "Map<string, boolean>",
91
- description: "Per-route auth overrides. Keys are `METHOD:PATH` (e.g., `GET:/api/health`). Value `false` makes route public, `true` requires auth.",
92
- isOptional: true,
93
- },
94
- ]}
95
- />
25
+ - [@mastra/express](/reference/v1/server/express-adapter): Express framework adapter.
26
+ - [@mastra/hono](/reference/v1/server/hono-adapter): Hono framework adapter.
27
+
28
+ ## Installation
29
+
30
+ Install the adapter for the framework you’re using.
31
+
32
+ <Tabs>
33
+ <TabItem value="express" label="Express">
34
+
35
+ ```bash
36
+ npm install @mastra/express@beta
37
+ ```
38
+ </TabItem>
39
+ <TabItem value="hono" label="Hono">
40
+
41
+ ```bash
42
+ npm install @mastra/hono@beta
43
+ ```
44
+ </TabItem>
45
+ </Tabs>
46
+
47
+ ## Configuration
48
+
49
+ Initialize your Express or Hono app as usual, then create a `MastraServer` by passing in the `app` and your main `mastra` instance from `src/mastra`. Calling `init()` automatically registers Mastra middleware and all available endpoints. You can continue adding your own routes as normal, either before or after `init()`, and they’ll run alongside Mastra’s endpoints.
50
+
51
+ <Tabs>
52
+ <TabItem value="express" label="Express">
53
+
54
+ ```typescript {8} title="express-server.ts" showLineNumbers
55
+ import express from "express";
56
+ import { MastraServer } from "@mastra/express";
57
+ import { mastra } from "./mastra"; // src/mastra/index.ts
58
+
59
+ const app = express();
60
+ app.use(express.json());
61
+
62
+ const server = new MastraServer({ app, mastra });
63
+
64
+ await server.init();
65
+
66
+ app.listen(4111, () => {
67
+ console.log('Server running on port 4111');
68
+ });
69
+ ```
70
+
71
+ </TabItem>
72
+ <TabItem value="hono" label="Hono">
73
+
74
+ ```typescript {8} title="hono-server.ts" showLineNumbers
75
+ import { Hono } from "hono";
76
+ import { serve } from "@hono/node-server";
77
+ import { HonoBindings, HonoVariables, MastraServer } from "@mastra/hono";
78
+ import { mastra } from "./mastra"; // src/mastra/index.ts
79
+
80
+ const app = new Hono<{ Bindings: HonoBindings; Variables: HonoVariables }>();
81
+
82
+ const server = new MastraServer({ app, mastra });
83
+
84
+ await server.init();
85
+
86
+ serve({ fetch: app.fetch, port: 4111 }, () => {
87
+ console.log('Server running on port 4111');
88
+ });
89
+ ```
90
+
91
+ </TabItem>
92
+ </Tabs>
93
+
94
+ > See the [Express Adapter](/reference/v1/server/express-adapter) or [Hono Adapter](/reference/v1/server/hono-adapter) docs for full configuration options.
95
+
96
96
 
97
97
  ## Initialization flow
98
98
 
99
99
  Calling `init()` runs three steps in order. Understanding this flow helps when you need to insert your own middleware at specific points.
100
100
 
101
- 1. **`registerContextMiddleware()`** - Attaches the Mastra instance, request context, tools, and abort signal to every request. This makes Mastra available to all subsequent middleware and route handlers.
102
- 2. **`registerAuthMiddleware()`** - Adds authentication and authorization middleware, but only if `server.auth` is configured in your Mastra instance. Skipped entirely if no auth is configured.
103
- 3. **`registerRoutes()`** - Registers all Mastra API routes for agents, workflows, and other features. Also registers MCP routes if MCP servers are configured.
101
+ 1. `registerContextMiddleware()`: Attaches the Mastra instance, request context, tools, and abort signal to every request. This makes Mastra available to all subsequent middleware and route handlers.
102
+ 2. `registerAuthMiddleware()`: Adds authentication and authorization middleware, but only if `server.auth` is configured in your Mastra instance. Skipped entirely if no auth is configured.
103
+ 3. `registerRoutes()`: Registers all Mastra API routes for agents, workflows, and other features. Also registers MCP routes if MCP servers are configured.
104
104
 
105
105
  ### Manual initialization
106
106
 
@@ -132,18 +132,19 @@ Use manual initialization when you need middleware that runs before Mastra's con
132
132
 
133
133
  ## Adding custom routes
134
134
 
135
- You can add your own routes to the app alongside Mastra's routes. Routes added after `init()` have access to the Mastra context (the Mastra instance, request context, authenticated user, etc.) through framework-specific mechanisms.
135
+ You can add your own routes to the app alongside Mastra's routes.
136
+
137
+ - Routes added **before** `init()` won't have Mastra context available.
138
+ - Routes added **after** `init()` have access to the Mastra context (the Mastra instance, request context, authenticated user, etc.).
136
139
 
137
- The timing matters: routes added before `init()` won't have Mastra context available, while routes added after `init()` will. See the framework-specific docs for syntax and examples:
140
+ > See adding custom routes for [Express](/reference/v1/server/express-adapter#adding-custom-routes) and [Hono](/reference/v1/server/hono-adapter#adding-custom-routes) for more information.
138
141
 
139
- - [Hono: Adding custom routes](/reference/v1/server/hono-adapter#adding-custom-routes)
140
- - [Express: Adding custom routes](/reference/v1/server/express-adapter#adding-custom-routes)
141
142
 
142
143
  ## Route prefixes
143
144
 
144
145
  By default, Mastra routes are registered at `/api/agents`, `/api/workflows`, etc. Use the `prefix` option to change this, which is useful for API versioning or when integrating with an existing app that has its own `/api` routes.
145
146
 
146
- ```typescript copy showLineNumbers
147
+ ```typescript showLineNumbers copy
147
148
  const server = new MastraServer({
148
149
  app,
149
150
  mastra,
@@ -157,7 +158,7 @@ With this prefix, Mastra routes become `/api/v2/agents`, `/api/v2/workflows`, et
157
158
 
158
159
  Mastra can generate an OpenAPI specification for all registered routes. This is useful for documentation, client generation, or integration with API tools. Enable it by setting the `openapiPath` option:
159
160
 
160
- ```typescript copy showLineNumbers
161
+ ```typescript showLineNumbers copy
161
162
  const server = new MastraServer({
162
163
  app,
163
164
  mastra,
@@ -178,9 +179,9 @@ When streaming agent responses over HTTP, the HTTP streaming layer redacts sensi
178
179
 
179
180
  This redaction happens at the HTTP boundary, so internal callbacks like `onStepFinish` still have access to the full request data for debugging and observability purposes.
180
181
 
181
- By default, redaction is enabled. Configure this behavior via `streamOptions`:
182
+ By default, redaction is enabled. Configure this behavior via `streamOptions`. Set `redact: false` only for internal services or debugging scenarios where you need access to the full request data in stream responses.
182
183
 
183
- ```typescript copy showLineNumbers
184
+ ```typescript showLineNumbers copy
184
185
  const server = new MastraServer({
185
186
  app,
186
187
  mastra,
@@ -190,15 +191,15 @@ const server = new MastraServer({
190
191
  });
191
192
  ```
192
193
 
193
- Set `redact: false` only for internal services or debugging scenarios where you need access to the full request data in stream responses.
194
+ > See [MastraServer](/reference/v1/server/mastra-server) for full configuration options.
194
195
 
195
196
  ## Per-route auth overrides
196
197
 
197
198
  When authentication is configured on your Mastra instance, all routes require authentication by default. Sometimes you need exceptions: public health check endpoints, webhook receivers, or admin routes that need stricter controls.
198
199
 
199
- Use `customRouteAuthConfig` to override authentication behavior for specific routes:
200
+ Use `customRouteAuthConfig` to override authentication behavior for specific routes. Keys follow the format `METHOD:PATH` where method is `GET`, `POST`, `PUT`, `DELETE`, or `ALL`. Paths support wildcards (`*`) for matching multiple routes. Setting a value to `false` makes the route public, while `true` requires authentication.
200
201
 
201
- ```typescript copy showLineNumbers
202
+ ```typescript showLineNumbers copy
202
203
  const server = new MastraServer({
203
204
  app,
204
205
  mastra,
@@ -212,13 +213,15 @@ const server = new MastraServer({
212
213
  });
213
214
  ```
214
215
 
215
- Keys follow the format `METHOD:PATH` where method is `GET`, `POST`, `PUT`, `DELETE`, or `ALL`. Paths support wildcards (`*`) for matching multiple routes. Setting a value to `false` makes the route public, while `true` requires authentication.
216
+
217
+
218
+ > See [MastraServer](/reference/v1/server/mastra-server) for full configuration options.
216
219
 
217
220
  ## Accessing the app
218
221
 
219
- After creating the adapter, you may need to access the underlying framework app instance—for example, to pass it to a platform's serve function or to add routes programmatically from another module.
222
+ After creating the adapter, you may still need access to the underlying framework app. This is useful when passing it to a platforms `serve` function or when adding routes from another module.
220
223
 
221
- ```typescript copy showLineNumbers
224
+ ```typescript showLineNumbers copy
222
225
  // Via the MastraServer instance
223
226
  const app = server.getApp();
224
227