@mastra/mcp-docs-server 1.0.0-beta.10 → 1.0.0-beta.13
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%2Fagent-builder.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +50 -50
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +109 -109
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +38 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +264 -264
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Flance.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +104 -104
- package/.docs/organized/changelogs/%40mastra%2Freact.md +66 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +59 -59
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +39 -39
- package/.docs/organized/changelogs/create-mastra.md +31 -31
- package/.docs/organized/changelogs/mastra.md +49 -49
- package/.docs/organized/code-examples/quick-start.md +0 -4
- package/.docs/organized/code-examples/stock-price-tool.md +21 -2
- package/.docs/raw/agents/agent-approval.mdx +136 -2
- package/.docs/raw/agents/agent-memory.mdx +4 -4
- package/.docs/raw/agents/guardrails.mdx +44 -7
- package/.docs/raw/agents/networks.mdx +1 -1
- package/.docs/raw/agents/overview.mdx +2 -2
- package/.docs/raw/agents/processors.mdx +151 -0
- package/.docs/raw/agents/using-tools.mdx +1 -1
- package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +1 -2
- package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +1 -1
- package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +1 -2
- package/.docs/raw/course/02-agent-tools-mcp/05-updating-your-agent.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/10-updating-agent-instructions-zapier.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/16-updating-agent-instructions-github.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/21-updating-agent-instructions-hackernews.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/27-updating-agent-instructions-filesystem.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +2 -2
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -2
- package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +1 -2
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +3 -4
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +2 -3
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +2 -3
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +1 -2
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +2 -3
- package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +2 -3
- package/.docs/raw/deployment/cloud-providers.mdx +20 -0
- package/.docs/raw/deployment/{building-mastra.mdx → mastra-server.mdx} +2 -2
- package/.docs/raw/deployment/monorepo.mdx +23 -44
- package/.docs/raw/deployment/overview.mdx +28 -53
- package/.docs/raw/deployment/web-framework.mdx +12 -14
- package/.docs/raw/getting-started/mcp-docs-server.mdx +57 -0
- package/.docs/raw/getting-started/start.mdx +10 -1
- package/.docs/raw/getting-started/studio.mdx +25 -2
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +1021 -67
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/aws-lambda.mdx +3 -6
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/azure-app-services.mdx +4 -6
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/cloudflare-deployer.mdx +4 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/digital-ocean.mdx +3 -6
- package/.docs/raw/guides/deployment/index.mdx +32 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/netlify-deployer.mdx +4 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/vercel-deployer.mdx +4 -0
- package/.docs/raw/guides/getting-started/express.mdx +71 -152
- package/.docs/raw/guides/getting-started/hono.mdx +227 -0
- package/.docs/raw/guides/getting-started/next-js.mdx +173 -63
- package/.docs/raw/guides/getting-started/vite-react.mdx +307 -137
- package/.docs/raw/guides/guide/research-assistant.mdx +4 -4
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +70 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +17 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +6 -0
- package/.docs/raw/index.mdx +1 -1
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/dashboard.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/observability.mdx +1 -5
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/overview.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/setting-up.mdx +3 -6
- package/.docs/raw/memory/overview.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-pg.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +1 -1
- package/.docs/raw/{server-db/storage.mdx → memory/storage/overview.mdx} +2 -2
- package/.docs/raw/observability/logging.mdx +1 -1
- package/.docs/raw/observability/tracing/exporters/cloud.mdx +1 -1
- package/.docs/raw/observability/tracing/exporters/default.mdx +1 -1
- package/.docs/raw/rag/chunking-and-embedding.mdx +12 -25
- package/.docs/raw/rag/graph-rag.mdx +220 -0
- package/.docs/raw/rag/overview.mdx +1 -2
- package/.docs/raw/rag/retrieval.mdx +13 -29
- package/.docs/raw/rag/vector-databases.mdx +7 -3
- package/.docs/raw/reference/agents/agent.mdx +11 -4
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +1 -1
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/getMemory.mdx +1 -1
- package/.docs/raw/reference/agents/getModel.mdx +1 -1
- package/.docs/raw/reference/agents/listScorers.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/network-route.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +127 -0
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +107 -0
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +1 -1
- package/.docs/raw/reference/auth/auth0.mdx +1 -1
- package/.docs/raw/reference/auth/clerk.mdx +1 -1
- package/.docs/raw/reference/auth/firebase.mdx +1 -1
- package/.docs/raw/reference/auth/jwt.mdx +1 -1
- package/.docs/raw/reference/auth/supabase.mdx +1 -1
- package/.docs/raw/reference/auth/workos.mdx +1 -1
- package/.docs/raw/reference/cli/mastra.mdx +1 -1
- package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
- package/.docs/raw/reference/client-js/workflows.mdx +20 -0
- package/.docs/raw/reference/core/getServer.mdx +3 -3
- package/.docs/raw/reference/core/getStorage.mdx +1 -1
- package/.docs/raw/reference/core/getStoredAgentById.mdx +1 -1
- package/.docs/raw/reference/core/listStoredAgents.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +1 -1
- package/.docs/raw/reference/processors/processor-interface.mdx +314 -13
- package/.docs/raw/reference/rag/database-config.mdx +1 -1
- package/.docs/raw/reference/server/create-route.mdx +1 -1
- package/.docs/raw/reference/server/express-adapter.mdx +4 -4
- package/.docs/raw/reference/server/hono-adapter.mdx +4 -4
- package/.docs/raw/reference/server/mastra-server.mdx +2 -2
- package/.docs/raw/reference/server/routes.mdx +28 -1
- package/.docs/raw/reference/streaming/ChunkType.mdx +23 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +38 -29
- package/.docs/raw/reference/streaming/workflows/stream.mdx +33 -20
- package/.docs/raw/reference/tools/create-tool.mdx +23 -1
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +3 -3
- package/.docs/raw/reference/tools/vector-query-tool.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +143 -0
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +35 -0
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +68 -3
- package/.docs/raw/reference/workflows/workflow.mdx +37 -0
- package/.docs/raw/{auth → server/auth}/auth0.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/clerk.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/firebase.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/index.mdx +6 -6
- package/.docs/raw/{auth → server/auth}/jwt.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/supabase.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/workos.mdx +1 -1
- package/.docs/raw/{server-db → server}/custom-adapters.mdx +3 -3
- package/.docs/raw/{server-db → server}/custom-api-routes.mdx +1 -1
- package/.docs/raw/{server-db → server}/mastra-client.mdx +2 -2
- package/.docs/raw/{server-db → server}/mastra-server.mdx +12 -10
- package/.docs/raw/{server-db → server}/middleware.mdx +2 -2
- package/.docs/raw/{server-db → server}/request-context.mdx +3 -3
- package/.docs/raw/{server-db → server}/server-adapters.mdx +6 -6
- package/.docs/raw/tools-mcp/overview.mdx +2 -2
- package/.docs/raw/workflows/control-flow.mdx +348 -2
- package/.docs/raw/workflows/error-handling.mdx +162 -1
- package/.docs/raw/workflows/overview.mdx +2 -2
- package/CHANGELOG.md +21 -0
- package/package.json +5 -5
- package/.docs/organized/changelogs/%40internal%2Fai-sdk-v4.md +0 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +0 -55
- /package/.docs/raw/{deployment/cloud-providers → guides/deployment}/amazon-ec2.mdx +0 -0
|
@@ -12,13 +12,7 @@ The `.stream()` method enables real-time streaming of responses from an agent wi
|
|
|
12
12
|
## Usage example
|
|
13
13
|
|
|
14
14
|
```ts title="index.ts" copy
|
|
15
|
-
|
|
16
|
-
const mastraStream = await agent.stream("message for agent");
|
|
17
|
-
|
|
18
|
-
// AI SDK v5 compatible format
|
|
19
|
-
const aiSdkStream = await agent.stream("message for agent", {
|
|
20
|
-
format: "aisdk",
|
|
21
|
-
});
|
|
15
|
+
const stream = await agent.stream("message for agent");
|
|
22
16
|
```
|
|
23
17
|
|
|
24
18
|
:::info
|
|
@@ -50,14 +44,6 @@ const aiSdkStream = await agent.stream("message for agent", {
|
|
|
50
44
|
|
|
51
45
|
<PropertiesTable
|
|
52
46
|
content={[
|
|
53
|
-
{
|
|
54
|
-
name: "format",
|
|
55
|
-
type: "'mastra' | 'aisdk'",
|
|
56
|
-
isOptional: true,
|
|
57
|
-
defaultValue: "'mastra'",
|
|
58
|
-
description:
|
|
59
|
-
"Determines the output stream format. Use 'mastra' for Mastra's native format (default) or 'aisdk' for AI SDK v5 compatibility.",
|
|
60
|
-
},
|
|
61
47
|
{
|
|
62
48
|
name: "maxSteps",
|
|
63
49
|
type: "number",
|
|
@@ -491,6 +477,27 @@ const aiSdkStream = await agent.stream("message for agent", {
|
|
|
491
477
|
description:
|
|
492
478
|
"Save messages incrementally after each stream step completes (default: false).",
|
|
493
479
|
},
|
|
480
|
+
{
|
|
481
|
+
name: "requireToolApproval",
|
|
482
|
+
type: "boolean",
|
|
483
|
+
isOptional: true,
|
|
484
|
+
description:
|
|
485
|
+
"When true, all tool calls require explicit approval before execution. The stream will emit `tool-call-approval` chunks and pause until `approveToolCall()` or `declineToolCall()` is called.",
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
name: "autoResumeSuspendedTools",
|
|
489
|
+
type: "boolean",
|
|
490
|
+
isOptional: true,
|
|
491
|
+
description:
|
|
492
|
+
"When true, automatically resumes suspended tools when the user sends a new message on the same thread. The agent extracts `resumeData` from the user's message based on the tool's `resumeSchema`. Requires memory to be configured.",
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
name: "toolCallConcurrency",
|
|
496
|
+
type: "number",
|
|
497
|
+
isOptional: true,
|
|
498
|
+
description:
|
|
499
|
+
"Maximum number of tool calls to execute concurrently. Defaults to 1 when approval may be required, otherwise 10.",
|
|
500
|
+
},
|
|
494
501
|
{
|
|
495
502
|
name: "providerOptions",
|
|
496
503
|
type: "Record<string, Record<string, JSONValue>>",
|
|
@@ -650,9 +657,9 @@ const aiSdkStream = await agent.stream("message for agent", {
|
|
|
650
657
|
content={[
|
|
651
658
|
{
|
|
652
659
|
name: "stream",
|
|
653
|
-
type: "MastraModelOutput<Output>
|
|
660
|
+
type: "MastraModelOutput<Output>",
|
|
654
661
|
description:
|
|
655
|
-
"Returns a
|
|
662
|
+
"Returns a MastraModelOutput instance that provides access to the streaming output.",
|
|
656
663
|
},
|
|
657
664
|
{
|
|
658
665
|
name: "traceId",
|
|
@@ -683,32 +690,34 @@ for await (const chunk of stream.textStream) {
|
|
|
683
690
|
console.log(chunk);
|
|
684
691
|
}
|
|
685
692
|
|
|
693
|
+
// or access full stream
|
|
694
|
+
for await (const chunk of stream.fullStream) {
|
|
695
|
+
console.log(chunk);
|
|
696
|
+
}
|
|
697
|
+
|
|
686
698
|
// Get full text after streaming
|
|
687
699
|
const fullText = await stream.text;
|
|
688
700
|
```
|
|
689
701
|
|
|
690
702
|
### AI SDK v5 Format
|
|
691
703
|
|
|
704
|
+
To use the stream with AI SDK v5, you can convert it using our utility function `toAISdkStream`.
|
|
705
|
+
|
|
692
706
|
```ts title="index.ts" showLineNumbers copy
|
|
693
|
-
import { stepCountIs } from "ai
|
|
707
|
+
import { stepCountIs, createUIMessageStreamResponse } from "ai";
|
|
708
|
+
import { toAISdkStream } from "@mastra/ai-sdk";
|
|
694
709
|
|
|
695
710
|
const stream = await agent.stream("Tell me a story", {
|
|
696
|
-
format: "aisdk",
|
|
697
711
|
stopWhen: stepCountIs(3), // Stop after 3 steps
|
|
698
712
|
modelSettings: {
|
|
699
713
|
temperature: 0.7,
|
|
700
714
|
},
|
|
701
715
|
});
|
|
702
716
|
|
|
703
|
-
// Use with AI SDK v5 compatible interfaces
|
|
704
|
-
for await (const part of stream.fullStream) {
|
|
705
|
-
if (part.type === "text-delta") {
|
|
706
|
-
console.log(part.text);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
717
|
// In an API route for frontend integration
|
|
711
|
-
return
|
|
718
|
+
return createUIMessageStreamResponse({
|
|
719
|
+
stream: toAISdkStream(stream, { from: "agent" }),
|
|
720
|
+
})
|
|
712
721
|
```
|
|
713
722
|
|
|
714
723
|
### Using Callbacks
|
|
@@ -744,10 +753,9 @@ for await (const chunk of stream.textStream) {
|
|
|
744
753
|
|
|
745
754
|
```ts title="index.ts" showLineNumbers copy
|
|
746
755
|
import { z } from "zod";
|
|
747
|
-
import { stepCountIs } from "ai
|
|
756
|
+
import { stepCountIs } from "ai";
|
|
748
757
|
|
|
749
758
|
await agent.stream("message for agent", {
|
|
750
|
-
format: "aisdk", // Enable AI SDK v5 compatibility
|
|
751
759
|
stopWhen: stepCountIs(3), // Stop after 3 steps
|
|
752
760
|
modelSettings: {
|
|
753
761
|
temperature: 0.7,
|
|
@@ -778,3 +786,4 @@ await agent.stream("message for agent", {
|
|
|
778
786
|
|
|
779
787
|
- [Generating responses](/docs/v1/agents/overview#generating-responses)
|
|
780
788
|
- [Streaming responses](/docs/v1/agents/overview#generating-responses)
|
|
789
|
+
- [Agent Approval](/docs/v1/agents/agent-approval)
|
|
@@ -5,18 +5,22 @@ description: Documentation for the `Run.stream()` method in workflows, which ena
|
|
|
5
5
|
|
|
6
6
|
# Run.stream()
|
|
7
7
|
|
|
8
|
-
The `.stream()` method enables real-time streaming of responses from a workflow.
|
|
8
|
+
The `.stream()` method enables real-time streaming of responses from a workflow. It returns a `ReadableStream` of events directly.
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
12
12
|
```typescript showLineNumbers copy
|
|
13
13
|
const run = await workflow.createRun();
|
|
14
14
|
|
|
15
|
-
const stream = run.stream({
|
|
15
|
+
const stream = await run.stream({
|
|
16
16
|
inputData: {
|
|
17
17
|
value: "initial data",
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
|
+
|
|
21
|
+
for await (const chunk of stream) {
|
|
22
|
+
console.log(chunk);
|
|
23
|
+
}
|
|
20
24
|
```
|
|
21
25
|
|
|
22
26
|
## Parameters
|
|
@@ -129,35 +133,30 @@ const stream = run.stream({
|
|
|
129
133
|
|
|
130
134
|
## Returns
|
|
131
135
|
|
|
136
|
+
Returns a `WorkflowRunOutput` object that implements the async iterable interface (can be used directly in `for await...of` loops) and provides access to the stream and workflow execution results.
|
|
137
|
+
|
|
132
138
|
<PropertiesTable
|
|
133
139
|
content={[
|
|
134
140
|
{
|
|
135
|
-
name: "
|
|
136
|
-
type: "
|
|
141
|
+
name: "fullStream",
|
|
142
|
+
type: "ReadableStream<WorkflowStreamEvent>",
|
|
137
143
|
description:
|
|
138
|
-
"A
|
|
144
|
+
"A ReadableStream of workflow events that you can iterate over to track progress in real-time. You can also iterate over the WorkflowRunOutput object directly.",
|
|
139
145
|
},
|
|
140
146
|
{
|
|
141
|
-
name: "
|
|
142
|
-
type: "Promise<
|
|
143
|
-
description: "A promise that resolves to the current workflow run status",
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
name: "stream.result",
|
|
147
|
-
type: "Promise<WorkflowResult<TState, TOutput, TSteps>>",
|
|
147
|
+
name: "result",
|
|
148
|
+
type: "Promise<WorkflowResult<TState, TInput, TOutput, TSteps>>",
|
|
148
149
|
description: "A promise that resolves to the final workflow result",
|
|
149
150
|
},
|
|
150
151
|
{
|
|
151
|
-
name: "
|
|
152
|
-
type: "
|
|
153
|
-
description: "
|
|
152
|
+
name: "status",
|
|
153
|
+
type: "WorkflowRunStatus",
|
|
154
|
+
description: "The current workflow run status ('running', 'suspended', 'success', 'failed', 'canceled', or 'tripwire')",
|
|
154
155
|
},
|
|
155
156
|
{
|
|
156
|
-
name: "
|
|
157
|
-
type: "
|
|
158
|
-
|
|
159
|
-
description:
|
|
160
|
-
"The trace ID associated with this execution when Tracing is enabled.",
|
|
157
|
+
name: "usage",
|
|
158
|
+
type: "Promise<{ inputTokens: number; outputTokens: number; totalTokens: number, reasoningTokens?: number, cachedInputTokens?: number }>",
|
|
159
|
+
description: "A promise that resolves to token usage statistics",
|
|
161
160
|
},
|
|
162
161
|
]}
|
|
163
162
|
/>
|
|
@@ -173,7 +172,21 @@ const stream = run.stream({
|
|
|
173
172
|
},
|
|
174
173
|
});
|
|
175
174
|
|
|
175
|
+
// Iterate over stream events (you can iterate over stream directly or use stream.fullStream)
|
|
176
|
+
for await (const chunk of stream) {
|
|
177
|
+
console.log(chunk);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Access the final result
|
|
176
181
|
const result = await stream.result;
|
|
182
|
+
console.log("Final result:", result);
|
|
183
|
+
|
|
184
|
+
// Access token usage
|
|
185
|
+
const usage = await stream.usage;
|
|
186
|
+
console.log("Token usage:", usage);
|
|
187
|
+
|
|
188
|
+
// Check current status
|
|
189
|
+
console.log("Status:", stream.status);
|
|
177
190
|
```
|
|
178
191
|
|
|
179
192
|
## Stream Events
|
|
@@ -63,6 +63,27 @@ export const tool = createTool({
|
|
|
63
63
|
"A Zod schema defining the expected output structure of the tool's `execute` function.",
|
|
64
64
|
isOptional: true,
|
|
65
65
|
},
|
|
66
|
+
{
|
|
67
|
+
name: "suspendSchema",
|
|
68
|
+
type: "Zod schema",
|
|
69
|
+
description:
|
|
70
|
+
"A Zod schema defining the structure of the payload passed to `suspend()`. This payload is returned to the client when the tool suspends execution.",
|
|
71
|
+
isOptional: true,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "resumeSchema",
|
|
75
|
+
type: "Zod schema",
|
|
76
|
+
description:
|
|
77
|
+
"A Zod 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.",
|
|
78
|
+
isOptional: true,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "requireApproval",
|
|
82
|
+
type: "boolean",
|
|
83
|
+
description:
|
|
84
|
+
"When true, the tool requires explicit approval before execution. The agent will emit a `tool-call-approval` chunk and pause until approved or declined.",
|
|
85
|
+
isOptional: true,
|
|
86
|
+
},
|
|
66
87
|
{
|
|
67
88
|
name: "execute",
|
|
68
89
|
type: "function",
|
|
@@ -284,5 +305,6 @@ Hook errors are caught and logged automatically, but do not prevent tool executi
|
|
|
284
305
|
|
|
285
306
|
- [MCP Overview](/docs/v1/mcp/overview)
|
|
286
307
|
- [Using Tools with Agents](/docs/v1/agents/using-tools)
|
|
308
|
+
- [Agent Approval](/docs/v1/agents/agent-approval)
|
|
287
309
|
- [Tool Streaming](/docs/v1/streaming/tool-streaming)
|
|
288
|
-
- [Request Context](/docs/v1/server
|
|
310
|
+
- [Request Context](/docs/v1/server/request-context#accessing-values-with-tools)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Reference: createGraphRAGTool() | Tools & MCP"
|
|
3
|
-
description: Documentation for the
|
|
3
|
+
description: Documentation for the GraphRAG Tool in Mastra, which enhances RAG by building a graph of semantic relationships between documents.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# createGraphRAGTool()
|
|
@@ -253,8 +253,8 @@ const response = await agent.generate(
|
|
|
253
253
|
|
|
254
254
|
For more information on request context, please see:
|
|
255
255
|
|
|
256
|
-
- [Agent Request Context](/docs/v1/server
|
|
257
|
-
- [Request Context](/docs/v1/server
|
|
256
|
+
- [Agent Request Context](/docs/v1/server/request-context)
|
|
257
|
+
- [Request Context](/docs/v1/server/request-context#accessing-values-with-tools)
|
|
258
258
|
|
|
259
259
|
## Related
|
|
260
260
|
|
|
@@ -326,7 +326,7 @@ This agent-driven approach:
|
|
|
326
326
|
|
|
327
327
|
For detailed filter syntax and store-specific capabilities, see the [Metadata Filters](../rag/metadata-filters) documentation.
|
|
328
328
|
|
|
329
|
-
For an example of how agent-driven filtering works, see the [Agent-Driven Metadata Filtering](/examples/
|
|
329
|
+
For an example of how agent-driven filtering works, see the [Agent-Driven Metadata Filtering](https://github.com/mastra-ai/mastra/tree/main/examples/basics/rag/filter-rag) example.
|
|
330
330
|
|
|
331
331
|
## Example with Reranking
|
|
332
332
|
|
|
@@ -567,8 +567,8 @@ const response = await agent.generate(
|
|
|
567
567
|
|
|
568
568
|
For more information on request context, please see:
|
|
569
569
|
|
|
570
|
-
- [Agent Request Context](/docs/v1/server
|
|
571
|
-
- [Request Context](/docs/v1/server
|
|
570
|
+
- [Agent Request Context](/docs/v1/server/request-context)
|
|
571
|
+
- [Request Context](/docs/v1/server/request-context#accessing-values-with-tools)
|
|
572
572
|
|
|
573
573
|
## Usage Without a Mastra Server
|
|
574
574
|
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Run.startAsync() | Workflows"
|
|
3
|
+
description: Documentation for the `Run.startAsync()` method in workflows, which starts a workflow run without waiting for completion (fire-and-forget).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Run.startAsync()
|
|
7
|
+
|
|
8
|
+
The `.startAsync()` method starts a workflow run without waiting for completion. It returns immediately with the `runId`, allowing the workflow to execute in the background. This is useful for long-running workflows, scheduled tasks, or when you want to avoid blocking on workflow completion.
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const run = await workflow.createRun();
|
|
14
|
+
|
|
15
|
+
// Fire-and-forget - returns immediately
|
|
16
|
+
const { runId } = await run.startAsync({
|
|
17
|
+
inputData: {
|
|
18
|
+
value: "initial data",
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Optionally poll for completion later
|
|
23
|
+
const result = await workflow.getWorkflowRunExecutionResult(runId);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Parameters
|
|
27
|
+
|
|
28
|
+
<PropertiesTable
|
|
29
|
+
content={[
|
|
30
|
+
{
|
|
31
|
+
name: "inputData",
|
|
32
|
+
type: "z.infer<TInput>",
|
|
33
|
+
description: "Input data that matches the workflow's input schema",
|
|
34
|
+
isOptional: true,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "requestContext",
|
|
38
|
+
type: "RequestContext",
|
|
39
|
+
description: "Request Context data to use during workflow execution",
|
|
40
|
+
isOptional: true,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "initialState",
|
|
44
|
+
type: "z.infer<TState>",
|
|
45
|
+
description: "Initial state to use for the workflow execution",
|
|
46
|
+
isOptional: true,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "tracingOptions",
|
|
50
|
+
type: "TracingOptions",
|
|
51
|
+
isOptional: true,
|
|
52
|
+
description: "Options for Tracing configuration.",
|
|
53
|
+
properties: [
|
|
54
|
+
{
|
|
55
|
+
parameters: [
|
|
56
|
+
{
|
|
57
|
+
name: "metadata",
|
|
58
|
+
type: "Record<string, any>",
|
|
59
|
+
isOptional: true,
|
|
60
|
+
description:
|
|
61
|
+
"Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags.",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
parameters: [
|
|
67
|
+
{
|
|
68
|
+
name: "traceId",
|
|
69
|
+
type: "string",
|
|
70
|
+
isOptional: true,
|
|
71
|
+
description:
|
|
72
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "outputOptions",
|
|
80
|
+
type: "OutputOptions",
|
|
81
|
+
isOptional: true,
|
|
82
|
+
description: "Options for output configuration.",
|
|
83
|
+
properties: [
|
|
84
|
+
{
|
|
85
|
+
parameters: [
|
|
86
|
+
{
|
|
87
|
+
name: "includeState",
|
|
88
|
+
type: "boolean",
|
|
89
|
+
isOptional: true,
|
|
90
|
+
description:
|
|
91
|
+
"Whether to include the workflow run state in the result.",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
]}
|
|
98
|
+
/>
|
|
99
|
+
|
|
100
|
+
## Returns
|
|
101
|
+
|
|
102
|
+
<PropertiesTable
|
|
103
|
+
content={[
|
|
104
|
+
{
|
|
105
|
+
name: "runId",
|
|
106
|
+
type: "string",
|
|
107
|
+
description:
|
|
108
|
+
"The unique identifier for this workflow run. Use this to check status or retrieve results later.",
|
|
109
|
+
},
|
|
110
|
+
]}
|
|
111
|
+
/>
|
|
112
|
+
|
|
113
|
+
## When to use startAsync()
|
|
114
|
+
|
|
115
|
+
Use `startAsync()` instead of `start()` when:
|
|
116
|
+
|
|
117
|
+
- **Long-running workflows**: The workflow may take minutes or hours to complete
|
|
118
|
+
- **Scheduled/cron triggers**: You want to trigger a workflow without blocking the scheduler
|
|
119
|
+
- **Avoiding polling failures**: With Inngest workflows, `start()` polls for completion which can fail and cause retries. `startAsync()` avoids this issue
|
|
120
|
+
- **Background processing**: You want to queue work and handle results asynchronously
|
|
121
|
+
|
|
122
|
+
## Checking workflow status
|
|
123
|
+
|
|
124
|
+
After calling `startAsync()`, you can check the workflow status using:
|
|
125
|
+
|
|
126
|
+
```typescript showLineNumbers copy
|
|
127
|
+
// Get the execution result (including step outputs)
|
|
128
|
+
const result = await workflow.getWorkflowRunExecutionResult(runId);
|
|
129
|
+
|
|
130
|
+
if (result?.status === 'success') {
|
|
131
|
+
console.log('Workflow completed:', result.steps);
|
|
132
|
+
} else if (result?.status === 'failed') {
|
|
133
|
+
console.log('Workflow failed:', result.error);
|
|
134
|
+
} else if (result?.status === 'running') {
|
|
135
|
+
console.log('Workflow still running...');
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Related
|
|
140
|
+
|
|
141
|
+
- [Run.start()](./start) - Start a workflow and wait for completion
|
|
142
|
+
- [Workflows overview](/docs/v1/workflows/overview)
|
|
143
|
+
- [Workflow.createRun()](../workflow-methods/create-run)
|
|
@@ -23,6 +23,18 @@ await workflow.createRun();
|
|
|
23
23
|
description: "Optional custom identifier for the workflow run",
|
|
24
24
|
isOptional: true,
|
|
25
25
|
},
|
|
26
|
+
{
|
|
27
|
+
name: "resourceId",
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Optional identifier to associate the workflow run with a specific resource (e.g., user ID, tenant ID). This value is persisted with the workflow run and can be used for filtering and querying runs.",
|
|
30
|
+
isOptional: true,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "disableScorers",
|
|
34
|
+
type: "boolean",
|
|
35
|
+
description: "Optional flag to disable scorers for this workflow run",
|
|
36
|
+
isOptional: true,
|
|
37
|
+
},
|
|
26
38
|
]}
|
|
27
39
|
/>
|
|
28
40
|
|
|
@@ -53,6 +65,29 @@ const result = await run.start({
|
|
|
53
65
|
});
|
|
54
66
|
```
|
|
55
67
|
|
|
68
|
+
## Using resourceId
|
|
69
|
+
|
|
70
|
+
The `resourceId` parameter associates a workflow run with a specific resource, such as a user or tenant. This is useful for multi-tenant applications or when you need to track which user initiated a workflow.
|
|
71
|
+
|
|
72
|
+
```typescript showLineNumbers copy
|
|
73
|
+
const workflow = mastra.getWorkflow("workflow");
|
|
74
|
+
|
|
75
|
+
// Create a run associated with a specific user
|
|
76
|
+
const run = await workflow.createRun({
|
|
77
|
+
resourceId: "user-123",
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const result = await run.start({
|
|
81
|
+
inputData: {
|
|
82
|
+
value: 10,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Later, retrieve the run and access the resourceId
|
|
87
|
+
const storedRun = await workflow.getWorkflowRunById(run.runId);
|
|
88
|
+
console.log(storedRun.resourceId); // "user-123"
|
|
89
|
+
```
|
|
90
|
+
|
|
56
91
|
## Related
|
|
57
92
|
|
|
58
93
|
- [Run Class](../run)
|
|
@@ -5,7 +5,7 @@ description: Documentation for the `Workflow.foreach()` method in workflows, whi
|
|
|
5
5
|
|
|
6
6
|
# Workflow.foreach()
|
|
7
7
|
|
|
8
|
-
The `.foreach()` method creates a loop that executes a step for each item in an array.
|
|
8
|
+
The `.foreach()` method creates a loop that executes a step for each item in an array. It always returns an array containing the output from each iteration, preserving the original order.
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
@@ -50,11 +50,76 @@ workflow.foreach(step1, { concurrency: 2 });
|
|
|
50
50
|
{
|
|
51
51
|
name: "workflow",
|
|
52
52
|
type: "Workflow",
|
|
53
|
-
description: "The workflow instance for method chaining",
|
|
53
|
+
description: "The workflow instance for method chaining. The output type is an array of the step's output type.",
|
|
54
54
|
},
|
|
55
55
|
]}
|
|
56
56
|
/>
|
|
57
57
|
|
|
58
|
+
## Behavior
|
|
59
|
+
|
|
60
|
+
### Execution and waiting
|
|
61
|
+
|
|
62
|
+
The `.foreach()` method processes all items before the next step executes. The step following `.foreach()` only runs after every iteration has completed, regardless of concurrency settings. With `concurrency: 1` (default), items process sequentially. With higher concurrency, items process in parallel batches, but the next step still waits for all batches to finish.
|
|
63
|
+
|
|
64
|
+
If you need to run multiple operations per item, use a nested workflow as the step. This keeps all operations for each item together and is cleaner than chaining multiple `.foreach()` calls. See [Nested workflows inside foreach](/docs/v1/workflows/control-flow#nested-workflows-inside-foreach) for examples.
|
|
65
|
+
|
|
66
|
+
### Output structure
|
|
67
|
+
|
|
68
|
+
`.foreach()` always outputs an array. Each element in the output array corresponds to the result of processing the element at the same index in the input array.
|
|
69
|
+
|
|
70
|
+
```typescript copy
|
|
71
|
+
// Input: [{ value: 1 }, { value: 2 }, { value: 3 }]
|
|
72
|
+
// Step adds 10 to each value
|
|
73
|
+
// Output: [{ value: 11 }, { value: 12 }, { value: 13 }]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Using `.then()` after `.foreach()`
|
|
77
|
+
|
|
78
|
+
When you chain `.then()` after `.foreach()`, the next step receives the entire output array as its input. This allows you to aggregate or process all results together.
|
|
79
|
+
|
|
80
|
+
```typescript copy
|
|
81
|
+
workflow
|
|
82
|
+
.foreach(processItemStep) // Output: array of processed items
|
|
83
|
+
.then(aggregateStep) // Input: the entire array
|
|
84
|
+
.commit();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Using `.map()` after `.foreach()`
|
|
88
|
+
|
|
89
|
+
Use `.map()` to transform the array output before passing it to the next step:
|
|
90
|
+
|
|
91
|
+
```typescript copy
|
|
92
|
+
workflow
|
|
93
|
+
.foreach(processItemStep)
|
|
94
|
+
.map(async ({ inputData }) => ({
|
|
95
|
+
total: inputData.reduce((sum, item) => sum + item.value, 0),
|
|
96
|
+
count: inputData.length
|
|
97
|
+
}))
|
|
98
|
+
.then(nextStep)
|
|
99
|
+
.commit();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Chaining multiple `.foreach()` calls
|
|
103
|
+
|
|
104
|
+
When you chain `.foreach()` calls, each operates on the array from the previous step:
|
|
105
|
+
|
|
106
|
+
```typescript copy
|
|
107
|
+
workflow
|
|
108
|
+
.foreach(stepA) // If input is [a, b, c], output is [A, B, C]
|
|
109
|
+
.foreach(stepB) // Operates on [A, B, C], output is [A', B', C']
|
|
110
|
+
.commit();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
If a step inside `.foreach()` returns an array, the output becomes an array of arrays. Use `.map()` with `.flat()` to flatten:
|
|
114
|
+
|
|
115
|
+
```typescript copy
|
|
116
|
+
workflow
|
|
117
|
+
.foreach(chunkStep) // Output: [[chunk1, chunk2], [chunk3, chunk4]]
|
|
118
|
+
.map(async ({ inputData }) => inputData.flat()) // Output: [chunk1, chunk2, chunk3, chunk4]
|
|
119
|
+
.foreach(embedStep)
|
|
120
|
+
.commit();
|
|
121
|
+
```
|
|
122
|
+
|
|
58
123
|
## Related
|
|
59
124
|
|
|
60
|
-
- [
|
|
125
|
+
- [Looping with foreach](/docs/v1/workflows/control-flow#looping-with-foreach)
|
|
@@ -85,6 +85,20 @@ export const workflow = createWorkflow({
|
|
|
85
85
|
isOptional: true,
|
|
86
86
|
defaultValue: "() => true",
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
name: "onFinish",
|
|
90
|
+
type: "(result: WorkflowFinishCallbackResult) => void | Promise<void>",
|
|
91
|
+
description:
|
|
92
|
+
"Callback invoked when workflow completes with any status (success, failed, suspended, tripwire). Receives the workflow result including status, output, error, and step results. Errors thrown in this callback are caught and logged, not propagated.",
|
|
93
|
+
isOptional: true,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "onError",
|
|
97
|
+
type: "(errorInfo: WorkflowErrorCallbackInfo) => void | Promise<void>",
|
|
98
|
+
description:
|
|
99
|
+
"Callback invoked only when workflow fails (failed or tripwire status). Receives error details and step results. Errors thrown in this callback are caught and logged, not propagated.",
|
|
100
|
+
isOptional: true,
|
|
101
|
+
},
|
|
88
102
|
]}
|
|
89
103
|
/>
|
|
90
104
|
|
|
@@ -130,9 +144,32 @@ A workflow's `status` indicates its current execution state. The possible values
|
|
|
130
144
|
description:
|
|
131
145
|
"Workflow execution is paused waiting for resume, with suspended step information",
|
|
132
146
|
},
|
|
147
|
+
{
|
|
148
|
+
name: "tripwire",
|
|
149
|
+
type: "string",
|
|
150
|
+
description:
|
|
151
|
+
"Workflow was terminated by a processor tripwire. This occurs when an agent step within the workflow triggers a tripwire (e.g., content was blocked by a guardrail). The tripwire information is available on the result.",
|
|
152
|
+
},
|
|
133
153
|
]}
|
|
134
154
|
/>
|
|
135
155
|
|
|
156
|
+
### Handling tripwire status
|
|
157
|
+
|
|
158
|
+
When a workflow contains an agent step that triggers a tripwire, the workflow returns with `status: 'tripwire'` and includes tripwire details:
|
|
159
|
+
|
|
160
|
+
```typescript showLineNumbers copy
|
|
161
|
+
const run = await workflow.createRun();
|
|
162
|
+
const result = await run.start({ inputData: { message: "Hello" } });
|
|
163
|
+
|
|
164
|
+
if (result.status === "tripwire") {
|
|
165
|
+
console.log("Workflow terminated by tripwire:", result.tripwire?.reason);
|
|
166
|
+
console.log("Processor ID:", result.tripwire?.processorId);
|
|
167
|
+
console.log("Retry requested:", result.tripwire?.retry);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
This is distinct from `status: 'failed'` which indicates an unexpected error. A tripwire status means a processor intentionally stopped execution (e.g., for content moderation).
|
|
172
|
+
|
|
136
173
|
## Related
|
|
137
174
|
|
|
138
175
|
- [Step Class](./step)
|
|
@@ -170,7 +170,7 @@ export const createMastraClient = (accessToken: string) => {
|
|
|
170
170
|
|
|
171
171
|
> **Note:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
172
172
|
|
|
173
|
-
> See [Mastra Client SDK](/docs/v1/server
|
|
173
|
+
> See [Mastra Client SDK](/docs/v1/server/mastra-client) for more configuration options.
|
|
174
174
|
|
|
175
175
|
### Making authenticated requests
|
|
176
176
|
|
|
@@ -93,7 +93,7 @@ export const mastraClient = new MastraClient({
|
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
> **Note:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
96
|
-
> See [Mastra Client SDK](/docs/v1/server
|
|
96
|
+
> See [Mastra Client SDK](/docs/v1/server/mastra-client) for more configuration options.
|
|
97
97
|
|
|
98
98
|
### Making authenticated requests
|
|
99
99
|
|
|
@@ -190,7 +190,7 @@ export const createMastraClient = (idToken: string) => {
|
|
|
190
190
|
|
|
191
191
|
> **Note:** The ID token must be prefixed with `Bearer` in the Authorization header.
|
|
192
192
|
|
|
193
|
-
> See [Mastra Client SDK](/docs/v1/server
|
|
193
|
+
> See [Mastra Client SDK](/docs/v1/server/mastra-client) for more configuration options.
|
|
194
194
|
|
|
195
195
|
### Making authenticated requests
|
|
196
196
|
|