@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.
Files changed (56) hide show
  1. package/.docs/docs/agents/human-in-the-loop.md +6 -4
  2. package/.docs/docs/agents/processors.md +58 -4
  3. package/.docs/docs/connections/mcp.md +2 -0
  4. package/.docs/docs/deployment/workers.md +3 -1
  5. package/.docs/docs/guides/authentication-identity.md +4 -2
  6. package/.docs/docs/guides/mcp-authentication-authorization.md +136 -0
  7. package/.docs/docs/index.md +1 -1
  8. package/.docs/docs/server/server-adapters.md +54 -11
  9. package/.docs/docs/workflows/control-flow.md +2 -4
  10. package/.docs/docs/workflows/scheduled-workflows.md +5 -1
  11. package/.docs/models/environment-variables.md +1 -1
  12. package/.docs/models/gateways/merge-gateway.md +2 -1
  13. package/.docs/models/gateways/openrouter.md +2 -1
  14. package/.docs/models/gateways/vercel.md +6 -1
  15. package/.docs/models/index.md +2 -2
  16. package/.docs/models/providers/302ai.md +2 -1
  17. package/.docs/models/providers/baseten.md +2 -1
  18. package/.docs/models/providers/cortecs.md +3 -2
  19. package/.docs/models/providers/crossmodel.md +3 -3
  20. package/.docs/models/providers/deepinfra.md +1 -5
  21. package/.docs/models/providers/edenai.md +3 -2
  22. package/.docs/models/providers/kilo.md +16 -14
  23. package/.docs/models/providers/llmgateway-providers.md +3 -11
  24. package/.docs/models/providers/llmgateway.md +2 -1
  25. package/.docs/models/providers/nano-gpt.md +5 -2
  26. package/.docs/models/providers/opencode.md +2 -1
  27. package/.docs/models/providers/requesty.md +3 -1
  28. package/.docs/models/providers/tempr.md +23 -4
  29. package/.docs/models/providers/vivgrid.md +3 -1
  30. package/.docs/models/providers/vultr.md +22 -17
  31. package/.docs/models/providers.md +1 -1
  32. package/.docs/reference/agent-controller/agent-controller-class.md +2 -0
  33. package/.docs/reference/agent-controller/session.md +8 -8
  34. package/.docs/reference/classifier/classifier.md +49 -22
  35. package/.docs/reference/client-js/observability.md +1 -1
  36. package/.docs/reference/coding-agent/create-coding-agent.md +2 -2
  37. package/.docs/reference/configuration.md +2 -4
  38. package/.docs/reference/evals/create-classifier-scorer.md +2 -4
  39. package/.docs/reference/evals/create-scorer.md +1 -1
  40. package/.docs/reference/memory/observational-memory.md +3 -1
  41. package/.docs/reference/observability/tracing/spans.md +1 -1
  42. package/.docs/reference/processors/classifier-processor.md +8 -10
  43. package/.docs/reference/processors/model-selection-processor.md +8 -10
  44. package/.docs/reference/processors/prefill-error-handler.md +2 -2
  45. package/.docs/reference/processors/processor-interface.md +2 -2
  46. package/.docs/reference/processors/provider-history-compat.md +37 -17
  47. package/.docs/reference/processors/stream-error-retry-processor.md +9 -4
  48. package/.docs/reference/server/elysia-adapter.md +2 -0
  49. package/.docs/reference/server/express-adapter.md +1 -1
  50. package/.docs/reference/server/fastify-adapter.md +2 -0
  51. package/.docs/reference/server/hono-adapter.md +2 -0
  52. package/.docs/reference/server/koa-adapter.md +2 -0
  53. package/.docs/reference/server/nestjs-adapter.md +48 -0
  54. package/.docs/reference/tools/mcp-server.md +25 -10
  55. package/.docs/reference/workflows/step.md +2 -4
  56. 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 reads the caller's token
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 user data using authentication from MCP context',
167
+ description: 'Fetches data for the authenticated MCP caller',
166
168
  inputSchema: z.object({
167
- userId: z.string().describe('The ID of the user to fetch'),
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 (!authInfo?.token) {
175
+ if (!user?.id) {
173
176
  throw new Error('Authentication required')
174
177
  }
175
178
 
176
- const response = await fetch(`https://api.example.com/users/${inputData.userId}`, {
177
- headers: {
178
- Authorization: `Bearer ${authInfo.token}`,
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
- signal: context.mcp?.extra.signal,
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 ${authInfo.token}` },
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 { createTypeSafeAi } from '@ai-sdk/typesafe-ai'
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: createTypeSafeAi({ apiKey: process.env.TYPESAFE_AI_API_KEY }).evaluationModel(
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.2",
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.72.0",
30
- "@mastra/mcp": "^2.1.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
- "@mastra/core": "1.72.0",
48
- "@internal/types-builder": "0.0.113"
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": {