@mastra/mcp-docs-server 1.0.0-beta.5 → 1.0.0-beta.7
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 +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +67 -67
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +110 -110
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fcodemod.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +60 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +358 -358
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +79 -79
- package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +61 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Flance.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +55 -55
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +125 -125
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +59 -59
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +77 -77
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Frag.md +43 -43
- package/.docs/organized/changelogs/%40mastra%2Freact.md +16 -0
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +113 -113
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +57 -57
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +19 -19
- package/.docs/organized/changelogs/create-mastra.md +15 -15
- package/.docs/organized/changelogs/mastra.md +30 -30
- package/.docs/organized/code-examples/agui.md +1 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
- package/.docs/organized/code-examples/ai-sdk-v5.md +2 -1
- package/.docs/organized/code-examples/assistant-ui.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +1 -1
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +1 -1
- package/.docs/organized/code-examples/crypto-chatbot.md +1 -1
- package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
- package/.docs/organized/code-examples/server-app-access.md +342 -0
- package/.docs/organized/code-examples/server-express-adapter.md +87 -0
- package/.docs/organized/code-examples/server-hono-adapter.md +85 -0
- package/.docs/raw/agents/agent-approval.mdx +189 -0
- package/.docs/raw/agents/guardrails.mdx +13 -9
- package/.docs/raw/agents/networks.mdx +1 -0
- package/.docs/raw/agents/overview.mdx +8 -152
- package/.docs/raw/agents/processors.mdx +279 -0
- package/.docs/raw/agents/structured-output.mdx +224 -0
- package/.docs/raw/deployment/cloud-providers/index.mdx +19 -26
- package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
- package/.docs/raw/evals/running-in-ci.mdx +0 -2
- package/.docs/raw/{guides/getting-started → getting-started}/manual-install.mdx +2 -2
- package/.docs/raw/getting-started/start.mdx +1 -1
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +8 -0
- package/.docs/raw/guides/getting-started/quickstart.mdx +1 -1
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
- package/.docs/raw/guides/index.mdx +3 -35
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +11 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +37 -0
- package/.docs/raw/index.mdx +1 -1
- package/.docs/raw/memory/memory-processors.mdx +265 -79
- package/.docs/raw/memory/working-memory.mdx +11 -2
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +200 -0
- package/.docs/raw/observability/tracing/exporters/arize.mdx +36 -0
- package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +83 -0
- package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
- package/.docs/raw/observability/tracing/exporters/otel.mdx +34 -22
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +20 -0
- package/.docs/raw/observability/tracing/overview.mdx +76 -6
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
- package/.docs/raw/rag/retrieval.mdx +23 -6
- package/.docs/raw/rag/vector-databases.mdx +93 -2
- package/.docs/raw/reference/agents/generate.mdx +55 -6
- package/.docs/raw/reference/agents/network.mdx +44 -0
- package/.docs/raw/reference/client-js/memory.mdx +43 -0
- package/.docs/raw/reference/client-js/workflows.mdx +92 -63
- package/.docs/raw/reference/deployer/netlify.mdx +1 -2
- package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
- package/.docs/raw/reference/index.mdx +1 -0
- package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +177 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +29 -0
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +43 -0
- package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
- package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +33 -43
- package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
- package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
- package/.docs/raw/reference/processors/language-detector.mdx +9 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
- package/.docs/raw/reference/processors/moderation-processor.mdx +10 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +10 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +9 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
- package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
- package/.docs/raw/reference/server/create-route.mdx +314 -0
- package/.docs/raw/reference/server/express-adapter.mdx +193 -0
- package/.docs/raw/reference/server/hono-adapter.mdx +174 -0
- package/.docs/raw/reference/server/mastra-server.mdx +316 -0
- package/.docs/raw/reference/server/routes.mdx +250 -0
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
- package/.docs/raw/reference/storage/convex.mdx +164 -0
- package/.docs/raw/reference/storage/lance.mdx +33 -0
- package/.docs/raw/reference/storage/libsql.mdx +37 -0
- package/.docs/raw/reference/storage/mongodb.mdx +39 -0
- package/.docs/raw/reference/storage/mssql.mdx +37 -0
- package/.docs/raw/reference/storage/postgresql.mdx +37 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +56 -1
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
- package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
- package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +170 -0
- package/.docs/raw/reference/tools/mcp-client.mdx +128 -18
- package/.docs/raw/reference/vectors/convex.mdx +429 -0
- package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
- package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
- package/.docs/raw/reference/voice/google.mdx +159 -20
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +310 -0
- package/.docs/raw/reference/workflows/run.mdx +27 -5
- package/.docs/raw/reference/workflows/step.mdx +13 -0
- package/.docs/raw/reference/workflows/workflow.mdx +19 -0
- package/.docs/raw/server-db/custom-adapters.mdx +380 -0
- package/.docs/raw/server-db/mastra-server.mdx +16 -8
- package/.docs/raw/server-db/request-context.mdx +0 -1
- package/.docs/raw/server-db/server-adapters.mdx +286 -0
- package/.docs/raw/server-db/storage.mdx +11 -0
- package/.docs/raw/streaming/overview.mdx +6 -6
- package/.docs/raw/streaming/tool-streaming.mdx +2 -2
- package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
- package/.docs/raw/workflows/error-handling.mdx +1 -0
- package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
- package/.docs/raw/workflows/overview.mdx +56 -44
- package/.docs/raw/workflows/snapshots.mdx +1 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
- package/.docs/raw/workflows/time-travel.mdx +313 -0
- package/.docs/raw/workflows/workflow-state.mdx +191 -0
- package/CHANGELOG.md +16 -0
- package/package.json +4 -4
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -91
- package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Reference: Run.stream() | Streaming"
|
|
3
|
-
description: Documentation for the `Run.stream()` method in workflows, which
|
|
3
|
+
description: Documentation for the `Run.stream()` method in workflows, which enables real-time streaming of responses.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Run.stream()
|
|
7
7
|
|
|
8
|
-
The `.stream()` method
|
|
8
|
+
The `.stream()` method enables real-time streaming of responses from a workflow.
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
12
12
|
```typescript showLineNumbers copy
|
|
13
13
|
const run = await workflow.createRun();
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const stream = run.stream({
|
|
16
16
|
inputData: {
|
|
17
17
|
value: "initial data",
|
|
18
18
|
},
|
|
@@ -40,7 +40,7 @@ const { stream } = await run.stream({
|
|
|
40
40
|
type: "TracingContext",
|
|
41
41
|
isOptional: true,
|
|
42
42
|
description:
|
|
43
|
-
"Tracing context for creating child spans and adding metadata.
|
|
43
|
+
"Tracing context for creating child spans and adding metadata.",
|
|
44
44
|
properties: [
|
|
45
45
|
{
|
|
46
46
|
parameters: [
|
|
@@ -49,7 +49,7 @@ const { stream } = await run.stream({
|
|
|
49
49
|
type: "Span",
|
|
50
50
|
isOptional: true,
|
|
51
51
|
description:
|
|
52
|
-
"Current span for creating child spans and adding metadata.
|
|
52
|
+
"Current span for creating child spans and adding metadata.",
|
|
53
53
|
},
|
|
54
54
|
],
|
|
55
55
|
},
|
|
@@ -67,13 +67,63 @@ const { stream } = await run.stream({
|
|
|
67
67
|
name: "metadata",
|
|
68
68
|
type: "Record<string, any>",
|
|
69
69
|
isOptional: true,
|
|
70
|
+
description: "Metadata to add to the root trace span.",
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
parameters: [
|
|
76
|
+
{
|
|
77
|
+
name: "requestContextKeys",
|
|
78
|
+
type: "string[]",
|
|
79
|
+
isOptional: true,
|
|
80
|
+
description:
|
|
81
|
+
"Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
parameters: [
|
|
87
|
+
{
|
|
88
|
+
name: "traceId",
|
|
89
|
+
type: "string",
|
|
90
|
+
isOptional: true,
|
|
91
|
+
description:
|
|
92
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
parameters: [
|
|
98
|
+
{
|
|
99
|
+
name: "parentSpanId",
|
|
100
|
+
type: "string",
|
|
101
|
+
isOptional: true,
|
|
70
102
|
description:
|
|
71
|
-
"
|
|
103
|
+
"Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.",
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
parameters: [
|
|
109
|
+
{
|
|
110
|
+
name: "tags",
|
|
111
|
+
type: "string[]",
|
|
112
|
+
isOptional: true,
|
|
113
|
+
description:
|
|
114
|
+
"Tags to apply to this trace. String labels for categorizing and filtering traces.",
|
|
72
115
|
},
|
|
73
116
|
],
|
|
74
117
|
},
|
|
75
118
|
],
|
|
76
119
|
},
|
|
120
|
+
{
|
|
121
|
+
name: "closeOnSuspend",
|
|
122
|
+
type: "boolean",
|
|
123
|
+
description:
|
|
124
|
+
"Whether to close the stream when the workflow is suspended, or to keep the stream open until the workflow is finished (by success or error). Default value is true.",
|
|
125
|
+
isOptional: true,
|
|
126
|
+
},
|
|
77
127
|
]}
|
|
78
128
|
/>
|
|
79
129
|
|
|
@@ -83,22 +133,31 @@ const { stream } = await run.stream({
|
|
|
83
133
|
content={[
|
|
84
134
|
{
|
|
85
135
|
name: "stream",
|
|
86
|
-
type: "
|
|
136
|
+
type: "MastraWorkflowStream<ChunkType>",
|
|
87
137
|
description:
|
|
88
|
-
"A
|
|
138
|
+
"A custom stream that extends ReadableStream<ChunkType> with additional workflow-specific properties",
|
|
89
139
|
},
|
|
90
140
|
{
|
|
91
|
-
name: "
|
|
92
|
-
type: "
|
|
93
|
-
description:
|
|
94
|
-
|
|
141
|
+
name: "stream.status",
|
|
142
|
+
type: "Promise<RunStatus>",
|
|
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>>",
|
|
148
|
+
description: "A promise that resolves to the final workflow result",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "stream.usage",
|
|
152
|
+
type: "Promise<{ inputTokens: number; outputTokens: number; totalTokens: number, reasoningTokens?: number, cacheInputTokens?: number }>",
|
|
153
|
+
description: "A promise that resolves to token usage statistics",
|
|
95
154
|
},
|
|
96
155
|
{
|
|
97
|
-
name: "traceId",
|
|
156
|
+
name: "stream.traceId",
|
|
98
157
|
type: "string",
|
|
99
158
|
isOptional: true,
|
|
100
159
|
description:
|
|
101
|
-
"The trace ID associated with this execution when Tracing is enabled.
|
|
160
|
+
"The trace ID associated with this execution when Tracing is enabled.",
|
|
102
161
|
},
|
|
103
162
|
]}
|
|
104
163
|
/>
|
|
@@ -106,29 +165,29 @@ const { stream } = await run.stream({
|
|
|
106
165
|
## Extended usage example
|
|
107
166
|
|
|
108
167
|
```typescript showLineNumbers copy
|
|
109
|
-
const
|
|
168
|
+
const run = await workflow.createRun();
|
|
169
|
+
|
|
170
|
+
const stream = run.stream({
|
|
110
171
|
inputData: {
|
|
111
172
|
value: "initial data",
|
|
112
173
|
},
|
|
113
174
|
});
|
|
114
175
|
|
|
115
|
-
const result = await
|
|
176
|
+
const result = await stream.result;
|
|
116
177
|
```
|
|
117
178
|
|
|
118
179
|
## Stream Events
|
|
119
180
|
|
|
120
181
|
The stream emits various event types during workflow execution. Each event has a `type` field and a `payload` containing relevant data:
|
|
121
182
|
|
|
122
|
-
- **`start`**: Workflow execution begins
|
|
123
|
-
- **`step-start`**: A step begins execution
|
|
124
|
-
- **`
|
|
125
|
-
- **`
|
|
126
|
-
- **`
|
|
127
|
-
- **`step-result`**: A step completes with results
|
|
128
|
-
- **`step-finish`**: A step finishes execution
|
|
129
|
-
- **`finish`**: Workflow execution completes
|
|
183
|
+
- **`workflow-start`**: Workflow execution begins
|
|
184
|
+
- **`workflow-step-start`**: A step begins execution
|
|
185
|
+
- **`workflow-step-output`**: Custom output from a step
|
|
186
|
+
- **`workflow-step-result`**: A step completes with results
|
|
187
|
+
- **`workflow-finish`**: Workflow execution completes with usage statistics
|
|
130
188
|
|
|
131
189
|
## Related
|
|
132
190
|
|
|
133
191
|
- [Workflows overview](/docs/v1/workflows/overview#running-workflows)
|
|
134
192
|
- [Workflow.createRun()](/reference/v1/workflows/workflow-methods/create-run)
|
|
193
|
+
- [Run.resumeStream()](./resumeStream)
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Run.timeTravelStream() | Streaming"
|
|
3
|
+
description: Documentation for the `Run.timeTravelStream()` method for streaming workflow time travel execution.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Run.timeTravelStream()
|
|
7
|
+
|
|
8
|
+
The `.timeTravelStream()` method re-executes a workflow starting from any specific step with streaming events. This allows you to receive real-time updates during time travel execution while maintaining full visibility into each step's progress.
|
|
9
|
+
|
|
10
|
+
## Usage example
|
|
11
|
+
|
|
12
|
+
```typescript showLineNumbers copy
|
|
13
|
+
const run = await workflow.createRun();
|
|
14
|
+
|
|
15
|
+
const output = run.timeTravelStream({
|
|
16
|
+
step: "step2",
|
|
17
|
+
inputData: { value: 10 },
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Process events as they arrive
|
|
21
|
+
for await (const event of output.fullStream) {
|
|
22
|
+
console.log(event.type, event.payload);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Get the final result
|
|
26
|
+
const result = await output.result;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Parameters
|
|
30
|
+
|
|
31
|
+
All parameters are the same as [`Run.timeTravel()`](../../workflows/run-methods/timeTravel#parameters). See the [timeTravel reference](../../workflows/run-methods/timeTravel#parameters) for detailed parameter documentation.
|
|
32
|
+
|
|
33
|
+
## Returns
|
|
34
|
+
|
|
35
|
+
<PropertiesTable
|
|
36
|
+
content={[
|
|
37
|
+
{
|
|
38
|
+
name: "output",
|
|
39
|
+
type: "WorkflowRunOutput<WorkflowResult<TState, TInput, TOutput, TSteps>>",
|
|
40
|
+
description:
|
|
41
|
+
"An object containing both the stream and result promise",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "output.fullStream",
|
|
45
|
+
type: "ReadableStream<WorkflowStreamEvent>",
|
|
46
|
+
description:
|
|
47
|
+
"A readable stream that emits workflow events as execution progresses",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "output.result",
|
|
51
|
+
type: "Promise<WorkflowResult<TState, TInput, TOutput, TSteps>>",
|
|
52
|
+
description:
|
|
53
|
+
"A promise that resolves to the final workflow execution result",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "output.traceId",
|
|
57
|
+
type: "string",
|
|
58
|
+
isOptional: true,
|
|
59
|
+
description:
|
|
60
|
+
"The trace ID associated with this execution when Tracing is enabled",
|
|
61
|
+
},
|
|
62
|
+
]}
|
|
63
|
+
/>
|
|
64
|
+
|
|
65
|
+
## Stream events
|
|
66
|
+
|
|
67
|
+
The stream emits various workflow events during execution:
|
|
68
|
+
|
|
69
|
+
- `workflow-step-start`: Emitted when a step begins execution
|
|
70
|
+
- `workflow-step-finish`: Emitted when a step completes successfully
|
|
71
|
+
- `workflow-step-error`: Emitted when a step encounters an error
|
|
72
|
+
- `workflow-step-suspended`: Emitted when a step suspends
|
|
73
|
+
- Additional events depending on step types (agents, tools, etc.)
|
|
74
|
+
|
|
75
|
+
## Extended usage examples
|
|
76
|
+
|
|
77
|
+
### Processing events during time travel
|
|
78
|
+
|
|
79
|
+
```typescript showLineNumbers copy
|
|
80
|
+
const run = await workflow.createRun();
|
|
81
|
+
|
|
82
|
+
const output = run.timeTravelStream({
|
|
83
|
+
step: "step2",
|
|
84
|
+
inputData: { value: 10 },
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
for await (const event of output.fullStream) {
|
|
88
|
+
switch (event.type) {
|
|
89
|
+
case "workflow-step-start":
|
|
90
|
+
console.log(`Starting step: ${event.payload.stepName}`);
|
|
91
|
+
break;
|
|
92
|
+
case "workflow-step-finish":
|
|
93
|
+
console.log(`Completed step: ${event.payload.stepName}`);
|
|
94
|
+
break;
|
|
95
|
+
case "workflow-step-error":
|
|
96
|
+
console.error(`Error in step: ${event.payload.stepName}`, event.payload.error);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const result = await output.result;
|
|
102
|
+
console.log("Time travel completed:", result);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Time travel stream with context
|
|
106
|
+
|
|
107
|
+
```typescript showLineNumbers copy
|
|
108
|
+
const output = run.timeTravelStream({
|
|
109
|
+
step: "step2",
|
|
110
|
+
context: {
|
|
111
|
+
step1: {
|
|
112
|
+
status: "success",
|
|
113
|
+
payload: { value: 0 },
|
|
114
|
+
output: { step1Result: 2 },
|
|
115
|
+
startedAt: Date.now(),
|
|
116
|
+
endedAt: Date.now(),
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
for await (const event of output.fullStream) {
|
|
122
|
+
// Handle events
|
|
123
|
+
console.log(event);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const result = await output.result;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Time travel stream with nested workflows
|
|
130
|
+
|
|
131
|
+
```typescript showLineNumbers copy
|
|
132
|
+
const output = run.timeTravelStream({
|
|
133
|
+
step: ["nestedWorkflow", "step3"],
|
|
134
|
+
inputData: { value: 10 },
|
|
135
|
+
nestedStepsContext: {
|
|
136
|
+
nestedWorkflow: {
|
|
137
|
+
step2: {
|
|
138
|
+
status: "success",
|
|
139
|
+
payload: { step1Result: 2 },
|
|
140
|
+
output: { step2Result: 3 },
|
|
141
|
+
startedAt: Date.now(),
|
|
142
|
+
endedAt: Date.now(),
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
for await (const event of output.fullStream) {
|
|
149
|
+
console.log(event.type, event.payload);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const result = await output.result;
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Notes
|
|
156
|
+
|
|
157
|
+
- The stream closes automatically when time travel execution completes or encounters an error
|
|
158
|
+
- You can process events from the stream while the workflow is still executing
|
|
159
|
+
- The `result` promise resolves only after all steps have completed
|
|
160
|
+
- Stream events follow the same format as regular workflow streaming
|
|
161
|
+
- Time travel streaming requires storage to be configured since it relies on persisted workflow snapshots
|
|
162
|
+
|
|
163
|
+
## Related
|
|
164
|
+
|
|
165
|
+
- [Run.timeTravel()](../../workflows/run-methods/timeTravel)
|
|
166
|
+
- [Time Travel](/docs/v1/workflows/time-travel)
|
|
167
|
+
- [Workflow Streaming](/docs/v1/streaming/workflow-streaming)
|
|
168
|
+
- [Run.stream()](./stream)
|
|
169
|
+
- [Run.resumeStream()](./resumeStream)
|
|
170
|
+
|
|
@@ -99,6 +99,13 @@ Each server in the `servers` map is configured using the `MastraMCPServerDefinit
|
|
|
99
99
|
description:
|
|
100
100
|
"For SSE fallback: Custom fetch configuration for SSE connections. Required when using custom headers with SSE.",
|
|
101
101
|
},
|
|
102
|
+
{
|
|
103
|
+
name: "fetch",
|
|
104
|
+
type: "FetchLike",
|
|
105
|
+
isOptional: true,
|
|
106
|
+
description:
|
|
107
|
+
"For HTTP servers: Custom fetch implementation used for all network requests. When provided, this function will be used for all HTTP requests, allowing you to add dynamic authentication headers (e.g., refreshing bearer tokens), customize request behavior per-request, or intercept and modify requests/responses. When `fetch` is provided, `requestInit`, `eventSourceInit`, and `authProvider` become optional, as you can handle these concerns within your custom fetch function.",
|
|
108
|
+
},
|
|
102
109
|
{
|
|
103
110
|
name: "logger",
|
|
104
111
|
type: "LogHandler",
|
|
@@ -291,23 +298,6 @@ mcpClient.resources.onListChanged("myWeatherServer", () => {
|
|
|
291
298
|
});
|
|
292
299
|
```
|
|
293
300
|
|
|
294
|
-
### `prompts` Property
|
|
295
|
-
|
|
296
|
-
The `MCPClient` instance has a `prompts` property that provides access to prompt-related operations.
|
|
297
|
-
|
|
298
|
-
```typescript
|
|
299
|
-
const mcpClient = new MCPClient({
|
|
300
|
-
/* ...servers configuration... */
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
// Access prompt methods via mcpClient.prompts
|
|
304
|
-
const allPromptsByServer = await mcpClient.prompts.list();
|
|
305
|
-
const { prompt, messages } = await mcpClient.prompts.get({
|
|
306
|
-
serverName: "myWeatherServer",
|
|
307
|
-
name: "current",
|
|
308
|
-
});
|
|
309
|
-
```
|
|
310
|
-
|
|
311
301
|
### `elicitation` Property
|
|
312
302
|
|
|
313
303
|
The `MCPClient` instance has an `elicitation` property that provides access to elicitation-related operations. Elicitation allows MCP servers to request structured information from users.
|
|
@@ -451,6 +441,23 @@ await mcpClient.elicitation.onRequest("interactiveServer", async (request) => {
|
|
|
451
441
|
});
|
|
452
442
|
```
|
|
453
443
|
|
|
444
|
+
### `prompts` Property
|
|
445
|
+
|
|
446
|
+
The `MCPClient` instance has a `prompts` property that provides access to prompt-related operations.
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
const mcpClient = new MCPClient({
|
|
450
|
+
/* ...servers configuration... */
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
// Access prompt methods via mcpClient.prompts
|
|
454
|
+
const allPromptsByServer = await mcpClient.prompts.list();
|
|
455
|
+
const { prompt, messages } = await mcpClient.prompts.get({
|
|
456
|
+
serverName: "myWeatherServer",
|
|
457
|
+
name: "current",
|
|
458
|
+
});
|
|
459
|
+
```
|
|
460
|
+
|
|
454
461
|
#### `prompts.list()`
|
|
455
462
|
|
|
456
463
|
Retrieves all available prompts from all connected MCP servers, grouped by server name.
|
|
@@ -516,6 +523,63 @@ mcpClient.prompts.onListChanged("myWeatherServer", () => {
|
|
|
516
523
|
});
|
|
517
524
|
```
|
|
518
525
|
|
|
526
|
+
### `progress` Property
|
|
527
|
+
|
|
528
|
+
The `MCPClient` instance has a `progress` property for subscribing to progress notifications emitted by MCP servers while tools execute.
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
const mcpClient = new MCPClient({
|
|
532
|
+
servers: {
|
|
533
|
+
myServer: {
|
|
534
|
+
url: new URL('http://localhost:4111/api/mcp/myServer/mcp'),
|
|
535
|
+
// Enabled by default; set to false to disable
|
|
536
|
+
enableProgressTracking: true,
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
// Subscribe to progress updates for a specific server
|
|
542
|
+
await mcpClient.progress.onUpdate('myServer', (params) => {
|
|
543
|
+
console.log('📊 Progress:', params.progress, '/', params.total);
|
|
544
|
+
if (params.message) console.log('Message:', params.message);
|
|
545
|
+
if (params.progressToken) console.log('Token:', params.progressToken);
|
|
546
|
+
});
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
#### `progress.onUpdate(serverName: string, handler)`
|
|
550
|
+
|
|
551
|
+
Registers a handler function to receive progress updates from the specified server.
|
|
552
|
+
|
|
553
|
+
```typescript
|
|
554
|
+
async onUpdate(
|
|
555
|
+
serverName: string,
|
|
556
|
+
handler: (params: {
|
|
557
|
+
progressToken: string;
|
|
558
|
+
progress: number;
|
|
559
|
+
total?: number;
|
|
560
|
+
message?: string;
|
|
561
|
+
}) => void,
|
|
562
|
+
): Promise<void>
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
Notes:
|
|
566
|
+
|
|
567
|
+
- When `enableProgressTracking` is true (default), tool calls include a `progressToken` so you can correlate updates to a specific run.
|
|
568
|
+
- If you pass a `runId` when executing a tool, it will be used as the `progressToken`.
|
|
569
|
+
|
|
570
|
+
To disable progress tracking for a server:
|
|
571
|
+
|
|
572
|
+
```typescript
|
|
573
|
+
const mcpClient = new MCPClient({
|
|
574
|
+
servers: {
|
|
575
|
+
myServer: {
|
|
576
|
+
url: new URL('http://localhost:4111/api/mcp/myServer/mcp'),
|
|
577
|
+
enableProgressTracking: false,
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
});
|
|
581
|
+
```
|
|
582
|
+
|
|
519
583
|
## Elicitation
|
|
520
584
|
|
|
521
585
|
Elicitation is a feature that allows MCP servers to request structured information from users. When a server needs additional data, it can send an elicitation request that the client handles by prompting the user. A common example is during a tool call.
|
|
@@ -797,11 +861,40 @@ MCPClient handles server connections gracefully:
|
|
|
797
861
|
2. Graceful server shutdown to prevent error messages during development
|
|
798
862
|
3. Proper cleanup of resources when disconnecting
|
|
799
863
|
|
|
864
|
+
## Using Custom Fetch for Dynamic Authentication
|
|
865
|
+
|
|
866
|
+
For HTTP servers, you can provide a custom `fetch` function to handle dynamic authentication, request interception, or other custom behavior. This is particularly useful when you need to refresh tokens on each request or customize request behavior.
|
|
867
|
+
|
|
868
|
+
When `fetch` is provided, `requestInit`, `eventSourceInit`, and `authProvider` become optional, as you can handle these concerns within your custom fetch function.
|
|
869
|
+
|
|
870
|
+
```typescript
|
|
871
|
+
const mcpClient = new MCPClient({
|
|
872
|
+
servers: {
|
|
873
|
+
apiServer: {
|
|
874
|
+
url: new URL("https://api.example.com/mcp"),
|
|
875
|
+
fetch: async (url, init) => {
|
|
876
|
+
// Refresh token on each request
|
|
877
|
+
const token = await getAuthToken(); // Your token refresh logic
|
|
878
|
+
|
|
879
|
+
return fetch(url, {
|
|
880
|
+
...init,
|
|
881
|
+
headers: {
|
|
882
|
+
...init?.headers,
|
|
883
|
+
Authorization: `Bearer ${token}`,
|
|
884
|
+
},
|
|
885
|
+
});
|
|
886
|
+
},
|
|
887
|
+
},
|
|
888
|
+
},
|
|
889
|
+
});
|
|
890
|
+
```
|
|
891
|
+
|
|
800
892
|
## Using SSE Request Headers
|
|
801
893
|
|
|
802
|
-
When using the legacy SSE MCP transport, you must configure both `requestInit` and `eventSourceInit` due to a bug in the MCP SDK:
|
|
894
|
+
When using the legacy SSE MCP transport, you must configure both `requestInit` and `eventSourceInit` due to a bug in the MCP SDK. Alternatively, you can use a custom `fetch` function which will be automatically used for both POST requests and SSE connections:
|
|
803
895
|
|
|
804
896
|
```ts
|
|
897
|
+
// Option 1: Using requestInit and eventSourceInit (required for SSE)
|
|
805
898
|
const sseClient = new MCPClient({
|
|
806
899
|
servers: {
|
|
807
900
|
exampleServer: {
|
|
@@ -826,6 +919,23 @@ const sseClient = new MCPClient({
|
|
|
826
919
|
},
|
|
827
920
|
},
|
|
828
921
|
});
|
|
922
|
+
|
|
923
|
+
// Option 2: Using custom fetch (simpler, works for both Streamable HTTP and SSE)
|
|
924
|
+
const sseClientWithFetch = new MCPClient({
|
|
925
|
+
servers: {
|
|
926
|
+
exampleServer: {
|
|
927
|
+
url: new URL("https://your-mcp-server.com/sse"),
|
|
928
|
+
fetch: async (url, init) => {
|
|
929
|
+
const headers = new Headers(init?.headers || {});
|
|
930
|
+
headers.set("Authorization", "Bearer your-token");
|
|
931
|
+
return fetch(url, {
|
|
932
|
+
...init,
|
|
933
|
+
headers,
|
|
934
|
+
});
|
|
935
|
+
},
|
|
936
|
+
},
|
|
937
|
+
},
|
|
938
|
+
});
|
|
829
939
|
```
|
|
830
940
|
|
|
831
941
|
## Related Information
|