@mastra/mcp-docs-server 1.0.0-beta.4 → 1.0.0-beta.5
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/%40internal%2Fstorage-test-utils.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +326 -126
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flance.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Frag.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Freact.md +80 -1
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +36 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +92 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +67 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +201 -1
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +201 -1
- package/.docs/organized/changelogs/create-mastra.md +201 -1
- package/.docs/organized/changelogs/mastra.md +201 -1
- package/.docs/organized/code-examples/memory-with-processors.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +7 -10
- package/.docs/raw/agents/guardrails.mdx +19 -20
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +6 -5
- package/.docs/raw/agents/networks.mdx +1 -2
- package/.docs/raw/agents/overview.mdx +5 -5
- package/.docs/raw/agents/using-tools.mdx +4 -5
- package/.docs/raw/course/01-first-agent/05-running-playground.md +5 -5
- package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +3 -3
- package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +3 -3
- package/.docs/raw/course/01-first-agent/17-testing-memory.md +2 -2
- package/.docs/raw/course/04-workflows/07-using-playground.md +1 -1
- package/.docs/raw/deployment/building-mastra.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/azure-app-services.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +1 -1
- package/.docs/raw/deployment/mastra-cloud/observability.mdx +19 -17
- package/.docs/raw/deployment/mastra-cloud/setting-up.mdx +1 -1
- package/.docs/raw/deployment/overview.mdx +2 -2
- package/.docs/raw/deployment/web-framework.mdx +5 -5
- package/.docs/raw/evals/custom-scorers.mdx +3 -5
- package/.docs/raw/evals/overview.mdx +2 -3
- package/.docs/raw/getting-started/project-structure.mdx +1 -1
- package/.docs/raw/getting-started/start.mdx +72 -0
- package/.docs/raw/getting-started/studio.mdx +1 -1
- package/.docs/raw/{frameworks/agentic-uis/ai-sdk.mdx → guides/build-your-ui/ai-sdk-ui.mdx} +105 -11
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/astro.mdx +23 -25
- package/.docs/raw/{frameworks/servers → guides/getting-started}/express.mdx +3 -4
- package/.docs/raw/guides/{guide → getting-started}/manual-install.mdx +1 -1
- package/.docs/raw/guides/{quickstarts/nextjs.mdx → getting-started/next-js.mdx} +11 -11
- package/.docs/raw/guides/{quickstarts/standalone-server.mdx → getting-started/quickstart.mdx} +7 -7
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/sveltekit.mdx +23 -25
- package/.docs/raw/{frameworks/web-frameworks → guides/getting-started}/vite-react.mdx +7 -7
- package/.docs/raw/guides/guide/ai-recruiter.mdx +2 -3
- package/.docs/raw/guides/guide/chef-michel.mdx +2 -3
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +2 -2
- package/.docs/raw/guides/guide/research-assistant.mdx +7 -8
- package/.docs/raw/guides/guide/stock-agent.mdx +4 -6
- package/.docs/raw/guides/guide/web-search.mdx +12 -10
- package/.docs/raw/guides/migrations/agentnetwork.mdx +4 -4
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +29 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/tools.mdx +5 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +22 -0
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +2 -2
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mcp/overview.mdx +3 -5
- package/.docs/raw/memory/memory-processors.mdx +1 -2
- package/.docs/raw/memory/semantic-recall.mdx +7 -7
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-pg.mdx +2 -4
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +2 -4
- package/.docs/raw/memory/threads-and-resources.mdx +3 -3
- package/.docs/raw/memory/working-memory.mdx +4 -5
- package/.docs/raw/{logging.mdx → observability/logging.mdx} +1 -1
- package/.docs/raw/observability/overview.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/otel.mdx +21 -2
- package/.docs/raw/observability/tracing/exporters/posthog.mdx +107 -0
- package/.docs/raw/observability/tracing/overview.mdx +3 -2
- package/.docs/raw/rag/chunking-and-embedding.mdx +16 -17
- package/.docs/raw/rag/overview.mdx +3 -2
- package/.docs/raw/rag/retrieval.mdx +20 -32
- package/.docs/raw/reference/agents/agent.mdx +7 -10
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/network.mdx +2 -3
- package/.docs/raw/reference/cli/mastra.mdx +2 -1
- package/.docs/raw/reference/client-js/agents.mdx +3 -3
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +1 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
- package/.docs/raw/reference/core/mastra-model-gateway.mdx +5 -19
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/evals/answer-relevancy.mdx +28 -98
- package/.docs/raw/reference/evals/answer-similarity.mdx +12 -258
- package/.docs/raw/reference/evals/bias.mdx +29 -87
- package/.docs/raw/reference/evals/completeness.mdx +31 -90
- package/.docs/raw/reference/evals/content-similarity.mdx +28 -88
- package/.docs/raw/reference/evals/context-precision.mdx +28 -130
- package/.docs/raw/reference/evals/context-relevance.mdx +11 -11
- package/.docs/raw/reference/evals/faithfulness.mdx +28 -101
- package/.docs/raw/reference/evals/hallucination.mdx +28 -103
- package/.docs/raw/reference/evals/keyword-coverage.mdx +28 -107
- package/.docs/raw/reference/evals/noise-sensitivity.mdx +11 -11
- package/.docs/raw/reference/evals/prompt-alignment.mdx +15 -15
- package/.docs/raw/reference/evals/textual-difference.mdx +27 -100
- package/.docs/raw/reference/evals/tone-consistency.mdx +25 -98
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +7 -7
- package/.docs/raw/reference/evals/toxicity.mdx +29 -92
- package/.docs/raw/reference/memory/memory-class.mdx +5 -7
- package/.docs/raw/reference/observability/tracing/exporters/posthog.mdx +132 -0
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +1 -1
- package/.docs/raw/reference/processors/language-detector.mdx +1 -1
- package/.docs/raw/reference/processors/moderation-processor.mdx +2 -2
- package/.docs/raw/reference/processors/pii-detector.mdx +2 -2
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +1 -1
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -3
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +1 -1
- package/.docs/raw/reference/rag/embeddings.mdx +5 -5
- package/.docs/raw/reference/rag/rerank.mdx +1 -2
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +0 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +8 -1
- package/.docs/raw/reference/templates/overview.mdx +1 -4
- package/.docs/raw/reference/tools/client.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +132 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +5 -5
- package/.docs/raw/reference/tools/mcp-client.mdx +2 -4
- package/.docs/raw/reference/tools/mcp-server.mdx +1 -2
- package/.docs/raw/reference/tools/vector-query-tool.mdx +14 -15
- package/.docs/raw/reference/vectors/chroma.mdx +81 -1
- package/.docs/raw/reference/vectors/couchbase.mdx +24 -17
- package/.docs/raw/reference/vectors/lance.mdx +38 -22
- package/.docs/raw/reference/vectors/libsql.mdx +35 -2
- package/.docs/raw/reference/vectors/mongodb.mdx +35 -2
- package/.docs/raw/reference/vectors/opensearch.mdx +37 -16
- package/.docs/raw/reference/vectors/pg.mdx +43 -36
- package/.docs/raw/reference/vectors/pinecone.mdx +48 -1
- package/.docs/raw/reference/vectors/qdrant.mdx +36 -1
- package/.docs/raw/reference/vectors/turbopuffer.mdx +74 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +2 -2
- package/.docs/raw/reference/voice/voice.addInstructions.mdx +2 -3
- package/.docs/raw/reference/voice/voice.addTools.mdx +1 -1
- package/.docs/raw/reference/voice/voice.answer.mdx +1 -1
- package/.docs/raw/reference/voice/voice.close.mdx +1 -1
- package/.docs/raw/reference/voice/voice.connect.mdx +1 -1
- package/.docs/raw/reference/voice/voice.off.mdx +1 -1
- package/.docs/raw/reference/voice/voice.on.mdx +1 -1
- package/.docs/raw/reference/voice/voice.send.mdx +1 -1
- package/.docs/raw/reference/voice/voice.updateConfig.mdx +1 -1
- package/.docs/raw/server-db/mastra-client.mdx +1 -2
- package/.docs/raw/streaming/overview.mdx +20 -9
- package/.docs/raw/streaming/tool-streaming.mdx +47 -4
- package/.docs/raw/tools-mcp/advanced-usage.mdx +1 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +3 -5
- package/.docs/raw/voice/overview.mdx +21 -41
- package/.docs/raw/voice/speech-to-speech.mdx +4 -4
- package/.docs/raw/voice/speech-to-text.mdx +1 -2
- package/.docs/raw/voice/text-to-speech.mdx +1 -2
- package/.docs/raw/workflows/control-flow.mdx +180 -0
- package/CHANGELOG.md +10 -0
- package/dist/{chunk-5NJC7NRO.js → chunk-4CM2BQNP.js} +24 -4
- package/dist/prepare-docs/package-changes.d.ts.map +1 -1
- package/dist/prepare-docs/prepare.js +1 -1
- package/dist/stdio.js +1 -1
- package/package.json +7 -7
- package/.docs/raw/frameworks/agentic-uis/cedar-os.mdx +0 -102
- package/.docs/raw/frameworks/agentic-uis/openrouter.mdx +0 -179
- package/.docs/raw/frameworks/web-frameworks/next-js.mdx +0 -379
- package/.docs/raw/getting-started/quickstart.mdx +0 -27
- package/.docs/raw/getting-started/templates.mdx +0 -73
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/assistant-ui.mdx +0 -0
- /package/.docs/raw/{frameworks/agentic-uis → guides/build-your-ui}/copilotkit.mdx +0 -0
|
@@ -112,6 +112,70 @@ export const testWorkflow = createWorkflow({
|
|
|
112
112
|
|
|
113
113
|
> 📹 Watch: How to run steps in parallel and optimize your Mastra workflow → [YouTube (3 minutes)](https://youtu.be/GQJxve5Hki4)
|
|
114
114
|
|
|
115
|
+
### Output structure
|
|
116
|
+
|
|
117
|
+
When steps run in parallel, the output is an object where each key is the step's `id` and the value is that step's output. This allows you to access each parallel step's result independently.
|
|
118
|
+
|
|
119
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
120
|
+
const step1 = createStep({
|
|
121
|
+
id: "format-step",
|
|
122
|
+
inputSchema: z.object({ message: z.string() }),
|
|
123
|
+
outputSchema: z.object({ formatted: z.string() }),
|
|
124
|
+
execute: async ({ inputData }) => ({
|
|
125
|
+
formatted: inputData.message.toUpperCase()
|
|
126
|
+
})
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const step2 = createStep({
|
|
130
|
+
id: "count-step",
|
|
131
|
+
inputSchema: z.object({ message: z.string() }),
|
|
132
|
+
outputSchema: z.object({ count: z.number() }),
|
|
133
|
+
execute: async ({ inputData }) => ({
|
|
134
|
+
count: inputData.message.length
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const step3 = createStep({
|
|
139
|
+
id: "combine-step",
|
|
140
|
+
// The inputSchema must match the structure of parallel outputs
|
|
141
|
+
inputSchema: z.object({
|
|
142
|
+
"format-step": z.object({ formatted: z.string() }),
|
|
143
|
+
"count-step": z.object({ count: z.number() })
|
|
144
|
+
}),
|
|
145
|
+
outputSchema: z.object({ result: z.string() }),
|
|
146
|
+
execute: async ({ inputData }) => {
|
|
147
|
+
// Access each parallel step's output by its id
|
|
148
|
+
const formatted = inputData["format-step"].formatted;
|
|
149
|
+
const count = inputData["count-step"].count;
|
|
150
|
+
return {
|
|
151
|
+
result: `${formatted} (${count} characters)`
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export const testWorkflow = createWorkflow({
|
|
157
|
+
id: "parallel-output-example",
|
|
158
|
+
inputSchema: z.object({ message: z.string() }),
|
|
159
|
+
outputSchema: z.object({ result: z.string() })
|
|
160
|
+
})
|
|
161
|
+
.parallel([step1, step2])
|
|
162
|
+
.then(step3)
|
|
163
|
+
.commit();
|
|
164
|
+
|
|
165
|
+
// When executed with { message: "hello" }
|
|
166
|
+
// The parallel output structure will be:
|
|
167
|
+
// {
|
|
168
|
+
// "format-step": { formatted: "HELLO" },
|
|
169
|
+
// "count-step": { count: 5 }
|
|
170
|
+
// }
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Key points:**
|
|
174
|
+
- Each parallel step's output is keyed by its `id`
|
|
175
|
+
- All parallel steps execute simultaneously
|
|
176
|
+
- The next step receives an object containing all parallel step outputs
|
|
177
|
+
- You must define the `inputSchema` of the following step to match this structure
|
|
178
|
+
|
|
115
179
|
## Conditional logic with `.branch()`
|
|
116
180
|
|
|
117
181
|
Use `.branch()` to choose which step to run based on a condition. All steps in a branch need the same `inputSchema` and `outputSchema` because branching requires consistent schemas so workflows can follow different paths.
|
|
@@ -158,6 +222,85 @@ export const testWorkflow = createWorkflow({
|
|
|
158
222
|
.commit();
|
|
159
223
|
```
|
|
160
224
|
|
|
225
|
+
### Output structure
|
|
226
|
+
|
|
227
|
+
When using conditional branching, only one branch executes based on which condition evaluates to `true` first. The output structure is similar to `.parallel()`, where the result is keyed by the executed step's `id`.
|
|
228
|
+
|
|
229
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
230
|
+
const step1 = createStep({
|
|
231
|
+
id: "initial-step",
|
|
232
|
+
inputSchema: z.object({ value: z.number() }),
|
|
233
|
+
outputSchema: z.object({ value: z.number() }),
|
|
234
|
+
execute: async ({ inputData }) => inputData
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const highValueStep = createStep({
|
|
238
|
+
id: "high-value-step",
|
|
239
|
+
inputSchema: z.object({ value: z.number() }),
|
|
240
|
+
outputSchema: z.object({ result: z.string() }),
|
|
241
|
+
execute: async ({ inputData }) => ({
|
|
242
|
+
result: `High value: ${inputData.value}`
|
|
243
|
+
})
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const lowValueStep = createStep({
|
|
247
|
+
id: "low-value-step",
|
|
248
|
+
inputSchema: z.object({ value: z.number() }),
|
|
249
|
+
outputSchema: z.object({ result: z.string() }),
|
|
250
|
+
execute: async ({ inputData }) => ({
|
|
251
|
+
result: `Low value: ${inputData.value}`
|
|
252
|
+
})
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const finalStep = createStep({
|
|
256
|
+
id: "final-step",
|
|
257
|
+
// The inputSchema must account for either branch's output
|
|
258
|
+
inputSchema: z.object({
|
|
259
|
+
"high-value-step": z.object({ result: z.string() }).optional(),
|
|
260
|
+
"low-value-step": z.object({ result: z.string() }).optional()
|
|
261
|
+
}),
|
|
262
|
+
outputSchema: z.object({ message: z.string() }),
|
|
263
|
+
execute: async ({ inputData }) => {
|
|
264
|
+
// Only one branch will have executed
|
|
265
|
+
const result = inputData["high-value-step"]?.result ||
|
|
266
|
+
inputData["low-value-step"]?.result;
|
|
267
|
+
return { message: result };
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
export const testWorkflow = createWorkflow({
|
|
272
|
+
id: "branch-output-example",
|
|
273
|
+
inputSchema: z.object({ value: z.number() }),
|
|
274
|
+
outputSchema: z.object({ message: z.string() })
|
|
275
|
+
})
|
|
276
|
+
.then(step1)
|
|
277
|
+
.branch([
|
|
278
|
+
[async ({ inputData }) => inputData.value > 10, highValueStep],
|
|
279
|
+
[async ({ inputData }) => inputData.value <= 10, lowValueStep]
|
|
280
|
+
])
|
|
281
|
+
.then(finalStep)
|
|
282
|
+
.commit();
|
|
283
|
+
|
|
284
|
+
// When executed with { value: 15 }
|
|
285
|
+
// Only the high-value-step executes, output structure:
|
|
286
|
+
// {
|
|
287
|
+
// "high-value-step": { result: "High value: 15" }
|
|
288
|
+
// }
|
|
289
|
+
|
|
290
|
+
// When executed with { value: 5 }
|
|
291
|
+
// Only the low-value-step executes, output structure:
|
|
292
|
+
// {
|
|
293
|
+
// "low-value-step": { result: "Low value: 5" }
|
|
294
|
+
// }
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**Key points:**
|
|
298
|
+
- Only one branch executes based on condition evaluation order
|
|
299
|
+
- The output is keyed by the executed step's `id`
|
|
300
|
+
- Subsequent steps should handle all possible branch outputs
|
|
301
|
+
- Use optional fields in the `inputSchema` when the next step needs to handle multiple possible branches
|
|
302
|
+
- Conditions are evaluated in the order they're defined
|
|
303
|
+
|
|
161
304
|
## Input data mapping
|
|
162
305
|
|
|
163
306
|
When using `.then()`, `.parallel()`, or `.branch()`, it is sometimes necessary to transform the output of a previous step to match the input of the next. In these cases you can use `.map()` to access the `inputData` and transform it to create a suitable data shape for the next step.
|
|
@@ -188,6 +331,43 @@ The `.map()` method provides additional helper functions for more complex mappin
|
|
|
188
331
|
- [`getInitData()`](/reference/v1/workflows/workflow-methods/map#using-getinitdata): Access the workflow's initial input data
|
|
189
332
|
- [`mapVariable()`](/reference/v1/workflows/workflow-methods/map#using-mapvariable): Use declarative object syntax to extract and rename fields
|
|
190
333
|
|
|
334
|
+
### Parallel and Branch outputs
|
|
335
|
+
|
|
336
|
+
When working with `.parallel()` or `.branch()` outputs, you can use `.map()` to transform the data structure before passing it to the next step. This is especially useful when you need to flatten or restructure the output.
|
|
337
|
+
|
|
338
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
339
|
+
export const testWorkflow = createWorkflow({...})
|
|
340
|
+
.parallel([step1, step2])
|
|
341
|
+
.map(async ({ inputData }) => {
|
|
342
|
+
// Transform the parallel output structure
|
|
343
|
+
return {
|
|
344
|
+
combined: `${inputData["step1"].value} - ${inputData["step2"].value}`
|
|
345
|
+
};
|
|
346
|
+
})
|
|
347
|
+
.then(nextStep)
|
|
348
|
+
.commit();
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
You can also use the helper functions provided by `.map()`:
|
|
352
|
+
|
|
353
|
+
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
354
|
+
export const testWorkflow = createWorkflow({...})
|
|
355
|
+
.branch([
|
|
356
|
+
[condition1, stepA],
|
|
357
|
+
[condition2, stepB]
|
|
358
|
+
])
|
|
359
|
+
.map(async ({ inputData, getStepResult }) => {
|
|
360
|
+
// Access specific step results
|
|
361
|
+
const stepAResult = getStepResult("stepA");
|
|
362
|
+
const stepBResult = getStepResult("stepB");
|
|
363
|
+
|
|
364
|
+
// Return the result from whichever branch executed
|
|
365
|
+
return stepAResult || stepBResult;
|
|
366
|
+
})
|
|
367
|
+
.then(nextStep)
|
|
368
|
+
.commit();
|
|
369
|
+
```
|
|
370
|
+
|
|
191
371
|
## Looping steps
|
|
192
372
|
|
|
193
373
|
Workflows support different looping methods that let you repeat steps until or while a condition is met, or iterate over arrays. Loops can be combined with other control methods like `.then()`.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Ensure changelog truncation includes at least 2 versions before cutting off ([#10496](https://github.com/mastra-ai/mastra/pull/10496))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`21a15de`](https://github.com/mastra-ai/mastra/commit/21a15de369fe82aac26bb642ed7be73505475e8b), [`feb7ee4`](https://github.com/mastra-ai/mastra/commit/feb7ee4d09a75edb46c6669a3beaceec78811747), [`3f5f04d`](https://github.com/mastra-ai/mastra/commit/3f5f04d07b21fd373e70aa7d863226cc7bec4b4b), [`b0e2ea5`](https://github.com/mastra-ai/mastra/commit/b0e2ea5b52c40fae438b9e2f7baee6f0f89c5442), [`c456e01`](https://github.com/mastra-ai/mastra/commit/c456e0149e3c176afcefdbd9bb1d2c5917723725), [`ab035c2`](https://github.com/mastra-ai/mastra/commit/ab035c2ef6d8cc7bb25f06f1a38508bd9e6f126b), [`1a46a56`](https://github.com/mastra-ai/mastra/commit/1a46a566f45a3fcbadc1cf36bf86d351f264bfa3), [`3cf540b`](https://github.com/mastra-ai/mastra/commit/3cf540b9fbfea8f4fc8d3a2319a4e6c0b0cbfd52), [`1c6ce51`](https://github.com/mastra-ai/mastra/commit/1c6ce51f875915ab57fd36873623013699a2a65d), [`898a972`](https://github.com/mastra-ai/mastra/commit/898a9727d286c2510d6b702dfd367e6aaf5c6b0f), [`a97003a`](https://github.com/mastra-ai/mastra/commit/a97003aa1cf2f4022a41912324a1e77263b326b8), [`ccc141e`](https://github.com/mastra-ai/mastra/commit/ccc141ed27da0abc3a3fc28e9e5128152e8e37f4), [`fe3b897`](https://github.com/mastra-ai/mastra/commit/fe3b897c2ccbcd2b10e81b099438c7337feddf89), [`00123ba`](https://github.com/mastra-ai/mastra/commit/00123ba96dc9e5cd0b110420ebdba56d8f237b25), [`29c4309`](https://github.com/mastra-ai/mastra/commit/29c4309f818b24304c041bcb4a8f19b5f13f6b62), [`16785ce`](https://github.com/mastra-ai/mastra/commit/16785ced928f6f22638f4488cf8a125d99211799), [`de8239b`](https://github.com/mastra-ai/mastra/commit/de8239bdcb1d8c0cfa06da21f1569912a66bbc8a), [`b5e6cd7`](https://github.com/mastra-ai/mastra/commit/b5e6cd77fc8c8e64e0494c1d06cee3d84e795d1e), [`e2bbb9c`](https://github.com/mastra-ai/mastra/commit/e2bbb9ceee9bd04c807b06ed9582f01e3bafb3e1), [`3759cb0`](https://github.com/mastra-ai/mastra/commit/3759cb064935b5f74c65ac2f52a1145f7352899d), [`651e772`](https://github.com/mastra-ai/mastra/commit/651e772eb1475fb13e126d3fcc01751297a88214), [`b61b93f`](https://github.com/mastra-ai/mastra/commit/b61b93f9e058b11dd2eec169853175d31dbdd567), [`bae33d9`](https://github.com/mastra-ai/mastra/commit/bae33d91a63fbb64d1e80519e1fc1acaed1e9013), [`c0b731f`](https://github.com/mastra-ai/mastra/commit/c0b731fb27d712dc8582e846df5c0332a6a0c5ba), [`43ca8f2`](https://github.com/mastra-ai/mastra/commit/43ca8f2c7334851cc7b4d3d2f037d8784bfbdd5f), [`2ca67cc`](https://github.com/mastra-ai/mastra/commit/2ca67cc3bb1f6a617353fdcab197d9efebe60d6f), [`9e67002`](https://github.com/mastra-ai/mastra/commit/9e67002b52c9be19936c420a489dbee9c5fd6a78), [`35edc49`](https://github.com/mastra-ai/mastra/commit/35edc49ac0556db609189641d6341e76771b81fc)]:
|
|
10
|
+
- @mastra/core@1.0.0-beta.5
|
|
11
|
+
- @mastra/mcp@1.0.0-beta.3
|
|
12
|
+
|
|
3
13
|
## 1.0.0-beta.4
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -274,15 +274,35 @@ var SOURCE_DIRS = ["packages", "speech", "stores", "voice", "integrations", "dep
|
|
|
274
274
|
fromRepoRoot
|
|
275
275
|
);
|
|
276
276
|
var CHANGELOGS_DEST = fromPackageRoot(".docs/organized/changelogs");
|
|
277
|
-
var MAX_LINES =
|
|
277
|
+
var MAX_LINES = 500;
|
|
278
|
+
var MIN_VERSIONS = 2;
|
|
279
|
+
var VERSION_HEADER_REGEX = /^## \d+\.\d+\.\d+/;
|
|
278
280
|
function truncateContent(content, maxLines) {
|
|
279
281
|
const lines = content.split("\n");
|
|
280
282
|
if (lines.length <= maxLines) return content;
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
283
|
+
const versionIndices = [];
|
|
284
|
+
for (let i = 0; i < lines.length; i++) {
|
|
285
|
+
if (VERSION_HEADER_REGEX.test(lines[i])) {
|
|
286
|
+
versionIndices.push(i);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const versionsInMaxLines = versionIndices.filter((idx) => idx < maxLines).length;
|
|
290
|
+
let cutoffLine;
|
|
291
|
+
if (versionsInMaxLines >= MIN_VERSIONS) {
|
|
292
|
+
cutoffLine = maxLines;
|
|
293
|
+
} else if (versionIndices.length > MIN_VERSIONS) {
|
|
294
|
+
cutoffLine = versionIndices[MIN_VERSIONS];
|
|
295
|
+
} else {
|
|
296
|
+
cutoffLine = lines.length;
|
|
297
|
+
}
|
|
298
|
+
const visibleLines = lines.slice(0, cutoffLine);
|
|
299
|
+
const hiddenCount = lines.length - cutoffLine;
|
|
300
|
+
if (hiddenCount > 0) {
|
|
301
|
+
return visibleLines.join("\n") + `
|
|
284
302
|
|
|
285
303
|
... ${hiddenCount} more lines hidden. See full changelog in package directory.`;
|
|
304
|
+
}
|
|
305
|
+
return visibleLines.join("\n");
|
|
286
306
|
}
|
|
287
307
|
async function processPackageDir(packagePath, outputDir) {
|
|
288
308
|
let packageName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-changes.d.ts","sourceRoot":"","sources":["../../src/prepare-docs/package-changes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"package-changes.d.ts","sourceRoot":"","sources":["../../src/prepare-docs/package-changes.ts"],"names":[],"mappings":"AAiGA;;GAEG;AACH,wBAAsB,qBAAqB,kBAmC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { prepare } from '../chunk-
|
|
1
|
+
export { prepare } from '../chunk-4CM2BQNP.js';
|
package/dist/stdio.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { fromPackageRoot, prepare, getMatchingPaths, blogPostSchema } from './chunk-
|
|
2
|
+
import { fromPackageRoot, prepare, getMatchingPaths, blogPostSchema } from './chunk-4CM2BQNP.js';
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import { existsSync, mkdirSync } from 'fs';
|
|
5
5
|
import * as os2 from 'os';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.17.5",
|
|
29
29
|
"jsdom": "^26.1.0",
|
|
30
30
|
"zod": "^3.25.76",
|
|
31
|
-
"@mastra/
|
|
32
|
-
"@mastra/
|
|
31
|
+
"@mastra/core": "1.0.0-beta.5",
|
|
32
|
+
"@mastra/mcp": "^1.0.0-beta.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@hono/node-server": "^1.19.6",
|
|
36
36
|
"@types/jsdom": "^21.1.7",
|
|
37
37
|
"@types/node": "22.13.17",
|
|
38
|
-
"@vitest/coverage-v8": "4.0.
|
|
39
|
-
"@vitest/ui": "4.0.
|
|
38
|
+
"@vitest/coverage-v8": "4.0.12",
|
|
39
|
+
"@vitest/ui": "4.0.12",
|
|
40
40
|
"@wong2/mcp-cli": "^1.13.0",
|
|
41
41
|
"cross-env": "^10.1.0",
|
|
42
42
|
"eslint": "^9.37.0",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"tsup": "^8.5.0",
|
|
45
45
|
"tsx": "^4.19.4",
|
|
46
46
|
"typescript": "^5.8.3",
|
|
47
|
-
"vitest": "
|
|
47
|
+
"vitest": "4.0.12",
|
|
48
48
|
"@internal/lint": "0.0.53",
|
|
49
|
-
"@mastra/core": "1.0.0-beta.
|
|
49
|
+
"@mastra/core": "1.0.0-beta.5"
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://mastra.ai",
|
|
52
52
|
"repository": {
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Using Cedar-OS | Frameworks"
|
|
3
|
-
description: "Learn how to integrate Cedar-OS with Mastra"
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
import Tabs from "@theme/Tabs";
|
|
7
|
-
import TabItem from "@theme/TabItem";
|
|
8
|
-
import Steps from "@site/src/components/Steps";
|
|
9
|
-
import StepItem from "@site/src/components/StepItem";
|
|
10
|
-
|
|
11
|
-
# Using Cedar-OS
|
|
12
|
-
|
|
13
|
-
[Cedar-OS](https://docs.cedarcopilot.com/introduction/overview) is an open-source agentic UI framework designed specifically for building the most ambitious AI-native applications. Cedar was built with Mastra in mind.
|
|
14
|
-
|
|
15
|
-
:::info
|
|
16
|
-
|
|
17
|
-
Also see the [Extending Mastra](https://docs.cedarcopilot.com/agent-backend-connection/mastra) and [Custom Backend Implementation](https://docs.cedarcopilot.com/agent-backend-connection/custom) guides on Cedar's documentation site for more advanced integration patterns.
|
|
18
|
-
|
|
19
|
-
:::
|
|
20
|
-
|
|
21
|
-
## Integration Guide
|
|
22
|
-
|
|
23
|
-
<Steps>
|
|
24
|
-
|
|
25
|
-
<StepItem>
|
|
26
|
-
|
|
27
|
-
Run Cedar's CLI command:
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npx cedar-os-cli plant-seed
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
If starting from scratch, select the **Mastra starter** template for a complete setup with both frontend and backend in a monorepo
|
|
34
|
-
|
|
35
|
-
If you already have a Mastra backend, use the **blank frontend cedar repo** option instead. This will give you the option to download components and download all dependencies for Cedar. It is recommended to download at least one of the chat components to get started.
|
|
36
|
-
|
|
37
|
-
</StepItem>
|
|
38
|
-
|
|
39
|
-
<StepItem>
|
|
40
|
-
|
|
41
|
-
Wrap your application with the CedarCopilot provider to connect to your Mastra backend:
|
|
42
|
-
|
|
43
|
-
```tsx
|
|
44
|
-
import { CedarCopilot } from "cedar-os";
|
|
45
|
-
|
|
46
|
-
function App() {
|
|
47
|
-
return (
|
|
48
|
-
<CedarCopilot
|
|
49
|
-
llmProvider={{
|
|
50
|
-
provider: "mastra",
|
|
51
|
-
baseURL: "http://localhost:4111", // default dev port for Mastra
|
|
52
|
-
apiKey: process.env.NEXT_PUBLIC_MASTRA_API_KEY, // optional — only for backend auth
|
|
53
|
-
}}
|
|
54
|
-
>
|
|
55
|
-
<YourApp />
|
|
56
|
-
</CedarCopilot>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
</StepItem>
|
|
62
|
-
|
|
63
|
-
<StepItem>
|
|
64
|
-
|
|
65
|
-
Configure your Mastra backend to work with Cedar by following the [Mastra Configuration Options](https://docs.cedarcopilot.com/agent-backend-connection/agent-backend-connection#mastra-configuration-options).
|
|
66
|
-
|
|
67
|
-
[Register API routes](https://mastra.ai/en/examples/deployment/custom-api-route) in your Mastra server (or NextJS serverless routes if in a monorepo):
|
|
68
|
-
|
|
69
|
-
```ts mastra/src/index.ts
|
|
70
|
-
import { registerApiRoute } from "@mastra/core/server";
|
|
71
|
-
|
|
72
|
-
// POST /chat
|
|
73
|
-
// The chat's non-streaming default endpoint
|
|
74
|
-
registerApiRoute("/chat", {
|
|
75
|
-
method: "POST",
|
|
76
|
-
// …validate input w/ zod
|
|
77
|
-
handler: async (c) => {
|
|
78
|
-
/* your agent.generate() logic */
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// POST /chat/stream (SSE)
|
|
83
|
-
// The chat's streaming default endpoint
|
|
84
|
-
registerApiRoute("/chat/stream", {
|
|
85
|
-
method: "POST",
|
|
86
|
-
handler: async (c) => {
|
|
87
|
-
/* stream agent output in SSE format */
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
</StepItem>
|
|
93
|
-
|
|
94
|
-
<StepItem>
|
|
95
|
-
|
|
96
|
-
Drop Cedar components into your frontend – see [Chat Overview](https://docs.cedarcopilot.com/chat/chat-overview).
|
|
97
|
-
|
|
98
|
-
Your backend and frontend are now linked! You're ready to start building AI-native experiences with your Mastra agents.
|
|
99
|
-
|
|
100
|
-
</StepItem>
|
|
101
|
-
|
|
102
|
-
</Steps>
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Using OpenRouter | Frameworks"
|
|
3
|
-
description: "Learn how to integrate OpenRouter with Mastra"
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
import Steps from "@site/src/components/Steps";
|
|
7
|
-
import StepItem from "@site/src/components/StepItem";
|
|
8
|
-
|
|
9
|
-
# Using OpenRouter
|
|
10
|
-
|
|
11
|
-
Integrate [OpenRouter](https://openrouter.ai/) with Mastra to leverage the numerous models available on OpenRouter.
|
|
12
|
-
|
|
13
|
-
<Steps>
|
|
14
|
-
|
|
15
|
-
<StepItem>
|
|
16
|
-
|
|
17
|
-
The simplest way to get started with Mastra is to use the `mastra` CLI to initialize a new project:
|
|
18
|
-
|
|
19
|
-
```bash copy
|
|
20
|
-
npx create-mastra@beta
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
You'll be guided through prompts to set up your project. For this example, select:
|
|
24
|
-
|
|
25
|
-
- Name your project: my-mastra-openrouter-app
|
|
26
|
-
- Components: Agents (recommended)
|
|
27
|
-
- For default provider, select OpenAI (recommended) - we'll configure OpenRouter manually later
|
|
28
|
-
- Optionally include example code
|
|
29
|
-
|
|
30
|
-
</StepItem>
|
|
31
|
-
|
|
32
|
-
<StepItem>
|
|
33
|
-
|
|
34
|
-
After creating your project with `create-mastra`, you'll find a `.env` file in your project root.
|
|
35
|
-
Since we selected OpenAI during setup, we'll configure OpenRouter manually:
|
|
36
|
-
|
|
37
|
-
```bash title=".env" copy
|
|
38
|
-
OPENROUTER_API_KEY=
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
We remove the `@ai-sdk/openai` package from the project:
|
|
42
|
-
|
|
43
|
-
```bash copy
|
|
44
|
-
npm uninstall @ai-sdk/openai
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Then, we install the `@openrouter/ai-sdk-provider` package:
|
|
48
|
-
|
|
49
|
-
```bash copy
|
|
50
|
-
npm install @openrouter/ai-sdk-provider
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
</StepItem>
|
|
54
|
-
|
|
55
|
-
<StepItem>
|
|
56
|
-
|
|
57
|
-
We will now configure our agent to use OpenRouter.
|
|
58
|
-
|
|
59
|
-
```typescript title="src/mastra/agents/assistant.ts" copy showLineNumbers {4-6,11}
|
|
60
|
-
import { Agent } from "@mastra/core/agent";
|
|
61
|
-
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
|
62
|
-
|
|
63
|
-
const openrouter = createOpenRouter({
|
|
64
|
-
apiKey: process.env.OPENROUTER_API_KEY,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
export const assistant = new Agent({
|
|
68
|
-
id: "assistant",
|
|
69
|
-
name: "assistant",
|
|
70
|
-
instructions: "You are a helpful assistant.",
|
|
71
|
-
model: openrouter("anthropic/claude-sonnet-4"),
|
|
72
|
-
});
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Make sure to register your agent to the Mastra instance:
|
|
76
|
-
|
|
77
|
-
```typescript title="src/mastra/index.ts" copy showLineNumbers {4}
|
|
78
|
-
import { assistant } from "./agents/assistant";
|
|
79
|
-
|
|
80
|
-
export const mastra = new Mastra({
|
|
81
|
-
agents: { assistant },
|
|
82
|
-
});
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
</StepItem>
|
|
86
|
-
|
|
87
|
-
<StepItem>
|
|
88
|
-
|
|
89
|
-
```bash copy
|
|
90
|
-
npm run dev
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
This will start the Mastra development server.
|
|
94
|
-
|
|
95
|
-
You can now test your agent by visiting [http://localhost:4111](http://localhost:4111) and using Studio or via the Mastra API at [http://localhost:4111/api/agents/assistant/stream](http://localhost:4111/api/agents/assistant/stream).
|
|
96
|
-
|
|
97
|
-
</StepItem>
|
|
98
|
-
|
|
99
|
-
</Steps>
|
|
100
|
-
|
|
101
|
-
## Advanced Configuration
|
|
102
|
-
|
|
103
|
-
For more control over your OpenRouter requests, you can pass additional configuration options.
|
|
104
|
-
|
|
105
|
-
### Provider-wide options:
|
|
106
|
-
|
|
107
|
-
You can pass provider-wide options to the OpenRouter provider:
|
|
108
|
-
|
|
109
|
-
```typescript title="src/mastra/agents/assistant.ts" {6-10} copy showLineNumbers
|
|
110
|
-
import { Agent } from "@mastra/core/agent";
|
|
111
|
-
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
|
112
|
-
|
|
113
|
-
const openrouter = createOpenRouter({
|
|
114
|
-
apiKey: process.env.OPENROUTER_API_KEY,
|
|
115
|
-
extraBody: {
|
|
116
|
-
reasoning: {
|
|
117
|
-
max_tokens: 10,
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
export const assistant = new Agent({
|
|
123
|
-
id: "assistant",
|
|
124
|
-
name: "assistant",
|
|
125
|
-
instructions: "You are a helpful assistant.",
|
|
126
|
-
model: openrouter("anthropic/claude-sonnet-4"),
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Model-specific options:
|
|
131
|
-
|
|
132
|
-
You can pass model-specific options to the OpenRouter provider:
|
|
133
|
-
|
|
134
|
-
```typescript title="src/mastra/agents/assistant.ts" {11-17} copy showLineNumbers
|
|
135
|
-
import { Agent } from "@mastra/core/agent";
|
|
136
|
-
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
|
137
|
-
|
|
138
|
-
const openrouter = createOpenRouter({
|
|
139
|
-
apiKey: process.env.OPENROUTER_API_KEY,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
export const assistant = new Agent({
|
|
143
|
-
id: "assistant",
|
|
144
|
-
name: "assistant",
|
|
145
|
-
instructions: "You are a helpful assistant.",
|
|
146
|
-
model: openrouter("anthropic/claude-sonnet-4", {
|
|
147
|
-
extraBody: {
|
|
148
|
-
reasoning: {
|
|
149
|
-
max_tokens: 10,
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
}),
|
|
153
|
-
});
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Provider-specific options:
|
|
157
|
-
|
|
158
|
-
You can pass provider-specific options to the OpenRouter provider:
|
|
159
|
-
|
|
160
|
-
```typescript copy showLineNumbers {7-12}
|
|
161
|
-
// Get a response with provider-specific options
|
|
162
|
-
const response = await assistant.generate([
|
|
163
|
-
{
|
|
164
|
-
role: "system",
|
|
165
|
-
content:
|
|
166
|
-
"You are Chef Michel, a culinary expert specializing in ketogenic (keto) diet...",
|
|
167
|
-
providerOptions: {
|
|
168
|
-
// Provider-specific options - key can be 'anthropic' or 'openrouter'
|
|
169
|
-
anthropic: {
|
|
170
|
-
cacheControl: { type: "ephemeral" },
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
role: "user",
|
|
176
|
-
content: "Can you suggest a keto breakfast?",
|
|
177
|
-
},
|
|
178
|
-
]);
|
|
179
|
-
```
|