@mastra/mcp-docs-server 0.13.2-alpha.0 → 0.13.2-alpha.2
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/organized/changelogs/%40mastra%2Fagui.md +12 -0
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +32 -32
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +40 -40
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +44 -44
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +42 -42
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Flance.md +25 -0
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +35 -35
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +24 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +38 -38
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Frag.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +32 -32
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +12 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +14 -14
- package/.docs/organized/changelogs/create-mastra.md +7 -7
- package/.docs/organized/changelogs/mastra.md +48 -48
- package/.docs/organized/code-examples/a2a.md +1 -1
- package/.docs/organized/code-examples/agent-network.md +125 -7
- package/.docs/organized/code-examples/agent.md +183 -6
- package/.docs/organized/code-examples/agui.md +4 -4
- package/.docs/organized/code-examples/ai-sdk-useChat.md +6 -6
- package/.docs/organized/code-examples/assistant-ui.md +6 -6
- package/.docs/organized/code-examples/bird-checker-with-express.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +6 -6
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +6 -6
- package/.docs/organized/code-examples/client-side-tools.md +6 -6
- package/.docs/organized/code-examples/crypto-chatbot.md +6 -6
- package/.docs/organized/code-examples/experimental-auth-weather-agent.md +1 -1
- package/.docs/organized/code-examples/fireworks-r1.md +1 -1
- package/.docs/organized/code-examples/mcp-configuration.md +2 -2
- package/.docs/organized/code-examples/mcp-registry-registry.md +1 -1
- package/.docs/organized/code-examples/memory-per-resource-example.md +236 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +1 -1
- package/.docs/organized/code-examples/memory-with-processors.md +1 -1
- package/.docs/organized/code-examples/openapi-spec-writer.md +6 -6
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/organized/code-examples/stock-price-tool.md +1 -1
- package/.docs/organized/code-examples/weather-agent.md +1 -1
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +1 -1
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +1 -1
- package/.docs/organized/code-examples/workflow-with-memory.md +1 -1
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +1 -1
- package/.docs/raw/agents/using-tools-and-mcp.mdx +3 -2
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +111 -0
- package/.docs/raw/deployment/cloud-providers/index.mdx +15 -0
- package/.docs/raw/frameworks/agentic-uis/copilotkit.mdx +53 -10
- package/.docs/raw/mastra-cloud/dashboard.mdx +100 -0
- package/.docs/raw/mastra-cloud/observability.mdx +24 -138
- package/.docs/raw/mastra-cloud/overview.mdx +50 -42
- package/.docs/raw/mastra-cloud/setting-up.mdx +51 -87
- package/.docs/raw/memory/overview.mdx +4 -0
- package/.docs/raw/memory/working-memory.mdx +144 -1
- package/.docs/raw/networks-vnext/complex-task-execution.mdx +137 -0
- package/.docs/raw/networks-vnext/overview.mdx +85 -0
- package/.docs/raw/networks-vnext/single-task-execution.mdx +131 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +2 -2
- package/.docs/raw/reference/client-js/agents.mdx +41 -0
- package/.docs/raw/reference/deployer/netlify.mdx +22 -68
- package/.docs/raw/reference/deployer/vercel.mdx +7 -77
- package/.docs/raw/reference/storage/libsql.mdx +1 -0
- package/.docs/raw/reference/tools/mcp-client.mdx +244 -0
- package/.docs/raw/reference/tools/mcp-server.mdx +186 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +1 -0
- package/.docs/raw/reference/workflows/create-run.mdx +1 -1
- package/.docs/raw/reference/workflows/resume.mdx +1 -1
- package/.docs/raw/reference/workflows/sleep.mdx +43 -0
- package/.docs/raw/reference/workflows/sleepUntil.mdx +43 -0
- package/.docs/raw/reference/workflows/start.mdx +1 -1
- package/.docs/raw/reference/workflows/stream.mdx +1 -1
- package/.docs/raw/reference/workflows/waitForEvent.mdx +49 -0
- package/.docs/raw/reference/workflows/watch.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow.mdx +6 -2
- package/.docs/raw/storage/overview.mdx +50 -1
- package/.docs/raw/tools-mcp/mcp-overview.mdx +52 -0
- package/.docs/raw/workflows/control-flow.mdx +42 -1
- package/.docs/raw/workflows/inngest-workflow.mdx +1 -1
- package/.docs/raw/workflows/overview.mdx +73 -5
- package/.docs/raw/workflows/pausing-execution.mdx +60 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +68 -23
- package/.docs/raw/workflows/using-with-agents-and-tools.mdx +1 -1
- package/package.json +6 -6
- package/.docs/raw/mastra-cloud/deploying.mdx +0 -142
|
@@ -539,6 +539,7 @@ runtimeContext.set("filter", { category: "docs" });
|
|
|
539
539
|
runtimeContext.set("databaseConfig", {
|
|
540
540
|
pinecone: { namespace: "runtime-namespace" }
|
|
541
541
|
});
|
|
542
|
+
runtimeContext.set("model", openai.embedding("text-embedding-3-small"));
|
|
542
543
|
|
|
543
544
|
const response = await agent.generate(
|
|
544
545
|
"Find documentation from the knowledge base.",
|
|
@@ -10,7 +10,7 @@ The `.resume()` method resumes a suspended workflow run with new data, allowing
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
12
12
|
```typescript
|
|
13
|
-
const run = counterWorkflow.
|
|
13
|
+
const run = await counterWorkflow.createRunAsync();
|
|
14
14
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
15
15
|
|
|
16
16
|
if (result.status === "suspended") {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Workflow.sleep() | Building Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the `.sleep()` method in workflows, which pauses execution for a specified number of milliseconds.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow.sleep()
|
|
7
|
+
|
|
8
|
+
The `.sleep()` method pauses execution for a specified number of milliseconds.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
workflow.sleep(1000);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Parameters
|
|
17
|
+
|
|
18
|
+
<PropertiesTable
|
|
19
|
+
content={[
|
|
20
|
+
{
|
|
21
|
+
name: "milliseconds",
|
|
22
|
+
type: "number",
|
|
23
|
+
description: "The number of milliseconds to pause execution",
|
|
24
|
+
isOptional: false,
|
|
25
|
+
},
|
|
26
|
+
]}
|
|
27
|
+
/>
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
<PropertiesTable
|
|
32
|
+
content={[
|
|
33
|
+
{
|
|
34
|
+
name: "workflow",
|
|
35
|
+
type: "Workflow",
|
|
36
|
+
description: "The workflow instance for method chaining",
|
|
37
|
+
},
|
|
38
|
+
]}
|
|
39
|
+
/>
|
|
40
|
+
|
|
41
|
+
## Related
|
|
42
|
+
|
|
43
|
+
- [Sleep & Events](../../docs/workflows/pausing-execution.mdx)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Workflow.sleepUntil() | Building Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the `.sleepUntil()` method in workflows, which pauses execution until a specified date.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow.sleepUntil()
|
|
7
|
+
|
|
8
|
+
The `.sleepUntil()` method pauses execution until a specified date.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
workflow.sleepUntil(new Date(Date.now() + 1000));
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Parameters
|
|
17
|
+
|
|
18
|
+
<PropertiesTable
|
|
19
|
+
content={[
|
|
20
|
+
{
|
|
21
|
+
name: "date",
|
|
22
|
+
type: "Date",
|
|
23
|
+
description: "The date until which to pause execution",
|
|
24
|
+
isOptional: false,
|
|
25
|
+
},
|
|
26
|
+
]}
|
|
27
|
+
/>
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
<PropertiesTable
|
|
32
|
+
content={[
|
|
33
|
+
{
|
|
34
|
+
name: "workflow",
|
|
35
|
+
type: "Workflow",
|
|
36
|
+
description: "The workflow instance for method chaining",
|
|
37
|
+
},
|
|
38
|
+
]}
|
|
39
|
+
/>
|
|
40
|
+
|
|
41
|
+
## Related
|
|
42
|
+
|
|
43
|
+
- [Sleep & Events](../../docs/workflows/pausing-execution.mdx)
|
|
@@ -10,7 +10,7 @@ The `.start()` method starts a workflow run with input data, allowing you to exe
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
12
12
|
```typescript
|
|
13
|
-
const run = myWorkflow.
|
|
13
|
+
const run = await myWorkflow.createRunAsync();
|
|
14
14
|
|
|
15
15
|
// Start the workflow with input data
|
|
16
16
|
const result = await run.start({
|
|
@@ -10,7 +10,7 @@ The `.stream()` method allows you to monitor the execution of a workflow run, pr
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
12
12
|
```typescript
|
|
13
|
-
const run = myWorkflow.
|
|
13
|
+
const run = await myWorkflow.createRunAsync();
|
|
14
14
|
|
|
15
15
|
// Add a stream to monitor execution
|
|
16
16
|
const result = run.stream({ inputData: {...} });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Workflow.waitForEvent() | Building Workflows | Mastra Docs"
|
|
3
|
+
description: Documentation for the `.waitForEvent()` method in workflows, which pauses execution until an event is received.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow.waitForEvent()
|
|
7
|
+
|
|
8
|
+
The `.waitForEvent()` method pauses execution until an event is received.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
workflow.waitForEvent('my-event-name', step1);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Parameters
|
|
17
|
+
|
|
18
|
+
<PropertiesTable
|
|
19
|
+
content={[
|
|
20
|
+
{
|
|
21
|
+
name: "eventName",
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "The name of the event to wait for",
|
|
24
|
+
isOptional: false,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "step",
|
|
28
|
+
type: "Step",
|
|
29
|
+
description: "The step to resume after the event is received",
|
|
30
|
+
isOptional: false,
|
|
31
|
+
},
|
|
32
|
+
]}
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
## Returns
|
|
36
|
+
|
|
37
|
+
<PropertiesTable
|
|
38
|
+
content={[
|
|
39
|
+
{
|
|
40
|
+
name: "workflow",
|
|
41
|
+
type: "Workflow",
|
|
42
|
+
description: "The workflow instance for method chaining",
|
|
43
|
+
},
|
|
44
|
+
]}
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
## Related
|
|
48
|
+
|
|
49
|
+
- [Sleep & Events](../../docs/workflows/pausing-execution.mdx)
|
|
@@ -10,7 +10,7 @@ The `.watch()` method allows you to monitor the execution of a workflow run, pro
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
12
12
|
```typescript
|
|
13
|
-
const run = myWorkflow.
|
|
13
|
+
const run = await myWorkflow.createRunAsync();
|
|
14
14
|
|
|
15
15
|
// Add a watcher to monitor execution
|
|
16
16
|
run.watch(event => {
|
|
@@ -31,7 +31,7 @@ const mastra = new Mastra({
|
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
const run = mastra.getWorkflow("myWorkflow").
|
|
34
|
+
const run = await mastra.getWorkflow("myWorkflow").createRunAsync();
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
## API Reference
|
|
@@ -99,7 +99,11 @@ Validates and finalizes the workflow configuration. Must be called after adding
|
|
|
99
99
|
|
|
100
100
|
#### `createRun()`
|
|
101
101
|
|
|
102
|
-
Creates a new workflow run instance, allowing you to execute the workflow with specific input data. Accepts optional run ID.
|
|
102
|
+
Deprecated. Creates a new workflow run instance, allowing you to execute the workflow with specific input data. Accepts optional run ID.
|
|
103
|
+
|
|
104
|
+
#### `createRunAsync()`
|
|
105
|
+
|
|
106
|
+
Creates a new workflow run instance, allowing you to execute the workflow with specific input data. Accepts optional run ID. Stores a pending workflow run snapshot into storage.
|
|
103
107
|
|
|
104
108
|
#### `execute()`
|
|
105
109
|
|
|
@@ -55,7 +55,7 @@ Each tab includes detailed column information with types, constraints, and examp
|
|
|
55
55
|
The data types include Messages, Threads, Workflows, Eval Datasets, and Traces.
|
|
56
56
|
*/}
|
|
57
57
|
|
|
58
|
-
<Tabs items={['Messages', 'Threads', 'Workflows', 'Eval Datasets', 'Traces']}>
|
|
58
|
+
<Tabs items={['Messages', 'Threads', 'Resources', 'Workflows', 'Eval Datasets', 'Traces']}>
|
|
59
59
|
<Tabs.Tab>
|
|
60
60
|
Stores conversation messages and their metadata. Each message belongs to a thread and contains the actual content along with metadata about the sender role and message type.
|
|
61
61
|
|
|
@@ -212,6 +212,55 @@ Groups related messages together and associates them with a resource. Contains m
|
|
|
212
212
|
]}
|
|
213
213
|
/>
|
|
214
214
|
|
|
215
|
+
</Tabs.Tab>
|
|
216
|
+
<Tabs.Tab>
|
|
217
|
+
Stores user-specific data for resource-scoped working memory. Each resource represents a user or entity, allowing working memory to persist across all conversation threads for that user.
|
|
218
|
+
|
|
219
|
+
<br />
|
|
220
|
+
<SchemaTable
|
|
221
|
+
columns={[
|
|
222
|
+
{
|
|
223
|
+
name: "id",
|
|
224
|
+
type: "text",
|
|
225
|
+
description: "Resource identifier (user or entity ID) - same as resourceId used in threads and agent calls",
|
|
226
|
+
constraints: [
|
|
227
|
+
{ type: "primaryKey" },
|
|
228
|
+
{ type: "nullable", value: false }
|
|
229
|
+
]
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: "workingMemory",
|
|
233
|
+
type: "text",
|
|
234
|
+
description: "Persistent working memory data as Markdown text. Contains user profile, preferences, and contextual information that persists across conversation threads.",
|
|
235
|
+
constraints: [{ type: "nullable", value: true }]
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: "metadata",
|
|
239
|
+
type: "jsonb",
|
|
240
|
+
description: "Additional resource metadata as JSON. Example:",
|
|
241
|
+
example: {
|
|
242
|
+
preferences: { language: "en", timezone: "UTC" },
|
|
243
|
+
tags: ["premium", "beta-user"]
|
|
244
|
+
},
|
|
245
|
+
constraints: [{ type: "nullable", value: true }]
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: "createdAt",
|
|
249
|
+
type: "timestamp",
|
|
250
|
+
description: "When the resource record was first created",
|
|
251
|
+
constraints: [{ type: "nullable", value: false }]
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: "updatedAt",
|
|
255
|
+
type: "timestamp",
|
|
256
|
+
description: "When the working memory was last updated",
|
|
257
|
+
constraints: [{ type: "nullable", value: false }]
|
|
258
|
+
}
|
|
259
|
+
]}
|
|
260
|
+
/>
|
|
261
|
+
|
|
262
|
+
**Note**: This table is only created and used by storage adapters that support resource-scoped working memory (LibSQL, PostgreSQL, Upstash). Other storage adapters will provide helpful error messages if resource-scoped memory is attempted.
|
|
263
|
+
|
|
215
264
|
</Tabs.Tab>
|
|
216
265
|
<Tabs.Tab>
|
|
217
266
|
When `suspend` is called on a workflow, its state is saved in the following format. When `resume` is called, that state is rehydrated.
|
|
@@ -309,4 +309,56 @@ const server = new MCPServer({
|
|
|
309
309
|
For an agent to be exposed as a tool, it must have a non-empty `description` string. Similarly, for a workflow to be exposed, its `description` must also be a non-empty string. If the description is missing or empty for either, `MCPServer` will throw an error during initialization.
|
|
310
310
|
Workflows will use their `inputSchema` for the tool's input.
|
|
311
311
|
|
|
312
|
+
### Tools with Structured Outputs
|
|
313
|
+
|
|
314
|
+
You can define an `outputSchema` for your tools to enforce a specific structure for the tool's output. This is useful for ensuring that the tool returns data in a consistent and predictable format, which can then be validated by the client.
|
|
315
|
+
|
|
316
|
+
When a tool includes an `outputSchema`, its `execute` function **must** return an object containing a `structuredContent` property. The value of `structuredContent` must conform to the `outputSchema`. Mastra will automatically validate this output on both the server and client sides.
|
|
317
|
+
|
|
318
|
+
Here's an example of a tool with an `outputSchema`:
|
|
319
|
+
|
|
320
|
+
```typescript filename="src/tools/structured-tool.ts"
|
|
321
|
+
import { createTool } from '@mastra/core';
|
|
322
|
+
import { z } from 'zod';
|
|
323
|
+
|
|
324
|
+
export const structuredTool = createTool({
|
|
325
|
+
description: 'A test tool that returns structured data.',
|
|
326
|
+
parameters: z.object({
|
|
327
|
+
input: z.string().describe('Some input string.'),
|
|
328
|
+
}),
|
|
329
|
+
outputSchema: z.object({
|
|
330
|
+
processedInput: z.string().describe('The processed input string.'),
|
|
331
|
+
timestamp: z.string().describe('An ISO timestamp.'),
|
|
332
|
+
}),
|
|
333
|
+
execute: async ({ input }) => {
|
|
334
|
+
// When outputSchema is defined, you must return a structuredContent object
|
|
335
|
+
return {
|
|
336
|
+
structuredContent: {
|
|
337
|
+
processedInput: `processed: ${input}`,
|
|
338
|
+
timestamp: new Date().toISOString(),
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
When this tool is called, the MCP client will receive both the structured data and a text representation of it.
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
Tool result
|
|
349
|
+
|
|
350
|
+
{
|
|
351
|
+
"content": [
|
|
352
|
+
{
|
|
353
|
+
"type": "text",
|
|
354
|
+
"text": "{\"processedInput\": \"hello\", \"timestamp\": \"2025-06-19T16:53:16.472Z\"}"
|
|
355
|
+
}
|
|
356
|
+
],
|
|
357
|
+
"structuredContent": {
|
|
358
|
+
"processedInput": "processed: hello",
|
|
359
|
+
"timestamp": "2025-06-19T16:53:16.472Z",
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
312
364
|
For detailed usage and examples, see the [`MCPServer` reference documentation](/reference/tools/mcp-server).
|
|
@@ -126,6 +126,47 @@ export const testWorkflow = createWorkflow({...})
|
|
|
126
126
|
.commit();
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
+
### Early exit
|
|
130
|
+
|
|
131
|
+
You can bail out of a workflow execution successfully by calling `bail()` in a step. This returns whatever payload is passed to the `bail()` function as the result of the workflow.
|
|
132
|
+
|
|
133
|
+
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
134
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
135
|
+
import { z } from "zod";
|
|
136
|
+
|
|
137
|
+
const step1 = createStep({
|
|
138
|
+
id: 'step1',
|
|
139
|
+
execute: async ({ bail, inputData }) => {
|
|
140
|
+
return bail({ result: 'bailed' });
|
|
141
|
+
},
|
|
142
|
+
inputSchema: z.object({ value: z.string() }),
|
|
143
|
+
outputSchema: z.object({ result: z.string() }),
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
export const testWorkflow = createWorkflow({...})
|
|
147
|
+
.then(step1)
|
|
148
|
+
.commit();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Unsuccessful bails happen through throwing an error in the step.
|
|
152
|
+
|
|
153
|
+
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
154
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
155
|
+
import { z } from "zod";
|
|
156
|
+
|
|
157
|
+
const step1 = createStep({
|
|
158
|
+
id: 'step1',
|
|
159
|
+
execute: async ({ bail, inputData }) => {
|
|
160
|
+
throw new Error('bailed');
|
|
161
|
+
},
|
|
162
|
+
inputSchema: z.object({ value: z.string() }),
|
|
163
|
+
outputSchema: z.object({ result: z.string() }),
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
export const testWorkflow = createWorkflow({...})
|
|
167
|
+
.then(step1)
|
|
168
|
+
.commit();
|
|
169
|
+
```
|
|
129
170
|
#### Example Run Instance
|
|
130
171
|
|
|
131
172
|
The following example demonstrates how to start a run with multiple inputs. Each input will pass through the `mapStep` sequentially.
|
|
@@ -133,7 +174,7 @@ The following example demonstrates how to start a run with multiple inputs. Each
|
|
|
133
174
|
```typescript {6} filename="src/test-workflow.ts" showLineNumbers copy
|
|
134
175
|
import { mastra } from "./mastra";
|
|
135
176
|
|
|
136
|
-
const run = mastra.getWorkflow("testWorkflow").
|
|
177
|
+
const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
|
|
137
178
|
|
|
138
179
|
const result = await run.start({
|
|
139
180
|
inputData: [{ number: 10 }, { number: 100 }, { number: 200 }]
|
|
@@ -163,7 +163,7 @@ export const mastra = new Mastra({
|
|
|
163
163
|
```sh
|
|
164
164
|
docker run --rm -p 8288:8288 \
|
|
165
165
|
inngest/inngest \
|
|
166
|
-
inngest dev -u http://host.docker.internal:4111/inngest
|
|
166
|
+
inngest dev -u http://host.docker.internal:4111/api/inngest
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
> **Note:** The URL after `-u` tells the Inngest dev server where to find your Mastra `/api/inngest` endpoint.
|
|
@@ -157,12 +157,12 @@ With the Mastra Dev Server running you can run the workflow from the Mastra Play
|
|
|
157
157
|
|
|
158
158
|
#### Command line
|
|
159
159
|
|
|
160
|
-
Create a run instance of any Mastra workflow using `
|
|
160
|
+
Create a run instance of any Mastra workflow using `createRunAsync` and `start`:
|
|
161
161
|
|
|
162
162
|
```typescript {3,5} filename="src/test-workflow.ts" showLineNumbers copy
|
|
163
163
|
import { mastra } from "./mastra";
|
|
164
164
|
|
|
165
|
-
const run = mastra.getWorkflow("testWorkflow").
|
|
165
|
+
const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
|
|
166
166
|
|
|
167
167
|
const result = await run.start({
|
|
168
168
|
inputData: {
|
|
@@ -172,7 +172,7 @@ const result = await run.start({
|
|
|
172
172
|
|
|
173
173
|
console.log(JSON.stringify(result, null, 2));
|
|
174
174
|
```
|
|
175
|
-
> see [
|
|
175
|
+
> see [createRunAsync](/reference/workflows/create-run-async) and [start](/reference/workflows/start) for more information.
|
|
176
176
|
|
|
177
177
|
To trigger this workflow, run the following:
|
|
178
178
|
|
|
@@ -182,6 +182,74 @@ npx tsx src/test-workflow.ts
|
|
|
182
182
|
|
|
183
183
|
</Steps>
|
|
184
184
|
|
|
185
|
+
#### Run Workflow Results
|
|
186
|
+
|
|
187
|
+
The result of running a workflow using either `start()` or `resume()` will look like one of the following, depending on the outcome.
|
|
188
|
+
|
|
189
|
+
##### Status success
|
|
190
|
+
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"status": "success",
|
|
194
|
+
"steps": {
|
|
195
|
+
// ...
|
|
196
|
+
"step-1": {
|
|
197
|
+
// ...
|
|
198
|
+
"status": "success",
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
"result": {
|
|
202
|
+
"output": "London + step-1"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
- **status**: Shows the final state of the workflow execution, either: `success`, `suspended`, or `error`
|
|
208
|
+
- **steps**: Lists each step in the workflow, including inputs and outputs
|
|
209
|
+
- **status**: Shows the outcome of each individual step
|
|
210
|
+
- **result**: Includes the final output of the workflow, typed according to the `outputSchema`
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
##### Status suspended
|
|
214
|
+
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"status": "suspended",
|
|
218
|
+
"steps": {
|
|
219
|
+
// ...
|
|
220
|
+
"step-1": {
|
|
221
|
+
// ...
|
|
222
|
+
"status": "suspended",
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
"suspended": [
|
|
226
|
+
[
|
|
227
|
+
"step-1"
|
|
228
|
+
]
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
- **suspended**: An optional array listing any steps currently awaiting input before continuing
|
|
234
|
+
|
|
235
|
+
##### Status failed
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"status": "failed",
|
|
240
|
+
"steps": {
|
|
241
|
+
// ...
|
|
242
|
+
"step-1": {
|
|
243
|
+
// ...
|
|
244
|
+
"status": "failed",
|
|
245
|
+
"error": "Test error",
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
"error": "Test error"
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
- **error**: An optional field that includes the error message if the workflow fails
|
|
252
|
+
|
|
185
253
|
### Stream Workflow
|
|
186
254
|
|
|
187
255
|
Similar to the run method shown above, workflows can also be streamed:
|
|
@@ -189,7 +257,7 @@ Similar to the run method shown above, workflows can also be streamed:
|
|
|
189
257
|
```typescript {5} filename="src/test-workflow.ts" showLineNumbers copy
|
|
190
258
|
import { mastra } from "./mastra";
|
|
191
259
|
|
|
192
|
-
const run = mastra.getWorkflow("testWorkflow").
|
|
260
|
+
const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
|
|
193
261
|
|
|
194
262
|
const result = await run.stream({
|
|
195
263
|
inputData: {
|
|
@@ -211,7 +279,7 @@ A workflow can also be watched, allowing you to inspect each event that is emitt
|
|
|
211
279
|
```typescript {5} filename="src/test-workflow.ts" showLineNumbers copy
|
|
212
280
|
import { mastra } from "./mastra";
|
|
213
281
|
|
|
214
|
-
const run = mastra.getWorkflow("testWorkflow").
|
|
282
|
+
const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
|
|
215
283
|
|
|
216
284
|
run.watch((event) => {
|
|
217
285
|
console.log(event);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Pausing Execution | Mastra Docs"
|
|
3
|
+
description: "Pausing execution in Mastra workflows allows you to pause execution while waiting for external input or resources via .sleep(), .sleepUntil() and .waitForEvent()."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Sleep & Events
|
|
7
|
+
|
|
8
|
+
Pausing execution in Mastra workflows allows you to pause execution while waiting for external input or resources via `sleep()`, `sleepUntil()` and `waitForEvent()`.
|
|
9
|
+
|
|
10
|
+
This sets the workflow status to `waiting`.
|
|
11
|
+
|
|
12
|
+
## sleep()
|
|
13
|
+
|
|
14
|
+
`sleep()` pauses execution for a specified number of milliseconds.
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
workflow
|
|
18
|
+
.then(step1)
|
|
19
|
+
.sleep(1000)
|
|
20
|
+
.then(step2)
|
|
21
|
+
.commit();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## sleepUntil()
|
|
25
|
+
|
|
26
|
+
`sleepUntil()` pauses execution until a specified date.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
workflow
|
|
30
|
+
.then(step1)
|
|
31
|
+
.sleepUntil(new Date(Date.now() + 1000))
|
|
32
|
+
.then(step2)
|
|
33
|
+
.commit();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## waitForEvent()
|
|
37
|
+
|
|
38
|
+
`waitForEvent()` pauses execution until an event is received. Events can be sent to the workflow using `run.sendEvent()`. The event name and the step to resume after the event is received are provided as arguments to `waitForEvent()`.
|
|
39
|
+
|
|
40
|
+
`.sendEvent()` takes as arguments the event name and the event data. The event data is optional and can be any JSON-serializable value.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
workflow
|
|
44
|
+
.then(step1)
|
|
45
|
+
.waitForEvent('my-event-name', step2)
|
|
46
|
+
.then(step3)
|
|
47
|
+
.commit();
|
|
48
|
+
|
|
49
|
+
const run = await workflow.createRunAsync()
|
|
50
|
+
run.start({})
|
|
51
|
+
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
run.sendEvent('my-event-name', {
|
|
54
|
+
data1: 'hello',
|
|
55
|
+
data2: {
|
|
56
|
+
anyData: 12
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}, 2e3)
|
|
60
|
+
```
|