@mastra/mcp-docs-server 1.3.2 → 1.3.3-alpha.3
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/agents/human-in-the-loop.md +6 -4
- package/.docs/docs/agents/processors.md +58 -4
- package/.docs/docs/connections/mcp.md +2 -0
- package/.docs/docs/deployment/workers.md +3 -1
- package/.docs/docs/guides/authentication-identity.md +4 -2
- package/.docs/docs/guides/mcp-authentication-authorization.md +136 -0
- package/.docs/docs/index.md +1 -1
- package/.docs/docs/server/server-adapters.md +54 -11
- package/.docs/docs/workflows/control-flow.md +2 -4
- package/.docs/docs/workflows/scheduled-workflows.md +5 -1
- package/.docs/models/environment-variables.md +1 -1
- package/.docs/models/gateways/merge-gateway.md +2 -1
- package/.docs/models/gateways/openrouter.md +2 -1
- package/.docs/models/gateways/vercel.md +6 -1
- package/.docs/models/index.md +2 -2
- package/.docs/models/providers/302ai.md +2 -1
- package/.docs/models/providers/baseten.md +2 -1
- package/.docs/models/providers/cortecs.md +3 -2
- package/.docs/models/providers/crossmodel.md +3 -3
- package/.docs/models/providers/deepinfra.md +1 -5
- package/.docs/models/providers/edenai.md +3 -2
- package/.docs/models/providers/kilo.md +16 -14
- package/.docs/models/providers/llmgateway-providers.md +3 -11
- package/.docs/models/providers/llmgateway.md +2 -1
- package/.docs/models/providers/nano-gpt.md +5 -2
- package/.docs/models/providers/opencode.md +2 -1
- package/.docs/models/providers/requesty.md +3 -1
- package/.docs/models/providers/tempr.md +23 -4
- package/.docs/models/providers/vivgrid.md +3 -1
- package/.docs/models/providers/vultr.md +22 -17
- package/.docs/models/providers.md +1 -1
- package/.docs/reference/agent-controller/agent-controller-class.md +2 -0
- package/.docs/reference/agent-controller/session.md +8 -8
- package/.docs/reference/classifier/classifier.md +49 -22
- package/.docs/reference/client-js/observability.md +1 -1
- package/.docs/reference/coding-agent/create-coding-agent.md +2 -2
- package/.docs/reference/configuration.md +2 -4
- package/.docs/reference/evals/create-classifier-scorer.md +2 -4
- package/.docs/reference/evals/create-scorer.md +1 -1
- package/.docs/reference/memory/observational-memory.md +3 -1
- package/.docs/reference/observability/tracing/spans.md +1 -1
- package/.docs/reference/processors/classifier-processor.md +8 -10
- package/.docs/reference/processors/model-selection-processor.md +8 -10
- package/.docs/reference/processors/prefill-error-handler.md +2 -2
- package/.docs/reference/processors/processor-interface.md +2 -2
- package/.docs/reference/processors/provider-history-compat.md +37 -17
- package/.docs/reference/processors/stream-error-retry-processor.md +9 -4
- package/.docs/reference/server/elysia-adapter.md +2 -0
- package/.docs/reference/server/express-adapter.md +1 -1
- package/.docs/reference/server/fastify-adapter.md +2 -0
- package/.docs/reference/server/hono-adapter.md +2 -0
- package/.docs/reference/server/koa-adapter.md +2 -0
- package/.docs/reference/server/nestjs-adapter.md +48 -0
- package/.docs/reference/tools/mcp-server.md +25 -10
- package/.docs/reference/workflows/step.md +2 -4
- package/package.json +5 -5
|
@@ -49,6 +49,8 @@ await server.init()
|
|
|
49
49
|
export default app
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
`init()` doesn't start Mastra's background workers. To run [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows), agent schedules, or event listeners, call `await mastra.startWorkers()` after the server starts listening. See [Start background workers](https://mastra.ai/docs/server/server-adapters).
|
|
53
|
+
|
|
52
54
|
## Constructor parameters
|
|
53
55
|
|
|
54
56
|
**app** (`Hono`): Hono app instance
|
|
@@ -54,6 +54,8 @@ app.listen(3000, () => {
|
|
|
54
54
|
})
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
`init()` doesn't start Mastra's background workers. To run [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows), agent schedules, or event listeners, call `await mastra.startWorkers()` after the server starts listening. See [Start background workers](https://mastra.ai/docs/server/server-adapters).
|
|
58
|
+
|
|
57
59
|
## Constructor parameters
|
|
58
60
|
|
|
59
61
|
**app** (`Koa`): Koa app instance
|
|
@@ -149,6 +149,54 @@ export class WorkflowService {
|
|
|
149
149
|
}
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
+
## Start background workers
|
|
153
|
+
|
|
154
|
+
`MastraModule` doesn't start Mastra's background workers. Without them, [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows), agent schedules, and event listeners never run. Call `mastra.startWorkers()` after the app starts listening:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { NestFactory } from '@nestjs/core'
|
|
158
|
+
import { MASTRA } from '@mastra/nestjs'
|
|
159
|
+
import type { Mastra } from '@mastra/core/mastra'
|
|
160
|
+
import { AppModule } from './app.module'
|
|
161
|
+
|
|
162
|
+
async function bootstrap() {
|
|
163
|
+
const app = await NestFactory.create(AppModule)
|
|
164
|
+
app.enableShutdownHooks()
|
|
165
|
+
await app.listen(3000)
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
await app.get<Mastra>(MASTRA).startWorkers()
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.error('Failed to start background workers', error)
|
|
171
|
+
await app.close()
|
|
172
|
+
process.exit(1)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
bootstrap()
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The module's shutdown handling drains in-flight requests but doesn't stop Mastra. To stop workers and drain in-flight workflow runs, call `mastra.shutdown()` from a shutdown hook. The drain is bounded by `drainTimeout` (default 5 seconds), and runs that don't settle within it are abandoned with a warning:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { Inject, Injectable, type OnApplicationShutdown } from '@nestjs/common'
|
|
183
|
+
import { MASTRA } from '@mastra/nestjs'
|
|
184
|
+
import type { Mastra } from '@mastra/core/mastra'
|
|
185
|
+
|
|
186
|
+
@Injectable()
|
|
187
|
+
export class MastraLifecycleService implements OnApplicationShutdown {
|
|
188
|
+
constructor(@Inject(MASTRA) private readonly mastra: Mastra) {}
|
|
189
|
+
|
|
190
|
+
async onApplicationShutdown() {
|
|
191
|
+
await this.mastra.shutdown()
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Add `MastraLifecycleService` to the `providers` of a module that imports `MastraModule`. Shutdown hooks only run when `app.enableShutdownHooks()` is called.
|
|
197
|
+
|
|
198
|
+
See [Start background workers](https://mastra.ai/docs/server/server-adapters) for more details.
|
|
199
|
+
|
|
152
200
|
## MCP routes
|
|
153
201
|
|
|
154
202
|
MCP endpoints are exposed under the API prefix:
|
|
@@ -154,37 +154,48 @@ The same request also populates `context.requestContext`, the trusted applicatio
|
|
|
154
154
|
const authInfo = context.mcp?.extra.authInfo ?? context.requestContext?.get('authInfo')
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
#### Example: Tool that
|
|
157
|
+
#### Example: Tool that uses caller identity with a separate credential
|
|
158
158
|
|
|
159
159
|
```typescript
|
|
160
160
|
import { createTool } from '@mastra/core/tools'
|
|
161
161
|
import { z } from 'zod'
|
|
162
162
|
|
|
163
|
+
import { apiCredentials } from '../lib/api-credentials'
|
|
164
|
+
|
|
163
165
|
const fetchUserData = createTool({
|
|
164
166
|
id: 'fetchUserData',
|
|
165
|
-
description: 'Fetches
|
|
167
|
+
description: 'Fetches data for the authenticated MCP caller',
|
|
166
168
|
inputSchema: z.object({
|
|
167
|
-
|
|
169
|
+
resourceId: z.string().describe('The ID of the record to fetch'),
|
|
168
170
|
}),
|
|
169
171
|
execute: async (inputData, context) => {
|
|
170
172
|
const authInfo = context.mcp?.extra.authInfo ?? context.requestContext?.get('authInfo')
|
|
173
|
+
const user = authInfo?.extra?.user as { id?: string } | undefined
|
|
171
174
|
|
|
172
|
-
if (!
|
|
175
|
+
if (!user?.id) {
|
|
173
176
|
throw new Error('Authentication required')
|
|
174
177
|
}
|
|
175
178
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
// Resolve the owner from trusted context, not from model input
|
|
180
|
+
const credential = await apiCredentials.getForUser(user.id)
|
|
181
|
+
|
|
182
|
+
const response = await fetch(
|
|
183
|
+
`https://api.example.com/users/${encodeURIComponent(user.id)}/records/${encodeURIComponent(inputData.resourceId)}`,
|
|
184
|
+
{
|
|
185
|
+
headers: {
|
|
186
|
+
Authorization: `Bearer ${credential.token}`,
|
|
187
|
+
},
|
|
188
|
+
signal: context.mcp?.extra.signal,
|
|
179
189
|
},
|
|
180
|
-
|
|
181
|
-
})
|
|
190
|
+
)
|
|
182
191
|
|
|
183
192
|
return response.json()
|
|
184
193
|
},
|
|
185
194
|
})
|
|
186
195
|
```
|
|
187
196
|
|
|
197
|
+
Use `authInfo` for caller identity, then select a credential intended for the service the tool calls. The model supplies business input such as `resourceId`, while trusted code selects the credential. An MCP access token is for your MCP server, so it must not be forwarded to another API. See [Access upstream services safely](https://mastra.ai/docs/guides/mcp-authentication-authorization).
|
|
198
|
+
|
|
188
199
|
#### Where `authInfo` comes from
|
|
189
200
|
|
|
190
201
|
When an MCP server is served by a Mastra server, `extra.authInfo` is populated from the principal resolved by `server.auth`. Nothing extra is required:
|
|
@@ -1113,8 +1124,12 @@ execute: async (inputData, context) => {
|
|
|
1113
1124
|
console.log('User ID:', authInfo.extra.sub)
|
|
1114
1125
|
console.log('Email:', authInfo.extra.email)
|
|
1115
1126
|
|
|
1127
|
+
// Use a credential intended for the API being called, not the MCP token.
|
|
1128
|
+
// See https://mastra.ai/docs/guides/mcp-authentication-authorization#access-upstream-services-safely
|
|
1129
|
+
const credential = await apiCredentials.getForUser(authInfo.extra.sub as string)
|
|
1130
|
+
|
|
1116
1131
|
const response = await fetch('/api/data', {
|
|
1117
|
-
headers: { Authorization: `Bearer ${
|
|
1132
|
+
headers: { Authorization: `Bearer ${credential.token}` },
|
|
1118
1133
|
signal: context.mcp?.extra.signal,
|
|
1119
1134
|
})
|
|
1120
1135
|
|
|
@@ -155,14 +155,12 @@ Pass a [`Classifier`](https://mastra.ai/reference/classifier/classifier) with co
|
|
|
155
155
|
|
|
156
156
|
```typescript
|
|
157
157
|
import { Classifier } from '@mastra/core/classifier'
|
|
158
|
-
import {
|
|
158
|
+
import { typeSafeAi } from '@ai-sdk/typesafe-ai'
|
|
159
159
|
import { createStep } from '@mastra/core/workflows'
|
|
160
160
|
|
|
161
161
|
const router = new Classifier({
|
|
162
162
|
id: 'ticket-router',
|
|
163
|
-
model:
|
|
164
|
-
'jev-latest',
|
|
165
|
-
),
|
|
163
|
+
model: typeSafeAi.evaluationModel('jev-latest'),
|
|
166
164
|
questions: {
|
|
167
165
|
route: {
|
|
168
166
|
type: 'choice',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3-alpha.3",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@mastra/mcp-legacy": "npm:@mastra/mcp@^1.18.0",
|
|
27
27
|
"local-pkg": "^1.1.2",
|
|
28
28
|
"zod": "^4.6.4",
|
|
29
|
-
"@mastra/core": "1.
|
|
30
|
-
"@mastra/mcp": "^2.1.
|
|
29
|
+
"@mastra/core": "1.73.0-alpha.1",
|
|
30
|
+
"@mastra/mcp": "^2.1.2-alpha.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@hono/node-server": "^2.0.0",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"typescript": "^7.0.2",
|
|
45
45
|
"vitest": "4.1.11",
|
|
46
46
|
"@internal/lint": "0.0.138",
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
47
|
+
"@internal/types-builder": "0.0.113",
|
|
48
|
+
"@mastra/core": "1.73.0-alpha.1"
|
|
49
49
|
},
|
|
50
50
|
"homepage": "https://mastra.ai",
|
|
51
51
|
"repository": {
|