@mastra/mcp-docs-server 0.0.1-alpha.1
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%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcomposio.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +11 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fstabilityai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +59 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +24 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +12 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent.md +385 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +377 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/integrations.md +184 -0
- package/.docs/organized/code-examples/mcp-configuration.md +341 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +161 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +127 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +352 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/00-overview.mdx +185 -0
- package/.docs/raw/agents/01-agent-memory.mdx +610 -0
- package/.docs/raw/agents/02-adding-tools.mdx +224 -0
- package/.docs/raw/agents/03-adding-voice.mdx +170 -0
- package/.docs/raw/deployment/deployment.mdx +156 -0
- package/.docs/raw/deployment/logging-and-tracing.mdx +242 -0
- package/.docs/raw/deployment/server.mdx +114 -0
- package/.docs/raw/evals/00-overview.mdx +106 -0
- package/.docs/raw/evals/01-supported-evals.mdx +31 -0
- package/.docs/raw/evals/02-custom-eval.mdx +187 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/01-next-js.mdx +238 -0
- package/.docs/raw/frameworks/02-ai-sdk.mdx +218 -0
- package/.docs/raw/getting-started/installation.mdx +436 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/guides/01-chef-michel.mdx +242 -0
- package/.docs/raw/guides/02-stock-agent.mdx +182 -0
- package/.docs/raw/guides/03-recruiter.mdx +187 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/local-dev/creating-projects.mdx +74 -0
- package/.docs/raw/local-dev/integrations.mdx +127 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +65 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +128 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +362 -0
- package/.docs/raw/rag/vector-databases.mdx +271 -0
- package/.docs/raw/reference/agents/createTool.mdx +190 -0
- package/.docs/raw/reference/agents/generate.mdx +327 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +361 -0
- package/.docs/raw/reference/cli/build.mdx +48 -0
- package/.docs/raw/reference/cli/deploy.mdx +22 -0
- package/.docs/raw/reference/cli/dev.mdx +97 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +90 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/index.mdx +127 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +94 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +137 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +176 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +88 -0
- package/.docs/raw/reference/deployer/vercel.mdx +97 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +8 -0
- package/.docs/raw/reference/memory/Memory.mdx +186 -0
- package/.docs/raw/reference/memory/createThread.mdx +93 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +43 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +45 -0
- package/.docs/raw/reference/memory/query.mdx +164 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +15 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +46 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +237 -0
- package/.docs/raw/reference/rag/document.mdx +129 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +72 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +249 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +198 -0
- package/.docs/raw/reference/rag/vectorize.mdx +253 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +180 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/suspend.mdx +80 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/workflows/00-overview.mdx +168 -0
- package/.docs/raw/workflows/control-flow.mdx +712 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +232 -0
- package/.docs/raw/workflows/steps.mdx +98 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +196 -0
- package/.docs/raw/workflows/variables.mdx +248 -0
- package/LICENSE +44 -0
- package/README.md +129 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/prepare-docs/code-examples.d.ts +4 -0
- package/dist/prepare-docs/code-examples.js +91 -0
- package/dist/prepare-docs/copy-raw.d.ts +1 -0
- package/dist/prepare-docs/copy-raw.js +41 -0
- package/dist/prepare-docs/index.d.ts +1 -0
- package/dist/prepare-docs/index.js +8 -0
- package/dist/prepare-docs/package-changes.d.ts +4 -0
- package/dist/prepare-docs/package-changes.js +92 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +13 -0
- package/dist/sse.d.ts +1 -0
- package/dist/sse.js +9 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +8 -0
- package/dist/tools/__tests__/blog.test.d.ts +1 -0
- package/dist/tools/__tests__/blog.test.js +48 -0
- package/dist/tools/__tests__/changes.test.d.ts +1 -0
- package/dist/tools/__tests__/changes.test.js +36 -0
- package/dist/tools/__tests__/docs.test.d.ts +1 -0
- package/dist/tools/__tests__/docs.test.js +46 -0
- package/dist/tools/__tests__/examples.test.d.ts +1 -0
- package/dist/tools/__tests__/examples.test.js +52 -0
- package/dist/tools/blog.d.ts +15 -0
- package/dist/tools/blog.js +73 -0
- package/dist/tools/changes.d.ts +11 -0
- package/dist/tools/changes.js +69 -0
- package/dist/tools/docs.d.ts +11 -0
- package/dist/tools/docs.js +176 -0
- package/dist/tools/examples.d.ts +11 -0
- package/dist/tools/examples.js +61 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +9 -0
- package/package.json +66 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Data Mapping with Workflow Variables | Mastra Docs"
|
|
3
|
+
description: "Learn how to use workflow variables to map data between steps and create dynamic data flows in your Mastra workflows."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Data Mapping with Workflow Variables
|
|
7
|
+
|
|
8
|
+
Workflow variables in Mastra provide a powerful mechanism for mapping data between steps, allowing you to create dynamic data flows and pass information from one step to another.
|
|
9
|
+
|
|
10
|
+
## Understanding Workflow Variables
|
|
11
|
+
|
|
12
|
+
In Mastra workflows, variables serve as a way to:
|
|
13
|
+
|
|
14
|
+
- Map data from trigger inputs to step inputs
|
|
15
|
+
- Pass outputs from one step to inputs of another step
|
|
16
|
+
- Access nested properties within step outputs
|
|
17
|
+
- Create more flexible and reusable workflow steps
|
|
18
|
+
|
|
19
|
+
## Using Variables for Data Mapping
|
|
20
|
+
|
|
21
|
+
### Basic Variable Mapping
|
|
22
|
+
|
|
23
|
+
You can map data between steps using the `variables` property when adding a step to your workflow:
|
|
24
|
+
|
|
25
|
+
```typescript showLineNumbers filename="src/mastra/workflows/index.ts" copy
|
|
26
|
+
const workflow = new Workflow({
|
|
27
|
+
name: 'data-mapping-workflow',
|
|
28
|
+
triggerSchema: z.object({
|
|
29
|
+
inputData: z.string(),
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
workflow
|
|
34
|
+
.step(step1, {
|
|
35
|
+
variables: {
|
|
36
|
+
// Map trigger data to step input
|
|
37
|
+
inputData: { step: 'trigger', path: 'inputData' }
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.then(step2, {
|
|
41
|
+
variables: {
|
|
42
|
+
// Map output from step1 to input for step2
|
|
43
|
+
previousValue: { step: step1, path: 'outputField' }
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
.commit();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Accessing Nested Properties
|
|
50
|
+
|
|
51
|
+
You can access nested properties using dot notation in the `path` field:
|
|
52
|
+
|
|
53
|
+
```typescript showLineNumbers filename="src/mastra/workflows/index.ts" copy
|
|
54
|
+
workflow
|
|
55
|
+
.step(step1)
|
|
56
|
+
.then(step2, {
|
|
57
|
+
variables: {
|
|
58
|
+
// Access a nested property from step1's output
|
|
59
|
+
nestedValue: { step: step1, path: 'nested.deeply.value' }
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
.commit();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Mapping Entire Objects
|
|
66
|
+
|
|
67
|
+
You can map an entire object by using `.` as the path:
|
|
68
|
+
|
|
69
|
+
```typescript showLineNumbers filename="src/mastra/workflows/index.ts" copy
|
|
70
|
+
workflow
|
|
71
|
+
.step(step1, {
|
|
72
|
+
variables: {
|
|
73
|
+
// Map the entire trigger data object
|
|
74
|
+
triggerData: { step: 'trigger', path: '.' }
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
.commit();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Variable Resolution
|
|
81
|
+
|
|
82
|
+
When a workflow executes, Mastra resolves variables at runtime by:
|
|
83
|
+
|
|
84
|
+
1. Identifying the source step specified in the `step` property
|
|
85
|
+
2. Retrieving the output from that step
|
|
86
|
+
3. Navigating to the specified property using the `path`
|
|
87
|
+
4. Injecting the resolved value into the target step's context as the `inputData` property
|
|
88
|
+
|
|
89
|
+
## Examples
|
|
90
|
+
|
|
91
|
+
### Mapping from Trigger Data
|
|
92
|
+
|
|
93
|
+
This example shows how to map data from the workflow trigger to a step:
|
|
94
|
+
|
|
95
|
+
```typescript showLineNumbers filename="src/mastra/workflows/trigger-mapping.ts" copy
|
|
96
|
+
import { Step, Workflow } from "@mastra/core/workflows";
|
|
97
|
+
import { z } from "zod";
|
|
98
|
+
|
|
99
|
+
// Define a step that needs user input
|
|
100
|
+
const processUserInput = new Step({
|
|
101
|
+
id: "processUserInput",
|
|
102
|
+
execute: async ({ context }) => {
|
|
103
|
+
// The inputData will be available in context because of the variable mapping
|
|
104
|
+
const { inputData } = context.inputData;
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
processedData: `Processed: ${inputData}`
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Create the workflow
|
|
113
|
+
const workflow = new Workflow({
|
|
114
|
+
name: "trigger-mapping",
|
|
115
|
+
triggerSchema: z.object({
|
|
116
|
+
inputData: z.string(),
|
|
117
|
+
}),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Map the trigger data to the step
|
|
121
|
+
workflow
|
|
122
|
+
.step(processUserInput, {
|
|
123
|
+
variables: {
|
|
124
|
+
inputData: { step: 'trigger', path: 'inputData' },
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
.commit();
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Mapping Between Steps
|
|
131
|
+
|
|
132
|
+
This example demonstrates mapping data from one step to another:
|
|
133
|
+
|
|
134
|
+
```typescript showLineNumbers filename="src/mastra/workflows/step-mapping.ts" copy
|
|
135
|
+
import { Step, Workflow } from "@mastra/core/workflows";
|
|
136
|
+
import { z } from "zod";
|
|
137
|
+
|
|
138
|
+
// Step 1: Generate data
|
|
139
|
+
const generateData = new Step({
|
|
140
|
+
id: "generateData",
|
|
141
|
+
outputSchema: z.object({
|
|
142
|
+
nested: z.object({
|
|
143
|
+
value: z.string(),
|
|
144
|
+
}),
|
|
145
|
+
}),
|
|
146
|
+
execute: async () => {
|
|
147
|
+
return {
|
|
148
|
+
nested: {
|
|
149
|
+
value: "step1-data"
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Step 2: Process the data from step 1
|
|
156
|
+
const processData = new Step({
|
|
157
|
+
id: "processData",
|
|
158
|
+
inputSchema: z.object({
|
|
159
|
+
previousValue: z.string(),
|
|
160
|
+
}),
|
|
161
|
+
execute: async ({ context }) => {
|
|
162
|
+
// previousValue will be available because of the variable mapping
|
|
163
|
+
const { previousValue } = context.inputData;
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
result: `Processed: ${previousValue}`
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Create the workflow
|
|
172
|
+
const workflow = new Workflow({
|
|
173
|
+
name: "step-mapping",
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Map data from step1 to step2
|
|
177
|
+
workflow
|
|
178
|
+
.step(generateData)
|
|
179
|
+
.then(processData, {
|
|
180
|
+
variables: {
|
|
181
|
+
// Map the nested.value property from generateData's output
|
|
182
|
+
previousValue: { step: generateData, path: 'nested.value' },
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
.commit();
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Type Safety
|
|
189
|
+
|
|
190
|
+
Mastra provides type safety for variable mappings when using TypeScript:
|
|
191
|
+
|
|
192
|
+
```typescript showLineNumbers filename="src/mastra/workflows/type-safe.ts" copy
|
|
193
|
+
import { Step, Workflow } from "@mastra/core/workflows";
|
|
194
|
+
import { z } from "zod";
|
|
195
|
+
|
|
196
|
+
// Define schemas for better type safety
|
|
197
|
+
const triggerSchema = z.object({
|
|
198
|
+
inputValue: z.string(),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
type TriggerType = z.infer<typeof triggerSchema>;
|
|
202
|
+
|
|
203
|
+
// Step with typed context
|
|
204
|
+
const step1 = new Step({
|
|
205
|
+
id: "step1",
|
|
206
|
+
outputSchema: z.object({
|
|
207
|
+
nested: z.object({
|
|
208
|
+
value: z.string(),
|
|
209
|
+
}),
|
|
210
|
+
}),
|
|
211
|
+
execute: async ({ context }) => {
|
|
212
|
+
// TypeScript knows the shape of triggerData
|
|
213
|
+
const triggerData = context.getStepResult<TriggerType>('trigger');
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
nested: {
|
|
217
|
+
value: `processed-${triggerData?.inputValue}`
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// Create the workflow with the schema
|
|
224
|
+
const workflow = new Workflow({
|
|
225
|
+
name: "type-safe-workflow",
|
|
226
|
+
triggerSchema,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
workflow.step(step1).commit();
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Best Practices
|
|
233
|
+
|
|
234
|
+
1. **Validate Inputs and Outputs**: Use `inputSchema` and `outputSchema` to ensure data consistency.
|
|
235
|
+
|
|
236
|
+
2. **Keep Mappings Simple**: Avoid overly complex nested paths when possible.
|
|
237
|
+
|
|
238
|
+
3. **Consider Default Values**: Handle cases where mapped data might be undefined.
|
|
239
|
+
|
|
240
|
+
## Comparison with Direct Context Access
|
|
241
|
+
|
|
242
|
+
While you can access previous step results directly via `context.steps`, using variable mappings offers several advantages:
|
|
243
|
+
|
|
244
|
+
| Feature | Variable Mapping | Direct Context Access |
|
|
245
|
+
| ------- | --------------- | --------------------- |
|
|
246
|
+
| Clarity | Explicit data dependencies | Implicit dependencies |
|
|
247
|
+
| Reusability | Steps can be reused with different mappings | Steps are tightly coupled |
|
|
248
|
+
| Type Safety | Better TypeScript integration | Requires manual type assertions |
|
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Elastic License 2.0 (ELv2)
|
|
2
|
+
|
|
3
|
+
**Acceptance**
|
|
4
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
5
|
+
|
|
6
|
+
**Copyright License**
|
|
7
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
8
|
+
|
|
9
|
+
**Limitations**
|
|
10
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
11
|
+
|
|
12
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
13
|
+
|
|
14
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
15
|
+
|
|
16
|
+
**Patents**
|
|
17
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
18
|
+
|
|
19
|
+
**Notices**
|
|
20
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
21
|
+
|
|
22
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
23
|
+
|
|
24
|
+
**No Other Rights**
|
|
25
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
26
|
+
|
|
27
|
+
**Termination**
|
|
28
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
29
|
+
|
|
30
|
+
**No Liability**
|
|
31
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
32
|
+
|
|
33
|
+
**Definitions**
|
|
34
|
+
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
35
|
+
|
|
36
|
+
_you_ refers to the individual or entity agreeing to these terms.
|
|
37
|
+
|
|
38
|
+
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
39
|
+
|
|
40
|
+
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
41
|
+
|
|
42
|
+
_use_ means anything you do with the software requiring one of your licenses.
|
|
43
|
+
|
|
44
|
+
_trademark_ means trademarks, service marks, and similar rights.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @mastra/mcp-docs-server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server that provides AI assistants with direct access to Mastra.ai's complete knowledge base. This includes comprehensive documentation with MDX support, a collection of production-ready code examples, technical blog posts, and detailed package changelogs. The server integrates with popular AI development environments like Cursor and Windsurf, as well as Mastra agents, making it easy to build documentation-aware AI assistants that can provide accurate, up-to-date information about Mastra.ai's ecosystem.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### In Cursor
|
|
8
|
+
|
|
9
|
+
Create or update `.cursor/mcp.json` in your project root:
|
|
10
|
+
|
|
11
|
+
MacOS/Linux
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"mastra": {
|
|
17
|
+
"command": "npx",
|
|
18
|
+
"args": ["-y", "@mastra/mcp-docs-server@latest"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Windows
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"mcpServers": {
|
|
29
|
+
"mastra": {
|
|
30
|
+
"command": "cmd",
|
|
31
|
+
"args": ["/c", "npx", "-y", "@mastra/mcp-docs-server@latest"]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This will make all Mastra documentation tools available in your Cursor workspace.
|
|
38
|
+
Note that the MCP server wont be enabled by default. You'll need to go to Cursor settings -> MCP settings and click "enable" on the Mastra MCP server.
|
|
39
|
+
|
|
40
|
+
### In Windsurf
|
|
41
|
+
|
|
42
|
+
Create or update `~/.codeium/windsurf/mcp_config.json`:
|
|
43
|
+
|
|
44
|
+
MacOS/Linux
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"mcpServers": {
|
|
49
|
+
"mastra": {
|
|
50
|
+
"command": "npx",
|
|
51
|
+
"args": ["-y", "@mastra/mcp-docs-server@latest"]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Windows
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"mastra": {
|
|
63
|
+
"command": "cmd",
|
|
64
|
+
"args": ["/c", "npx", "-y", "@mastra/mcp-docs-server@latest"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
This will make all Mastra documentation tools available in your Windsurf workspace.
|
|
71
|
+
Note that Windsurf MCP tool calling doesn't work very well. You will need to fully quit and re-open Windsurf after adding this.
|
|
72
|
+
If a tool call fails you will need to go into Windsurf MCP settings and re-start the MCP server.
|
|
73
|
+
|
|
74
|
+
### In a Mastra Agent
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { MCPConfiguration } from '@mastra/mcp';
|
|
78
|
+
import { Agent } from '@mastra/core/agent';
|
|
79
|
+
import { openai } from '@ai-sdk/openai';
|
|
80
|
+
|
|
81
|
+
// Configure MCP with the docs server
|
|
82
|
+
const mcp = new MCPConfiguration({
|
|
83
|
+
servers: {
|
|
84
|
+
mastra: {
|
|
85
|
+
command: 'npx',
|
|
86
|
+
args: ['-y', '@mastra/mcp-docs-server@latest'],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Create an agent with access to all documentation tools
|
|
92
|
+
const agent = new Agent({
|
|
93
|
+
name: 'Documentation Assistant',
|
|
94
|
+
instructions: 'You help users find and understand Mastra.ai documentation.',
|
|
95
|
+
model: openai('gpt-4'),
|
|
96
|
+
tools: await mcp.getTools(),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Or use toolsets dynamically in generate/stream
|
|
100
|
+
const response = await agent.stream('Show me the quick start example', {
|
|
101
|
+
toolsets: await mcp.getToolsets(),
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Tools
|
|
106
|
+
|
|
107
|
+
### Documentation Tool (`mastraDocs`)
|
|
108
|
+
|
|
109
|
+
- Get Mastra.ai documentation by requesting specific paths
|
|
110
|
+
- Explore both general guides and API reference documentation
|
|
111
|
+
- Automatically lists available paths when a requested path isn't found
|
|
112
|
+
|
|
113
|
+
### Examples Tool (`mastraExamples`)
|
|
114
|
+
|
|
115
|
+
- Access code examples showing Mastra.ai implementation patterns
|
|
116
|
+
- List all available examples
|
|
117
|
+
- Get detailed source code for specific examples
|
|
118
|
+
|
|
119
|
+
### Blog Tool (`mastraBlog`)
|
|
120
|
+
|
|
121
|
+
- Access technical blog posts and articles
|
|
122
|
+
- Posts are properly formatted with code block handling
|
|
123
|
+
- Supports various date formats in blog metadata
|
|
124
|
+
|
|
125
|
+
### Changes Tool (`mastraChanges`)
|
|
126
|
+
|
|
127
|
+
- Access package changelogs
|
|
128
|
+
- List all available package changelogs
|
|
129
|
+
- Get detailed changelog content for specific packages
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { FastMCP } from 'tylerbarnes-fastmcp-fix';
|
|
3
|
+
import { blogTool } from './tools/blog';
|
|
4
|
+
import { changesTool } from './tools/changes';
|
|
5
|
+
import { docsTool } from './tools/docs';
|
|
6
|
+
import { examplesTool } from './tools/examples';
|
|
7
|
+
import { fromPackageRoot } from './utils';
|
|
8
|
+
// console.error('Starting Mastra Documentation Server...');
|
|
9
|
+
// console.error('Docs base dir:', path.join(__dirname, '../.docs/raw/'));
|
|
10
|
+
const server = new FastMCP({
|
|
11
|
+
name: 'Mastra Documentation Server',
|
|
12
|
+
version: JSON.parse(await fs.readFile(fromPackageRoot(`package.json`), 'utf8')).version,
|
|
13
|
+
});
|
|
14
|
+
// Add tools
|
|
15
|
+
server.addTool(blogTool);
|
|
16
|
+
server.addTool(docsTool);
|
|
17
|
+
server.addTool(examplesTool);
|
|
18
|
+
server.addTool(changesTool);
|
|
19
|
+
export { server };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fromPackageRoot, fromRepoRoot, log } from '../utils';
|
|
4
|
+
const EXAMPLES_SOURCE = fromRepoRoot('examples');
|
|
5
|
+
const OUTPUT_DIR = fromPackageRoot('.docs/organized/code-examples');
|
|
6
|
+
/**
|
|
7
|
+
* Scans example directories and creates flattened code example files
|
|
8
|
+
*/
|
|
9
|
+
export async function prepareCodeExamples() {
|
|
10
|
+
// Clean up existing output directory
|
|
11
|
+
try {
|
|
12
|
+
await fs.rm(OUTPUT_DIR, { recursive: true, force: true });
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// Ignore errors if directory doesn't exist
|
|
16
|
+
}
|
|
17
|
+
// Ensure output directory exists
|
|
18
|
+
await fs.mkdir(OUTPUT_DIR, { recursive: true });
|
|
19
|
+
// Get all example directories
|
|
20
|
+
const examples = await fs.readdir(EXAMPLES_SOURCE, { withFileTypes: true });
|
|
21
|
+
const exampleDirs = examples.filter(entry => entry.isDirectory());
|
|
22
|
+
for (const dir of exampleDirs) {
|
|
23
|
+
const examplePath = path.join(EXAMPLES_SOURCE, dir.name);
|
|
24
|
+
const outputFile = path.join(OUTPUT_DIR, `${dir.name}.md`);
|
|
25
|
+
// Collect all relevant files
|
|
26
|
+
const files = [];
|
|
27
|
+
// First add package.json if it exists
|
|
28
|
+
try {
|
|
29
|
+
const packageJson = await fs.readFile(path.join(examplePath, 'package.json'), 'utf-8');
|
|
30
|
+
files.push({
|
|
31
|
+
path: 'package.json',
|
|
32
|
+
content: packageJson,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Skip if no package.json
|
|
37
|
+
}
|
|
38
|
+
// Then scan for TypeScript files in src
|
|
39
|
+
try {
|
|
40
|
+
const srcPath = path.join(examplePath, 'src');
|
|
41
|
+
await scanDirectory(srcPath, srcPath, files);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Skip if no src directory
|
|
45
|
+
}
|
|
46
|
+
// If we found any files, generate markdown and check line count
|
|
47
|
+
if (files.length > 0) {
|
|
48
|
+
const output = files
|
|
49
|
+
.map(file => `### ${file.path}\n\`\`\`${getFileType(file.path)}\n${file.content}\n\`\`\`\n`)
|
|
50
|
+
.join('\n');
|
|
51
|
+
const totalLines = output.split('\n').length;
|
|
52
|
+
// Skip if total lines would exceed 500
|
|
53
|
+
if (totalLines > 500) {
|
|
54
|
+
log(`Skipping ${dir.name}: ${totalLines} lines exceeds limit of 500`);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
await fs.writeFile(outputFile, output, 'utf-8');
|
|
58
|
+
log(`Generated ${dir.name}.md with ${totalLines} lines`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Recursively scan a directory for TypeScript files
|
|
64
|
+
*/
|
|
65
|
+
async function scanDirectory(basePath, currentPath, files) {
|
|
66
|
+
const entries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
67
|
+
for (const entry of entries) {
|
|
68
|
+
const fullPath = path.join(currentPath, entry.name);
|
|
69
|
+
const relativePath = path.relative(basePath, fullPath);
|
|
70
|
+
if (entry.isDirectory()) {
|
|
71
|
+
await scanDirectory(basePath, fullPath, files);
|
|
72
|
+
}
|
|
73
|
+
else if (entry.isFile() && entry.name.endsWith('.ts')) {
|
|
74
|
+
const content = await fs.readFile(fullPath, 'utf-8');
|
|
75
|
+
files.push({
|
|
76
|
+
path: relativePath,
|
|
77
|
+
content,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the appropriate code fence language based on file extension
|
|
84
|
+
*/
|
|
85
|
+
function getFileType(filePath) {
|
|
86
|
+
if (filePath === 'package.json')
|
|
87
|
+
return 'json';
|
|
88
|
+
if (filePath.endsWith('.ts'))
|
|
89
|
+
return 'typescript';
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copyRaw(): Promise<void>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fromPackageRoot, fromRepoRoot, log } from '../utils';
|
|
4
|
+
const DOCS_SOURCE = fromRepoRoot('docs/src/pages/docs');
|
|
5
|
+
const DOCS_DEST = fromPackageRoot('.docs/raw');
|
|
6
|
+
async function copyDir(src, dest) {
|
|
7
|
+
// Create destination directory
|
|
8
|
+
await fs.mkdir(dest, { recursive: true });
|
|
9
|
+
// Read source directory
|
|
10
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
11
|
+
for (const entry of entries) {
|
|
12
|
+
const srcPath = path.join(src, entry.name);
|
|
13
|
+
const destPath = path.join(dest, entry.name);
|
|
14
|
+
if (entry.isDirectory()) {
|
|
15
|
+
// Recursively copy directories
|
|
16
|
+
await copyDir(srcPath, destPath);
|
|
17
|
+
}
|
|
18
|
+
else if (entry.isFile() && entry.name.endsWith('.mdx')) {
|
|
19
|
+
// Copy only MDX files
|
|
20
|
+
await fs.copyFile(srcPath, destPath);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function copyRaw() {
|
|
25
|
+
try {
|
|
26
|
+
// Clean up existing docs directory if it exists
|
|
27
|
+
try {
|
|
28
|
+
await fs.rm(DOCS_DEST, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Ignore if directory doesn't exist
|
|
32
|
+
}
|
|
33
|
+
// Copy docs
|
|
34
|
+
await copyDir(DOCS_SOURCE, DOCS_DEST);
|
|
35
|
+
log('✅ Documentation files copied successfully');
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error('❌ Failed to copy documentation files:', error);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|