@mastra/mcp-docs-server 1.0.0-beta.13 → 1.0.0-beta.15
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 +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +78 -78
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +195 -195
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +173 -173
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +195 -195
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +195 -195
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +248 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +338 -338
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +41 -41
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +195 -195
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Flance.md +195 -195
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +195 -195
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +139 -139
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +219 -219
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +219 -219
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +235 -235
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +102 -102
- package/.docs/organized/changelogs/%40mastra%2Frag.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Freact.md +77 -70
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +218 -218
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +195 -195
- package/.docs/organized/changelogs/create-mastra.md +13 -13
- package/.docs/organized/changelogs/mastra.md +56 -56
- package/.docs/organized/code-examples/agent-v6.md +210 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/organized/code-examples/client-side-tools.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +10 -6
- package/.docs/raw/agents/agent-approval.mdx +5 -6
- package/.docs/raw/agents/agent-memory.mdx +22 -30
- package/.docs/raw/agents/guardrails.mdx +60 -50
- package/.docs/raw/agents/networks.mdx +8 -12
- package/.docs/raw/agents/overview.mdx +39 -23
- package/.docs/raw/agents/processors.mdx +20 -19
- package/.docs/raw/agents/structured-output.mdx +11 -7
- package/.docs/raw/agents/using-tools.mdx +4 -5
- package/.docs/raw/deployment/mastra-server.mdx +3 -3
- package/.docs/raw/deployment/overview.mdx +7 -1
- package/.docs/raw/deployment/web-framework.mdx +4 -6
- package/.docs/raw/deployment/workflow-runners.mdx +14 -0
- package/.docs/raw/evals/custom-scorers.mdx +9 -6
- package/.docs/raw/evals/overview.mdx +3 -6
- package/.docs/raw/evals/running-in-ci.mdx +2 -2
- package/.docs/raw/getting-started/manual-install.mdx +20 -20
- package/.docs/raw/getting-started/mcp-docs-server.mdx +2 -2
- package/.docs/raw/getting-started/studio.mdx +1 -1
- package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +4 -4
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +30 -30
- package/.docs/raw/guides/build-your-ui/assistant-ui.mdx +8 -8
- package/.docs/raw/guides/build-your-ui/copilotkit.mdx +11 -11
- package/.docs/raw/guides/deployment/amazon-ec2.mdx +9 -9
- package/.docs/raw/guides/deployment/aws-lambda.mdx +11 -11
- package/.docs/raw/guides/deployment/azure-app-services.mdx +2 -2
- package/.docs/raw/guides/deployment/cloudflare-deployer.mdx +5 -6
- package/.docs/raw/guides/deployment/digital-ocean.mdx +10 -10
- package/.docs/raw/guides/deployment/index.mdx +1 -1
- package/.docs/raw/guides/deployment/inngest.mdx +444 -0
- package/.docs/raw/guides/deployment/netlify-deployer.mdx +4 -4
- package/.docs/raw/guides/deployment/vercel-deployer.mdx +5 -6
- package/.docs/raw/guides/getting-started/astro.mdx +292 -451
- package/.docs/raw/guides/getting-started/express.mdx +7 -7
- package/.docs/raw/guides/getting-started/hono.mdx +18 -18
- package/.docs/raw/guides/getting-started/next-js.mdx +19 -20
- package/.docs/raw/guides/getting-started/quickstart.mdx +4 -4
- package/.docs/raw/guides/getting-started/sveltekit.mdx +238 -409
- package/.docs/raw/guides/getting-started/vite-react.mdx +21 -21
- package/.docs/raw/guides/guide/ai-recruiter.mdx +10 -10
- package/.docs/raw/guides/guide/chef-michel.mdx +9 -11
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +15 -15
- package/.docs/raw/guides/guide/research-assistant.mdx +13 -13
- package/.docs/raw/guides/guide/stock-agent.mdx +5 -5
- package/.docs/raw/guides/guide/web-search.mdx +8 -8
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +7 -7
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +2 -2
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/memory.mdx +11 -3
- package/.docs/raw/guides/migrations/upgrade-to-v1/processors.mdx +11 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/storage.mdx +41 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +0 -2
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +21 -23
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mastra-cloud/deployment.mdx +39 -0
- package/.docs/raw/mastra-cloud/observability.mdx +9 -15
- package/.docs/raw/mastra-cloud/overview.mdx +14 -44
- package/.docs/raw/mastra-cloud/setup.mdx +64 -0
- package/.docs/raw/mastra-cloud/studio.mdx +35 -0
- package/.docs/raw/mcp/overview.mdx +31 -13
- package/.docs/raw/mcp/publishing-mcp-server.mdx +2 -2
- package/.docs/raw/memory/memory-processors.mdx +9 -9
- package/.docs/raw/memory/message-history.mdx +69 -0
- package/.docs/raw/memory/overview.mdx +34 -76
- package/.docs/raw/memory/semantic-recall.mdx +58 -49
- package/.docs/raw/memory/storage.mdx +188 -0
- package/.docs/raw/memory/working-memory.mdx +7 -7
- package/.docs/raw/observability/logging.mdx +9 -10
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/default.mdx +3 -3
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +1 -2
- package/.docs/raw/observability/tracing/overview.mdx +23 -25
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +3 -3
- package/.docs/raw/rag/chunking-and-embedding.mdx +6 -6
- package/.docs/raw/rag/graph-rag.mdx +7 -7
- package/.docs/raw/rag/overview.mdx +1 -1
- package/.docs/raw/rag/retrieval.mdx +21 -22
- package/.docs/raw/rag/vector-databases.mdx +22 -22
- package/.docs/raw/reference/agents/agent.mdx +3 -3
- package/.docs/raw/reference/agents/generate.mdx +1 -1
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDescription.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +2 -2
- package/.docs/raw/reference/agents/getMemory.mdx +2 -2
- package/.docs/raw/reference/agents/getModel.mdx +2 -2
- package/.docs/raw/reference/agents/getTools.mdx +2 -2
- package/.docs/raw/reference/agents/getVoice.mdx +2 -2
- package/.docs/raw/reference/agents/listAgents.mdx +2 -2
- package/.docs/raw/reference/agents/listScorers.mdx +2 -2
- package/.docs/raw/reference/agents/listTools.mdx +2 -2
- package/.docs/raw/reference/agents/listWorkflows.mdx +2 -2
- package/.docs/raw/reference/agents/network.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/network-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +6 -6
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/with-mastra.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +2 -2
- package/.docs/raw/reference/auth/auth0.mdx +1 -2
- package/.docs/raw/reference/auth/clerk.mdx +1 -2
- package/.docs/raw/reference/auth/firebase.mdx +2 -4
- package/.docs/raw/reference/auth/jwt.mdx +1 -2
- package/.docs/raw/reference/auth/supabase.mdx +1 -2
- package/.docs/raw/reference/auth/workos.mdx +1 -2
- package/.docs/raw/reference/cli/create-mastra.mdx +10 -10
- package/.docs/raw/reference/cli/mastra.mdx +9 -9
- package/.docs/raw/reference/client-js/agents.mdx +1 -2
- package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
- package/.docs/raw/reference/core/getAgent.mdx +1 -1
- package/.docs/raw/reference/core/getAgentById.mdx +1 -1
- package/.docs/raw/reference/core/getDeployer.mdx +1 -1
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServer.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServerById.mdx +1 -1
- package/.docs/raw/reference/core/getMemory.mdx +2 -2
- package/.docs/raw/reference/core/getServer.mdx +1 -1
- package/.docs/raw/reference/core/getStorage.mdx +2 -2
- package/.docs/raw/reference/core/getStoredAgentById.mdx +3 -3
- package/.docs/raw/reference/core/getTelemetry.mdx +1 -1
- package/.docs/raw/reference/core/getVector.mdx +1 -1
- package/.docs/raw/reference/core/getWorkflow.mdx +1 -1
- package/.docs/raw/reference/core/listAgents.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/listMCPServers.mdx +1 -1
- package/.docs/raw/reference/core/listMemory.mdx +2 -2
- package/.docs/raw/reference/core/listStoredAgents.mdx +4 -4
- package/.docs/raw/reference/core/listVectors.mdx +1 -1
- package/.docs/raw/reference/core/listWorkflows.mdx +1 -1
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +2 -2
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/deployer/cloudflare.mdx +1 -2
- package/.docs/raw/reference/deployer/deployer.mdx +0 -1
- package/.docs/raw/reference/deployer/netlify.mdx +1 -1
- package/.docs/raw/reference/deployer/vercel.mdx +2 -4
- package/.docs/raw/reference/evals/answer-relevancy.mdx +1 -1
- package/.docs/raw/reference/evals/answer-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/bias.mdx +1 -1
- package/.docs/raw/reference/evals/completeness.mdx +1 -1
- package/.docs/raw/reference/evals/content-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/context-precision.mdx +1 -1
- package/.docs/raw/reference/evals/faithfulness.mdx +1 -1
- package/.docs/raw/reference/evals/hallucination.mdx +1 -1
- package/.docs/raw/reference/evals/keyword-coverage.mdx +1 -1
- package/.docs/raw/reference/evals/prompt-alignment.mdx +7 -7
- package/.docs/raw/reference/evals/textual-difference.mdx +1 -1
- package/.docs/raw/reference/evals/tone-consistency.mdx +1 -1
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +10 -10
- package/.docs/raw/reference/evals/toxicity.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +7 -8
- package/.docs/raw/reference/memory/createThread.mdx +2 -2
- package/.docs/raw/reference/memory/deleteMessages.mdx +2 -2
- package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +2 -2
- package/.docs/raw/reference/memory/memory-class.mdx +3 -3
- package/.docs/raw/reference/memory/query.mdx +2 -2
- package/.docs/raw/reference/memory/recall.mdx +2 -2
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +1 -1
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +2 -2
- package/.docs/raw/reference/processors/language-detector.mdx +2 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +2 -2
- package/.docs/raw/reference/processors/moderation-processor.mdx +3 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +3 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +13 -13
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +2 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +2 -2
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +40 -19
- package/.docs/raw/reference/processors/tool-call-filter.mdx +3 -3
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +2 -2
- package/.docs/raw/reference/processors/working-memory-processor.mdx +3 -3
- package/.docs/raw/reference/rag/chunk.mdx +1 -1
- package/.docs/raw/reference/rag/extract-params.mdx +2 -2
- package/.docs/raw/reference/rag/metadata-filters.mdx +7 -7
- package/.docs/raw/reference/server/create-route.mdx +13 -13
- package/.docs/raw/reference/server/express-adapter.mdx +6 -7
- package/.docs/raw/reference/server/hono-adapter.mdx +6 -7
- package/.docs/raw/reference/server/mastra-server.mdx +20 -20
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +7 -5
- package/.docs/raw/reference/storage/cloudflare.mdx +2 -2
- package/.docs/raw/reference/storage/convex.mdx +6 -6
- package/.docs/raw/reference/storage/dynamodb.mdx +4 -4
- package/.docs/raw/reference/storage/lance.mdx +6 -5
- package/.docs/raw/reference/storage/libsql.mdx +72 -54
- package/.docs/raw/reference/storage/mongodb.mdx +84 -9
- package/.docs/raw/reference/storage/mssql.mdx +8 -6
- package/.docs/raw/{memory → reference}/storage/overview.mdx +12 -110
- package/.docs/raw/reference/storage/postgresql.mdx +82 -9
- package/.docs/raw/reference/storage/upstash.mdx +74 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +5 -5
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/resumeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/stream.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +4 -4
- package/.docs/raw/reference/templates/overview.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +1 -4
- package/.docs/raw/reference/tools/vector-query-tool.mdx +1 -1
- package/.docs/raw/reference/vectors/astra.mdx +3 -3
- package/.docs/raw/reference/vectors/chroma.mdx +3 -3
- package/.docs/raw/reference/vectors/convex.mdx +12 -12
- package/.docs/raw/reference/vectors/couchbase.mdx +5 -5
- package/.docs/raw/reference/vectors/duckdb.mdx +10 -10
- package/.docs/raw/reference/vectors/elasticsearch.mdx +4 -4
- package/.docs/raw/reference/vectors/lance.mdx +4 -4
- package/.docs/raw/reference/vectors/libsql.mdx +61 -11
- package/.docs/raw/reference/vectors/mongodb.mdx +58 -5
- package/.docs/raw/reference/vectors/pg.mdx +53 -6
- package/.docs/raw/reference/vectors/pinecone.mdx +3 -3
- package/.docs/raw/reference/vectors/qdrant.mdx +3 -3
- package/.docs/raw/reference/vectors/s3vectors.mdx +6 -6
- package/.docs/raw/reference/vectors/turbopuffer.mdx +4 -4
- package/.docs/raw/reference/vectors/upstash.mdx +55 -6
- package/.docs/raw/reference/vectors/vectorize.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +1 -3
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/start.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +5 -5
- package/.docs/raw/reference/workflows/run.mdx +1 -1
- package/.docs/raw/reference/workflows/step.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/dountil.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/dowhile.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +6 -6
- package/.docs/raw/reference/workflows/workflow-methods/map.mdx +7 -7
- package/.docs/raw/reference/workflows/workflow-methods/parallel.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/then.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow.mdx +3 -3
- package/.docs/raw/server/auth/auth0.mdx +20 -14
- package/.docs/raw/server/auth/clerk.mdx +16 -9
- package/.docs/raw/server/auth/firebase.mdx +21 -15
- package/.docs/raw/server/auth/jwt.mdx +14 -7
- package/.docs/raw/server/auth/supabase.mdx +16 -9
- package/.docs/raw/server/auth/workos.mdx +19 -13
- package/.docs/raw/server/custom-adapters.mdx +10 -10
- package/.docs/raw/server/custom-api-routes.mdx +2 -4
- package/.docs/raw/server/mastra-client.mdx +24 -13
- package/.docs/raw/server/mastra-server.mdx +3 -3
- package/.docs/raw/server/middleware.mdx +7 -7
- package/.docs/raw/server/request-context.mdx +31 -30
- package/.docs/raw/server/server-adapters.mdx +6 -6
- package/.docs/raw/streaming/events.mdx +14 -7
- package/.docs/raw/streaming/overview.mdx +21 -10
- package/.docs/raw/streaming/tool-streaming.mdx +6 -6
- package/.docs/raw/streaming/workflow-streaming.mdx +6 -8
- package/.docs/raw/tools-mcp/advanced-usage.mdx +2 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +31 -12
- package/.docs/raw/tools-mcp/overview.mdx +9 -10
- package/.docs/raw/voice/overview.mdx +2 -2
- package/.docs/raw/workflows/agents-and-tools.mdx +28 -19
- package/.docs/raw/workflows/control-flow.mdx +27 -40
- package/.docs/raw/workflows/error-handling.mdx +15 -22
- package/.docs/raw/workflows/human-in-the-loop.mdx +6 -7
- package/.docs/raw/workflows/input-data-mapping.mdx +7 -7
- package/.docs/raw/workflows/overview.mdx +34 -23
- package/.docs/raw/workflows/snapshots.mdx +16 -45
- package/.docs/raw/workflows/suspend-and-resume.mdx +7 -7
- package/.docs/raw/workflows/time-travel.mdx +16 -16
- package/.docs/raw/workflows/workflow-state.mdx +5 -8
- package/CHANGELOG.md +16 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/stdio.js +53 -0
- package/package.json +3 -3
- package/.docs/raw/mastra-cloud/dashboard.mdx +0 -96
- package/.docs/raw/mastra-cloud/setting-up.mdx +0 -102
- package/.docs/raw/memory/conversation-history.mdx +0 -24
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +0 -140
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +0 -150
- package/.docs/raw/memory/storage/memory-with-pg.mdx +0 -138
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +0 -146
- package/.docs/raw/memory/threads-and-resources.mdx +0 -95
- package/.docs/raw/workflows/inngest-workflow.mdx +0 -363
|
@@ -25,7 +25,7 @@ The `MastraServer` abstract class from `@mastra/server/server-adapter` provides
|
|
|
25
25
|
|
|
26
26
|
The class takes three type parameters that represent your framework's types:
|
|
27
27
|
|
|
28
|
-
```typescript title="my-framework-adapter.ts"
|
|
28
|
+
```typescript title="my-framework-adapter.ts"
|
|
29
29
|
import { MastraServer } from '@mastra/server/server-adapter';
|
|
30
30
|
|
|
31
31
|
export class MyFrameworkServer extends MastraServer<
|
|
@@ -50,7 +50,7 @@ You must implement these six abstract methods. Each handles a specific part of t
|
|
|
50
50
|
|
|
51
51
|
This method runs first and attaches Mastra context to every incoming request. Route handlers need access to the Mastra instance, tools, and other context to function. How you attach this context depends on your framework — Express uses `res.locals`, Hono uses `c.set()`, and other frameworks have their own patterns.
|
|
52
52
|
|
|
53
|
-
```typescript
|
|
53
|
+
```typescript
|
|
54
54
|
registerContextMiddleware(): void {
|
|
55
55
|
this.app.use('*', (req, res, next) => {
|
|
56
56
|
// Attach context to your framework's request/response
|
|
@@ -77,7 +77,7 @@ Context to attach:
|
|
|
77
77
|
|
|
78
78
|
Register authentication and authorization middleware. This method should check if authentication is configured on the Mastra instance and skip registration entirely if not. When auth is configured, you'll typically register two middleware functions: one for authentication (validating tokens and setting the user) and one for authorization (checking if the user can access the requested resource).
|
|
79
79
|
|
|
80
|
-
```typescript
|
|
80
|
+
```typescript
|
|
81
81
|
registerAuthMiddleware(): void {
|
|
82
82
|
const authConfig = this.mastra.getServer()?.auth;
|
|
83
83
|
if (!authConfig) return;
|
|
@@ -113,7 +113,7 @@ registerAuthMiddleware(): void {
|
|
|
113
113
|
|
|
114
114
|
Register a single route with your framework. This method is called once for each Mastra route during initialization. It receives a `ServerRoute` object containing the path, HTTP method, handler function, and Zod schemas for validation. Your implementation should wire this up to your framework's routing system.
|
|
115
115
|
|
|
116
|
-
```typescript
|
|
116
|
+
```typescript
|
|
117
117
|
async registerRoute(
|
|
118
118
|
app: MyApp,
|
|
119
119
|
route: ServerRoute,
|
|
@@ -160,7 +160,7 @@ async registerRoute(
|
|
|
160
160
|
|
|
161
161
|
Extract URL parameters, query parameters, and request body from the incoming request. Different frameworks expose these values in different ways—Express uses `req.params`, `req.query`, and `req.body`, while other frameworks may use different property names or require method calls. This method normalizes the extraction for your framework.
|
|
162
162
|
|
|
163
|
-
```typescript
|
|
163
|
+
```typescript
|
|
164
164
|
async getParams(
|
|
165
165
|
route: ServerRoute,
|
|
166
166
|
request: MyRequest
|
|
@@ -184,7 +184,7 @@ async getParams(
|
|
|
184
184
|
|
|
185
185
|
Send the response back to the client based on the route's response type. Mastra routes can return different response types: JSON for most API responses, streams for agent generation, and special types for MCP transports. Your implementation should handle each type appropriately for your framework.
|
|
186
186
|
|
|
187
|
-
```typescript
|
|
187
|
+
```typescript
|
|
188
188
|
async sendResponse(
|
|
189
189
|
route: ServerRoute,
|
|
190
190
|
response: MyResponse,
|
|
@@ -219,7 +219,7 @@ async sendResponse(
|
|
|
219
219
|
|
|
220
220
|
Handle streaming responses for agent generation. When an agent generates a response, it produces a stream of chunks that should be sent to the client as they become available. This method reads from the stream, optionally applies redaction to hide sensitive data, and writes chunks to the response in the appropriate format (SSE or newline-delimited JSON).
|
|
221
221
|
|
|
222
|
-
```typescript
|
|
222
|
+
```typescript
|
|
223
223
|
async stream(
|
|
224
224
|
route: ServerRoute,
|
|
225
225
|
response: MyResponse,
|
|
@@ -282,7 +282,7 @@ The `parse*` methods use Zod schemas defined on each route to validate input and
|
|
|
282
282
|
|
|
283
283
|
Your adapter's constructor should accept the same options as the base class and pass them to `super()`. You can add additional framework-specific options if needed:
|
|
284
284
|
|
|
285
|
-
```typescript
|
|
285
|
+
```typescript
|
|
286
286
|
constructor(options: {
|
|
287
287
|
app: MyApp;
|
|
288
288
|
mastra: Mastra;
|
|
@@ -302,7 +302,7 @@ See [Server Adapters](/docs/v1/server/server-adapters#constructor-options) for f
|
|
|
302
302
|
|
|
303
303
|
Here's a skeleton implementation showing all the required methods. This uses pseudocode for framework-specific parts—replace with your framework's actual APIs:
|
|
304
304
|
|
|
305
|
-
```typescript title="my-framework-adapter.ts"
|
|
305
|
+
```typescript title="my-framework-adapter.ts"
|
|
306
306
|
import { MastraServer, ServerRoute } from '@mastra/server/server-adapter';
|
|
307
307
|
import type { Mastra } from '@mastra/core';
|
|
308
308
|
|
|
@@ -359,7 +359,7 @@ export class MyFrameworkServer extends MastraServer<MyApp, MyRequest, MyResponse
|
|
|
359
359
|
|
|
360
360
|
Once your adapter is implemented, use it the same way as the provided adapters:
|
|
361
361
|
|
|
362
|
-
```typescript title="server.ts"
|
|
362
|
+
```typescript title="server.ts"
|
|
363
363
|
import { MyFrameworkServer } from './my-framework-adapter';
|
|
364
364
|
import { mastra } from './mastra';
|
|
365
365
|
|
|
@@ -9,12 +9,11 @@ By default, Mastra automatically exposes registered agents and workflows via its
|
|
|
9
9
|
|
|
10
10
|
Routes are provided with a helper `registerApiRoute()` from `@mastra/core/server`. Routes can live in the same file as the `Mastra` instance but separating them helps keep configuration concise.
|
|
11
11
|
|
|
12
|
-
```typescript title="src/mastra/index.ts"
|
|
12
|
+
```typescript title="src/mastra/index.ts"
|
|
13
13
|
import { Mastra } from "@mastra/core";
|
|
14
14
|
import { registerApiRoute } from "@mastra/core/server";
|
|
15
15
|
|
|
16
16
|
export const mastra = new Mastra({
|
|
17
|
-
// ...
|
|
18
17
|
server: {
|
|
19
18
|
apiRoutes: [
|
|
20
19
|
registerApiRoute("/my-custom-route", {
|
|
@@ -41,12 +40,11 @@ Each route's handler receives the Hono `Context`. Within the handler you can acc
|
|
|
41
40
|
|
|
42
41
|
To add route-specific middleware pass a `middleware` array when calling `registerApiRoute()`.
|
|
43
42
|
|
|
44
|
-
```typescript title="src/mastra/index.ts"
|
|
43
|
+
```typescript title="src/mastra/index.ts"
|
|
45
44
|
import { Mastra } from "@mastra/core";
|
|
46
45
|
import { registerApiRoute } from "@mastra/core/server";
|
|
47
46
|
|
|
48
47
|
export const mastra = new Mastra({
|
|
49
|
-
// ...
|
|
50
48
|
server: {
|
|
51
49
|
apiRoutes: [
|
|
52
50
|
registerApiRoute("/my-custom-route", {
|
|
@@ -61,7 +61,7 @@ To use the Mastra Client SDK, install the required dependencies:
|
|
|
61
61
|
|
|
62
62
|
Once initialized with a `baseUrl`, `MastraClient` exposes a type-safe interface for calling agents, tools, and workflows.
|
|
63
63
|
|
|
64
|
-
```typescript title="lib/mastra-client.ts"
|
|
64
|
+
```typescript title="lib/mastra-client.ts"
|
|
65
65
|
import { MastraClient } from "@mastra/client-js";
|
|
66
66
|
|
|
67
67
|
export const mastraClient = new MastraClient({
|
|
@@ -85,7 +85,7 @@ The Mastra Client SDK exposes all resources served by the Mastra Server
|
|
|
85
85
|
|
|
86
86
|
Call `.generate()` with an array of message objects that include `role` and `content`:
|
|
87
87
|
|
|
88
|
-
```typescript
|
|
88
|
+
```typescript
|
|
89
89
|
import { mastraClient } from "lib/mastra-client";
|
|
90
90
|
|
|
91
91
|
const testAgent = async () => {
|
|
@@ -108,13 +108,17 @@ const testAgent = async () => {
|
|
|
108
108
|
};
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
:::info
|
|
112
|
+
|
|
113
|
+
Visit [.generate()](/reference/v1/client-js/agents#generate-response) for more information.
|
|
114
|
+
|
|
115
|
+
:::
|
|
112
116
|
|
|
113
117
|
## Streaming responses
|
|
114
118
|
|
|
115
119
|
Use `.stream()` for real-time responses with an array of message objects that include `role` and `content`:
|
|
116
120
|
|
|
117
|
-
```typescript
|
|
121
|
+
```typescript
|
|
118
122
|
import { mastraClient } from "lib/mastra-client";
|
|
119
123
|
|
|
120
124
|
const testAgent = async () => {
|
|
@@ -141,17 +145,20 @@ const testAgent = async () => {
|
|
|
141
145
|
};
|
|
142
146
|
```
|
|
143
147
|
|
|
144
|
-
|
|
148
|
+
:::info
|
|
149
|
+
|
|
150
|
+
Visit [.stream()](/reference/v1/client-js/agents#stream-response) for more information.
|
|
151
|
+
|
|
152
|
+
:::
|
|
145
153
|
|
|
146
154
|
## Configuration options
|
|
147
155
|
|
|
148
156
|
`MastraClient` accepts optional parameters like `retries`, `backoffMs`, and `headers` to control request behavior. These parameters are useful for controlling retry behavior and including diagnostic metadata.
|
|
149
157
|
|
|
150
|
-
```typescript title="lib/mastra-client.ts"
|
|
158
|
+
```typescript title="lib/mastra-client.ts"
|
|
151
159
|
import { MastraClient } from "@mastra/client-js";
|
|
152
160
|
|
|
153
161
|
export const mastraClient = new MastraClient({
|
|
154
|
-
// ...
|
|
155
162
|
retries: 3,
|
|
156
163
|
backoffMs: 300,
|
|
157
164
|
maxBackoffMs: 5000,
|
|
@@ -161,7 +168,11 @@ export const mastraClient = new MastraClient({
|
|
|
161
168
|
});
|
|
162
169
|
```
|
|
163
170
|
|
|
164
|
-
|
|
171
|
+
:::info
|
|
172
|
+
|
|
173
|
+
Visit [MastraClient](/reference/v1/client-js/mastra-client) for more configuration options.
|
|
174
|
+
|
|
175
|
+
:::
|
|
165
176
|
|
|
166
177
|
## Adding request cancelling
|
|
167
178
|
|
|
@@ -169,7 +180,7 @@ export const mastraClient = new MastraClient({
|
|
|
169
180
|
|
|
170
181
|
Pass an `AbortSignal` to the client constructor to enable cancellation across all requests.
|
|
171
182
|
|
|
172
|
-
```typescript {3,7} title="lib/mastra-client.ts"
|
|
183
|
+
```typescript {3,7} title="lib/mastra-client.ts"
|
|
173
184
|
import { MastraClient } from "@mastra/client-js";
|
|
174
185
|
|
|
175
186
|
export const controller = new AbortController();
|
|
@@ -184,7 +195,7 @@ export const mastraClient = new MastraClient({
|
|
|
184
195
|
|
|
185
196
|
Calling `.abort()` will cancel any ongoing requests tied to that signal.
|
|
186
197
|
|
|
187
|
-
```typescript {4}
|
|
198
|
+
```typescript {4}
|
|
188
199
|
import { mastraClient, controller } from "lib/mastra-client";
|
|
189
200
|
|
|
190
201
|
const handleAbort = () => {
|
|
@@ -198,7 +209,7 @@ Define tools directly in client-side applications using the `createTool()` funct
|
|
|
198
209
|
|
|
199
210
|
This lets agents trigger browser-side functionality such as DOM manipulation, local storage access, or other Web APIs, enabling tool execution in the user's environment rather than on the server.
|
|
200
211
|
|
|
201
|
-
```typescript {27}
|
|
212
|
+
```typescript {27}
|
|
202
213
|
import { createTool } from "@mastra/client-js";
|
|
203
214
|
import { z } from "zod";
|
|
204
215
|
|
|
@@ -239,7 +250,7 @@ const handleClientTool = async () => {
|
|
|
239
250
|
|
|
240
251
|
This is a standard Mastra [agent](../agents/overview#setting-up-agents) configured to return hex color codes, intended to work with the browser-based client tool defined above.
|
|
241
252
|
|
|
242
|
-
```typescript title="src/mastra/agents/color-agent"
|
|
253
|
+
```typescript title="src/mastra/agents/color-agent"
|
|
243
254
|
import { Agent } from "@mastra/core/agent";
|
|
244
255
|
|
|
245
256
|
export const colorAgent = new Agent({
|
|
@@ -256,7 +267,7 @@ export const colorAgent = new Agent({
|
|
|
256
267
|
|
|
257
268
|
You can also use `MastraClient` in server-side environments such as API routes, serverless functions or actions. The usage will broadly remain the same but you may need to recreate the response to your client:
|
|
258
269
|
|
|
259
|
-
```typescript {8}
|
|
270
|
+
```typescript {8}
|
|
260
271
|
export async function action() {
|
|
261
272
|
const agent = mastraClient.getAgent("testAgent");
|
|
262
273
|
|
|
@@ -35,7 +35,7 @@ adding additional server behaviour.
|
|
|
35
35
|
|
|
36
36
|
You can configure server `port`, `host`, `studioBase`, and `timeout` in the Mastra instance.
|
|
37
37
|
|
|
38
|
-
```typescript title="src/mastra/index.ts"
|
|
38
|
+
```typescript title="src/mastra/index.ts"
|
|
39
39
|
import { Mastra } from "@mastra/core";
|
|
40
40
|
|
|
41
41
|
export const mastra = new Mastra({
|
|
@@ -54,7 +54,7 @@ The `studioBase` option allows you to host Mastra Studio on a sub-path of your e
|
|
|
54
54
|
|
|
55
55
|
Mastra requires `module` and `moduleResolution` values that support modern Node.js versions. Older settings like `CommonJS` or `node` are incompatible with Mastra’s packages and will cause resolution errors.
|
|
56
56
|
|
|
57
|
-
```json {4-5} title="tsconfig.json"
|
|
57
|
+
```json {4-5} title="tsconfig.json"
|
|
58
58
|
{
|
|
59
59
|
"compilerOptions": {
|
|
60
60
|
"target": "ES2022",
|
|
@@ -77,7 +77,7 @@ Mastra requires `module` and `moduleResolution` values that support modern Node.
|
|
|
77
77
|
|
|
78
78
|
Mastra allows you to configure CORS (Cross-Origin Resource Sharing) settings for your server.
|
|
79
79
|
|
|
80
|
-
```typescript title="src/mastra/index.ts"
|
|
80
|
+
```typescript title="src/mastra/index.ts"
|
|
81
81
|
import { Mastra } from "@mastra/core";
|
|
82
82
|
|
|
83
83
|
export const mastra = new Mastra({
|
|
@@ -13,7 +13,7 @@ A middleware receives the [Hono](https://hono.dev) `Context` (`c`) and a `next`
|
|
|
13
13
|
function. If it returns a `Response` the request is short-circuited. Calling
|
|
14
14
|
`next()` continues processing the next middleware or route handler.
|
|
15
15
|
|
|
16
|
-
```typescript
|
|
16
|
+
```typescript
|
|
17
17
|
import { Mastra } from "@mastra/core";
|
|
18
18
|
|
|
19
19
|
export const mastra = new Mastra({
|
|
@@ -44,7 +44,7 @@ export const mastra = new Mastra({
|
|
|
44
44
|
To attach middleware to a single route pass the `middleware` option to
|
|
45
45
|
`registerApiRoute`:
|
|
46
46
|
|
|
47
|
-
```typescript
|
|
47
|
+
```typescript
|
|
48
48
|
registerApiRoute("/my-custom-route", {
|
|
49
49
|
method: "GET",
|
|
50
50
|
middleware: [
|
|
@@ -68,7 +68,7 @@ registerApiRoute("/my-custom-route", {
|
|
|
68
68
|
|
|
69
69
|
You can populate `RequestContext` dynamically in server middleware by extracting information from the request. In this example, the `temperature-unit` is set based on the Cloudflare `CF-IPCountry` header to ensure responses match the user's locale.
|
|
70
70
|
|
|
71
|
-
```typescript title="src/mastra/index.ts"
|
|
71
|
+
```typescript title="src/mastra/index.ts"
|
|
72
72
|
import { Mastra } from "@mastra/core";
|
|
73
73
|
import { RequestContext } from "@mastra/core/request-context";
|
|
74
74
|
import { testWeatherAgent } from "./agents/test-weather-agent";
|
|
@@ -95,7 +95,7 @@ export const mastra = new Mastra({
|
|
|
95
95
|
|
|
96
96
|
### Authentication
|
|
97
97
|
|
|
98
|
-
```typescript
|
|
98
|
+
```typescript
|
|
99
99
|
{
|
|
100
100
|
handler: async (c, next) => {
|
|
101
101
|
const authHeader = c.req.header('Authorization');
|
|
@@ -112,7 +112,7 @@ export const mastra = new Mastra({
|
|
|
112
112
|
|
|
113
113
|
### CORS support
|
|
114
114
|
|
|
115
|
-
```typescript
|
|
115
|
+
```typescript
|
|
116
116
|
{
|
|
117
117
|
handler: async (c, next) => {
|
|
118
118
|
c.header('Access-Control-Allow-Origin', '*');
|
|
@@ -136,7 +136,7 @@ export const mastra = new Mastra({
|
|
|
136
136
|
|
|
137
137
|
### Request logging
|
|
138
138
|
|
|
139
|
-
```typescript
|
|
139
|
+
```typescript
|
|
140
140
|
{
|
|
141
141
|
handler: async (c, next) => {
|
|
142
142
|
const start = Date.now();
|
|
@@ -152,7 +152,7 @@ export const mastra = new Mastra({
|
|
|
152
152
|
When integrating with Mastra Cloud or custom clients the following headers can
|
|
153
153
|
be inspected by middleware to tailor behavior:
|
|
154
154
|
|
|
155
|
-
```typescript
|
|
155
|
+
```typescript
|
|
156
156
|
{
|
|
157
157
|
handler: async (c, next) => {
|
|
158
158
|
const isFromMastraCloud = c.req.header('x-mastra-cloud') === 'true';
|
|
@@ -28,7 +28,7 @@ The `.set()` method takes two arguments:
|
|
|
28
28
|
1. **key**: The name used to identify the value.
|
|
29
29
|
2. **value**: The data to associate with that key.
|
|
30
30
|
|
|
31
|
-
```typescript
|
|
31
|
+
```typescript
|
|
32
32
|
import { RequestContext } from "@mastra/core/request-context";
|
|
33
33
|
|
|
34
34
|
export type UserTier = {
|
|
@@ -74,7 +74,7 @@ await weatherTool.execute({
|
|
|
74
74
|
|
|
75
75
|
You can populate `requestContext` dynamically in server middleware by extracting information from the request. In this example, the `temperature-unit` is set based on the Cloudflare `CF-IPCountry` header to ensure responses match the user's locale.
|
|
76
76
|
|
|
77
|
-
```typescript title="src/mastra/index.ts"
|
|
77
|
+
```typescript title="src/mastra/index.ts"
|
|
78
78
|
import { Mastra } from "@mastra/core";
|
|
79
79
|
import { RequestContext } from "@mastra/core/request-context";
|
|
80
80
|
import { testWeatherAgent } from "./agents/test-weather-agent";
|
|
@@ -99,13 +99,17 @@ export const mastra = new Mastra({
|
|
|
99
99
|
});
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
:::info
|
|
103
|
+
|
|
104
|
+
Visit [Middleware](/docs/v1/server/middleware) for how to use server middleware.
|
|
105
|
+
|
|
106
|
+
:::
|
|
103
107
|
|
|
104
108
|
## Accessing values with agents
|
|
105
109
|
|
|
106
110
|
You can access the `requestContext` argument from any supported configuration options in agents. These functions can be sync or `async`. Use the `.get()` method to read values from `requestContext`.
|
|
107
111
|
|
|
108
|
-
```typescript
|
|
112
|
+
```typescript title="src/mastra/agents/weather-agent.ts"
|
|
109
113
|
export type UserTier = {
|
|
110
114
|
"user-tier": "enterprise" | "pro";
|
|
111
115
|
};
|
|
@@ -116,32 +120,27 @@ export const weatherAgent = new Agent({
|
|
|
116
120
|
instructions: async ({ requestContext }) => {
|
|
117
121
|
const userTier = requestContext.get("user-tier") as UserTier["user-tier"];
|
|
118
122
|
|
|
119
|
-
if (userTier === "enterprise") {
|
|
120
|
-
// ...
|
|
121
|
-
}
|
|
122
|
-
// ...
|
|
123
|
-
},
|
|
124
|
-
model: ({ requestContext }) => {
|
|
125
|
-
// ...
|
|
126
|
-
},
|
|
127
|
-
tools: ({ requestContext }) => {
|
|
128
|
-
// ...
|
|
129
|
-
},
|
|
130
|
-
memory: ({ requestContext }) => {
|
|
131
|
-
// ...
|
|
123
|
+
if (userTier === "enterprise") {}
|
|
132
124
|
},
|
|
125
|
+
model: ({ requestContext }) => {},
|
|
126
|
+
tools: ({ requestContext }) => {},
|
|
127
|
+
memory: ({ requestContext }) => {},
|
|
133
128
|
});
|
|
134
129
|
```
|
|
135
130
|
|
|
136
131
|
You can also use `requestContext` with other options like `agents`, `workflows`, `scorers`, `inputProcessors`, and `outputProcessors`.
|
|
137
132
|
|
|
138
|
-
|
|
133
|
+
:::info
|
|
134
|
+
|
|
135
|
+
Visit [Agent](/reference/v1/agents/agent) for a full list of configuration options.
|
|
136
|
+
|
|
137
|
+
:::
|
|
139
138
|
|
|
140
139
|
## Accessing values from workflow steps
|
|
141
140
|
|
|
142
141
|
You can access the `requestContext` argument from a workflow step's `execute` function. This function can be sync or async. Use the `.get()` method to read values from `requestContext`.
|
|
143
142
|
|
|
144
|
-
```typescript
|
|
143
|
+
```typescript title="src/mastra/workflows/weather-workflow.ts"
|
|
145
144
|
export type UserTier = {
|
|
146
145
|
"user-tier": "enterprise" | "pro";
|
|
147
146
|
};
|
|
@@ -151,21 +150,22 @@ const stepOne = createStep({
|
|
|
151
150
|
execute: async ({ requestContext }) => {
|
|
152
151
|
const userTier = requestContext.get("user-tier") as UserTier["user-tier"];
|
|
153
152
|
|
|
154
|
-
if (userTier === "enterprise") {
|
|
155
|
-
// ...
|
|
156
|
-
}
|
|
157
|
-
// ...
|
|
153
|
+
if (userTier === "enterprise") {}
|
|
158
154
|
},
|
|
159
155
|
});
|
|
160
156
|
```
|
|
161
157
|
|
|
162
|
-
|
|
158
|
+
:::info
|
|
159
|
+
|
|
160
|
+
Visit [createStep()](/reference/v1/workflows/step) for a full list of configuration options.
|
|
161
|
+
|
|
162
|
+
:::
|
|
163
163
|
|
|
164
164
|
## Accessing values with tools
|
|
165
165
|
|
|
166
166
|
You can access the `requestContext` argument from a tool’s `execute` function. This function is `async`. Use the `.get()` method to read values from `requestContext`.
|
|
167
167
|
|
|
168
|
-
```typescript
|
|
168
|
+
```typescript title="src/mastra/tools/weather-tool.ts"
|
|
169
169
|
export type UserTier = {
|
|
170
170
|
"user-tier": "enterprise" | "pro";
|
|
171
171
|
};
|
|
@@ -175,15 +175,16 @@ export const weatherTool = createTool({
|
|
|
175
175
|
execute: async ({ requestContext }) => {
|
|
176
176
|
const userTier = requestContext.get("user-tier") as UserTier["user-tier"];
|
|
177
177
|
|
|
178
|
-
if (userTier === "enterprise") {
|
|
179
|
-
// ...
|
|
180
|
-
}
|
|
181
|
-
// ...
|
|
178
|
+
if (userTier === "enterprise") {}
|
|
182
179
|
},
|
|
183
180
|
});
|
|
184
181
|
```
|
|
185
182
|
|
|
186
|
-
|
|
183
|
+
:::info
|
|
184
|
+
|
|
185
|
+
Visit [createTool()](/reference/v1/tools/create-tool) for a full list of configuration options.
|
|
186
|
+
|
|
187
|
+
:::
|
|
187
188
|
|
|
188
189
|
## Related
|
|
189
190
|
|
|
@@ -115,7 +115,7 @@ Calling `init()` runs three steps in order. Understanding this flow helps when y
|
|
|
115
115
|
|
|
116
116
|
For custom middleware ordering, call each method separately instead of `init()`. This is useful when you need middleware that runs before Mastra's context is set up, or when you need to insert logic between the initialization steps.
|
|
117
117
|
|
|
118
|
-
```typescript title="server.ts"
|
|
118
|
+
```typescript title="server.ts"
|
|
119
119
|
const server = new MastraServer({ app, mastra });
|
|
120
120
|
|
|
121
121
|
// Your middleware first
|
|
@@ -156,7 +156,7 @@ Visit "Adding custom routes" for [Express](/reference/v1/server/express-adapter#
|
|
|
156
156
|
|
|
157
157
|
By default, Mastra routes are registered at `/api/agents`, `/api/workflows`, etc. Use the `prefix` option to change this. This is useful for API versioning or when integrating with an existing app that has its own `/api` routes.
|
|
158
158
|
|
|
159
|
-
```typescript
|
|
159
|
+
```typescript
|
|
160
160
|
const server = new MastraServer({
|
|
161
161
|
app,
|
|
162
162
|
mastra,
|
|
@@ -170,7 +170,7 @@ With this prefix, Mastra routes become `/api/v2/agents`, `/api/v2/workflows`, et
|
|
|
170
170
|
|
|
171
171
|
Mastra can generate an OpenAPI specification for all registered routes. This is useful for documentation, client generation, or integration with API tools. Enable it by setting the `openapiPath` option:
|
|
172
172
|
|
|
173
|
-
```typescript
|
|
173
|
+
```typescript
|
|
174
174
|
const server = new MastraServer({
|
|
175
175
|
app,
|
|
176
176
|
mastra,
|
|
@@ -193,7 +193,7 @@ This redaction happens at the HTTP boundary, so internal callbacks like `onStepF
|
|
|
193
193
|
|
|
194
194
|
By default, redaction is enabled. Configure this behavior via `streamOptions`. Set `redact: false` only for internal services or debugging scenarios where you need access to the full request data in stream responses.
|
|
195
195
|
|
|
196
|
-
```typescript
|
|
196
|
+
```typescript
|
|
197
197
|
const server = new MastraServer({
|
|
198
198
|
app,
|
|
199
199
|
mastra,
|
|
@@ -215,7 +215,7 @@ When authentication is configured on your Mastra instance, all routes require au
|
|
|
215
215
|
|
|
216
216
|
Use `customRouteAuthConfig` to override authentication behavior for specific routes. Keys follow the format `METHOD:PATH` where method is `GET`, `POST`, `PUT`, `DELETE`, or `ALL`. Paths support wildcards (`*`) for matching multiple routes. Setting a value to `false` makes the route public, while `true` requires authentication.
|
|
217
217
|
|
|
218
|
-
```typescript
|
|
218
|
+
```typescript
|
|
219
219
|
const server = new MastraServer({
|
|
220
220
|
app,
|
|
221
221
|
mastra,
|
|
@@ -244,7 +244,7 @@ See [MastraServer](/reference/v1/server/mastra-server) for full configuration op
|
|
|
244
244
|
|
|
245
245
|
After creating the adapter, you may still need access to the underlying framework app. This is useful when passing it to a platform’s `serve` function or when adding routes from another module.
|
|
246
246
|
|
|
247
|
-
```typescript
|
|
247
|
+
```typescript
|
|
248
248
|
// Via the MastraServer instance
|
|
249
249
|
const app = server.getApp();
|
|
250
250
|
|
|
@@ -44,7 +44,7 @@ When using `agent.network()` for multi-agent collaboration, additional event typ
|
|
|
44
44
|
|
|
45
45
|
Iterate over the `stream` with a `for await` loop to inspect all emitted event chunks.
|
|
46
46
|
|
|
47
|
-
```typescript
|
|
47
|
+
```typescript
|
|
48
48
|
const testAgent = mastra.getAgent("testAgent");
|
|
49
49
|
|
|
50
50
|
const stream = await testAgent.stream([
|
|
@@ -56,7 +56,11 @@ for await (const chunk of stream) {
|
|
|
56
56
|
}
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
:::info
|
|
60
|
+
|
|
61
|
+
Visit [Agent.stream()](/reference/v1/streaming/agents/stream) for more information.
|
|
62
|
+
|
|
63
|
+
:::
|
|
60
64
|
|
|
61
65
|
### Example agent output
|
|
62
66
|
|
|
@@ -91,7 +95,7 @@ Below is an example of events that may be emitted. Each event always includes a
|
|
|
91
95
|
|
|
92
96
|
Iterate over the `stream` with a `for await` loop to inspect all emitted event chunks.
|
|
93
97
|
|
|
94
|
-
```typescript {5,11}
|
|
98
|
+
```typescript {5,11}
|
|
95
99
|
const testWorkflow = mastra.getWorkflow("testWorkflow");
|
|
96
100
|
|
|
97
101
|
const run = await testWorkflow.createRun();
|
|
@@ -136,7 +140,7 @@ Below is an example of events that may be emitted. Each event always includes a
|
|
|
136
140
|
|
|
137
141
|
When using multi-agent collaboration with `agent.network()`, iterate over the stream to track how tasks are delegated and executed across agents, workflows, and tools.
|
|
138
142
|
|
|
139
|
-
```typescript {3,5}
|
|
143
|
+
```typescript {3,5}
|
|
140
144
|
const networkAgent = mastra.getAgent("networkAgent");
|
|
141
145
|
|
|
142
146
|
const networkStream = await networkAgent.network(
|
|
@@ -148,7 +152,11 @@ for await (const chunk of networkStream) {
|
|
|
148
152
|
}
|
|
149
153
|
```
|
|
150
154
|
|
|
151
|
-
|
|
155
|
+
:::info
|
|
156
|
+
|
|
157
|
+
Visit [Agent.network()](/reference/v1/agents/network) for more information.
|
|
158
|
+
|
|
159
|
+
:::
|
|
152
160
|
|
|
153
161
|
### Example network output
|
|
154
162
|
|
|
@@ -195,14 +203,13 @@ Network streams emit events that track the orchestration flow. Each iteration be
|
|
|
195
203
|
}
|
|
196
204
|
}
|
|
197
205
|
}
|
|
198
|
-
// ...more events
|
|
199
206
|
```
|
|
200
207
|
|
|
201
208
|
### Filtering network events
|
|
202
209
|
|
|
203
210
|
You can filter events by type to track specific aspects of the network execution:
|
|
204
211
|
|
|
205
|
-
```typescript {5-8,11-13,16-18}
|
|
212
|
+
```typescript {5-8,11-13,16-18}
|
|
206
213
|
const networkStream = await networkAgent.network(
|
|
207
214
|
"Analyze data and create visualization",
|
|
208
215
|
);
|
|
@@ -22,7 +22,7 @@ You can pass a single string for simple prompts, an array of strings when provid
|
|
|
22
22
|
|
|
23
23
|
A `textStream` breaks the response into chunks as it's generated, allowing output to stream progressively instead of arriving all at once. Iterate over the `textStream` using a `for await` loop to inspect each stream chunk.
|
|
24
24
|
|
|
25
|
-
```typescript {3,7}
|
|
25
|
+
```typescript {3,7}
|
|
26
26
|
const testAgent = mastra.getAgent("testAgent");
|
|
27
27
|
|
|
28
28
|
const stream = await testAgent.stream([
|
|
@@ -34,7 +34,11 @@ for await (const chunk of stream.textStream) {
|
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
:::info
|
|
38
|
+
|
|
39
|
+
Visit [Agent.stream()](/reference/v1/streaming/agents/stream) for more information.
|
|
40
|
+
|
|
41
|
+
:::
|
|
38
42
|
|
|
39
43
|
### Output from `Agent.stream()`
|
|
40
44
|
|
|
@@ -62,7 +66,7 @@ AI SDK v5 uses `LanguageModelV2` for the model providers. If you are getting an
|
|
|
62
66
|
|
|
63
67
|
For integration with AI SDK v5, use the `toAISdkV5Stream()` utility from `@mastra/ai-sdk` to convert Mastra streams to AI SDK-compatible format:
|
|
64
68
|
|
|
65
|
-
```typescript {2,9-12}
|
|
69
|
+
```typescript {2,9-12}
|
|
66
70
|
import { toAISdkV5Stream } from "@mastra/ai-sdk";
|
|
67
71
|
|
|
68
72
|
const testAgent = mastra.getAgent("testAgent");
|
|
@@ -79,7 +83,7 @@ const aiSDKStream = toAISdkV5Stream(stream, { from: "agent" });
|
|
|
79
83
|
|
|
80
84
|
For converting messages to AI SDK v5 format, use the `toAISdkV5Messages()` utility from `@mastra/ai-sdk/ui`:
|
|
81
85
|
|
|
82
|
-
```typescript {1,4}
|
|
86
|
+
```typescript {1,4}
|
|
83
87
|
import { toAISdkV5Messages } from "@mastra/ai-sdk/ui";
|
|
84
88
|
|
|
85
89
|
const messages = [{ role: "user", content: "Hello" }];
|
|
@@ -92,7 +96,7 @@ The `network()` method enables multi-agent collaboration by executing a network
|
|
|
92
96
|
|
|
93
97
|
> **Note**: This method is experimental and requires memory to be configured on the agent.
|
|
94
98
|
|
|
95
|
-
```typescript {3,5-7}
|
|
99
|
+
```typescript {3,5-7}
|
|
96
100
|
const testAgent = mastra.getAgent("testAgent");
|
|
97
101
|
|
|
98
102
|
const networkStream = await testAgent.network("Help me organize my day");
|
|
@@ -102,7 +106,11 @@ for await (const chunk of networkStream) {
|
|
|
102
106
|
}
|
|
103
107
|
```
|
|
104
108
|
|
|
105
|
-
|
|
109
|
+
:::info
|
|
110
|
+
|
|
111
|
+
Visit [Agent.network()](/reference/v1/agents/network) for more information.
|
|
112
|
+
|
|
113
|
+
:::
|
|
106
114
|
|
|
107
115
|
#### Network stream properties
|
|
108
116
|
|
|
@@ -112,7 +120,7 @@ The network stream provides access to execution information:
|
|
|
112
120
|
- **`networkStream.result`**: Promise resolving to the complete execution results
|
|
113
121
|
- **`networkStream.usage`**: Promise resolving to token usage information
|
|
114
122
|
|
|
115
|
-
```typescript {9-11}
|
|
123
|
+
```typescript {9-11}
|
|
116
124
|
const testAgent = mastra.getAgent("testAgent");
|
|
117
125
|
|
|
118
126
|
const networkStream = await testAgent.network(
|
|
@@ -136,7 +144,7 @@ Streaming from a workflow returns a sequence of structured events describing the
|
|
|
136
144
|
|
|
137
145
|
The `stream()` method returns a `ReadableStream` of events directly.
|
|
138
146
|
|
|
139
|
-
```typescript {3,9}
|
|
147
|
+
```typescript {3,9}
|
|
140
148
|
const run = await testWorkflow.createRun();
|
|
141
149
|
|
|
142
150
|
const stream = await run.stream({
|
|
@@ -150,14 +158,17 @@ for await (const chunk of stream) {
|
|
|
150
158
|
}
|
|
151
159
|
```
|
|
152
160
|
|
|
153
|
-
|
|
161
|
+
:::info
|
|
162
|
+
|
|
163
|
+
Visit [Run.stream()](/reference/v1/streaming/workflows/stream) for more information.
|
|
164
|
+
|
|
165
|
+
:::
|
|
154
166
|
|
|
155
167
|
### Output from `Run.stream()`
|
|
156
168
|
|
|
157
169
|
The event structure includes `runId` and `from` at the top level, making it easier to identify and track workflow runs without digging into the payload.
|
|
158
170
|
|
|
159
171
|
```typescript
|
|
160
|
-
// ...
|
|
161
172
|
{
|
|
162
173
|
type: 'workflow-start',
|
|
163
174
|
runId: '1eeaf01a-d2bf-4e3f-8d1b-027795ccd3df',
|