@mastra/mcp-docs-server 1.1.28-alpha.3 → 1.1.28
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/structured-output.md +44 -1
- package/.docs/docs/agents/using-tools.md +72 -0
- package/.docs/docs/browser/agent-browser.md +3 -0
- package/.docs/docs/browser/overview.md +1 -0
- package/.docs/docs/browser/stagehand.md +1 -0
- package/.docs/docs/evals/custom-scorers.md +1 -1
- package/.docs/docs/evals/datasets/overview.md +1 -1
- package/.docs/docs/memory/working-memory.md +1 -1
- package/.docs/docs/server/request-context.md +1 -1
- package/.docs/docs/workflows/agents-and-tools.md +1 -1
- package/.docs/docs/workflows/overview.md +105 -4
- package/.docs/docs/workspace/filesystem.md +55 -1
- package/.docs/docs/workspace/overview.md +26 -7
- package/.docs/reference/agents/agent.md +1 -1
- package/.docs/reference/agents/generate.md +1 -1
- package/.docs/reference/browser/agent-browser.md +2 -1
- package/.docs/reference/browser/mastra-browser.md +2 -1
- package/.docs/reference/browser/stagehand-browser.md +2 -6
- package/.docs/reference/datasets/create.md +4 -4
- package/.docs/reference/datasets/update.md +4 -4
- package/.docs/reference/evals/create-scorer.md +3 -3
- package/.docs/reference/harness/harness-class.md +1 -1
- package/.docs/reference/streaming/agents/stream.md +1 -1
- package/.docs/reference/tools/create-tool.md +77 -5
- package/.docs/reference/workflows/step.md +88 -7
- package/.docs/reference/workflows/workflow.md +72 -4
- package/.docs/reference/workspace/workspace-class.md +34 -3
- package/CHANGELOG.md +15 -0
- package/package.json +6 -6
|
@@ -8,7 +8,7 @@ Use structured output when you need an agent to return a data object rather than
|
|
|
8
8
|
|
|
9
9
|
## Define schemas
|
|
10
10
|
|
|
11
|
-
Agents can return structured data by defining the expected output with either [Zod](https://zod.dev/) or [JSON Schema](https://json-schema.org/). Zod
|
|
11
|
+
Agents can return structured data by defining the expected output with either [Standard JSON Schema](https://standardschema.dev/json-schema) ([Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), etc.) or [JSON Schema](https://json-schema.org/). Libraries like Zod are recommended because they provide TypeScript type inference and runtime validation, while JSON Schema is useful when you need a language agnostic format.
|
|
12
12
|
|
|
13
13
|
**Zod**:
|
|
14
14
|
|
|
@@ -31,6 +31,49 @@ const response = await testAgent.generate('Help me plan my day.', {
|
|
|
31
31
|
console.log(response.object)
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
**Valibot**:
|
|
35
|
+
|
|
36
|
+
Define the `output` shape using [Valibot](https://valibot.dev/):
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import * as v from 'valibot'
|
|
40
|
+
import { toStandardJsonSchema } from '@valibot/to-json-schema'
|
|
41
|
+
|
|
42
|
+
const response = await testAgent.generate('Help me plan my day.', {
|
|
43
|
+
structuredOutput: {
|
|
44
|
+
schema: toStandardJsonSchema(
|
|
45
|
+
v.array(
|
|
46
|
+
v.object({
|
|
47
|
+
name: v.string(),
|
|
48
|
+
activities: v.array(v.string()),
|
|
49
|
+
}),
|
|
50
|
+
),
|
|
51
|
+
),
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
console.log(response.object)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**ArkType**:
|
|
59
|
+
|
|
60
|
+
Define the `output` shape using [ArkType](https://arktype.io/):
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { type } from 'arktype'
|
|
64
|
+
|
|
65
|
+
const response = await testAgent.generate('Help me plan my day.', {
|
|
66
|
+
structuredOutput: {
|
|
67
|
+
schema: type({
|
|
68
|
+
name: 'string',
|
|
69
|
+
activities: 'string[]',
|
|
70
|
+
}).array(),
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
console.log(response.object)
|
|
75
|
+
```
|
|
76
|
+
|
|
34
77
|
**JSON Schema**:
|
|
35
78
|
|
|
36
79
|
You can also use JSON Schema to define your output structure:
|
|
@@ -57,6 +57,78 @@ export const weatherAgent = new Agent({
|
|
|
57
57
|
})
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
## Define schemas
|
|
61
|
+
|
|
62
|
+
You can define the tool's `inputSchema` and `outputSchema` with any library that supports [Standard JSON Schema](https://standardschema.dev/json-schema). This includes libraries like [Zod](https://zod.dev/), [Valibot](https://valibot.dev/), and [ArkType](https://arktype.io/).
|
|
63
|
+
|
|
64
|
+
**Zod**:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { createTool } from '@mastra/core/tools'
|
|
68
|
+
import { z } from 'zod'
|
|
69
|
+
|
|
70
|
+
export const weatherTool = createTool({
|
|
71
|
+
id: 'weather-tool',
|
|
72
|
+
description: 'Fetches weather for a location',
|
|
73
|
+
inputSchema: z.object({
|
|
74
|
+
location: z.string(),
|
|
75
|
+
}),
|
|
76
|
+
outputSchema: z.object({
|
|
77
|
+
weather: z.string(),
|
|
78
|
+
}),
|
|
79
|
+
execute: async inputData => {
|
|
80
|
+
// Fetch weather data
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Valibot**:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { createTool } from '@mastra/core/tools'
|
|
89
|
+
import * as v from 'valibot'
|
|
90
|
+
import { toStandardJsonSchema } from '@valibot/to-json-schema'
|
|
91
|
+
|
|
92
|
+
export const weatherTool = createTool({
|
|
93
|
+
id: 'weather-tool',
|
|
94
|
+
description: 'Fetches weather for a location',
|
|
95
|
+
inputSchema: toStandardJsonSchema(
|
|
96
|
+
v.object({
|
|
97
|
+
location: v.string(),
|
|
98
|
+
}),
|
|
99
|
+
),
|
|
100
|
+
outputSchema: toStandardJsonSchema(
|
|
101
|
+
v.object({
|
|
102
|
+
weather: v.string(),
|
|
103
|
+
}),
|
|
104
|
+
),
|
|
105
|
+
execute: async inputData => {
|
|
106
|
+
// Fetch weather data
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**ArkType**:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { createTool } from '@mastra/core/tools'
|
|
115
|
+
import { type } from 'arktype'
|
|
116
|
+
|
|
117
|
+
export const weatherTool = createTool({
|
|
118
|
+
id: 'weather-tool',
|
|
119
|
+
description: 'Fetches weather for a location',
|
|
120
|
+
inputSchema: type({
|
|
121
|
+
location: 'string',
|
|
122
|
+
}),
|
|
123
|
+
outputSchema: type({
|
|
124
|
+
weather: 'string',
|
|
125
|
+
}),
|
|
126
|
+
execute: async inputData => {
|
|
127
|
+
// Fetch weather data
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
```
|
|
131
|
+
|
|
60
132
|
## Multiple tools
|
|
61
133
|
|
|
62
134
|
An agent can use multiple tools to handle more complex tasks by delegating specific parts to individual tools. The agent decides which tools to use based on the user's message, the agent's instructions, and the tool descriptions and schemas.
|
|
@@ -51,6 +51,7 @@ const browser = new AgentBrowser({
|
|
|
51
51
|
|
|
52
52
|
export const browserAgent = new Agent({
|
|
53
53
|
id: 'browser-agent',
|
|
54
|
+
name: 'Browser Agent',
|
|
54
55
|
model: 'openai/gpt-5.4',
|
|
55
56
|
browser,
|
|
56
57
|
instructions: `You are a web automation assistant.
|
|
@@ -62,6 +63,8 @@ When interacting with pages:
|
|
|
62
63
|
})
|
|
63
64
|
```
|
|
64
65
|
|
|
66
|
+
> **Note:** For local launches (the default), AgentBrowser requires a Chromium binary installed via Playwright. This is normally downloaded automatically when you install `@mastra/agent-browser`. If launching the browser fails with `"browser executable is missing"`, run `npx playwright install chromium`. If you connect to a remote browser using the [`cdpUrl`](https://mastra.ai/reference/browser/agent-browser) option, no local Chromium is needed.
|
|
67
|
+
|
|
65
68
|
## Element refs
|
|
66
69
|
|
|
67
70
|
AgentBrowser uses accessibility tree refs to identify elements. When an agent calls `browser_snapshot`, it receives a text representation of the page with refs like `@e1`, `@e2`, etc. The agent then uses these refs with other tools to interact with elements.
|
|
@@ -402,7 +402,7 @@ Defines how the LLM should analyze the input and what structured output to retur
|
|
|
402
402
|
The analysis step uses a prompt object to:
|
|
403
403
|
|
|
404
404
|
- Provide a clear description of the analysis task
|
|
405
|
-
- Define expected output structure with
|
|
405
|
+
- Define expected output structure with a Standard JSON Schema (both boolean result and list of gluten sources)
|
|
406
406
|
- Generate dynamic prompts based on the input content
|
|
407
407
|
|
|
408
408
|
### Score Generation
|
|
@@ -68,7 +68,7 @@ console.log(dataset.id) // auto-generated UUID
|
|
|
68
68
|
|
|
69
69
|
### Defining schemas
|
|
70
70
|
|
|
71
|
-
You can enforce the shape of `input` and `groundTruth` by passing
|
|
71
|
+
You can enforce the shape of `input` and `groundTruth` by passing a [Standard JSON Schema](https://standardschema.dev/json-schema) ([Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), etc.) when creating the dataset:
|
|
72
72
|
|
|
73
73
|
```typescript
|
|
74
74
|
import { z } from 'zod'
|
|
@@ -208,7 +208,7 @@ const paragraphMemory = new Memory({
|
|
|
208
208
|
|
|
209
209
|
## Structured working memory
|
|
210
210
|
|
|
211
|
-
Working memory can also be defined using a structured schema instead of a Markdown template. This allows you to specify the exact fields and types that should be tracked, using a [Zod](https://zod.dev/)
|
|
211
|
+
Working memory can also be defined using a structured schema instead of a Markdown template. This allows you to specify the exact fields and types that should be tracked, using a [Standard JSON Schema](https://standardschema.dev/json-schema) ([Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), etc.). When using a schema, the agent will see and update working memory as a JSON object matching your schema.
|
|
212
212
|
|
|
213
213
|
**Important:** You must specify either `template` or `schema`, but not both.
|
|
214
214
|
|
|
@@ -308,7 +308,7 @@ for (const [key, value] of ctx.entries()) {
|
|
|
308
308
|
|
|
309
309
|
## Schema validation
|
|
310
310
|
|
|
311
|
-
Use `requestContextSchema` to define a
|
|
311
|
+
Use `requestContextSchema` to define a [Standard JSON Schema](https://standardschema.dev/json-schema) ([Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), etc.) that validates request context values at runtime. This catches missing or invalid context values early, provides clear error messages, and gives you type inference within your component.
|
|
312
312
|
|
|
313
313
|
### Agent schema validation
|
|
314
314
|
|
|
@@ -104,7 +104,7 @@ export const testWorkflow = createWorkflow({})
|
|
|
104
104
|
.commit()
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
The `structuredOutput.schema` option accepts any
|
|
107
|
+
The `structuredOutput.schema` option accepts any Standard JSON Schema. The agent will generate output conforming to this schema, and the step's `outputSchema` will be automatically set to match.
|
|
108
108
|
|
|
109
109
|
> **Info:** Visit [Structured Output](https://mastra.ai/docs/agents/structured-output) for more options like error handling strategies and streaming with structured output.
|
|
110
110
|
|
|
@@ -14,18 +14,21 @@ Use workflows for tasks that are clearly defined upfront and involve multiple st
|
|
|
14
14
|
|
|
15
15
|
Mastra workflows operate using these principles:
|
|
16
16
|
|
|
17
|
-
- Defining **steps** with `createStep
|
|
18
|
-
- Composing **steps** with `createWorkflow` to define the execution flow.
|
|
17
|
+
- Defining **steps** with [`createStep`](https://mastra.ai/reference/workflows/step), specifying input/output schemas and business logic.
|
|
18
|
+
- Composing **steps** with [`createWorkflow`](https://mastra.ai/reference/workflows/workflow) to define the execution flow.
|
|
19
19
|
- Running **workflows** to execute the entire sequence, with built-in support for suspension, resumption, and streaming results.
|
|
20
20
|
|
|
21
21
|
## Creating a workflow step
|
|
22
22
|
|
|
23
|
-
Steps are the building blocks of workflows. Create a step using `createStep()` with `inputSchema` and `outputSchema` to define the data it accepts and returns.
|
|
23
|
+
Steps are the building blocks of workflows. Create a step using `createStep()` with `inputSchema` and `outputSchema` to define the data it accepts and returns. You can define both schemas using [Standard JSON Schema](https://standardschema.dev/json-schema) ([Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), etc.).
|
|
24
24
|
|
|
25
25
|
The `execute` function defines what the step does. Use it to call functions in your codebase, external APIs, agents, or tools.
|
|
26
26
|
|
|
27
|
+
**Zod**:
|
|
28
|
+
|
|
27
29
|
```typescript
|
|
28
30
|
import { createStep } from '@mastra/core/workflows'
|
|
31
|
+
import { z } from 'zod'
|
|
29
32
|
|
|
30
33
|
const step1 = createStep({
|
|
31
34
|
id: 'step-1',
|
|
@@ -45,6 +48,59 @@ const step1 = createStep({
|
|
|
45
48
|
})
|
|
46
49
|
```
|
|
47
50
|
|
|
51
|
+
**Valibot**:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createStep } from '@mastra/core/workflows'
|
|
55
|
+
import * as v from 'valibot'
|
|
56
|
+
import { toStandardJsonSchema } from '@valibot/to-json-schema'
|
|
57
|
+
|
|
58
|
+
const step1 = createStep({
|
|
59
|
+
id: 'step-1',
|
|
60
|
+
inputSchema: toStandardJsonSchema(
|
|
61
|
+
v.object({
|
|
62
|
+
message: v.string(),
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
65
|
+
outputSchema: toStandardJsonSchema(
|
|
66
|
+
v.object({
|
|
67
|
+
formatted: v.string(),
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
execute: async ({ inputData }) => {
|
|
71
|
+
const { message } = inputData
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
formatted: message.toUpperCase(),
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**ArkType**:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { createStep } from '@mastra/core/workflows'
|
|
84
|
+
import { type } from 'arktype'
|
|
85
|
+
|
|
86
|
+
const step1 = createStep({
|
|
87
|
+
id: 'step-1',
|
|
88
|
+
inputSchema: type({
|
|
89
|
+
message: 'string',
|
|
90
|
+
}),
|
|
91
|
+
outputSchema: type({
|
|
92
|
+
formatted: 'string',
|
|
93
|
+
}),
|
|
94
|
+
execute: async ({ inputData }) => {
|
|
95
|
+
const { message } = inputData
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
formatted: message.toUpperCase(),
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
48
104
|
> **Info:** Visit [`Step`](https://mastra.ai/reference/workflows/step) for a full list of configuration options.
|
|
49
105
|
|
|
50
106
|
### Using agents and tools
|
|
@@ -53,7 +109,9 @@ Workflow steps can also call registered agents or import and execute tools direc
|
|
|
53
109
|
|
|
54
110
|
## Creating a workflow
|
|
55
111
|
|
|
56
|
-
Create a workflow using `createWorkflow()` with `inputSchema` and `outputSchema` to define the data it accepts and returns. Add steps using `.then()` and complete the workflow with `.commit()`.
|
|
112
|
+
Create a workflow using `createWorkflow()` with `inputSchema` and `outputSchema` to define the data it accepts and returns. You can define both schemas using [Standard JSON Schema](https://standardschema.dev/json-schema) ([Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), etc.). Add steps using `.then()` and complete the workflow with `.commit()`.
|
|
113
|
+
|
|
114
|
+
**Zod**:
|
|
57
115
|
|
|
58
116
|
```typescript
|
|
59
117
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
@@ -74,6 +132,49 @@ export const testWorkflow = createWorkflow({
|
|
|
74
132
|
.commit();
|
|
75
133
|
```
|
|
76
134
|
|
|
135
|
+
**Valibot**:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
139
|
+
import * as v from "valibot";
|
|
140
|
+
import { toStandardJsonSchema } from "@valibot/to-json-schema";
|
|
141
|
+
|
|
142
|
+
const step1 = createStep({...});
|
|
143
|
+
|
|
144
|
+
export const testWorkflow = createWorkflow({
|
|
145
|
+
id: "test-workflow",
|
|
146
|
+
inputSchema: toStandardJsonSchema(v.object({
|
|
147
|
+
message: v.string()
|
|
148
|
+
})),
|
|
149
|
+
outputSchema: toStandardJsonSchema(v.object({
|
|
150
|
+
output: v.string()
|
|
151
|
+
}))
|
|
152
|
+
})
|
|
153
|
+
.then(step1)
|
|
154
|
+
.commit();
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**ArkType**:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
161
|
+
import { type } from "arktype";
|
|
162
|
+
|
|
163
|
+
const step1 = createStep({...});
|
|
164
|
+
|
|
165
|
+
export const testWorkflow = createWorkflow({
|
|
166
|
+
id: "test-workflow",
|
|
167
|
+
inputSchema: type({
|
|
168
|
+
message: "string"
|
|
169
|
+
}),
|
|
170
|
+
outputSchema: type({
|
|
171
|
+
output: "string"
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
.then(step1)
|
|
175
|
+
.commit();
|
|
176
|
+
```
|
|
177
|
+
|
|
77
178
|
> **Info:** Visit [Workflow Class](https://mastra.ai/reference/workflows/workflow) for a full list of configuration options.
|
|
78
179
|
|
|
79
180
|
### Understanding control flow
|
|
@@ -93,6 +93,58 @@ const workspace = new Workspace({
|
|
|
93
93
|
|
|
94
94
|
When `contained` is `false`, absolute paths are treated as real filesystem paths with no restriction.
|
|
95
95
|
|
|
96
|
+
## Dynamic filesystem
|
|
97
|
+
|
|
98
|
+
The `filesystem` option accepts a resolver function instead of a static instance. The resolver receives `requestContext` and returns a filesystem per request, allowing a single workspace to serve different filesystems based on the caller's identity, role, or tenant.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { Agent } from '@mastra/core/agent'
|
|
102
|
+
import { Workspace, LocalFilesystem } from '@mastra/core/workspace'
|
|
103
|
+
|
|
104
|
+
const workspace = new Workspace({
|
|
105
|
+
filesystem: ({ requestContext }) => {
|
|
106
|
+
const role = requestContext.get('agent-role') || 'guest'
|
|
107
|
+
return new LocalFilesystem({
|
|
108
|
+
basePath: `/workspaces/${role}`,
|
|
109
|
+
readOnly: role !== 'admin',
|
|
110
|
+
})
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const agent = new Agent({
|
|
115
|
+
id: 'multi-role-agent',
|
|
116
|
+
model: 'openai/gpt-4o',
|
|
117
|
+
workspace,
|
|
118
|
+
})
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Each request resolves its own filesystem at tool execution time:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { RequestContext } from '@mastra/core/request-context'
|
|
125
|
+
|
|
126
|
+
// Admin request — reads and writes from /workspaces/admin/
|
|
127
|
+
const adminCtx = new RequestContext([['agent-role', 'admin']])
|
|
128
|
+
await agent.generate('Write report.txt with Q4 results', { requestContext: adminCtx })
|
|
129
|
+
|
|
130
|
+
// Viewer request — reads from /workspaces/viewer/, writes are blocked
|
|
131
|
+
const viewerCtx = new RequestContext([['agent-role', 'viewer']])
|
|
132
|
+
await agent.generate('Read info.txt', { requestContext: viewerCtx })
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The resolver can also be asynchronous, for example to look up configuration from a database:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
const workspace = new Workspace({
|
|
139
|
+
filesystem: async ({ requestContext }) => {
|
|
140
|
+
const tenantConfig = await db.getTenant(requestContext.get('tenant-id'))
|
|
141
|
+
return new LocalFilesystem({ basePath: tenantConfig.storagePath })
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
> **Note:** `filesystem` and `mounts` are mutually exclusive. You cannot use a resolver function together with `mounts` in the same workspace.
|
|
147
|
+
|
|
96
148
|
## Read-only mode
|
|
97
149
|
|
|
98
150
|
To prevent agents from modifying files, enable read-only mode:
|
|
@@ -106,7 +158,9 @@ const workspace = new Workspace({
|
|
|
106
158
|
})
|
|
107
159
|
```
|
|
108
160
|
|
|
109
|
-
|
|
161
|
+
With a static filesystem, write tools (`write_file`, `edit_file`, `delete`, `mkdir`) are excluded from the agent's toolset entirely. The agent can still read and list files.
|
|
162
|
+
|
|
163
|
+
When using a [dynamic filesystem](#dynamic-filesystem), write tools are always included because `readOnly` isn't known until the resolver runs. Instead, write operations are blocked at runtime — the tool returns an error if the resolved filesystem is read-only.
|
|
110
164
|
|
|
111
165
|
## Mounts and `CompositeFilesystem`
|
|
112
166
|
|
|
@@ -153,15 +153,34 @@ const workspace = new Workspace({
|
|
|
153
153
|
|
|
154
154
|
The agent receives the `execute_command` tool.
|
|
155
155
|
|
|
156
|
+
### Dynamic filesystem (per-request)
|
|
157
|
+
|
|
158
|
+
Pass a resolver function to `filesystem` to return a different filesystem per request. This is useful for multi-tenant applications or multi-role agents where each request needs a different storage root or different permissions.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
const workspace = new Workspace({
|
|
162
|
+
filesystem: ({ requestContext }) => {
|
|
163
|
+
const role = requestContext.get('agent-role') || 'guest'
|
|
164
|
+
return new LocalFilesystem({
|
|
165
|
+
basePath: `/workspaces/${role}`,
|
|
166
|
+
readOnly: role !== 'admin',
|
|
167
|
+
})
|
|
168
|
+
},
|
|
169
|
+
})
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
One workspace instance serves all requests. The resolver runs at tool execution time, so each request gets its own filesystem. See [dynamic filesystem](https://mastra.ai/docs/workspace/filesystem) for details.
|
|
173
|
+
|
|
156
174
|
### Which pattern should I use?
|
|
157
175
|
|
|
158
|
-
| Scenario
|
|
159
|
-
|
|
|
160
|
-
| Local development with files and commands
|
|
161
|
-
| Cloud storage accessible inside a cloud sandbox
|
|
162
|
-
| Multiple cloud providers in one sandbox
|
|
163
|
-
| Agent reads/writes files, no command execution needed
|
|
164
|
-
| Agent runs commands, no file tools needed
|
|
176
|
+
| Scenario | Pattern |
|
|
177
|
+
| --------------------------------------------------------- | ----------------------------------------------------- |
|
|
178
|
+
| Local development with files and commands | `filesystem` + `sandbox` (both local, same directory) |
|
|
179
|
+
| Cloud storage accessible inside a cloud sandbox | `mounts` + `sandbox` |
|
|
180
|
+
| Multiple cloud providers in one sandbox | `mounts` + `sandbox` (one mount per provider) |
|
|
181
|
+
| Agent reads/writes files, no command execution needed | `filesystem` only |
|
|
182
|
+
| Agent runs commands, no file tools needed | `sandbox` only |
|
|
183
|
+
| Multi-role or multi-tenant agent with per-request storage | `filesystem` with resolver function |
|
|
165
184
|
|
|
166
185
|
## Tool configuration
|
|
167
186
|
|
|
@@ -132,7 +132,7 @@ export const agent = new Agent({
|
|
|
132
132
|
|
|
133
133
|
**maxProcessorRetries** (`number`): Maximum number of times a processor can request retrying the LLM step.
|
|
134
134
|
|
|
135
|
-
**requestContextSchema** (`
|
|
135
|
+
**requestContextSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for validating request context values. When provided, the context is validated at the start of generate() or stream(), throwing a MastraError if validation fails.
|
|
136
136
|
|
|
137
137
|
## Returns
|
|
138
138
|
|
|
@@ -184,7 +184,7 @@ const response = await agent.generate('Help me organize my day', {
|
|
|
184
184
|
|
|
185
185
|
**options.structuredOutput** (`StructuredOutputOptions<S extends ZodTypeAny = ZodTypeAny>`): Options to fine tune your structured output generation.
|
|
186
186
|
|
|
187
|
-
**options.structuredOutput.schema** (`
|
|
187
|
+
**options.structuredOutput.schema** (`StandardJSONSchemaV1`): Standard JSON Schema defining the expected output structure.
|
|
188
188
|
|
|
189
189
|
**options.structuredOutput.model** (`MastraLanguageModel`): Language model to use for structured output generation. If provided, enables the agent to respond in multi step with tool calls, text, and structured output
|
|
190
190
|
|
|
@@ -17,7 +17,8 @@ const browser = new AgentBrowser({
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
export const browserAgent = new Agent({
|
|
20
|
-
|
|
20
|
+
id: 'browser-agent',
|
|
21
|
+
name: 'Browser Agent',
|
|
21
22
|
instructions: `You can browse the web. Use browser_snapshot to see the page structure,
|
|
22
23
|
then interact with elements using their refs (e.g., @e5).`,
|
|
23
24
|
model: 'openai/gpt-5.4',
|
|
@@ -21,7 +21,8 @@ const browser = new AgentBrowser({
|
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
export const browserAgent = new Agent({
|
|
24
|
-
|
|
24
|
+
id: 'browser-agent',
|
|
25
|
+
name: 'Browser Agent',
|
|
25
26
|
instructions: 'You can browse the web to find information.',
|
|
26
27
|
model: 'openai/gpt-5.4',
|
|
27
28
|
browser,
|
|
@@ -17,7 +17,8 @@ const browser = new StagehandBrowser({
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
export const browserAgent = new Agent({
|
|
20
|
-
|
|
20
|
+
id: 'browser-agent',
|
|
21
|
+
name: 'Browser Agent',
|
|
21
22
|
instructions: `You can browse the web using natural language.
|
|
22
23
|
Use stagehand_act to perform actions like "click the login button".
|
|
23
24
|
Use stagehand_extract to get data from pages.`,
|
|
@@ -265,11 +266,6 @@ const browser = new StagehandBrowser({
|
|
|
265
266
|
})
|
|
266
267
|
```
|
|
267
268
|
|
|
268
|
-
Supported providers:
|
|
269
|
-
|
|
270
|
-
- OpenAI: `"openai/gpt-5.4"`, `"openai/gpt-5.4-mini"`
|
|
271
|
-
- Anthropic: `"anthropic/claude-3-5-sonnet-20241022"`
|
|
272
|
-
|
|
273
269
|
## AgentBrowser vs StagehandBrowser
|
|
274
270
|
|
|
275
271
|
| Aspect | AgentBrowser | StagehandBrowser |
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Added in:** `@mastra/core@1.4.0`
|
|
4
4
|
|
|
5
|
-
Creates a new dataset.
|
|
5
|
+
Creates a new dataset. Use Standard JSON Schema (Zod, Valibot, ArkType, etc.) for defining schemas.
|
|
6
6
|
|
|
7
7
|
## Usage example
|
|
8
8
|
|
|
@@ -21,7 +21,7 @@ const dataset = await mastra.datasets.create({
|
|
|
21
21
|
metadata: { team: 'ml' },
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
// Create with Zod
|
|
24
|
+
// Create with Zod schema (library that supports Standard JSON Schema)
|
|
25
25
|
const typedDataset = await mastra.datasets.create({
|
|
26
26
|
name: 'Typed QA set',
|
|
27
27
|
inputSchema: z.object({
|
|
@@ -40,9 +40,9 @@ const typedDataset = await mastra.datasets.create({
|
|
|
40
40
|
|
|
41
41
|
**description** (`string`): Description of the dataset.
|
|
42
42
|
|
|
43
|
-
**inputSchema** (`
|
|
43
|
+
**inputSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for item inputs.
|
|
44
44
|
|
|
45
|
-
**groundTruthSchema** (`
|
|
45
|
+
**groundTruthSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for item ground truths.
|
|
46
46
|
|
|
47
47
|
**metadata** (`Record<string, unknown>`): Arbitrary metadata.
|
|
48
48
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Added in:** `@mastra/core@1.4.0`
|
|
4
4
|
|
|
5
|
-
Updates dataset metadata, name, description, and/or schemas.
|
|
5
|
+
Updates dataset metadata, name, description, and/or schemas. Use Standard JSON Schema (Zod, Valibot, ArkType, etc.) for defining schemas.
|
|
6
6
|
|
|
7
7
|
## Usage example
|
|
8
8
|
|
|
@@ -22,7 +22,7 @@ const updated = await dataset.update({
|
|
|
22
22
|
description: 'Revised evaluation set',
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
// Update with Zod schema (
|
|
25
|
+
// Update with Zod schema (library that supports Standard JSON Schema)
|
|
26
26
|
const updated2 = await dataset.update({
|
|
27
27
|
inputSchema: z.object({
|
|
28
28
|
question: z.string(),
|
|
@@ -39,9 +39,9 @@ const updated2 = await dataset.update({
|
|
|
39
39
|
|
|
40
40
|
**metadata** (`Record<string, unknown>`): Updated metadata.
|
|
41
41
|
|
|
42
|
-
**inputSchema** (`
|
|
42
|
+
**inputSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for item inputs.
|
|
43
43
|
|
|
44
|
-
**groundTruthSchema** (`
|
|
44
|
+
**groundTruthSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for item ground truths.
|
|
45
45
|
|
|
46
46
|
## Returns
|
|
47
47
|
|
|
@@ -164,7 +164,7 @@ The method can return any value. The returned value will be available to subsequ
|
|
|
164
164
|
|
|
165
165
|
**description** (`string`): Description of what this preprocessing step does.
|
|
166
166
|
|
|
167
|
-
**outputSchema** (`
|
|
167
|
+
**outputSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for the expected output of the preprocess step.
|
|
168
168
|
|
|
169
169
|
**createPrompt** (`function`): Function: ({ run, results }) => string. Returns the prompt for the LLM.
|
|
170
170
|
|
|
@@ -193,7 +193,7 @@ The method can return any value. The returned value will be available to subsequ
|
|
|
193
193
|
|
|
194
194
|
**description** (`string`): Description of what this analysis step does.
|
|
195
195
|
|
|
196
|
-
**outputSchema** (`
|
|
196
|
+
**outputSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for the expected output of the analyze step.
|
|
197
197
|
|
|
198
198
|
**createPrompt** (`function`): Function: ({ run, results }) => string. Returns the prompt for the LLM.
|
|
199
199
|
|
|
@@ -224,7 +224,7 @@ The method must return a numerical score.
|
|
|
224
224
|
|
|
225
225
|
**description** (`string`): Description of what this scoring step does.
|
|
226
226
|
|
|
227
|
-
**outputSchema** (`
|
|
227
|
+
**outputSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for the expected output of the generateScore step.
|
|
228
228
|
|
|
229
229
|
**createPrompt** (`function`): Function: ({ run, results }) => string. Returns the prompt for the LLM.
|
|
230
230
|
|
|
@@ -44,7 +44,7 @@ await harness.sendMessage({ content: 'Hello!' })
|
|
|
44
44
|
|
|
45
45
|
**storage** (`MastraCompositeStore`): Storage backend for persistence (threads, messages, state).
|
|
46
46
|
|
|
47
|
-
**stateSchema** (`
|
|
47
|
+
**stateSchema** (`StandardJSONSchemaV1`): Standard JSON Schema defining the shape of harness state. Used for validation and extracting defaults.
|
|
48
48
|
|
|
49
49
|
**initialState** (`Partial<z.infer<TState>>`): Initial state values. Must conform to the schema if provided.
|
|
50
50
|
|
|
@@ -88,7 +88,7 @@ const stream = await agent.stream('message for agent')
|
|
|
88
88
|
|
|
89
89
|
**options.structuredOutput** (`StructuredOutputOptions<S extends ZodTypeAny = ZodTypeAny>`): Options to fine tune your structured output generation.
|
|
90
90
|
|
|
91
|
-
**options.structuredOutput.schema** (`
|
|
91
|
+
**options.structuredOutput.schema** (`StandardJSONSchemaV1`): Standard JSON Schema defining the expected output structure.
|
|
92
92
|
|
|
93
93
|
**options.structuredOutput.model** (`MastraLanguageModel`): Language model to use for structured output generation. If provided, enables the agent to respond in multi step with tool calls, text, and structured output
|
|
94
94
|
|
|
@@ -27,6 +27,78 @@ export const tool = createTool({
|
|
|
27
27
|
})
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Define schemas
|
|
31
|
+
|
|
32
|
+
You can define the tool's `inputSchema` and `outputSchema` with any library that supports [Standard JSON Schema](https://standardschema.dev/json-schema). This includes libraries like [Zod](https://zod.dev/), [Valibot](https://valibot.dev/), and [ArkType](https://arktype.io/).
|
|
33
|
+
|
|
34
|
+
**Zod**:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { createTool } from '@mastra/core/tools'
|
|
38
|
+
import { z } from 'zod'
|
|
39
|
+
|
|
40
|
+
export const weatherTool = createTool({
|
|
41
|
+
id: 'weather-tool',
|
|
42
|
+
description: 'Fetches weather for a location',
|
|
43
|
+
inputSchema: z.object({
|
|
44
|
+
location: z.string(),
|
|
45
|
+
}),
|
|
46
|
+
outputSchema: z.object({
|
|
47
|
+
weather: z.string(),
|
|
48
|
+
}),
|
|
49
|
+
execute: async inputData => {
|
|
50
|
+
// Fetch weather data
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Valibot**:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { createTool } from '@mastra/core/tools'
|
|
59
|
+
import * as v from 'valibot'
|
|
60
|
+
import { toStandardJsonSchema } from '@valibot/to-json-schema'
|
|
61
|
+
|
|
62
|
+
export const weatherTool = createTool({
|
|
63
|
+
id: 'weather-tool',
|
|
64
|
+
description: 'Fetches weather for a location',
|
|
65
|
+
inputSchema: toStandardJsonSchema(
|
|
66
|
+
v.object({
|
|
67
|
+
location: v.string(),
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
outputSchema: toStandardJsonSchema(
|
|
71
|
+
v.object({
|
|
72
|
+
weather: v.string(),
|
|
73
|
+
}),
|
|
74
|
+
),
|
|
75
|
+
execute: async inputData => {
|
|
76
|
+
// Fetch weather data
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**ArkType**:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { createTool } from '@mastra/core/tools'
|
|
85
|
+
import { type } from 'arktype'
|
|
86
|
+
|
|
87
|
+
export const weatherTool = createTool({
|
|
88
|
+
id: 'weather-tool',
|
|
89
|
+
description: 'Fetches weather for a location',
|
|
90
|
+
inputSchema: type({
|
|
91
|
+
location: 'string',
|
|
92
|
+
}),
|
|
93
|
+
outputSchema: type({
|
|
94
|
+
weather: 'string',
|
|
95
|
+
}),
|
|
96
|
+
execute: async inputData => {
|
|
97
|
+
// Fetch weather data
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
30
102
|
## Example with strict tool inputs
|
|
31
103
|
|
|
32
104
|
Set `strict: true` when you want Mastra to ask supported model providers to generate tool arguments that exactly match the tool schema.
|
|
@@ -144,23 +216,23 @@ export const weatherTool = createTool({
|
|
|
144
216
|
|
|
145
217
|
**description** (`string`): A description of what the tool does. This is used by the agent to decide when to use the tool.
|
|
146
218
|
|
|
147
|
-
**inputSchema** (`
|
|
219
|
+
**inputSchema** (`StandardJSONSchemaV1`): A Standard JSON Schema defining the expected input parameters for the tool's \`execute\` function.
|
|
148
220
|
|
|
149
|
-
**outputSchema** (`
|
|
221
|
+
**outputSchema** (`StandardJSONSchemaV1`): A Standard JSON Schema defining the expected output structure of the tool's \`execute\` function.
|
|
150
222
|
|
|
151
223
|
**strict** (`boolean`): When true, Mastra enables strict tool input generation on model adapters that support it. This helps supported providers return arguments that match the tool schema more closely.
|
|
152
224
|
|
|
153
225
|
**toModelOutput** (`(output: TSchemaOut) => unknown`): Optional function that transforms the tool's \`execute\` output before it is sent back to the model. Use this to return \`text\`, \`json\`, or \`content\`-shaped outputs (including multimodal parts like images/files) to the model while still keeping the full raw output in your application code.
|
|
154
226
|
|
|
155
|
-
**suspendSchema** (`
|
|
227
|
+
**suspendSchema** (`StandardJSONSchemaV1`): A Standard JSON Schema defining the structure of the payload passed to \`suspend()\`. This payload is returned to the client when the tool suspends execution.
|
|
156
228
|
|
|
157
|
-
**resumeSchema** (`
|
|
229
|
+
**resumeSchema** (`StandardJSONSchemaV1`): A Standard JSON Schema defining the expected structure of \`resumeData\` when the tool is resumed. Used by the agent to extract data from user messages when \`autoResumeSuspendedTools\` is enabled.
|
|
158
230
|
|
|
159
231
|
**requireApproval** (`boolean`): When true, the tool requires explicit approval before execution. The agent will emit a \`tool-call-approval\` chunk and pause until approved or declined.
|
|
160
232
|
|
|
161
233
|
**mcp** (`MCPToolProperties`): MCP-specific properties for tools exposed via Model Context Protocol. Includes \`annotations\` (tool behavior hints like \`title\`, \`readOnlyHint\`, \`destructiveHint\`, \`idempotentHint\`, \`openWorldHint\`) and \`\_meta\` (arbitrary metadata passed through to MCP clients).
|
|
162
234
|
|
|
163
|
-
**requestContextSchema** (`
|
|
235
|
+
**requestContextSchema** (`StandardJSONSchemaV1`): A Standard JSON Schema for validating request context values. When provided, the context is validated before execute() runs, returning an error object if validation fails.
|
|
164
236
|
|
|
165
237
|
**execute** (`function`): The function that contains the tool's logic. It receives two parameters: the validated input data (first parameter) and an optional execution context object (second parameter) containing \`requestContext\`, \`tracingContext\`, \`abortSignal\`, and other execution metadata.
|
|
166
238
|
|
|
@@ -26,6 +26,87 @@ const step1 = createStep({
|
|
|
26
26
|
})
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
## Define schemas
|
|
30
|
+
|
|
31
|
+
You can define the step's `inputSchema` and `outputSchema` with any library that supports [Standard JSON Schema](https://standardschema.dev/json-schema). This includes libraries like [Zod](https://zod.dev/), [Valibot](https://valibot.dev/), and [ArkType](https://arktype.io/).
|
|
32
|
+
|
|
33
|
+
**Zod**:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { createStep } from '@mastra/core/workflows'
|
|
37
|
+
import { z } from 'zod'
|
|
38
|
+
|
|
39
|
+
const step1 = createStep({
|
|
40
|
+
id: 'step-1',
|
|
41
|
+
inputSchema: z.object({
|
|
42
|
+
message: z.string(),
|
|
43
|
+
}),
|
|
44
|
+
outputSchema: z.object({
|
|
45
|
+
formatted: z.string(),
|
|
46
|
+
}),
|
|
47
|
+
execute: async ({ inputData }) => {
|
|
48
|
+
const { message } = inputData
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
formatted: message.toUpperCase(),
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Valibot**:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { createStep } from '@mastra/core/workflows'
|
|
61
|
+
import * as v from 'valibot'
|
|
62
|
+
import { toStandardJsonSchema } from '@valibot/to-json-schema'
|
|
63
|
+
|
|
64
|
+
const step1 = createStep({
|
|
65
|
+
id: 'step-1',
|
|
66
|
+
inputSchema: toStandardJsonSchema(
|
|
67
|
+
v.object({
|
|
68
|
+
message: v.string(),
|
|
69
|
+
}),
|
|
70
|
+
),
|
|
71
|
+
outputSchema: toStandardJsonSchema(
|
|
72
|
+
v.object({
|
|
73
|
+
formatted: v.string(),
|
|
74
|
+
}),
|
|
75
|
+
),
|
|
76
|
+
execute: async ({ inputData }) => {
|
|
77
|
+
const { message } = inputData
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
formatted: message.toUpperCase(),
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**ArkType**:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { createStep } from '@mastra/core/workflows'
|
|
90
|
+
import { type } from 'arktype'
|
|
91
|
+
|
|
92
|
+
const step1 = createStep({
|
|
93
|
+
id: 'step-1',
|
|
94
|
+
inputSchema: type({
|
|
95
|
+
message: 'string',
|
|
96
|
+
}),
|
|
97
|
+
outputSchema: type({
|
|
98
|
+
formatted: 'string',
|
|
99
|
+
}),
|
|
100
|
+
execute: async ({ inputData }) => {
|
|
101
|
+
const { message } = inputData
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
formatted: message.toUpperCase(),
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
29
110
|
## Creating steps from agents
|
|
30
111
|
|
|
31
112
|
You can create a step directly from an agent. The step will use the agent's name as its ID.
|
|
@@ -60,7 +141,7 @@ const agentStep = createStep(testAgent, {
|
|
|
60
141
|
|
|
61
142
|
### Agent step options
|
|
62
143
|
|
|
63
|
-
**structuredOutput** (`{ schema:
|
|
144
|
+
**structuredOutput** (`{ schema: StandardJSONSchemaV1 }`): When provided, the agent returns structured data matching this schema instead of plain text. The step's outputSchema is set to the provided schema.
|
|
64
145
|
|
|
65
146
|
**onFinish** (`(result: AgentResult) => void`): Callback invoked when the agent completes generation.
|
|
66
147
|
|
|
@@ -70,17 +151,17 @@ const agentStep = createStep(testAgent, {
|
|
|
70
151
|
|
|
71
152
|
**description** (`string`): Optional description of what the step does
|
|
72
153
|
|
|
73
|
-
**inputSchema** (`
|
|
154
|
+
**inputSchema** (`StandardJSONSchemaV1`): Standard JSON Schema defining the input structure
|
|
74
155
|
|
|
75
|
-
**outputSchema** (`
|
|
156
|
+
**outputSchema** (`StandardJSONSchemaV1`): Standard JSON Schema defining the output structure
|
|
76
157
|
|
|
77
|
-
**resumeSchema** (`
|
|
158
|
+
**resumeSchema** (`StandardJSONSchemaV1`): Optional Standard JSON Schema for resuming the step
|
|
78
159
|
|
|
79
|
-
**suspendSchema** (`
|
|
160
|
+
**suspendSchema** (`StandardJSONSchemaV1`): Optional Standard JSON Schema for suspending the step
|
|
80
161
|
|
|
81
|
-
**stateSchema** (`
|
|
162
|
+
**stateSchema** (`StandardJSONSchemaV1`): Optional Standard JSON Schema for the step state. Automatically injected when using Mastra's state system. The stateSchema must be a subset of the workflow's stateSchema. If not specified, type is 'any'.
|
|
82
163
|
|
|
83
|
-
**requestContextSchema** (`
|
|
164
|
+
**requestContextSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for validating request context values. When provided, the context is validated before the step's execute() runs, failing the step if validation fails.
|
|
84
165
|
|
|
85
166
|
**execute** (`(params: ExecuteParams) => Promise<any>`): Async function containing step logic
|
|
86
167
|
|
|
@@ -19,17 +19,85 @@ export const workflow = createWorkflow({
|
|
|
19
19
|
})
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
## Define schemas
|
|
23
|
+
|
|
24
|
+
You can define the workflow's `inputSchema` and `outputSchema` with any library that supports [Standard JSON Schema](https://standardschema.dev/json-schema). This includes libraries like [Zod](https://zod.dev/), [Valibot](https://valibot.dev/), and [ArkType](https://arktype.io/).
|
|
25
|
+
|
|
26
|
+
**Zod**:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
30
|
+
import { z } from "zod";
|
|
31
|
+
|
|
32
|
+
const step1 = createStep({...});
|
|
33
|
+
|
|
34
|
+
export const testWorkflow = createWorkflow({
|
|
35
|
+
id: "test-workflow",
|
|
36
|
+
inputSchema: z.object({
|
|
37
|
+
message: z.string()
|
|
38
|
+
}),
|
|
39
|
+
outputSchema: z.object({
|
|
40
|
+
output: z.string()
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
.then(step1)
|
|
44
|
+
.commit();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Valibot**:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
51
|
+
import * as v from "valibot";
|
|
52
|
+
import { toStandardJsonSchema } from "@valibot/to-json-schema";
|
|
53
|
+
|
|
54
|
+
const step1 = createStep({...});
|
|
55
|
+
|
|
56
|
+
export const testWorkflow = createWorkflow({
|
|
57
|
+
id: "test-workflow",
|
|
58
|
+
inputSchema: toStandardJsonSchema(v.object({
|
|
59
|
+
message: v.string()
|
|
60
|
+
})),
|
|
61
|
+
outputSchema: toStandardJsonSchema(v.object({
|
|
62
|
+
output: v.string()
|
|
63
|
+
}))
|
|
64
|
+
})
|
|
65
|
+
.then(step1)
|
|
66
|
+
.commit();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**ArkType**:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
73
|
+
import { type } from "arktype";
|
|
74
|
+
|
|
75
|
+
const step1 = createStep({...});
|
|
76
|
+
|
|
77
|
+
export const testWorkflow = createWorkflow({
|
|
78
|
+
id: "test-workflow",
|
|
79
|
+
inputSchema: type({
|
|
80
|
+
message: "string"
|
|
81
|
+
}),
|
|
82
|
+
outputSchema: type({
|
|
83
|
+
output: "string"
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
.then(step1)
|
|
87
|
+
.commit();
|
|
88
|
+
```
|
|
89
|
+
|
|
22
90
|
## Constructor parameters
|
|
23
91
|
|
|
24
92
|
**id** (`string`): Unique identifier for the workflow
|
|
25
93
|
|
|
26
|
-
**inputSchema** (`
|
|
94
|
+
**inputSchema** (`StandardJSONSchemaV1`): Standard JSON Schema defining the input structure for the workflow
|
|
27
95
|
|
|
28
|
-
**outputSchema** (`
|
|
96
|
+
**outputSchema** (`StandardJSONSchemaV1`): Standard JSON Schema defining the output structure for the workflow
|
|
29
97
|
|
|
30
|
-
**stateSchema** (`
|
|
98
|
+
**stateSchema** (`StandardJSONSchemaV1`): Optional Standard JSON Schema for the workflow state. Automatically injected when using Mastra's state system. If not specified, type is 'any'.
|
|
31
99
|
|
|
32
|
-
**requestContextSchema** (`
|
|
100
|
+
**requestContextSchema** (`StandardJSONSchemaV1`): Standard JSON Schema for validating request context values. When provided, the context is validated at the start of run.start(), throwing an error if validation fails.
|
|
33
101
|
|
|
34
102
|
**options** (`WorkflowOptions`): Optional options for the workflow
|
|
35
103
|
|
|
@@ -29,7 +29,7 @@ const workspace = new Workspace({
|
|
|
29
29
|
|
|
30
30
|
**name** (`string`): Human-readable name (Default: `workspace-{id}`)
|
|
31
31
|
|
|
32
|
-
**filesystem** (`WorkspaceFilesystem`): Filesystem provider instance
|
|
32
|
+
**filesystem** (`WorkspaceFilesystem | WorkspaceFilesystemResolver`): Filesystem provider instance, or a resolver function that receives \`requestContext\` and returns a filesystem per request. See \[dynamic filesystem]\(/docs/workspace/filesystem#dynamic-filesystem).
|
|
33
33
|
|
|
34
34
|
**sandbox** (`WorkspaceSandbox`): Sandbox provider instance (e.g., LocalSandbox)
|
|
35
35
|
|
|
@@ -122,7 +122,7 @@ Tool names must be unique across all workspace tools. Setting a custom name that
|
|
|
122
122
|
|
|
123
123
|
**status** (`WorkspaceStatus`): 'pending' | 'initializing' | 'ready' | 'paused' | 'error' | 'destroying' | 'destroyed'
|
|
124
124
|
|
|
125
|
-
**filesystem** (`WorkspaceFilesystem | undefined`): The filesystem provider
|
|
125
|
+
**filesystem** (`WorkspaceFilesystem | undefined`): The static filesystem provider. Returns \`undefined\` when a resolver function is configured — use \`hasFilesystemConfig()\` to check availability.
|
|
126
126
|
|
|
127
127
|
**sandbox** (`WorkspaceSandbox | undefined`): The sandbox provider
|
|
128
128
|
|
|
@@ -251,6 +251,37 @@ workspace.setToolsConfig(undefined)
|
|
|
251
251
|
|
|
252
252
|
**config** (`WorkspaceToolsConfig | undefined`): New tool configuration to apply. Pass undefined to reset to defaults.
|
|
253
253
|
|
|
254
|
+
### Dynamic filesystem
|
|
255
|
+
|
|
256
|
+
#### `hasFilesystemConfig()`
|
|
257
|
+
|
|
258
|
+
Check whether a filesystem is configured, either as a static instance or a resolver function. Use this instead of checking `workspace.filesystem` directly, because a resolver-based workspace returns `undefined` from the `filesystem` property.
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
if (workspace.hasFilesystemConfig()) {
|
|
262
|
+
// Filesystem tools are available
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**Returns:** `boolean`
|
|
267
|
+
|
|
268
|
+
#### `resolveFilesystem({ requestContext })`
|
|
269
|
+
|
|
270
|
+
Resolve the filesystem for a given request context. When a resolver function is configured, calls it with the provided `requestContext`. When a static filesystem is configured, returns it directly. Returns `undefined` if no filesystem is configured.
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import { RequestContext } from '@mastra/core/request-context'
|
|
274
|
+
|
|
275
|
+
const ctx = new RequestContext([['agent-role', 'admin']])
|
|
276
|
+
const fs = await workspace.resolveFilesystem({ requestContext: ctx })
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
**Parameters:**
|
|
280
|
+
|
|
281
|
+
**requestContext** (`RequestContext`): The request context to pass to the resolver function.
|
|
282
|
+
|
|
283
|
+
**Returns:** `Promise<WorkspaceFilesystem | undefined>`
|
|
284
|
+
|
|
254
285
|
## Agent tools
|
|
255
286
|
|
|
256
287
|
A workspace provides tools to agents based on what's configured.
|
|
@@ -270,7 +301,7 @@ Added when a filesystem is configured:
|
|
|
270
301
|
| `mastra_workspace_mkdir` | Create a directory. Creates parent directories automatically if they don't exist. |
|
|
271
302
|
| `mastra_workspace_grep` | Search file contents using regex patterns. Supports glob filtering, context lines, and case-insensitive search. |
|
|
272
303
|
|
|
273
|
-
|
|
304
|
+
With a static filesystem, write tools (`write_file`, `edit_file`, `delete`, `mkdir`) are excluded when the filesystem is in read-only mode. With a [dynamic filesystem](https://mastra.ai/docs/workspace/filesystem), write tools are always included and read-only is enforced at runtime.
|
|
274
305
|
|
|
275
306
|
### Sandbox tools
|
|
276
307
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.1.28
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`733bf53`](https://github.com/mastra-ai/mastra/commit/733bf53d9352aedd3ef38c3d501edb275b65b43c), [`5405b3b`](https://github.com/mastra-ai/mastra/commit/5405b3b35325c5b8fb34fc7ac109bd2feb7bb6fe), [`45e29cb`](https://github.com/mastra-ai/mastra/commit/45e29cb5b5737f3083eb3852db02b944b9cf37ed), [`750b4d3`](https://github.com/mastra-ai/mastra/commit/750b4d3d8231f92e769b2c485921ac5a8ca639b9), [`c321127`](https://github.com/mastra-ai/mastra/commit/c3211275fc195de9ad1ead2746b354beb8eae6e8), [`a07bcef`](https://github.com/mastra-ai/mastra/commit/a07bcefea77c03d6d322caad973dca49b4b15fa1), [`696694e`](https://github.com/mastra-ai/mastra/commit/696694e00f29241a25dd1a1b749afa06c3a626b4), [`b084a80`](https://github.com/mastra-ai/mastra/commit/b084a800db0f82d62e1fc3d6e3e3480da1ba5a53), [`82b7a96`](https://github.com/mastra-ai/mastra/commit/82b7a964169636c1d1e0c694fc892a213b0179d5), [`e20a3d2`](https://github.com/mastra-ai/mastra/commit/e20a3d2cda9b94ca6625519da2e6492c335bd009), [`df97812`](https://github.com/mastra-ai/mastra/commit/df97812bd949dcafeb074b80ecab501724b49c3b), [`8bbe360`](https://github.com/mastra-ai/mastra/commit/8bbe36042af7fc4be0244dffd8913f6795179421), [`f6b8ba8`](https://github.com/mastra-ai/mastra/commit/f6b8ba8dbf533b7a8db90c72b6805ddc804a3a72), [`a07bcef`](https://github.com/mastra-ai/mastra/commit/a07bcefea77c03d6d322caad973dca49b4b15fa1)]:
|
|
8
|
+
- @mastra/core@1.28.0
|
|
9
|
+
- @mastra/mcp@1.5.2
|
|
10
|
+
|
|
11
|
+
## 1.1.28-alpha.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`45e29cb`](https://github.com/mastra-ai/mastra/commit/45e29cb5b5737f3083eb3852db02b944b9cf37ed), [`696694e`](https://github.com/mastra-ai/mastra/commit/696694e00f29241a25dd1a1b749afa06c3a626b4)]:
|
|
16
|
+
- @mastra/core@1.28.0-alpha.2
|
|
17
|
+
|
|
3
18
|
## 1.1.28-alpha.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.1.28
|
|
3
|
+
"version": "1.1.28",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"jsdom": "^26.1.0",
|
|
30
30
|
"local-pkg": "^1.1.2",
|
|
31
31
|
"zod": "^4.3.6",
|
|
32
|
-
"@mastra/
|
|
33
|
-
"@mastra/
|
|
32
|
+
"@mastra/mcp": "^1.5.2",
|
|
33
|
+
"@mastra/core": "1.28.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@hono/node-server": "^1.19.11",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"tsx": "^4.21.0",
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
48
|
"vitest": "4.1.5",
|
|
49
|
-
"@internal/lint": "0.0.
|
|
50
|
-
"@internal/types-builder": "0.0.
|
|
51
|
-
"@mastra/core": "1.28.0
|
|
49
|
+
"@internal/lint": "0.0.86",
|
|
50
|
+
"@internal/types-builder": "0.0.61",
|
|
51
|
+
"@mastra/core": "1.28.0"
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://mastra.ai",
|
|
54
54
|
"repository": {
|