@mastra/mcp-docs-server 1.3.7 → 1.3.8-alpha.0
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/harness/background-tasks.md +13 -10
- package/.docs/docs/memory/overview.md +31 -0
- package/.docs/docs/server/request-context.md +29 -5
- package/.docs/reference/agents/agent.md +2 -0
- package/.docs/reference/agents/generate.md +2 -0
- package/.docs/reference/streaming/agents/stream.md +2 -0
- package/package.json +5 -5
|
@@ -318,14 +318,14 @@ export const mastra = new Mastra({
|
|
|
318
318
|
|
|
319
319
|
### Subscribe to all task events
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
Pass `allResources: true` to receive every task event in the system, across all resources. On connection, the stream emits a snapshot of all currently running tasks, then forwards live events as they happen.
|
|
322
322
|
|
|
323
323
|
```typescript
|
|
324
324
|
const bgManager = mastra.backgroundTaskManager;
|
|
325
325
|
if (!bgManager) throw new Error('Background tasks are not enabled');
|
|
326
326
|
|
|
327
327
|
const controller = new AbortController();
|
|
328
|
-
const stream = bgManager.stream({ abortSignal: controller.signal });
|
|
328
|
+
const stream = bgManager.stream({ allResources: true, abortSignal: controller.signal });
|
|
329
329
|
|
|
330
330
|
for await (const chunk of stream) {
|
|
331
331
|
switch (chunk.type) {
|
|
@@ -344,6 +344,8 @@ for await (const chunk of stream) {
|
|
|
344
344
|
|
|
345
345
|
The stream stays open until the caller's `AbortSignal` fires. Always pass an `abortSignal` so you can disconnect cleanly.
|
|
346
346
|
|
|
347
|
+
> **Warning:** `allResources: true` delivers task arguments and results for every user. Use it only in trusted server-side code, never to serve a single user's request. Without `resourceId` or `allResources`, `stream()` only delivers tasks that have no `resourceId`. Agent tasks dispatched with memory always have a `resourceId`, so they won't appear in that stream.
|
|
348
|
+
|
|
347
349
|
### Filter the stream
|
|
348
350
|
|
|
349
351
|
Pass any combination of filter options to narrow the events you receive. Filters apply to both the initial snapshot and the live event subscription.
|
|
@@ -357,14 +359,15 @@ const stream = bgManager.stream({
|
|
|
357
359
|
})
|
|
358
360
|
```
|
|
359
361
|
|
|
360
|
-
| Filter
|
|
361
|
-
|
|
|
362
|
-
| `agentId`
|
|
363
|
-
| `runId`
|
|
364
|
-
| `threadId`
|
|
365
|
-
| `resourceId`
|
|
366
|
-
| `taskId`
|
|
367
|
-
| `
|
|
362
|
+
| Filter | Description |
|
|
363
|
+
| -------------- | --------------------------------------------------------------------------------------------- |
|
|
364
|
+
| `agentId` | Only events from tasks dispatched by this agent |
|
|
365
|
+
| `runId` | Only events from this specific agent run |
|
|
366
|
+
| `threadId` | Only events from tasks scoped to this memory thread |
|
|
367
|
+
| `resourceId` | Only events from tasks scoped to this resource |
|
|
368
|
+
| `taskId` | Only events for a single task |
|
|
369
|
+
| `allResources` | Include tasks from every resource when `resourceId` is omitted. Trusted server-side code only |
|
|
370
|
+
| `abortSignal` | Closes the stream when the signal aborts |
|
|
368
371
|
|
|
369
372
|
### Look up task state directly
|
|
370
373
|
|
|
@@ -151,6 +151,37 @@ const response = await memoryAgent.generate("What's my favorite color?", {
|
|
|
151
151
|
|
|
152
152
|
To list all threads for a resource, or retrieve a specific thread, [use the memory API directly](https://mastra.ai/docs/memory/message-history).
|
|
153
153
|
|
|
154
|
+
### Identify memory with scopes
|
|
155
|
+
|
|
156
|
+
Instead of a `memory` object, you can pass `scopes`: the addresses a run acts as, written as `<type>:<value>`. Memory reads the resource from a `resource:` scope and the thread from a `thread:` scope. Other scopes, such as `org:acme`, are passed to tools and processors.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const response = await memoryAgent.generate('Remember my favorite color is blue.', {
|
|
160
|
+
scopes: ['org:acme', 'resource:user-123', 'thread:conversation-123'],
|
|
161
|
+
})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Scopes can also come from the agent and from the request context. Mastra combines all three sources:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
export const memoryAgent = new Agent({
|
|
168
|
+
id: 'memory-agent',
|
|
169
|
+
name: 'Memory Agent',
|
|
170
|
+
scopes: ({ requestContext }) => {
|
|
171
|
+
// Set by your auth middleware. Request bodies can fill unreserved keys.
|
|
172
|
+
const orgId = requestContext.get('org-id')
|
|
173
|
+
return orgId ? [`org:${orgId}`] : []
|
|
174
|
+
},
|
|
175
|
+
memory: new Memory(),
|
|
176
|
+
})
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The resolver's inputs must come from the server, not the client: a request body can set any request context key that isn't reserved. Trusted server middleware can also set scopes directly with the `MASTRA_SCOPES_KEY` request context key. Visit [Request Context](https://mastra.ai/docs/server/request-context) for details. Clients can't send scopes in a request body.
|
|
180
|
+
|
|
181
|
+
You can mix scopes with `memory.resource`, `memory.thread`, or the resource and thread request context keys, as long as they agree. If a `resource:` or `thread:` scope names a different value than another source, the call throws an error.
|
|
182
|
+
|
|
183
|
+
Tools, processors, and subagents receive the run's other scopes, but not its `resource:` and `thread:` scopes. Each nested agent call picks its own resource and thread.
|
|
184
|
+
|
|
154
185
|
## Observational Memory
|
|
155
186
|
|
|
156
187
|
Long conversations can fill the context window with raw message history and reduce agent performance. [Observational Memory](https://mastra.ai/docs/memory/observational-memory) uses background agents to compress older messages into observations. This reduces the context used by message history while retaining information for later turns.
|
|
@@ -284,11 +284,35 @@ requestContext.set(MASTRA_RESOURCE_ID_KEY, user.id)
|
|
|
284
284
|
requestContext.set(MASTRA_THREAD_ID_KEY, threadId)
|
|
285
285
|
```
|
|
286
286
|
|
|
287
|
-
| Key | Purpose
|
|
288
|
-
| --------------------------- |
|
|
289
|
-
| `MASTRA_RESOURCE_ID_KEY` | Forces all memory operations to use this resource ID. The server validates that accessed threads belong to this resource and returns 403 if not.
|
|
290
|
-
| `MASTRA_THREAD_ID_KEY` | Forces thread operations to use this thread ID, overriding client-provided values
|
|
291
|
-
| `
|
|
287
|
+
| Key | Purpose |
|
|
288
|
+
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
289
|
+
| `MASTRA_RESOURCE_ID_KEY` | Forces all memory operations to use this resource ID. The server validates that accessed threads belong to this resource and returns 403 if not. |
|
|
290
|
+
| `MASTRA_THREAD_ID_KEY` | Forces thread operations to use this thread ID, overriding client-provided values |
|
|
291
|
+
| `MASTRA_SCOPES_KEY` | Sets the [scopes](https://mastra.ai/docs/memory/overview) the agent run acts as, as an array of `<type>:<value>` strings. Combined with the agent's `scopes` and per-call `scopes`. A `resource:` or `thread:` scope that conflicts with another resource or thread value returns a 400 error. |
|
|
292
|
+
| `MASTRA_MESSAGE_AUTHOR_KEY` | Names who sent a user message as `{ id, name?, avatarUrl? }`. Agent-controller sessions persist it at `content.metadata.signal.author` and mirror it to `providerMetadata.mastra.author` for compatibility, so a thread shared by several people can show who wrote what. |
|
|
293
|
+
|
|
294
|
+
Server ownership checks read only `MASTRA_RESOURCE_ID_KEY` and `MASTRA_THREAD_ID_KEY`. If your middleware sets identity through `MASTRA_SCOPES_KEY` and you want those checks, set `MASTRA_RESOURCE_ID_KEY` too:
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
import {
|
|
298
|
+
MASTRA_RESOURCE_ID_KEY,
|
|
299
|
+
MASTRA_THREAD_ID_KEY,
|
|
300
|
+
MASTRA_SCOPES_KEY,
|
|
301
|
+
} from '@mastra/core/request-context'
|
|
302
|
+
|
|
303
|
+
requestContext.set(MASTRA_SCOPES_KEY, [`org:${user.orgId}`, `resource:${user.id}`])
|
|
304
|
+
requestContext.set(MASTRA_RESOURCE_ID_KEY, user.id)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
The same applies to a `thread:` scope: it sets the run's thread identity, but only `MASTRA_THREAD_ID_KEY` drives the server's thread checks, so set both when middleware pins the thread:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
requestContext.set(MASTRA_SCOPES_KEY, [`resource:${user.id}`, `thread:${threadId}`])
|
|
311
|
+
requestContext.set(MASTRA_RESOURCE_ID_KEY, user.id)
|
|
312
|
+
requestContext.set(MASTRA_THREAD_ID_KEY, threadId)
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Scopes from the request context and per-call `scopes` need a `@mastra/server` release that reserves them. Older servers pass these values from request bodies through to the agent, so while one is registered, agents throw an `AGENT_SCOPES_SERVER_OUTDATED` error instead of using them. The agent's own `scopes` option still applies.
|
|
292
316
|
|
|
293
317
|
These keys are used to implement user isolation in multi-tenant applications. See [Authorization middleware](https://mastra.ai/docs/server/middleware) for usage examples.
|
|
294
318
|
|
|
@@ -587,6 +587,8 @@ Returns an `AgentThreadSubscription` object with these members:
|
|
|
587
587
|
|
|
588
588
|
**scorers** (`MastraScorers | ({ requestContext: RequestContext }) => MastraScorers | Promise<MastraScorers>`): Scoring configuration for runtime evaluation and telemetry. Can be static or dynamically provided.
|
|
589
589
|
|
|
590
|
+
**scopes** (`string[] | ({ requestContext: RequestContext }) => string[] | Promise<string[]>`): Scopes every run of this agent acts as, written as \<type>:\<value>. Combined with per-call scopes and the mastra\_\_scopes request context key.
|
|
591
|
+
|
|
590
592
|
**memory** (`MastraMemory | ({ requestContext: RequestContext }) => MastraMemory | Promise<MastraMemory>`): Memory module used for storing and retrieving stateful context.
|
|
591
593
|
|
|
592
594
|
**notifications** (`object`): Notification delivery configuration for durable notification signals.
|
|
@@ -128,6 +128,8 @@ const result = await agent.generate('message for agent')
|
|
|
128
128
|
|
|
129
129
|
**options.output** (`Zod schema | JsonSchema7`): \*\*Deprecated.\*\* Use structuredOutput without a model to achieve the same thing. Defines the expected structure of the output. Can be a JSON Schema object or a Zod schema.
|
|
130
130
|
|
|
131
|
+
**options.scopes** (`string[]`): Scopes the run acts as, written as \<type>:\<value> (for example org:acme, resource:user-123, thread:conversation-123). Memory reads its resource and thread from resource: and thread: scopes. Other scopes are passed to tools and processors. Combined with the agent's scopes and the mastra\_\_scopes request context key. Throws if a resource: or thread: scope conflicts with another resource or thread value.
|
|
132
|
+
|
|
131
133
|
**options.memory** (`object`): Memory configuration for conversation persistence and retrieval.
|
|
132
134
|
|
|
133
135
|
**options.memory.thread** (`string | { id: string; metadata?: Record<string, any>, title?: string }`): Thread identifier for conversation continuity. Can be a string ID or an object with ID and optional metadata/title.
|
|
@@ -122,6 +122,8 @@ const stream = await agent.stream('message for agent')
|
|
|
122
122
|
|
|
123
123
|
**options.output** (`Zod schema | JsonSchema7`): \*\*Deprecated.\*\* Use structuredOutput without a model to achieve the same thing. Defines the expected structure of the output. Can be a JSON Schema object or a Zod schema.
|
|
124
124
|
|
|
125
|
+
**options.scopes** (`string[]`): Scopes the run acts as, written as \<type>:\<value> (for example org:acme, resource:user-123, thread:conversation-123). Memory reads its resource and thread from resource: and thread: scopes. Other scopes are passed to tools and processors. Combined with the agent's scopes and the mastra\_\_scopes request context key. Throws if a resource: or thread: scope conflicts with another resource or thread value.
|
|
126
|
+
|
|
125
127
|
**options.memory** (`object`): Configuration for memory. This is the preferred way to manage memory.
|
|
126
128
|
|
|
127
129
|
**options.memory.thread** (`string | { id: string; metadata?: Record<string, any>, title?: string }`): The conversation thread, as a string ID or an object with an id and optional metadata.
|
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.8-alpha.0",
|
|
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/
|
|
30
|
-
"@mastra/
|
|
29
|
+
"@mastra/core": "1.78.0-alpha.0",
|
|
30
|
+
"@mastra/mcp": "^2.4.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@hono/node-server": "^2.0.0",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"tsx": "^4.23.1",
|
|
44
44
|
"typescript": "^7.0.2",
|
|
45
45
|
"vitest": "4.1.11",
|
|
46
|
+
"@internal/types-builder": "0.0.118",
|
|
46
47
|
"@internal/lint": "0.0.143",
|
|
47
|
-
"@mastra/core": "1.
|
|
48
|
-
"@internal/types-builder": "0.0.118"
|
|
48
|
+
"@mastra/core": "1.78.0-alpha.0"
|
|
49
49
|
},
|
|
50
50
|
"homepage": "https://mastra.ai",
|
|
51
51
|
"repository": {
|