@mastra/mcp-docs-server 1.1.16-alpha.3 → 1.1.16-alpha.5
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/docs/server/middleware.md +13 -1
- package/.docs/docs/server/server-adapters.md +3 -2
- package/.docs/models/index.md +21 -1
- package/.docs/reference/server/express-adapter.md +23 -0
- package/.docs/reference/server/fastify-adapter.md +28 -0
- package/.docs/reference/server/hono-adapter.md +22 -0
- package/.docs/reference/server/koa-adapter.md +23 -0
- package/.docs/reference/server/mastra-server.md +3 -2
- package/CHANGELOG.md +7 -0
- package/package.json +4 -4
|
@@ -104,6 +104,7 @@ Mastra provides reserved context keys that, when set by middleware, take precede
|
|
|
104
104
|
```typescript
|
|
105
105
|
import { Mastra } from '@mastra/core'
|
|
106
106
|
import { MASTRA_RESOURCE_ID_KEY } from '@mastra/core/request-context'
|
|
107
|
+
import { getAuthenticatedUser } from '@mastra/server/auth'
|
|
107
108
|
|
|
108
109
|
export const mastra = new Mastra({
|
|
109
110
|
server: {
|
|
@@ -117,8 +118,17 @@ export const mastra = new Mastra({
|
|
|
117
118
|
{
|
|
118
119
|
path: '/api/*',
|
|
119
120
|
handler: async (c, next) => {
|
|
121
|
+
const token = c.req.header('Authorization')
|
|
122
|
+
if (!token) {
|
|
123
|
+
return c.json({ error: 'Unauthorized' }, 401)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const user = await getAuthenticatedUser<{ id: string }>({
|
|
127
|
+
mastra: c.get('mastra'),
|
|
128
|
+
token,
|
|
129
|
+
request: c.req.raw,
|
|
130
|
+
})
|
|
120
131
|
const requestContext = c.get('requestContext')
|
|
121
|
-
const user = requestContext.get('user')
|
|
122
132
|
|
|
123
133
|
if (!user) {
|
|
124
134
|
return c.json({ error: 'Unauthorized' }, 401)
|
|
@@ -136,6 +146,8 @@ export const mastra = new Mastra({
|
|
|
136
146
|
})
|
|
137
147
|
```
|
|
138
148
|
|
|
149
|
+
`server.middleware` runs before Mastra's per-route auth checks. When middleware needs the authenticated user, call `getAuthenticatedUser()` to resolve it from the configured auth provider without changing the default route auth flow.
|
|
150
|
+
|
|
139
151
|
With this middleware, the server automatically:
|
|
140
152
|
|
|
141
153
|
- **Filters thread listing** to only return threads owned by the user
|
|
@@ -341,7 +341,7 @@ app.listen(port, () => {
|
|
|
341
341
|
Calling `init()` runs three steps in order. Understanding this flow helps when you need to insert your own middleware at specific points.
|
|
342
342
|
|
|
343
343
|
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.
|
|
344
|
-
2. `registerAuthMiddleware()`:
|
|
344
|
+
2. `registerAuthMiddleware()`: Runs the adapter auth hook during initialization. Official adapters enforce auth inline when Mastra registers built-in routes and `registerApiRoute()` routes, so raw framework routes should use the adapter's exported `createAuthMiddleware()` helper when they need Mastra auth.
|
|
345
345
|
3. `registerRoutes()`: Registers all Mastra API routes for agents, workflows, and other features. Also registers MCP routes if MCP servers are configured.
|
|
346
346
|
|
|
347
347
|
### Manual initialization
|
|
@@ -359,7 +359,6 @@ server.registerContextMiddleware();
|
|
|
359
359
|
// Middleware that needs Mastra context
|
|
360
360
|
app.use(customMiddleware);
|
|
361
361
|
|
|
362
|
-
server.registerAuthMiddleware();
|
|
363
362
|
await server.registerRoutes();
|
|
364
363
|
|
|
365
364
|
// Routes after Mastra
|
|
@@ -374,6 +373,8 @@ You can add your own routes to the app alongside Mastra's routes.
|
|
|
374
373
|
|
|
375
374
|
- Routes added **before** `init()` won't have Mastra context available.
|
|
376
375
|
- Routes added **after** `init()` have access to the Mastra context (the Mastra instance, request context, authenticated user, etc.).
|
|
376
|
+
- When you want Mastra-managed auth and route metadata such as `requiresAuth`, prefer `registerApiRoute()`.
|
|
377
|
+
- When you mount routes directly on the framework app, use the adapter's exported `createAuthMiddleware()` helper if those routes need Mastra auth.
|
|
377
378
|
|
|
378
379
|
> **Info:** Visit "Adding custom routes" for [Express](https://mastra.ai/reference/server/express-adapter) and [Hono](https://mastra.ai/reference/server/hono-adapter) for more information.
|
|
379
380
|
|
package/.docs/models/index.md
CHANGED
|
@@ -232,7 +232,11 @@ Your users never experience the disruption - the response comes back with the sa
|
|
|
232
232
|
|
|
233
233
|
Mastra also supports local models like `gpt-oss`, `Qwen3`, `DeepSeek` and many more that you run on your own hardware. The application running your local model needs to provide an OpenAI-compatible API server for Mastra to connect to. We recommend using [LMStudio](https://lmstudio.ai/) (see [Running the LMStudio server](https://lmstudio.ai/docs/developer/core/server)).
|
|
234
234
|
|
|
235
|
-
For
|
|
235
|
+
For custom OpenAI-compatible endpoints, `id` is the routing form that Mastra sends through the model router.
|
|
236
|
+
|
|
237
|
+
Use `provider/model` when the remote behaves like a direct provider and expects a bare model name such as `llama3.2`.
|
|
238
|
+
|
|
239
|
+
Use `gateway/provider/model` when the remote behaves like a model gateway and the upstream model namespace includes the provider, such as `mastra/google/gemini-2.5-flash` or `openrouter/google/gemini-2.5-flash`.
|
|
236
240
|
|
|
237
241
|
For the `url` it's **important** that you use the base URL of the OpenAI-compatible endpoint with Mastra's `model` setting and not the individual chat endpoints.
|
|
238
242
|
|
|
@@ -250,6 +254,22 @@ const agent = new Agent({
|
|
|
250
254
|
})
|
|
251
255
|
```
|
|
252
256
|
|
|
257
|
+
If the remote behaves like a model gateway, include the gateway prefix in `id`:
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
import { Agent } from "@mastra/core/agent";
|
|
261
|
+
|
|
262
|
+
const agent = new Agent({
|
|
263
|
+
id: "my-agent",
|
|
264
|
+
name: "My Agent",
|
|
265
|
+
instructions: "You are a helpful assistant",
|
|
266
|
+
model: {
|
|
267
|
+
id: "mastra/google/gemini-2.5-flash",
|
|
268
|
+
url: "http://your-custom-openai-compatible-endpoint.com/v1"
|
|
269
|
+
}
|
|
270
|
+
})
|
|
271
|
+
```
|
|
272
|
+
|
|
253
273
|
### Example: LMStudio
|
|
254
274
|
|
|
255
275
|
After starting the LMStudio server, the local server is available at `http://localhost:1234` and it provides endpoints like `/v1/models`, `/v1/chat/completions`, etc. The `url` will be `http://localhost:1234/v1`. For the `id` you can use (`lmstudio/${modelId}`) which will be displayed in the LMStudio interface.
|
|
@@ -110,6 +110,29 @@ app.listen(4111)
|
|
|
110
110
|
|
|
111
111
|
> **Tip:** Routes added before `init()` run without Mastra context. Add routes after `init()` to access the Mastra instance and request context.
|
|
112
112
|
|
|
113
|
+
When you want Mastra-managed auth and route metadata such as `requiresAuth`, prefer [`registerApiRoute()`](https://mastra.ai/reference/server/register-api-route). For raw Express routes mounted directly on `app`, use `createAuthMiddleware()`:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import express from 'express'
|
|
117
|
+
import { createAuthMiddleware, MastraServer } from '@mastra/express'
|
|
118
|
+
import { mastra } from './mastra'
|
|
119
|
+
|
|
120
|
+
const app = express()
|
|
121
|
+
app.use(express.json())
|
|
122
|
+
|
|
123
|
+
const server = new MastraServer({ app, mastra })
|
|
124
|
+
await server.init()
|
|
125
|
+
|
|
126
|
+
app.get('/custom/protected', createAuthMiddleware({ mastra }), (req, res) => {
|
|
127
|
+
const user = res.locals.requestContext.get('user')
|
|
128
|
+
res.json({ user })
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
app.get('/custom/public', createAuthMiddleware({ mastra, requiresAuth: false }), (req, res) => {
|
|
132
|
+
res.json({ ok: true })
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
113
136
|
## Accessing context
|
|
114
137
|
|
|
115
138
|
In Express middleware and routes, access Mastra context via `res.locals`:
|
|
@@ -75,6 +75,34 @@ app.listen({ port: 3000 }, (err, address) => {
|
|
|
75
75
|
|
|
76
76
|
**mcpOptions** (`MCPOptions`): MCP transport options. Set \`serverless: true\` for stateless environments like Cloudflare Workers or Vercel Edge.
|
|
77
77
|
|
|
78
|
+
## Protecting raw routes
|
|
79
|
+
|
|
80
|
+
When you want Mastra-managed auth and route metadata such as `requiresAuth`, prefer [`registerApiRoute()`](https://mastra.ai/reference/server/register-api-route). For raw Fastify routes mounted directly on the app, use `createAuthMiddleware()`:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import Fastify from 'fastify'
|
|
84
|
+
import { createAuthMiddleware, MastraServer } from '@mastra/fastify'
|
|
85
|
+
import { mastra } from './mastra'
|
|
86
|
+
|
|
87
|
+
const app = Fastify()
|
|
88
|
+
const server = new MastraServer({ app, mastra })
|
|
89
|
+
|
|
90
|
+
await server.init()
|
|
91
|
+
|
|
92
|
+
app.get('/custom/protected', { preHandler: createAuthMiddleware({ mastra }) }, async request => {
|
|
93
|
+
const user = request.requestContext.get('user')
|
|
94
|
+
return { user }
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
app.get(
|
|
98
|
+
'/custom/public',
|
|
99
|
+
{ preHandler: createAuthMiddleware({ mastra, requiresAuth: false }) },
|
|
100
|
+
async () => {
|
|
101
|
+
return { ok: true }
|
|
102
|
+
},
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
78
106
|
## Manual initialization
|
|
79
107
|
|
|
80
108
|
For custom middleware ordering, call each method separately instead of `init()`. See [manual initialization](https://mastra.ai/docs/server/server-adapters) for details.
|
|
@@ -94,6 +94,28 @@ app.get('/custom', c => {
|
|
|
94
94
|
|
|
95
95
|
> **Tip:** Routes added before `init()` run without Mastra context. Add routes after `init()` to access the Mastra instance and request context.
|
|
96
96
|
|
|
97
|
+
When you want Mastra-managed auth and route metadata such as `requiresAuth`, prefer [`registerApiRoute()`](https://mastra.ai/reference/server/register-api-route). For raw Hono routes mounted directly on `app`, use `createAuthMiddleware()`:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { Hono } from 'hono'
|
|
101
|
+
import { createAuthMiddleware, HonoBindings, HonoVariables, MastraServer } from '@mastra/hono'
|
|
102
|
+
import { mastra } from './mastra'
|
|
103
|
+
|
|
104
|
+
const app = new Hono<{ Bindings: HonoBindings; Variables: HonoVariables }>()
|
|
105
|
+
const server = new MastraServer({ app, mastra })
|
|
106
|
+
|
|
107
|
+
await server.init()
|
|
108
|
+
|
|
109
|
+
app.get('/custom/protected', createAuthMiddleware({ mastra }), c => {
|
|
110
|
+
const user = c.get('requestContext').get('user')
|
|
111
|
+
return c.json({ user })
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
app.get('/custom/public', createAuthMiddleware({ mastra, requiresAuth: false }), c => {
|
|
115
|
+
return c.json({ ok: true })
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
97
119
|
## Accessing context
|
|
98
120
|
|
|
99
121
|
In Hono middleware and route handlers, access Mastra context via `c.get()`:
|
|
@@ -112,6 +112,29 @@ const mastra = new Mastra({
|
|
|
112
112
|
|
|
113
113
|
When `init()` is used, a global error-handling middleware is also registered as a safety net. Errors that reach this middleware are emitted via `ctx.app.emit('error', err, ctx)` following the standard Koa convention.
|
|
114
114
|
|
|
115
|
+
## Protecting raw routes
|
|
116
|
+
|
|
117
|
+
When you want Mastra-managed auth and route metadata such as `requiresAuth`, prefer [`registerApiRoute()`](https://mastra.ai/reference/server/register-api-route). For raw Koa routes mounted directly on the app, use `createAuthMiddleware()`:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import Koa from 'koa'
|
|
121
|
+
import { createAuthMiddleware, MastraServer } from '@mastra/koa'
|
|
122
|
+
import { mastra } from './mastra'
|
|
123
|
+
|
|
124
|
+
const app = new Koa()
|
|
125
|
+
const server = new MastraServer({ app, mastra })
|
|
126
|
+
|
|
127
|
+
await server.init()
|
|
128
|
+
|
|
129
|
+
app.use(createAuthMiddleware({ mastra }))
|
|
130
|
+
app.use(async ctx => {
|
|
131
|
+
if (ctx.path !== '/custom/protected') return
|
|
132
|
+
|
|
133
|
+
const user = ctx.state.requestContext.get('user')
|
|
134
|
+
ctx.body = { user }
|
|
135
|
+
})
|
|
136
|
+
```
|
|
137
|
+
|
|
115
138
|
## Manual initialization
|
|
116
139
|
|
|
117
140
|
For custom middleware ordering, call each method separately instead of `init()`. See [manual initialization](https://mastra.ai/docs/server/server-adapters) for details.
|
|
@@ -69,7 +69,7 @@ abstract registerContextMiddleware(): void
|
|
|
69
69
|
|
|
70
70
|
### `registerAuthMiddleware()`
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
Run the adapter auth hook during initialization. Official adapters may implement this as a no-op when auth is enforced per-route.
|
|
73
73
|
|
|
74
74
|
```typescript
|
|
75
75
|
abstract registerAuthMiddleware(): void
|
|
@@ -266,7 +266,8 @@ export class MyServer extends MastraServer<MyApp, MyRequest, MyResponse> {
|
|
|
266
266
|
registerAuthMiddleware(): void {
|
|
267
267
|
const auth = this.mastra.getServer()?.auth
|
|
268
268
|
if (!auth) return
|
|
269
|
-
//
|
|
269
|
+
// Register global auth middleware, or leave this empty and
|
|
270
|
+
// enforce auth when routes are registered.
|
|
270
271
|
}
|
|
271
272
|
|
|
272
273
|
async registerRoute(app, route, { prefix }) {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.1.16-alpha.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`7dbd611`](https://github.com/mastra-ai/mastra/commit/7dbd611a85cb1e0c0a1581c57564268cb183d86e), [`41aee84`](https://github.com/mastra-ai/mastra/commit/41aee84561ceebe28bad1ecba8702d92838f67f0)]:
|
|
8
|
+
- @mastra/core@1.16.0-alpha.1
|
|
9
|
+
|
|
3
10
|
## 1.1.16-alpha.1
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.1.16-alpha.
|
|
3
|
+
"version": "1.1.16-alpha.5",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"jsdom": "^26.1.0",
|
|
30
30
|
"local-pkg": "^1.1.2",
|
|
31
31
|
"zod": "^4.3.6",
|
|
32
|
-
"@mastra/core": "1.16.0-alpha.
|
|
32
|
+
"@mastra/core": "1.16.0-alpha.1",
|
|
33
33
|
"@mastra/mcp": "^1.3.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"tsx": "^4.21.0",
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
48
|
"vitest": "4.0.18",
|
|
49
|
+
"@internal/lint": "0.0.73",
|
|
49
50
|
"@internal/types-builder": "0.0.48",
|
|
50
|
-
"@mastra/core": "1.16.0-alpha.
|
|
51
|
-
"@internal/lint": "0.0.73"
|
|
51
|
+
"@mastra/core": "1.16.0-alpha.1"
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://mastra.ai",
|
|
54
54
|
"repository": {
|