@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
|
@@ -70,7 +70,7 @@ The five processor methods run at different points in the agent execution lifecy
|
|
|
70
70
|
|
|
71
71
|
## Interface definition
|
|
72
72
|
|
|
73
|
-
```typescript
|
|
73
|
+
```typescript
|
|
74
74
|
interface Processor<TId extends string = string> {
|
|
75
75
|
readonly id: TId;
|
|
76
76
|
readonly name?: string;
|
|
@@ -108,7 +108,7 @@ interface Processor<TId extends string = string> {
|
|
|
108
108
|
|
|
109
109
|
Processes input messages before they are sent to the LLM. Runs once at the start of agent execution.
|
|
110
110
|
|
|
111
|
-
```typescript
|
|
111
|
+
```typescript
|
|
112
112
|
processInput?(args: ProcessInputArgs): Promise<ProcessInputResult> | ProcessInputResult;
|
|
113
113
|
```
|
|
114
114
|
|
|
@@ -191,7 +191,7 @@ The method can return one of three types:
|
|
|
191
191
|
|
|
192
192
|
Processes input messages at each step of the agentic loop, before they are sent to the LLM. Unlike `processInput` which runs once at the start, this runs at every step including tool call continuations.
|
|
193
193
|
|
|
194
|
-
```typescript
|
|
194
|
+
```typescript
|
|
195
195
|
processInputStep?(args: ProcessInputStepArgs): ProcessorMessageResult;
|
|
196
196
|
```
|
|
197
197
|
|
|
@@ -401,7 +401,7 @@ System messages are **reset to their original values** at the start of each step
|
|
|
401
401
|
|
|
402
402
|
Processes streaming output chunks with built-in state management. Allows processors to accumulate chunks and make decisions based on larger context.
|
|
403
403
|
|
|
404
|
-
```typescript
|
|
404
|
+
```typescript
|
|
405
405
|
processOutputStream?(args: ProcessOutputStreamArgs): Promise<ChunkType | null | undefined>;
|
|
406
406
|
```
|
|
407
407
|
|
|
@@ -465,7 +465,7 @@ processOutputStream?(args: ProcessOutputStreamArgs): Promise<ChunkType | null |
|
|
|
465
465
|
|
|
466
466
|
Processes the complete output result after streaming or generation is finished.
|
|
467
467
|
|
|
468
|
-
```typescript
|
|
468
|
+
```typescript
|
|
469
469
|
processOutputResult?(args: ProcessOutputResultArgs): ProcessorMessageResult;
|
|
470
470
|
```
|
|
471
471
|
|
|
@@ -512,7 +512,7 @@ processOutputResult?(args: ProcessOutputResultArgs): ProcessorMessageResult;
|
|
|
512
512
|
|
|
513
513
|
Processes output after each LLM response in the agentic loop, before tool execution. Unlike `processOutputResult` which runs once at the end, this runs at every step. This is the ideal method for implementing guardrails that can trigger retries.
|
|
514
514
|
|
|
515
|
-
```typescript
|
|
515
|
+
```typescript
|
|
516
516
|
processOutputStep?(args: ProcessOutputStepArgs): ProcessorMessageResult;
|
|
517
517
|
```
|
|
518
518
|
|
|
@@ -598,7 +598,7 @@ processOutputStep?(args: ProcessOutputStepArgs): ProcessorMessageResult;
|
|
|
598
598
|
|
|
599
599
|
#### Example: Quality guardrail with retry
|
|
600
600
|
|
|
601
|
-
```typescript title="src/mastra/processors/quality-guardrail.ts"
|
|
601
|
+
```typescript title="src/mastra/processors/quality-guardrail.ts"
|
|
602
602
|
import type { Processor } from "@mastra/core";
|
|
603
603
|
|
|
604
604
|
export class QualityGuardrail implements Processor {
|
|
@@ -629,7 +629,7 @@ export class QualityGuardrail implements Processor {
|
|
|
629
629
|
|
|
630
630
|
Mastra provides type aliases to ensure processors implement the required methods:
|
|
631
631
|
|
|
632
|
-
```typescript
|
|
632
|
+
```typescript
|
|
633
633
|
// Must implement processInput OR processInputStep (or both)
|
|
634
634
|
type InputProcessor = Processor & (
|
|
635
635
|
| { processInput: required }
|
|
@@ -648,7 +648,7 @@ type OutputProcessor = Processor & (
|
|
|
648
648
|
|
|
649
649
|
### Basic input processor
|
|
650
650
|
|
|
651
|
-
```typescript title="src/mastra/processors/lowercase.ts"
|
|
651
|
+
```typescript title="src/mastra/processors/lowercase.ts"
|
|
652
652
|
import type { Processor, MastraDBMessage } from "@mastra/core";
|
|
653
653
|
|
|
654
654
|
export class LowercaseProcessor implements Processor {
|
|
@@ -672,7 +672,7 @@ export class LowercaseProcessor implements Processor {
|
|
|
672
672
|
|
|
673
673
|
### Per-step processor with processInputStep
|
|
674
674
|
|
|
675
|
-
```typescript title="src/mastra/processors/dynamic-model.ts"
|
|
675
|
+
```typescript title="src/mastra/processors/dynamic-model.ts"
|
|
676
676
|
import type { Processor, ProcessInputStepArgs, ProcessInputStepResult } from "@mastra/core";
|
|
677
677
|
|
|
678
678
|
export class DynamicModelProcessor implements Processor {
|
|
@@ -705,7 +705,7 @@ export class DynamicModelProcessor implements Processor {
|
|
|
705
705
|
|
|
706
706
|
### Message transformer with processInputStep
|
|
707
707
|
|
|
708
|
-
```typescript title="src/mastra/processors/reasoning-transformer.ts"
|
|
708
|
+
```typescript title="src/mastra/processors/reasoning-transformer.ts"
|
|
709
709
|
import type { Processor, MastraDBMessage } from "@mastra/core";
|
|
710
710
|
|
|
711
711
|
export class ReasoningTransformer implements Processor {
|
|
@@ -730,7 +730,7 @@ export class ReasoningTransformer implements Processor {
|
|
|
730
730
|
|
|
731
731
|
### Hybrid processor (input and output)
|
|
732
732
|
|
|
733
|
-
```typescript title="src/mastra/processors/content-filter.ts"
|
|
733
|
+
```typescript title="src/mastra/processors/content-filter.ts"
|
|
734
734
|
import type { Processor, MastraDBMessage, ChunkType } from "@mastra/core";
|
|
735
735
|
|
|
736
736
|
export class ContentFilter implements Processor {
|
|
@@ -768,7 +768,7 @@ export class ContentFilter implements Processor {
|
|
|
768
768
|
|
|
769
769
|
### Stream accumulator with state
|
|
770
770
|
|
|
771
|
-
```typescript title="src/mastra/processors/word-counter.ts"
|
|
771
|
+
```typescript title="src/mastra/processors/word-counter.ts"
|
|
772
772
|
import type { Processor, ChunkType } from "@mastra/core";
|
|
773
773
|
|
|
774
774
|
export class WordCounter implements Processor {
|
|
@@ -9,7 +9,7 @@ The `PromptInjectionDetector` is an **input processor** that detects and prevent
|
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
12
|
+
```typescript
|
|
13
13
|
import { PromptInjectionDetector } from "@mastra/core/processors";
|
|
14
14
|
|
|
15
15
|
const processor = new PromptInjectionDetector({
|
|
@@ -115,7 +115,7 @@ const processor = new PromptInjectionDetector({
|
|
|
115
115
|
|
|
116
116
|
## Extended usage example
|
|
117
117
|
|
|
118
|
-
```typescript title="src/mastra/agents/secure-agent.ts"
|
|
118
|
+
```typescript title="src/mastra/agents/secure-agent.ts"
|
|
119
119
|
import { Agent } from "@mastra/core/agent";
|
|
120
120
|
import { PromptInjectionDetector } from "@mastra/core/processors";
|
|
121
121
|
|
|
@@ -9,7 +9,7 @@ The `SemanticRecall` is a **hybrid processor** that enables semantic search over
|
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
12
|
+
```typescript
|
|
13
13
|
import { SemanticRecall } from "@mastra/core/processors";
|
|
14
14
|
import { openai } from "@ai-sdk/openai";
|
|
15
15
|
|
|
@@ -133,7 +133,7 @@ const processor = new SemanticRecall({
|
|
|
133
133
|
|
|
134
134
|
## Extended usage example
|
|
135
135
|
|
|
136
|
-
```typescript title="src/mastra/agents/semantic-memory-agent.ts"
|
|
136
|
+
```typescript title="src/mastra/agents/semantic-memory-agent.ts"
|
|
137
137
|
import { Agent } from "@mastra/core/agent";
|
|
138
138
|
import { SemanticRecall, MessageHistory } from "@mastra/core/processors";
|
|
139
139
|
import { PostgresStorage } from "@mastra/pg";
|
|
@@ -9,7 +9,7 @@ The `SystemPromptScrubber` is an **output processor** that detects and handles s
|
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
12
|
+
```typescript
|
|
13
13
|
import { SystemPromptScrubber } from "@mastra/core/processors";
|
|
14
14
|
|
|
15
15
|
const processor = new SystemPromptScrubber({
|
|
@@ -123,7 +123,7 @@ const processor = new SystemPromptScrubber({
|
|
|
123
123
|
|
|
124
124
|
When using `SystemPromptScrubber` as an output processor, it's recommended to combine it with `BatchPartsProcessor` to optimize performance. The `BatchPartsProcessor` batches stream chunks together before passing them to the scrubber, reducing the number of LLM calls required for detection.
|
|
125
125
|
|
|
126
|
-
```typescript title="src/mastra/agents/scrubbed-agent.ts"
|
|
126
|
+
```typescript title="src/mastra/agents/scrubbed-agent.ts"
|
|
127
127
|
import { Agent } from "@mastra/core/agent";
|
|
128
128
|
import { BatchPartsProcessor, SystemPromptScrubber } from "@mastra/core/processors";
|
|
129
129
|
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Reference: Token Limiter Processor | Processors"
|
|
3
|
-
description: "Documentation for the TokenLimiterProcessor in Mastra, which limits the number of tokens in
|
|
3
|
+
description: "Documentation for the TokenLimiterProcessor in Mastra, which limits the number of tokens in messages."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# TokenLimiterProcessor
|
|
7
7
|
|
|
8
|
-
The `TokenLimiterProcessor`
|
|
8
|
+
The `TokenLimiterProcessor` limits the number of tokens in messages. It can be used as both an input and output processor:
|
|
9
|
+
|
|
10
|
+
- **Input processor**: Filters historical messages to fit within the context window, prioritizing recent messages
|
|
11
|
+
- **Output processor**: Limits generated response tokens via streaming or non-streaming with configurable strategies for handling exceeded limits
|
|
9
12
|
|
|
10
13
|
## Usage example
|
|
11
14
|
|
|
12
|
-
```typescript
|
|
15
|
+
```typescript
|
|
13
16
|
import { TokenLimiterProcessor } from "@mastra/core/processors";
|
|
14
17
|
|
|
15
18
|
const processor = new TokenLimiterProcessor({
|
|
@@ -82,6 +85,12 @@ const processor = new TokenLimiterProcessor({
|
|
|
82
85
|
description: "Optional processor display name",
|
|
83
86
|
isOptional: true,
|
|
84
87
|
},
|
|
88
|
+
{
|
|
89
|
+
name: "processInput",
|
|
90
|
+
type: "(args: { messages: MastraDBMessage[]; abort: (reason?: string) => never }) => Promise<MastraDBMessage[]>",
|
|
91
|
+
description: "Filters input messages to fit within token limit, prioritizing recent messages while preserving system messages",
|
|
92
|
+
isOptional: false,
|
|
93
|
+
},
|
|
85
94
|
{
|
|
86
95
|
name: "processOutputStream",
|
|
87
96
|
type: "(args: { part: ChunkType; streamParts: ChunkType[]; state: Record<string, any>; abort: (reason?: string) => never }) => Promise<ChunkType | null>",
|
|
@@ -90,22 +99,10 @@ const processor = new TokenLimiterProcessor({
|
|
|
90
99
|
},
|
|
91
100
|
{
|
|
92
101
|
name: "processOutputResult",
|
|
93
|
-
type: "(args: { messages:
|
|
102
|
+
type: "(args: { messages: MastraDBMessage[]; abort: (reason?: string) => never }) => Promise<MastraDBMessage[]>",
|
|
94
103
|
description: "Processes final output results to limit token count in non-streaming scenarios",
|
|
95
104
|
isOptional: false,
|
|
96
105
|
},
|
|
97
|
-
{
|
|
98
|
-
name: "reset",
|
|
99
|
-
type: "() => void",
|
|
100
|
-
description: "Reset the token counter (useful for testing or reusing the processor)",
|
|
101
|
-
isOptional: false,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
name: "getCurrentTokens",
|
|
105
|
-
type: "() => number",
|
|
106
|
-
description: "Get the current token count",
|
|
107
|
-
isOptional: false,
|
|
108
|
-
},
|
|
109
106
|
{
|
|
110
107
|
name: "getMaxTokens",
|
|
111
108
|
type: "() => number",
|
|
@@ -117,14 +114,38 @@ const processor = new TokenLimiterProcessor({
|
|
|
117
114
|
|
|
118
115
|
## Extended usage example
|
|
119
116
|
|
|
120
|
-
|
|
117
|
+
### As an input processor (limit context window)
|
|
118
|
+
|
|
119
|
+
Use `inputProcessors` to limit historical messages sent to the model, which helps stay within context window limits:
|
|
120
|
+
|
|
121
|
+
```typescript title="src/mastra/agents/context-limited-agent.ts"
|
|
122
|
+
import { Agent } from "@mastra/core/agent";
|
|
123
|
+
import { Memory } from "@mastra/memory";
|
|
124
|
+
import { TokenLimiterProcessor } from "@mastra/core/processors";
|
|
125
|
+
|
|
126
|
+
export const agent = new Agent({
|
|
127
|
+
name: "context-limited-agent",
|
|
128
|
+
instructions: "You are a helpful assistant",
|
|
129
|
+
model: "openai/gpt-4o",
|
|
130
|
+
memory: new Memory({ /* ... */ }),
|
|
131
|
+
inputProcessors: [
|
|
132
|
+
new TokenLimiterProcessor({ limit: 4000 }) // Limits historical messages to ~4000 tokens
|
|
133
|
+
]
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### As an output processor (limit response length)
|
|
138
|
+
|
|
139
|
+
Use `outputProcessors` to limit the length of generated responses:
|
|
140
|
+
|
|
141
|
+
```typescript title="src/mastra/agents/response-limited-agent.ts"
|
|
121
142
|
import { Agent } from "@mastra/core/agent";
|
|
122
143
|
import { TokenLimiterProcessor } from "@mastra/core/processors";
|
|
123
144
|
|
|
124
145
|
export const agent = new Agent({
|
|
125
|
-
name: "limited-agent",
|
|
146
|
+
name: "response-limited-agent",
|
|
126
147
|
instructions: "You are a helpful assistant",
|
|
127
|
-
model: "openai/gpt-
|
|
148
|
+
model: "openai/gpt-4o",
|
|
128
149
|
outputProcessors: [
|
|
129
150
|
new TokenLimiterProcessor({
|
|
130
151
|
limit: 1000,
|
|
@@ -9,7 +9,7 @@ The `ToolCallFilter` is an **input processor** that filters out tool calls and t
|
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
12
|
+
```typescript
|
|
13
13
|
import { ToolCallFilter } from "@mastra/core/processors";
|
|
14
14
|
|
|
15
15
|
// Exclude all tool calls
|
|
@@ -74,7 +74,7 @@ const filterSpecific = new ToolCallFilter({
|
|
|
74
74
|
|
|
75
75
|
## Extended usage example
|
|
76
76
|
|
|
77
|
-
```typescript title="src/mastra/agents/filtered-agent.ts"
|
|
77
|
+
```typescript title="src/mastra/agents/filtered-agent.ts"
|
|
78
78
|
import { Agent } from "@mastra/core/agent";
|
|
79
79
|
import { ToolCallFilter } from "@mastra/core/processors";
|
|
80
80
|
|
|
@@ -99,7 +99,7 @@ export const agent = new Agent({
|
|
|
99
99
|
|
|
100
100
|
## Filtering all tool calls
|
|
101
101
|
|
|
102
|
-
```typescript
|
|
102
|
+
```typescript
|
|
103
103
|
import { Agent } from "@mastra/core/agent";
|
|
104
104
|
import { ToolCallFilter } from "@mastra/core/processors";
|
|
105
105
|
|
|
@@ -9,7 +9,7 @@ The `UnicodeNormalizer` is an **input processor** that normalizes Unicode text t
|
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
12
|
+
```typescript
|
|
13
13
|
import { UnicodeNormalizer } from "@mastra/core/processors";
|
|
14
14
|
|
|
15
15
|
const processor = new UnicodeNormalizer({
|
|
@@ -94,7 +94,7 @@ const processor = new UnicodeNormalizer({
|
|
|
94
94
|
|
|
95
95
|
## Extended usage example
|
|
96
96
|
|
|
97
|
-
```typescript title="src/mastra/agents/normalized-agent.ts"
|
|
97
|
+
```typescript title="src/mastra/agents/normalized-agent.ts"
|
|
98
98
|
import { Agent } from "@mastra/core/agent";
|
|
99
99
|
import { UnicodeNormalizer } from "@mastra/core/processors";
|
|
100
100
|
|
|
@@ -9,7 +9,7 @@ The `WorkingMemory` is an **input processor** that injects working memory data a
|
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
12
|
+
```typescript
|
|
13
13
|
import { WorkingMemory } from "@mastra/core/processors";
|
|
14
14
|
|
|
15
15
|
const processor = new WorkingMemory({
|
|
@@ -135,7 +135,7 @@ const processor = new WorkingMemory({
|
|
|
135
135
|
|
|
136
136
|
## Extended usage example
|
|
137
137
|
|
|
138
|
-
```typescript title="src/mastra/agents/personalized-agent.ts"
|
|
138
|
+
```typescript title="src/mastra/agents/personalized-agent.ts"
|
|
139
139
|
import { Agent } from "@mastra/core/agent";
|
|
140
140
|
import { WorkingMemory, MessageHistory } from "@mastra/core/processors";
|
|
141
141
|
import { PostgresStorage } from "@mastra/pg";
|
|
@@ -173,7 +173,7 @@ export const agent = new Agent({
|
|
|
173
173
|
|
|
174
174
|
## JSON format example
|
|
175
175
|
|
|
176
|
-
```typescript
|
|
176
|
+
```typescript
|
|
177
177
|
import { WorkingMemory } from "@mastra/core/processors";
|
|
178
178
|
|
|
179
179
|
const processor = new WorkingMemory({
|
|
@@ -112,7 +112,7 @@ See [ExtractParams reference](/reference/v1/rag/extract-params) for details on t
|
|
|
112
112
|
|
|
113
113
|
Strategy-specific options are passed as top-level parameters alongside the strategy parameter. For example:
|
|
114
114
|
|
|
115
|
-
```typescript
|
|
115
|
+
```typescript
|
|
116
116
|
// Character strategy example
|
|
117
117
|
const chunks = await doc.chunk({
|
|
118
118
|
strategy: "character",
|
|
@@ -9,7 +9,7 @@ ExtractParams configures metadata extraction from document chunks using LLM anal
|
|
|
9
9
|
|
|
10
10
|
## Example
|
|
11
11
|
|
|
12
|
-
```typescript
|
|
12
|
+
```typescript
|
|
13
13
|
import { MDocument } from "@mastra/rag";
|
|
14
14
|
|
|
15
15
|
const doc = MDocument.fromText(text);
|
|
@@ -188,7 +188,7 @@ The `extract` parameter accepts the following fields:
|
|
|
188
188
|
|
|
189
189
|
## Advanced Example
|
|
190
190
|
|
|
191
|
-
```typescript
|
|
191
|
+
```typescript
|
|
192
192
|
import { MDocument } from "@mastra/rag";
|
|
193
193
|
|
|
194
194
|
const doc = MDocument.fromText(text);
|
|
@@ -98,7 +98,7 @@ const results = await store.query({
|
|
|
98
98
|
name: "$elemMatch",
|
|
99
99
|
description: "Matches array elements meeting criteria",
|
|
100
100
|
example: "{ scores: { $elemMatch: { $gt: 80 } } }",
|
|
101
|
-
supportedBy: ["
|
|
101
|
+
supportedBy: ["libSQL", "PgVector", "MongoDB"],
|
|
102
102
|
},
|
|
103
103
|
]}
|
|
104
104
|
/>
|
|
@@ -127,7 +127,7 @@ const results = await store.query({
|
|
|
127
127
|
"Qdrant",
|
|
128
128
|
"Upstash",
|
|
129
129
|
"PgVector",
|
|
130
|
-
"
|
|
130
|
+
"libSQL",
|
|
131
131
|
"MongoDB",
|
|
132
132
|
],
|
|
133
133
|
},
|
|
@@ -135,7 +135,7 @@ const results = await store.query({
|
|
|
135
135
|
name: "$nor",
|
|
136
136
|
description: "Logical NOR",
|
|
137
137
|
example: '{ $nor: [{ status: "deleted" }, { archived: true }] }',
|
|
138
|
-
supportedBy: ["Qdrant", "Upstash", "PgVector", "
|
|
138
|
+
supportedBy: ["Qdrant", "Upstash", "PgVector", "libSQL", "MongoDB"],
|
|
139
139
|
},
|
|
140
140
|
]}
|
|
141
141
|
/>
|
|
@@ -159,7 +159,7 @@ const results = await store.query({
|
|
|
159
159
|
name: "$contains",
|
|
160
160
|
description: "Text contains substring",
|
|
161
161
|
example: '{ description: { $contains: "sale" } }',
|
|
162
|
-
supportedBy: ["Upstash", "
|
|
162
|
+
supportedBy: ["Upstash", "libSQL", "PgVector"],
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
165
|
name: "$regex",
|
|
@@ -171,7 +171,7 @@ const results = await store.query({
|
|
|
171
171
|
name: "$size",
|
|
172
172
|
description: "Array length check",
|
|
173
173
|
example: "{ tags: { $size: { $gt: 2 } } }",
|
|
174
|
-
supportedBy: ["Astra", "
|
|
174
|
+
supportedBy: ["Astra", "libSQL", "PgVector", "MongoDB"],
|
|
175
175
|
},
|
|
176
176
|
{
|
|
177
177
|
name: "$geo",
|
|
@@ -263,7 +263,7 @@ const results = await store.query({
|
|
|
263
263
|
- Vectors must be re-upserted after creating new metadata indexes to be included in filtered results
|
|
264
264
|
- Range queries may have reduced accuracy with very large datasets (~10M+ vectors)
|
|
265
265
|
|
|
266
|
-
###
|
|
266
|
+
### libSQL
|
|
267
267
|
|
|
268
268
|
- Supports nested object queries with dot notation
|
|
269
269
|
- Array fields are validated to ensure they contain valid JSON arrays
|
|
@@ -338,7 +338,7 @@ const results = await store.query({
|
|
|
338
338
|
- [Astra](/reference/v1/vectors/astra)
|
|
339
339
|
- [Chroma](/reference/v1/vectors/chroma)
|
|
340
340
|
- [Cloudflare Vectorize](/reference/v1/vectors/vectorize)
|
|
341
|
-
- [
|
|
341
|
+
- [libSQL](/reference/v1/vectors/libsql)
|
|
342
342
|
- [MongoDB](/reference/v1/vectors/mongodb)
|
|
343
343
|
- [PgStore](/reference/v1/vectors/pg)
|
|
344
344
|
- [Pinecone](/reference/v1/vectors/pinecone)
|
|
@@ -11,13 +11,13 @@ The `createRoute()` function creates type-safe routes with Zod validation. When
|
|
|
11
11
|
|
|
12
12
|
## Import
|
|
13
13
|
|
|
14
|
-
```typescript
|
|
14
|
+
```typescript
|
|
15
15
|
import { createRoute } from '@mastra/server/server-adapter';
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Signature
|
|
19
19
|
|
|
20
|
-
```typescript
|
|
20
|
+
```typescript
|
|
21
21
|
function createRoute<TPath, TQuery, TBody, TResponse, TResponseType>(
|
|
22
22
|
config: RouteConfig<TPath, TQuery, TBody, TResponse, TResponseType>
|
|
23
23
|
): ServerRoute
|
|
@@ -118,7 +118,7 @@ function createRoute<TPath, TQuery, TBody, TResponse, TResponseType>(
|
|
|
118
118
|
|
|
119
119
|
The handler receives validated parameters plus runtime context:
|
|
120
120
|
|
|
121
|
-
```typescript
|
|
121
|
+
```typescript
|
|
122
122
|
handler: async (params) => {
|
|
123
123
|
// From schemas (typed from Zod)
|
|
124
124
|
params.id; // From pathParamSchema
|
|
@@ -142,7 +142,7 @@ Returns a `ServerRoute` object that can be registered with an adapter.
|
|
|
142
142
|
|
|
143
143
|
### GET route with path params
|
|
144
144
|
|
|
145
|
-
```typescript
|
|
145
|
+
```typescript
|
|
146
146
|
import { createRoute } from '@mastra/server/server-adapter';
|
|
147
147
|
import { z } from 'zod';
|
|
148
148
|
|
|
@@ -167,7 +167,7 @@ const getAgent = createRoute({
|
|
|
167
167
|
|
|
168
168
|
### POST route with body
|
|
169
169
|
|
|
170
|
-
```typescript
|
|
170
|
+
```typescript
|
|
171
171
|
const createItem = createRoute({
|
|
172
172
|
method: 'POST',
|
|
173
173
|
path: '/api/items',
|
|
@@ -190,7 +190,7 @@ const createItem = createRoute({
|
|
|
190
190
|
|
|
191
191
|
### Query params with coercion
|
|
192
192
|
|
|
193
|
-
```typescript
|
|
193
|
+
```typescript
|
|
194
194
|
const listItems = createRoute({
|
|
195
195
|
method: 'GET',
|
|
196
196
|
path: '/api/items',
|
|
@@ -209,7 +209,7 @@ const listItems = createRoute({
|
|
|
209
209
|
|
|
210
210
|
### Streaming route
|
|
211
211
|
|
|
212
|
-
```typescript
|
|
212
|
+
```typescript
|
|
213
213
|
const streamAgent = createRoute({
|
|
214
214
|
method: 'POST',
|
|
215
215
|
path: '/api/agents/:agentId/stream',
|
|
@@ -230,7 +230,7 @@ const streamAgent = createRoute({
|
|
|
230
230
|
|
|
231
231
|
### Custom body size limit
|
|
232
232
|
|
|
233
|
-
```typescript
|
|
233
|
+
```typescript
|
|
234
234
|
const uploadRoute = createRoute({
|
|
235
235
|
method: 'POST',
|
|
236
236
|
path: '/api/upload',
|
|
@@ -249,7 +249,7 @@ const uploadRoute = createRoute({
|
|
|
249
249
|
|
|
250
250
|
### Passthrough for extensibility
|
|
251
251
|
|
|
252
|
-
```typescript
|
|
252
|
+
```typescript
|
|
253
253
|
const bodySchema = z.object({
|
|
254
254
|
required: z.string(),
|
|
255
255
|
}).passthrough(); // Allow unknown fields
|
|
@@ -257,7 +257,7 @@ const bodySchema = z.object({
|
|
|
257
257
|
|
|
258
258
|
### Date coercion
|
|
259
259
|
|
|
260
|
-
```typescript
|
|
260
|
+
```typescript
|
|
261
261
|
const querySchema = z.object({
|
|
262
262
|
fromDate: z.coerce.date().optional(),
|
|
263
263
|
toDate: z.coerce.date().optional(),
|
|
@@ -266,7 +266,7 @@ const querySchema = z.object({
|
|
|
266
266
|
|
|
267
267
|
### Union types
|
|
268
268
|
|
|
269
|
-
```typescript
|
|
269
|
+
```typescript
|
|
270
270
|
const bodySchema = z.object({
|
|
271
271
|
messages: z.union([
|
|
272
272
|
z.array(z.any()),
|
|
@@ -279,7 +279,7 @@ const bodySchema = z.object({
|
|
|
279
279
|
|
|
280
280
|
Throw an error with a `status` property to return specific HTTP status codes from handlers. If using Hono, you can use `HTTPException` from `hono/http-exception`:
|
|
281
281
|
|
|
282
|
-
```typescript
|
|
282
|
+
```typescript
|
|
283
283
|
import { createRoute } from '@mastra/server/server-adapter';
|
|
284
284
|
import { HTTPException } from 'hono/http-exception';
|
|
285
285
|
|
|
@@ -300,7 +300,7 @@ const getAgent = createRoute({
|
|
|
300
300
|
|
|
301
301
|
For Express or framework-agnostic code, throw an error with a `status` property:
|
|
302
302
|
|
|
303
|
-
```typescript
|
|
303
|
+
```typescript
|
|
304
304
|
class HttpError extends Error {
|
|
305
305
|
constructor(public status: number, message: string) {
|
|
306
306
|
super(message);
|
|
@@ -25,7 +25,7 @@ For general adapter concepts (constructor options, initialization flow, etc.), s
|
|
|
25
25
|
|
|
26
26
|
Install the Express adapter and Express framework:
|
|
27
27
|
|
|
28
|
-
```bash
|
|
28
|
+
```bash
|
|
29
29
|
npm install @mastra/express@beta express
|
|
30
30
|
```
|
|
31
31
|
|
|
@@ -35,7 +35,7 @@ npm install @mastra/express@beta express
|
|
|
35
35
|
|
|
36
36
|
Create your server file:
|
|
37
37
|
|
|
38
|
-
```typescript title="server.ts"
|
|
38
|
+
```typescript title="server.ts"
|
|
39
39
|
import express from 'express';
|
|
40
40
|
import { MastraServer } from '@mastra/express';
|
|
41
41
|
import { mastra } from './mastra';
|
|
@@ -63,7 +63,7 @@ Express requires `express.json()` middleware for JSON body parsing. Add it befor
|
|
|
63
63
|
|
|
64
64
|
## Full example
|
|
65
65
|
|
|
66
|
-
```typescript title="server.ts"
|
|
66
|
+
```typescript title="server.ts"
|
|
67
67
|
import express from 'express';
|
|
68
68
|
import { MastraServer } from '@mastra/express';
|
|
69
69
|
import { mastra } from './mastra';
|
|
@@ -166,7 +166,7 @@ app.listen(4111);
|
|
|
166
166
|
|
|
167
167
|
Add routes directly to the Express app:
|
|
168
168
|
|
|
169
|
-
```typescript title="server.ts"
|
|
169
|
+
```typescript title="server.ts"
|
|
170
170
|
const app = express();
|
|
171
171
|
app.use(express.json());
|
|
172
172
|
|
|
@@ -196,7 +196,7 @@ Routes added before `init()` run without Mastra context. Add routes after `init(
|
|
|
196
196
|
|
|
197
197
|
In Express middleware and routes, access Mastra context via `res.locals`:
|
|
198
198
|
|
|
199
|
-
```typescript
|
|
199
|
+
```typescript
|
|
200
200
|
app.get('/custom', (req, res) => {
|
|
201
201
|
const mastra = res.locals.mastra;
|
|
202
202
|
const requestContext = res.locals.requestContext;
|
|
@@ -223,7 +223,7 @@ Available properties on `res.locals`:
|
|
|
223
223
|
|
|
224
224
|
Add Express middleware before or after `init()`:
|
|
225
225
|
|
|
226
|
-
```typescript title="server.ts"
|
|
226
|
+
```typescript title="server.ts"
|
|
227
227
|
const app = express();
|
|
228
228
|
app.use(express.json());
|
|
229
229
|
|
|
@@ -239,7 +239,6 @@ await server.init();
|
|
|
239
239
|
// Middleware after init has access to Mastra context
|
|
240
240
|
app.use((req, res, next) => {
|
|
241
241
|
const mastra = res.locals.mastra;
|
|
242
|
-
// ...
|
|
243
242
|
next();
|
|
244
243
|
});
|
|
245
244
|
```
|
|
@@ -25,7 +25,7 @@ For general adapter concepts (constructor options, initialization flow, etc.), s
|
|
|
25
25
|
|
|
26
26
|
Install the Hono adapter and Hono framework:
|
|
27
27
|
|
|
28
|
-
```bash
|
|
28
|
+
```bash
|
|
29
29
|
npm install @mastra/hono@beta hono
|
|
30
30
|
```
|
|
31
31
|
|
|
@@ -35,7 +35,7 @@ npm install @mastra/hono@beta hono
|
|
|
35
35
|
|
|
36
36
|
Create your server file:
|
|
37
37
|
|
|
38
|
-
```typescript title="server.ts"
|
|
38
|
+
```typescript title="server.ts"
|
|
39
39
|
import { Hono } from 'hono';
|
|
40
40
|
import { HonoBindings, HonoVariables, MastraServer } from '@mastra/hono';
|
|
41
41
|
import { mastra } from './mastra';
|
|
@@ -54,7 +54,7 @@ export default app;
|
|
|
54
54
|
|
|
55
55
|
## Full example
|
|
56
56
|
|
|
57
|
-
```typescript title="server.ts"
|
|
57
|
+
```typescript title="server.ts"
|
|
58
58
|
import { Hono } from 'hono';
|
|
59
59
|
import { HonoBindings, HonoVariables, MastraServer } from '@mastra/hono';
|
|
60
60
|
import { mastra } from './mastra';
|
|
@@ -147,7 +147,7 @@ export default app;
|
|
|
147
147
|
|
|
148
148
|
Add routes directly to the Hono app:
|
|
149
149
|
|
|
150
|
-
```typescript title="server.ts"
|
|
150
|
+
```typescript title="server.ts"
|
|
151
151
|
import { Hono } from 'hono';
|
|
152
152
|
import { HonoBindings, HonoVariables, MastraServer } from '@mastra/hono';
|
|
153
153
|
|
|
@@ -176,7 +176,7 @@ Routes added before `init()` run without Mastra context. Add routes after `init(
|
|
|
176
176
|
|
|
177
177
|
In Hono middleware and route handlers, access Mastra context via `c.get()`:
|
|
178
178
|
|
|
179
|
-
```typescript
|
|
179
|
+
```typescript
|
|
180
180
|
app.get('/custom', async (c) => {
|
|
181
181
|
const mastra = c.get('mastra');
|
|
182
182
|
const requestContext = c.get('requestContext');
|
|
@@ -203,7 +203,7 @@ Available context keys:
|
|
|
203
203
|
|
|
204
204
|
Add Hono middleware before or after `init()`:
|
|
205
205
|
|
|
206
|
-
```typescript title="server.ts"
|
|
206
|
+
```typescript title="server.ts"
|
|
207
207
|
import { Hono } from 'hono';
|
|
208
208
|
import { HonoBindings, HonoVariables, MastraServer } from '@mastra/hono';
|
|
209
209
|
|
|
@@ -221,7 +221,6 @@ await server.init();
|
|
|
221
221
|
// Middleware after init has access to Mastra context
|
|
222
222
|
app.use('*', async (c, next) => {
|
|
223
223
|
const mastra = c.get('mastra');
|
|
224
|
-
// ...
|
|
225
224
|
await next();
|
|
226
225
|
});
|
|
227
226
|
```
|