@mastra/mcp-docs-server 1.0.0-beta.8 → 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.
- package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +1 -15
- package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +1 -7
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +1 -55
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +58 -58
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +49 -49
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +49 -49
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Freact.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +49 -49
- package/.docs/organized/changelogs/create-mastra.md +13 -13
- package/.docs/organized/changelogs/mastra.md +21 -21
- package/.docs/organized/code-examples/mcp-server-adapters.md +1 -2
- package/.docs/organized/code-examples/processors-with-ai-sdk.md +14 -0
- package/.docs/organized/code-examples/server-app-access.md +1 -1
- package/.docs/organized/code-examples/server-hono-adapter.md +1 -1
- package/.docs/raw/getting-started/studio.mdx +4 -2
- package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +161 -0
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +4 -4
- package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +3 -3
- package/.docs/raw/reference/client-js/agents.mdx +251 -67
- package/.docs/raw/reference/client-js/mastra-client.mdx +2 -2
- package/.docs/raw/reference/client-js/memory.mdx +4 -1
- package/.docs/raw/reference/core/getMemory.mdx +73 -0
- package/.docs/raw/reference/core/getStoredAgentById.mdx +183 -0
- package/.docs/raw/reference/core/listMemory.mdx +70 -0
- package/.docs/raw/reference/core/listStoredAgents.mdx +151 -0
- package/.docs/raw/reference/core/mastra-class.mdx +8 -0
- package/.docs/raw/reference/server/express-adapter.mdx +52 -0
- package/.docs/raw/reference/server/hono-adapter.mdx +54 -0
- package/.docs/raw/server-db/server-adapters.mdx +94 -91
- package/.docs/raw/streaming/tool-streaming.mdx +10 -14
- package/CHANGELOG.md +8 -0
- package/package.json +4 -4
|
@@ -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
|
|
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
|
-
|
|
13
|
+
## When to use server adapters
|
|
15
14
|
|
|
16
|
-
|
|
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
|
-
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
##
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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.
|
|
102
|
-
2.
|
|
103
|
-
3.
|
|
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.
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
222
|
+
After creating the adapter, you may still need access to the underlying framework app. This is useful when passing it to a platform’s `serve` function or when adding routes from another module.
|
|
220
223
|
|
|
221
|
-
```typescript copy
|
|
224
|
+
```typescript showLineNumbers copy
|
|
222
225
|
// Via the MastraServer instance
|
|
223
226
|
const app = server.getApp();
|
|
224
227
|
|
|
@@ -18,9 +18,8 @@ By combining writable tool streams with agent streaming, you gain fine grained c
|
|
|
18
18
|
|
|
19
19
|
Agent streaming can be combined with tool calls, allowing tool outputs to be written directly into the agent’s streaming response. This makes it possible to surface tool activity as part of the overall interaction.
|
|
20
20
|
|
|
21
|
-
```typescript {
|
|
21
|
+
```typescript {2,9} showLineNumbers copy
|
|
22
22
|
import { Agent } from "@mastra/core/agent";
|
|
23
|
-
|
|
24
23
|
import { testTool } from "../tools/test-tool";
|
|
25
24
|
|
|
26
25
|
export const testAgent = new Agent({
|
|
@@ -34,30 +33,29 @@ export const testAgent = new Agent({
|
|
|
34
33
|
|
|
35
34
|
### Using `context.writer`
|
|
36
35
|
|
|
37
|
-
The `context.writer` object is available in a tool's `execute` function and can be used to emit custom events, data, or values into the active stream. This enables tools to provide intermediate results or status updates while execution is still in progress.
|
|
36
|
+
The `context.writer` object is available in a tool's `execute()` function and can be used to emit custom events, data, or values into the active stream. This enables tools to provide intermediate results or status updates while execution is still in progress.
|
|
38
37
|
|
|
39
38
|
:::warning
|
|
40
39
|
|
|
41
|
-
You must `await` the call to `writer.write(
|
|
40
|
+
You must `await` the call to `writer.write()` or else you will lock the stream and get a `WritableStream is locked` error.
|
|
42
41
|
|
|
43
42
|
:::
|
|
44
43
|
|
|
45
|
-
```typescript {
|
|
44
|
+
```typescript {4,7,14} showLineNumbers copy
|
|
46
45
|
import { createTool } from "@mastra/core/tools";
|
|
47
46
|
|
|
48
47
|
export const testTool = createTool({
|
|
49
|
-
// ...
|
|
50
48
|
execute: async (inputData, context) => {
|
|
51
49
|
const { value } = inputData;
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
await context?.writer?.write({
|
|
54
52
|
type: "custom-event",
|
|
55
53
|
status: "pending"
|
|
56
54
|
});
|
|
57
55
|
|
|
58
56
|
const response = await fetch(...);
|
|
59
57
|
|
|
60
|
-
|
|
58
|
+
await context?.writer?.write({
|
|
61
59
|
type: "custom-event",
|
|
62
60
|
status: "success"
|
|
63
61
|
});
|
|
@@ -69,14 +67,13 @@ export const testTool = createTool({
|
|
|
69
67
|
});
|
|
70
68
|
```
|
|
71
69
|
|
|
72
|
-
You can also use `writer.custom` if you want to emit top level stream chunks, This useful and relevant when
|
|
70
|
+
You can also use `writer.custom()` if you want to emit top level stream chunks, This useful and relevant when
|
|
73
71
|
integrating with UI Frameworks
|
|
74
72
|
|
|
75
|
-
```typescript {
|
|
73
|
+
```typescript {4,7,14} showLineNumbers copy
|
|
76
74
|
import { createTool } from "@mastra/core/tools";
|
|
77
75
|
|
|
78
76
|
export const testTool = createTool({
|
|
79
|
-
// ...
|
|
80
77
|
execute: async (inputData, context) => {
|
|
81
78
|
const { value } = inputData;
|
|
82
79
|
|
|
@@ -169,12 +166,11 @@ import { createTool } from "@mastra/core/tools";
|
|
|
169
166
|
import { z } from "zod";
|
|
170
167
|
|
|
171
168
|
export const testTool = createTool({
|
|
172
|
-
// ...
|
|
173
169
|
execute: async (inputData, context) => {
|
|
174
170
|
const { city } = inputData;
|
|
175
171
|
|
|
176
|
-
const
|
|
177
|
-
const stream = await
|
|
172
|
+
const agent = context?.mastra?.getAgent("testAgent");
|
|
173
|
+
const stream = await agent?.stream(`What is the weather in ${city}?`);
|
|
178
174
|
|
|
179
175
|
await stream!.fullStream.pipeTo(context?.writer!);
|
|
180
176
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`72df8ae`](https://github.com/mastra-ai/mastra/commit/72df8ae595584cdd7747d5c39ffaca45e4507227), [`9198899`](https://github.com/mastra-ai/mastra/commit/91988995c427b185c33714b7f3be955367911324), [`653e65a`](https://github.com/mastra-ai/mastra/commit/653e65ae1f9502c2958a32f47a5a2df11e612a92), [`c6fd6fe`](https://github.com/mastra-ai/mastra/commit/c6fd6fedd09e9cf8004b03a80925f5e94826ad7e), [`fdf5a82`](https://github.com/mastra-ai/mastra/commit/fdf5a822716b2fd7ba2e50bd4c1521851e208cd9), [`0bed332`](https://github.com/mastra-ai/mastra/commit/0bed332843f627202c6520eaf671771313cd20f3)]:
|
|
8
|
+
- @mastra/core@1.0.0-beta.9
|
|
9
|
+
- @mastra/mcp@1.0.0-beta.6
|
|
10
|
+
|
|
3
11
|
## 1.0.0-beta.8
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.17.5",
|
|
29
29
|
"jsdom": "^26.1.0",
|
|
30
30
|
"zod": "^3.25.76",
|
|
31
|
-
"@mastra/core": "1.0.0-beta.
|
|
32
|
-
"@mastra/mcp": "^1.0.0-beta.
|
|
31
|
+
"@mastra/core": "1.0.0-beta.9",
|
|
32
|
+
"@mastra/mcp": "^1.0.0-beta.6"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@hono/node-server": "^1.19.6",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"typescript": "^5.8.3",
|
|
47
47
|
"vitest": "4.0.12",
|
|
48
48
|
"@internal/lint": "0.0.53",
|
|
49
|
-
"@mastra/core": "1.0.0-beta.
|
|
49
|
+
"@mastra/core": "1.0.0-beta.9"
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://mastra.ai",
|
|
52
52
|
"repository": {
|