@mastra/mcp-docs-server 1.2.15-alpha.15 → 1.2.15-alpha.20
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/docs/agents/code-mode.md +16 -1
- package/.docs/docs/agents/processors.md +3 -3
- package/.docs/docs/browser/recording.md +2 -2
- package/.docs/docs/deployment/workers.md +1 -1
- package/.docs/docs/getting-started/develop.md +1 -1
- package/.docs/docs/harness/agent-controller.md +43 -2
- package/.docs/docs/harness/overview.md +2 -4
- package/.docs/docs/long-running-agents/durable-agents.md +1 -1
- package/.docs/docs/long-running-agents/goals.md +1 -1
- package/.docs/docs/long-running-agents/schedules.md +1 -1
- package/.docs/docs/long-running-agents/signal-providers.md +1 -1
- package/.docs/docs/long-running-agents/signals.md +1 -1
- package/.docs/docs/mastra-platform/deploy.md +27 -0
- package/.docs/docs/mastra-platform/trace-intelligence.md +9 -13
- package/.docs/docs/memory/message-history.md +2 -2
- package/.docs/docs/observability/integrations/exporters/mastra-platform.md +1 -1
- package/.docs/docs/observability/integrations/exporters/otel.md +2 -2
- package/.docs/docs/server/auth/auth0.md +1 -1
- package/.docs/docs/server/auth/clerk.md +2 -2
- package/.docs/docs/server/auth/firebase.md +1 -1
- package/.docs/docs/server/auth/okta.md +24 -4
- package/.docs/docs/server/auth/supabase.md +2 -2
- package/.docs/docs/server/auth/workers.md +2 -0
- package/.docs/docs/server/auth/workos.md +1 -1
- package/.docs/docs/server/custom-adapters.md +1 -1
- package/.docs/docs/server/custom-api-routes.md +35 -0
- package/.docs/docs/server/mastra-client.md +2 -2
- package/.docs/docs/server/mastra-server.md +1 -1
- package/.docs/docs/workflows/dynamic-workflows.md +1 -1
- package/.docs/docs/workflows/overview.md +1 -1
- package/.docs/docs/workflows/time-travel.md +2 -0
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +3 -3
- package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
- package/.docs/guides/build-your-ui/copilotkit/channels.md +1 -1
- package/.docs/guides/build-your-ui/copilotkit/overview.md +1 -1
- package/.docs/guides/deployment/amazon-ec2.md +1 -1
- package/.docs/guides/deployment/aws-bedrock-agentcore.md +1 -1
- package/.docs/guides/deployment/aws-lambda.md +1 -1
- package/.docs/guides/deployment/azure-app-services.md +1 -1
- package/.docs/guides/deployment/cloudflare.md +1 -1
- package/.docs/guides/deployment/digital-ocean.md +2 -2
- package/.docs/guides/deployment/kubernetes.md +2 -2
- package/.docs/guides/deployment/mastra-workers.md +3 -1
- package/.docs/guides/deployment/netlify.md +2 -2
- package/.docs/guides/deployment/vercel.md +1 -1
- package/.docs/guides/getting-started/electron.md +2 -2
- package/.docs/guides/getting-started/manual-install.md +2 -2
- package/.docs/guides/guide/signal-provider.md +1 -1
- package/.docs/guides/migrations/mastra-cloud.md +1 -1
- package/.docs/models/embeddings.md +1 -1
- package/.docs/models/environment-variables.md +1 -0
- package/.docs/models/gateways/neon.md +1 -1
- package/.docs/models/gateways/netlify.md +1 -1
- package/.docs/models/gateways/openrouter.md +2 -2
- package/.docs/models/gateways/vercel.md +2 -2
- package/.docs/models/index.md +3 -3
- package/.docs/models/providers/302ai.md +1 -1
- package/.docs/models/providers/abacus.md +1 -1
- package/.docs/models/providers/abliteration-ai.md +1 -1
- package/.docs/models/providers/agentrouter.md +1 -1
- package/.docs/models/providers/ai-router.md +1 -1
- package/.docs/models/providers/aiand.md +1 -1
- package/.docs/models/providers/aki-io.md +1 -1
- package/.docs/models/providers/alibaba-cn.md +1 -1
- package/.docs/models/providers/alibaba-coding-plan-cn.md +1 -1
- package/.docs/models/providers/alibaba-coding-plan.md +1 -1
- package/.docs/models/providers/alibaba-token-plan-cn.md +1 -1
- package/.docs/models/providers/alibaba-token-plan.md +1 -1
- package/.docs/models/providers/alibaba.md +1 -1
- package/.docs/models/providers/ambient.md +1 -1
- package/.docs/models/providers/anyapi.md +1 -1
- package/.docs/models/providers/atomic-chat.md +1 -1
- package/.docs/models/providers/auriko.md +1 -1
- package/.docs/models/providers/bailing.md +1 -1
- package/.docs/models/providers/baseten.md +1 -1
- package/.docs/models/providers/berget.md +1 -1
- package/.docs/models/providers/blueclaw.md +1 -1
- package/.docs/models/providers/chutes.md +1 -1
- package/.docs/models/providers/clarifai.md +1 -1
- package/.docs/models/providers/claudinio.md +1 -1
- package/.docs/models/providers/cline-pass.md +1 -1
- package/.docs/models/providers/cloudferro-sherlock.md +1 -1
- package/.docs/models/providers/cloudflare-workers-ai.md +1 -1
- package/.docs/models/providers/coralbricks.md +75 -0
- package/.docs/models/providers/cortecs.md +1 -1
- package/.docs/models/providers/crof.md +1 -1
- package/.docs/models/providers/crossmodel.md +2 -3
- package/.docs/models/providers/daoxe.md +1 -1
- package/.docs/models/providers/databricks.md +1 -1
- package/.docs/models/providers/deepinfra.md +1 -1
- package/.docs/models/providers/digitalocean.md +2 -2
- package/.docs/models/providers/dinference.md +1 -1
- package/.docs/models/providers/drun.md +1 -1
- package/.docs/models/providers/ebcloud.md +1 -1
- package/.docs/models/providers/empiriolabs.md +1 -1
- package/.docs/models/providers/evroc.md +3 -4
- package/.docs/models/providers/fastrouter.md +1 -1
- package/.docs/models/providers/firepass.md +1 -1
- package/.docs/models/providers/fireworks-ai.md +1 -1
- package/.docs/models/providers/firmware.md +1 -1
- package/.docs/models/providers/freemodel.md +1 -1
- package/.docs/models/providers/friendli.md +1 -1
- package/.docs/models/providers/frogbot.md +1 -1
- package/.docs/models/providers/github-models.md +1 -1
- package/.docs/models/providers/gmicloud.md +1 -1
- package/.docs/models/providers/google.md +1 -1
- package/.docs/models/providers/greenpt.md +1 -1
- package/.docs/models/providers/helicone.md +1 -1
- package/.docs/models/providers/hetzner.md +1 -1
- package/.docs/models/providers/hpc-ai.md +1 -1
- package/.docs/models/providers/huggingface.md +1 -1
- package/.docs/models/providers/hyper.md +7 -7
- package/.docs/models/providers/iflowcn.md +1 -1
- package/.docs/models/providers/impossibl.md +1 -1
- package/.docs/models/providers/inception.md +1 -1
- package/.docs/models/providers/inceptron.md +1 -1
- package/.docs/models/providers/inference.md +1 -1
- package/.docs/models/providers/inferx.md +1 -1
- package/.docs/models/providers/infomaniak.md +1 -1
- package/.docs/models/providers/io-intelligence.md +1 -1
- package/.docs/models/providers/io-net.md +1 -1
- package/.docs/models/providers/jiekou.md +1 -1
- package/.docs/models/providers/kenari.md +1 -1
- package/.docs/models/providers/kilo.md +6 -7
- package/.docs/models/providers/kimi-for-coding.md +1 -1
- package/.docs/models/providers/kiro.md +1 -1
- package/.docs/models/providers/kuae-cloud-coding-plan.md +1 -1
- package/.docs/models/providers/lilac.md +1 -1
- package/.docs/models/providers/llama.md +1 -1
- package/.docs/models/providers/llmgateway.md +2 -5
- package/.docs/models/providers/llmtr.md +1 -1
- package/.docs/models/providers/lmstudio.md +1 -1
- package/.docs/models/providers/longcat.md +1 -1
- package/.docs/models/providers/lucidquery.md +1 -1
- package/.docs/models/providers/lynkr.md +1 -1
- package/.docs/models/providers/meganova.md +1 -1
- package/.docs/models/providers/meta.md +1 -1
- package/.docs/models/providers/minimax-cn-coding-plan.md +1 -1
- package/.docs/models/providers/minimax-cn.md +1 -1
- package/.docs/models/providers/minimax-coding-plan.md +1 -1
- package/.docs/models/providers/minimax.md +1 -1
- package/.docs/models/providers/mixlayer.md +1 -1
- package/.docs/models/providers/moark.md +1 -1
- package/.docs/models/providers/modal.md +1 -1
- package/.docs/models/providers/model-oracle-ai.md +1 -1
- package/.docs/models/providers/modelis.md +1 -1
- package/.docs/models/providers/modelscope.md +1 -1
- package/.docs/models/providers/moonshotai-cn.md +1 -1
- package/.docs/models/providers/moonshotai.md +1 -1
- package/.docs/models/providers/morph.md +1 -1
- package/.docs/models/providers/nano-gpt.md +3 -3
- package/.docs/models/providers/nearai.md +1 -1
- package/.docs/models/providers/nebius.md +1 -1
- package/.docs/models/providers/neuralwatt.md +1 -1
- package/.docs/models/providers/nova.md +1 -1
- package/.docs/models/providers/novita-ai.md +1 -1
- package/.docs/models/providers/nvidia.md +1 -1
- package/.docs/models/providers/ofox.md +4 -3
- package/.docs/models/providers/ollama-cloud.md +1 -1
- package/.docs/models/providers/opencode-go.md +1 -1
- package/.docs/models/providers/opencode.md +1 -1
- package/.docs/models/providers/orcarouter.md +1 -1
- package/.docs/models/providers/ovhcloud.md +1 -1
- package/.docs/models/providers/perplexity-agent.md +1 -1
- package/.docs/models/providers/pioneer.md +1 -1
- package/.docs/models/providers/poe.md +1 -1
- package/.docs/models/providers/poolside.md +1 -1
- package/.docs/models/providers/privatemode-ai.md +6 -5
- package/.docs/models/providers/qihang-ai.md +1 -1
- package/.docs/models/providers/qiniu-ai.md +1 -1
- package/.docs/models/providers/regolo-ai.md +1 -1
- package/.docs/models/providers/requesty.md +3 -3
- package/.docs/models/providers/routing-run.md +1 -1
- package/.docs/models/providers/sakana.md +1 -1
- package/.docs/models/providers/sarvam.md +1 -1
- package/.docs/models/providers/scaleway.md +1 -1
- package/.docs/models/providers/scx.md +1 -1
- package/.docs/models/providers/siliconflow-cn.md +1 -1
- package/.docs/models/providers/siliconflow.md +1 -1
- package/.docs/models/providers/snowflake-cortex.md +6 -2
- package/.docs/models/providers/stackit.md +1 -1
- package/.docs/models/providers/stepfun-ai-step-plan.md +1 -1
- package/.docs/models/providers/stepfun-ai.md +1 -1
- package/.docs/models/providers/stepfun-step-plan.md +1 -1
- package/.docs/models/providers/stepfun.md +1 -1
- package/.docs/models/providers/subconscious.md +1 -1
- package/.docs/models/providers/submodel.md +1 -1
- package/.docs/models/providers/synthetic.md +1 -1
- package/.docs/models/providers/tencent-coding-plan.md +1 -1
- package/.docs/models/providers/tencent-token-plan.md +1 -1
- package/.docs/models/providers/tencent-tokenhub.md +1 -1
- package/.docs/models/providers/tensorx.md +1 -1
- package/.docs/models/providers/the-grid-ai.md +1 -1
- package/.docs/models/providers/thinkingmachines.md +1 -1
- package/.docs/models/providers/tinfoil.md +2 -3
- package/.docs/models/providers/togetherai.md +1 -1
- package/.docs/models/providers/trustedrouter.md +1 -1
- package/.docs/models/providers/umans-ai-coding-plan.md +1 -1
- package/.docs/models/providers/umans-ai.md +1 -1
- package/.docs/models/providers/unorouter.md +1 -1
- package/.docs/models/providers/upstage.md +1 -1
- package/.docs/models/providers/venice.md +1 -1
- package/.docs/models/providers/vivgrid.md +1 -1
- package/.docs/models/providers/vultr.md +1 -1
- package/.docs/models/providers/wafer.ai.md +1 -1
- package/.docs/models/providers/wandb.md +3 -2
- package/.docs/models/providers/xiaomi-token-plan-ams.md +1 -1
- package/.docs/models/providers/xiaomi-token-plan-cn.md +1 -1
- package/.docs/models/providers/xiaomi-token-plan-sgp.md +1 -1
- package/.docs/models/providers/xiaomi.md +1 -1
- package/.docs/models/providers/xpersona.md +1 -1
- package/.docs/models/providers/zai-coding-plan.md +1 -1
- package/.docs/models/providers/zai.md +1 -1
- package/.docs/models/providers/zeldoc.md +1 -1
- package/.docs/models/providers/zenifra.md +1 -1
- package/.docs/models/providers/zenmux.md +1 -16
- package/.docs/models/providers/zhipuai-coding-plan.md +1 -1
- package/.docs/models/providers/zhipuai.md +1 -1
- package/.docs/models/providers.md +1 -0
- package/.docs/reference/agent-controller/agent-controller-class.md +3 -3
- package/.docs/reference/agent-controller/session.md +1 -1
- package/.docs/reference/agents/durable-agent.md +2 -0
- package/.docs/reference/agents/generateLegacy.md +1 -1
- package/.docs/reference/agents/inngest-agent.md +2 -0
- package/.docs/reference/auth/okta.md +5 -1
- package/.docs/reference/cli/mastra.md +4 -4
- package/.docs/reference/client-js/workflows.md +3 -3
- package/.docs/reference/code-sdk/mount-agent-controller.md +1 -1
- package/.docs/reference/core/addDynamicWorkflow.md +1 -1
- package/.docs/reference/core/addDynamicWorkflows.md +1 -1
- package/.docs/reference/file-based-agents/config.md +2 -0
- package/.docs/reference/file-based-agents/instructions.md +2 -0
- package/.docs/reference/file-based-agents/logger.md +2 -0
- package/.docs/reference/file-based-agents/memory.md +2 -0
- package/.docs/reference/file-based-agents/observability.md +2 -0
- package/.docs/reference/file-based-agents/processors.md +2 -0
- package/.docs/reference/file-based-agents/schedules.md +2 -0
- package/.docs/reference/file-based-agents/scorers.md +2 -0
- package/.docs/reference/file-based-agents/server.md +2 -0
- package/.docs/reference/file-based-agents/skills.md +2 -0
- package/.docs/reference/file-based-agents/storage.md +2 -0
- package/.docs/reference/file-based-agents/studio.md +2 -0
- package/.docs/reference/file-based-agents/subagents.md +2 -0
- package/.docs/reference/file-based-agents/tools.md +2 -0
- package/.docs/reference/file-based-agents/workflows.md +2 -0
- package/.docs/reference/file-based-agents/workspace.md +2 -0
- package/.docs/reference/index.md +1 -0
- package/.docs/reference/observability/tracing/exporters/datadog.md +1 -1
- package/.docs/reference/processors/pii-detector.md +2 -0
- package/.docs/reference/processors/prompt-injection-detector.md +2 -0
- package/.docs/reference/processors/response-cache.md +2 -0
- package/.docs/reference/schedules/overview.md +2 -0
- package/.docs/reference/server/create-route.md +27 -1
- package/.docs/reference/signals/create-notification-inbox-tool.md +2 -0
- package/.docs/reference/signals/signal-provider.md +2 -0
- package/.docs/reference/signals/task-signal-provider.md +2 -0
- package/.docs/reference/signals/webhook-signal-provider.md +2 -0
- package/.docs/reference/storage/composite.md +1 -1
- package/.docs/reference/streaming/agents/stream.md +1 -1
- package/.docs/reference/streaming/agents/streamLegacy.md +1 -1
- package/.docs/reference/streaming/agents/streamUntilIdle.md +1 -1
- package/.docs/reference/tools/create-code-mode.md +3 -1
- package/.docs/reference/tools/isolated-vm-transport.md +1 -1
- package/.docs/reference/tools/mcp-client.md +51 -0
- package/.docs/reference/tools/quickjs-transport.md +92 -0
- package/.docs/reference/vectors/chroma.md +1 -1
- package/.docs/reference/workers/overview.md +2 -0
- package/.docs/reference/workflows/dynamic-workflow-definition.md +1 -1
- package/.docs/reference/workflows/run-methods/timeTravel.md +1 -0
- package/.docs/reference/workspace/mesa-filesystem.md +1 -1
- package/.docs/reference/workspace/platform-filesystem.md +1 -1
- package/.docs/reference/workspace/platform-sandbox.md +9 -1
- package/.docs/reference/workspace/railway-sandbox.md +8 -0
- package/.docs/reference/workspace/sandbox.md +10 -0
- package/CHANGELOG.md +29 -0
- package/package.json +5 -5
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Added in:** `@mastra/core@1.38.0`
|
|
6
6
|
|
|
7
|
-
> **Beta:**
|
|
7
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
8
8
|
|
|
9
9
|
Code mode lets an agent run multi-tool computations in an isolated sandbox and return the result as a single, more accurate response.
|
|
10
10
|
|
|
@@ -164,9 +164,24 @@ const { tool, instructions } = createCodeMode(
|
|
|
164
164
|
|
|
165
165
|
`isolated-vm` is a native addon, and on Node.js 20 and later the host process must be started with the `--no-node-snapshot` flag. See the [IsolatedVmCodeModeTransport reference](https://mastra.ai/reference/tools/isolated-vm-transport) for setup details.
|
|
166
166
|
|
|
167
|
+
When the host can't install native addons or set Node.js flags, which is common on serverless platforms, use [`QuickJsCodeModeTransport`](https://mastra.ai/reference/tools/quickjs-transport) from `@mastra/quickjs` instead. It gives the same in-process boundary using a QuickJS runtime compiled to WebAssembly, at the cost of slower execution:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { createCodeMode } from '@mastra/core/tools'
|
|
171
|
+
import { QuickJsCodeModeTransport } from '@mastra/quickjs'
|
|
172
|
+
|
|
173
|
+
const { tool, instructions } = createCodeMode(
|
|
174
|
+
{ tools }, // no sandbox needed
|
|
175
|
+
new QuickJsCodeModeTransport({ memoryLimitMb: 128 }),
|
|
176
|
+
)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
See [Choosing a transport](https://mastra.ai/reference/tools/quickjs-transport) for a side-by-side comparison.
|
|
180
|
+
|
|
167
181
|
## Related
|
|
168
182
|
|
|
169
183
|
- [createCodeMode() reference](https://mastra.ai/reference/tools/create-code-mode)
|
|
170
184
|
- [IsolatedVmCodeModeTransport reference](https://mastra.ai/reference/tools/isolated-vm-transport)
|
|
185
|
+
- [QuickJsCodeModeTransport reference](https://mastra.ai/reference/tools/quickjs-transport)
|
|
171
186
|
- [Tools](https://mastra.ai/docs/agents/using-tools)
|
|
172
187
|
- [Workspace overview](https://mastra.ai/docs/workspace/overview)
|
|
@@ -432,7 +432,7 @@ See the [`ProviderHistoryCompat` reference](https://mastra.ai/reference/processo
|
|
|
432
432
|
|
|
433
433
|
## Response caching
|
|
434
434
|
|
|
435
|
-
> **Beta:**
|
|
435
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
436
436
|
|
|
437
437
|
Response caching skips the LLM call and replays a previously cached response when an agent receives an identical request. Use it to reduce latency and avoid paying for repeated calls.
|
|
438
438
|
|
|
@@ -544,7 +544,7 @@ This means the cache key is derived from the resolved `LanguageModelV2Prompt` Ma
|
|
|
544
544
|
|
|
545
545
|
When you don't supply `key`, the processor derives one deterministically from the inputs that change the LLM's response at this step: `agentId`, `stepNumber` (so each step in a tool loop has its own cache entry), `scope`, model identity (`provider`, `modelId`, spec version), and the resolved `prompt` (post-memory + post-processors). Any change to these inputs automatically invalidates the cache.
|
|
546
546
|
|
|
547
|
-
Multimodal prompts are included too. Image and file parts reach the key by value: a URL
|
|
547
|
+
Multimodal prompts are included too. Image and file parts reach the key by value: the key includes a URL's full href, and a digest of the bytes for inline binary data (`Uint8Array`, `ArrayBuffer`). Requests that differ only in which image they reference therefore get different cache entries.
|
|
548
548
|
|
|
549
549
|
#### Customize the cache key
|
|
550
550
|
|
|
@@ -664,7 +664,7 @@ export class SteeringReminderProcessor implements Processor {
|
|
|
664
664
|
}
|
|
665
665
|
```
|
|
666
666
|
|
|
667
|
-
A transient signal still
|
|
667
|
+
A transient signal is still in the prompt for the current call, so the model sees it near the latest turn. It's not retained, so re-sending it each turn keeps a single fresh copy in context instead of an accumulating history, and stored thread history never includes it. Because nothing is written, it also keeps a stable prompt cache prefix across turns.
|
|
668
668
|
|
|
669
669
|
### Emit custom stream events
|
|
670
670
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
2
|
|
|
3
|
-
# Browser recording
|
|
3
|
+
# Browser recording
|
|
4
4
|
|
|
5
5
|
**Added in:** `@mastra/core@1.43.0`
|
|
6
6
|
|
|
7
7
|
Browser recording adds two opt-in tools that let an agent save a browser session as a Motion-JPEG AVI video. The agent can also add short captions while it works.
|
|
8
8
|
|
|
9
|
-
> **Beta:**
|
|
9
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
10
10
|
|
|
11
11
|
## When to use browser recording
|
|
12
12
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Workers
|
|
4
4
|
|
|
5
|
-
> **Beta:**
|
|
5
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable. See [known limitations](#known-limitations) for current gaps.
|
|
6
6
|
|
|
7
7
|
Workers handle background processing outside the request-response cycle. Workflow step execution, cron-based scheduling, and long-running tool calls all run in workers, keeping the API responsive.
|
|
8
8
|
|
|
@@ -138,7 +138,7 @@ See the [project structure reference](https://mastra.ai/reference/project-struct
|
|
|
138
138
|
|
|
139
139
|
## File-based agents
|
|
140
140
|
|
|
141
|
-
> **Beta:**
|
|
141
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
142
142
|
>
|
|
143
143
|
> File-based discovery only runs through `mastra dev` or `mastra build`. If your app imports `mastra` directly, including through a web framework or server adapter, file-based agents aren't discovered. Register those agents in code or run Mastra as a separate server.
|
|
144
144
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# AgentController
|
|
4
4
|
|
|
5
|
-
> **Beta:**
|
|
5
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
6
6
|
|
|
7
7
|
`AgentController` is a shared runtime host for interactive agent applications. It coordinates modes, models, storage, workspaces, tool approvals, subagents, and channels. Each user or active task works through an isolated [`Session`](https://mastra.ai/reference/agent-controller/session).
|
|
8
8
|
|
|
@@ -343,7 +343,48 @@ Point each platform webhook at the controller-specific route:
|
|
|
343
343
|
|
|
344
344
|
Each external chat thread maps to one controller Session and Mastra thread. By default, new sessions use a resource ID derived from the adapter's chat-thread ID, prefixed with `channel:`. Use `resolveResourceId` to map direct messages to an existing application user or choose another memory owner. The callback only affects new threads; an existing thread keeps its stored resource ID.
|
|
345
345
|
|
|
346
|
-
Channel sessions are created by the controller rather than by your code, so `onSessionStart` is where you configure them. It runs once per session, after the session is bound to its mapped thread and before the first message is handled.
|
|
346
|
+
Channel sessions are created by the controller rather than by your code, so `onSessionStart` is where you configure them. It runs once per session, after the session is bound to its mapped thread and before the first message is handled. A channel session starts with controller defaults, so this is where you set its model and memory settings. Later messages in the same thread reuse the session and don't call it again. Errors are logged and swallowed so a session that can't be configured still answers the message.
|
|
347
|
+
|
|
348
|
+
### Authorize and route channel sessions
|
|
349
|
+
|
|
350
|
+
`onSessionStart` runs after the session exists and swallows errors, so it can't refuse a request. Use `resolveSession` when your host decides whether a session may exist. It replaces the built-in session creation and runs before any session exists. Throwing refuses the request before the controller creates a session or calls the model. Mastra logs the refusal and leaves the chat thread silent, so your authorization message never reaches the channel.
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
channels: {
|
|
354
|
+
adapters: { slack: createSlackAdapter() },
|
|
355
|
+
resolveSession: async ({ controller, thread, requestContext }) => {
|
|
356
|
+
const install = await installs.authorize(requestContext.get('teamId'))
|
|
357
|
+
|
|
358
|
+
return controller.createSession({
|
|
359
|
+
resourceId: thread.resourceId,
|
|
360
|
+
scope: install.id,
|
|
361
|
+
ownerId: controller.id,
|
|
362
|
+
requestContext,
|
|
363
|
+
})
|
|
364
|
+
},
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Create the session under `thread.resourceId`. A session can only bind threads it owns, so use `resolveResourceId` if you want a different owner for the mapped thread. Sessions are get-or-create per `resourceId` and `scope`, so pass `scope` when one thread needs separate sessions per install or principal.
|
|
369
|
+
|
|
370
|
+
Failures that aren't refusals (a storage outage, a bug in your resolver's dependencies) still post an error to the thread, so a broken bot doesn't look like a silent one. If you need to tell them apart in your own code, a refusal is a `ChannelSessionRejectedError` with the original error as its `cause`.
|
|
371
|
+
|
|
372
|
+
`resolveSession` also runs when a user answers an approval card, with that action's request context, so a shared install revalidates the person approving rather than trusting the person who sent the original message.
|
|
373
|
+
|
|
374
|
+
### Handle stale approvals
|
|
375
|
+
|
|
376
|
+
An approval gate lives in memory, so every approval answered after a restart is stale. Mastra never runs the tool for a stale action. Use `onStaleToolApproval` to settle the attempt the user answered, instead of dropping it:
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
channels: {
|
|
380
|
+
adapters: { slack: createSlackAdapter() },
|
|
381
|
+
onStaleToolApproval: async ({ decision, toolCallId, runId, memory }) => {
|
|
382
|
+
await runs.markInterrupted({ runId, toolCallId, decision, threadId: memory.thread })
|
|
383
|
+
},
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
`runId` is the run the approval card was rendered for, which is the attempt the user answered and the one you settle against after a restart. The session's own run is passed separately as `currentRunId`, and is usually `null` or a different run by then.
|
|
347
388
|
|
|
348
389
|
Controller channel sessions and auto-approval state are held in memory, so use a long-lived server. Pending approvals and live Session state don't survive process restarts. Adapters that can't render approval controls automatically run tools without an approval prompt so the run doesn't remain suspended.
|
|
349
390
|
|
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
A harness lets an agent pursue long-running, complex goals while keeping its work durable, visible, and steerable. It preserves progress across retries and interruptions, while giving people and other systems a way to inspect progress, add context, approve actions, redirect the agent, or stop it.
|
|
6
6
|
|
|
7
|
-
In Mastra, harness refers to a set of capabilities for managing an agent beyond a single uninterrupted run. You can adopt these capabilities individually or combine them as needed.
|
|
8
|
-
|
|
9
|
-
[`AgentController`](https://mastra.ai/docs/harness/agent-controller) is a harness designed for interactive agent applications. It extends the base [`Agent`](https://mastra.ai/docs/agents/overview) loop with isolated sessions for each user or task, persistent threads and state, switchable modes and models, tool permissions and approvals, subagent orchestration, and streams for events and display state.
|
|
10
|
-
|
|
11
7
|
Agent harnesses are useful wherever work continues over time. Common examples include coding agents that carry changes through CI and review, software factories that coordinate many tasks in parallel, SRE agents that adapt as incidents evolve, and go-to-market agents that respond as accounts, signals, and conversations change.
|
|
12
8
|
|
|
9
|
+
In Mastra, harness refers to a set of capabilities for managing an agent beyond a single uninterrupted run. You can adopt these capabilities individually or combine them as needed.
|
|
10
|
+
|
|
13
11
|
## When to use a harness
|
|
14
12
|
|
|
15
13
|
Choose a starting point based on what the agent needs. You may use one capability or several.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Added in:** `@mastra/core@1.45.0`
|
|
6
6
|
|
|
7
|
-
> **
|
|
7
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
8
8
|
|
|
9
9
|
A durable agent wraps a regular [`Agent`](https://mastra.ai/docs/agents/overview) so the agentic loop runs inside a workflow. Events flow through [PubSub](https://mastra.ai/docs/server/pubsub), which means a client can disconnect and reconnect without missing chunks. The run state is persisted, so it survives process restarts.
|
|
10
10
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Added in:** `@mastra/core@1.42.0`
|
|
6
6
|
|
|
7
|
-
> **Beta:**
|
|
7
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
8
8
|
|
|
9
9
|
A goal is a durable, thread-scoped objective: a standing instruction the agent keeps working toward across loop iterations until a judge model decides it's satisfied or a run budget is exhausted.
|
|
10
10
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Added in:** `@mastra/core@1.50.0`
|
|
6
6
|
|
|
7
|
-
> **Beta:**
|
|
7
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
8
8
|
|
|
9
9
|
A schedule runs an agent on a cron cadence. On each fire, Mastra sends a prompt to the agent, either as a [signal](https://mastra.ai/docs/long-running-agents/signals) into a thread or as a threadless [`agent.generate()`](https://mastra.ai/reference/agents/generate) run. Use schedules for recurring agent work such as daily summaries, periodic checks, or scheduled nudges into a conversation.
|
|
10
10
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Added in:** `@mastra/core@1.39.0`
|
|
6
6
|
|
|
7
|
-
> **Beta:**
|
|
7
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
8
8
|
|
|
9
9
|
A signal provider monitors an external source, such as GitHub, Slack, continuous integration (CI), or your own API, and pushes [notification signals](https://mastra.ai/docs/long-running-agents/signals) into subscribed agent threads.
|
|
10
10
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Added in:** `@mastra/core@1.39.0`
|
|
6
6
|
|
|
7
|
-
> **Beta:**
|
|
7
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
8
8
|
|
|
9
9
|
Signals are a way to interact with an agent through a thread. Instead of starting every interaction with `agent.stream()`, subscribe to a thread and send messages or signals. Mastra either wakes the agent when the thread is idle or drops input into the running agent loop, or alternatively queues input for the next turn.
|
|
10
10
|
|
|
@@ -132,6 +132,33 @@ mastra deploy --env staging --env-file .env.staging
|
|
|
132
132
|
|
|
133
133
|
To change variables on a running service without a redeploy, update them in the dashboard and run [`mastra env restart`](https://mastra.ai/reference/cli/mastra).
|
|
134
134
|
|
|
135
|
+
## Private npm packages
|
|
136
|
+
|
|
137
|
+
Projects that depend on packages from a private registry install them during the deploy using the standard `NPM_TOKEN` contract.
|
|
138
|
+
|
|
139
|
+
1. Store a read-only registry token as `NPM_TOKEN` on the project or environment through the dashboard.
|
|
140
|
+
|
|
141
|
+
2. Commit a token-free `.npmrc` that points your scope at the registry and reads the token from the environment:
|
|
142
|
+
|
|
143
|
+
```ini
|
|
144
|
+
@your-org:registry=https://npm.pkg.github.com
|
|
145
|
+
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Keep the `${NPM_TOKEN}` reference literal. The package manager resolves it at install time, so the token itself never lands in your repository.
|
|
149
|
+
|
|
150
|
+
3. Deploy as usual:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
mastra deploy
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
In a monorepo, a `.npmrc` in your project directory takes precedence over one at the repository root.
|
|
157
|
+
|
|
158
|
+
`NPM_TOKEN` is available during dependency installation. Mastra redacts its value from the Mastra source-build logs that it streams. The generated Dockerfile receives it as a build argument, so the runtime image stays free of the token. `NPM_TOKEN` is also injected into the running service as a regular environment variable, so treat it as a secret your application can read.
|
|
159
|
+
|
|
160
|
+
Projects without a private-registry `.npmrc` need no changes. When your `.npmrc` references `${NPM_TOKEN}`, set the variable or the dependency install fails.
|
|
161
|
+
|
|
135
162
|
## Project resolution
|
|
136
163
|
|
|
137
164
|
Every deploy resolves its target project in this order:
|
|
@@ -56,12 +56,9 @@ The flow chart connects themes in adjacent trace signal columns:
|
|
|
56
56
|
|
|
57
57
|
The flow shows association, not causation or execution order. For example, a ribbon between a Goal and an Outcome means that both themes occurred in the same traces. It doesn't show that the goal caused the outcome.
|
|
58
58
|
|
|
59
|
-
###
|
|
59
|
+
### Other and Noise
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
- **Trace count**: The number of distinct traces assigned to a theme in the selected snapshot.
|
|
64
|
-
- **Stage share**: The percentage of analyzed traces for that trace signal assigned to the theme.
|
|
61
|
+
Each node shows its trace count: the number of distinct traces assigned to that theme in the selected snapshot. A theme's details also state its share, for example "28 of 70 traces in this snapshot (40%)".
|
|
65
62
|
|
|
66
63
|
Studio shows the most common themes for each trace signal type. It may combine smaller themes into **Other** to preserve totals without overcrowding the chart.
|
|
67
64
|
|
|
@@ -69,26 +66,25 @@ Studio shows the most common themes for each trace signal type. It may combine s
|
|
|
69
66
|
|
|
70
67
|
### Snapshots
|
|
71
68
|
|
|
72
|
-
A snapshot is a moving analysis window over a set of traces. Snapshots can overlap, so don't add their trace counts together. Compare trace count and
|
|
69
|
+
A snapshot is a moving analysis window over a set of traces. Snapshots can overlap, so don't add their trace counts together. Compare a theme's trace count and its share of the snapshot together because traffic volume can change between windows.
|
|
73
70
|
|
|
74
71
|
A theme can persist, disappear, split, merge, or return across snapshots. Treat theme names and descriptions as generated summaries, not fixed taxonomies.
|
|
75
72
|
|
|
76
73
|
## Use the Trace Intelligence page
|
|
77
74
|
|
|
78
75
|
1. Use the **Agent** selector to switch between agents with available analysis. An agent doesn't appear until its first themes are ready.
|
|
79
|
-
2. Select a theme in the flow to filter every column to traces containing that theme.
|
|
80
|
-
3.
|
|
76
|
+
2. Select a theme in the flow to open its details and filter every column to traces containing that theme.
|
|
77
|
+
3. The details panel shows the theme's description, its share of the snapshot, paged example summaries, and a trend of its trace count over time.
|
|
81
78
|
4. Select **Clear filter** to restore the complete flow.
|
|
82
79
|
|
|
83
80
|
You can also:
|
|
84
81
|
|
|
85
|
-
- Select
|
|
86
|
-
-
|
|
87
|
-
- Drag the distribution cards to reorder the trace signal columns and see a different relationship perspective.
|
|
82
|
+
- Select **Noise** in the flow to inspect its share and generated example summaries.
|
|
83
|
+
- Drag the column headers above the chart to reorder the trace signal columns and see a different relationship perspective.
|
|
88
84
|
- Use the timeline to select a snapshot, or select **Play** to watch themes change over time.
|
|
89
|
-
-
|
|
85
|
+
- Switch to **Compare** to see which themes grew, shrank, entered the range, or left the range between two points in time, or **Lifelines** to follow each theme's share across the whole selected range.
|
|
90
86
|
|
|
91
|
-
Filtering the flow by a theme is unavailable for snapshots with more than 2,000 traces.
|
|
87
|
+
Filtering the flow by a theme is unavailable for snapshots with more than 2,000 traces. Selecting a theme still opens its details there without filtering the flow.
|
|
92
88
|
|
|
93
89
|
## Troubleshooting
|
|
94
90
|
|
|
@@ -6,7 +6,7 @@ Message history is the most basic and important form of memory. It gives the LLM
|
|
|
6
6
|
|
|
7
7
|
You can also retrieve message history to display past conversations in your UI.
|
|
8
8
|
|
|
9
|
-
> **
|
|
9
|
+
> **Note:** Each message belongs to a thread (the conversation) and a resource (the user or entity it's associated with). See [Threads and resources](#threads-and-resources) for more detail.
|
|
10
10
|
|
|
11
11
|
> **Warning:** When you use memory with a client application, send **only the new message** from the client instead of the full conversation history.
|
|
12
12
|
>
|
|
@@ -113,7 +113,7 @@ await agent.stream('Hello', {
|
|
|
113
113
|
})
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
> **
|
|
116
|
+
> **Note:** Threads and messages are created automatically when you call `agent.generate()` or `agent.stream()`, but you can also create them manually with [`createThread()`](https://mastra.ai/reference/memory/createThread) and [`saveMessages()`](https://mastra.ai/reference/memory/memory-class).
|
|
117
117
|
|
|
118
118
|
You can use this history in two ways:
|
|
119
119
|
|
|
@@ -186,7 +186,7 @@ When you deploy with Mastra Studio, set **Deployment → Service Name** to a sta
|
|
|
186
186
|
|
|
187
187
|
## Performance
|
|
188
188
|
|
|
189
|
-
> **
|
|
189
|
+
> **Note:** MastraPlatformExporter uses batching to optimize network usage. Events are buffered and sent in batches, reducing overhead while maintaining near real-time visibility.
|
|
190
190
|
|
|
191
191
|
### Batching behavior
|
|
192
192
|
|
|
@@ -230,7 +230,7 @@ export const mastra = new Mastra({
|
|
|
230
230
|
})
|
|
231
231
|
```
|
|
232
232
|
|
|
233
|
-
> **
|
|
233
|
+
> **Note:** Get your Dash0 endpoint from your dashboard. It should be in the format `ingress.{region}.aws.dash0.com:4317`.
|
|
234
234
|
|
|
235
235
|
### `SigNoz`
|
|
236
236
|
|
|
@@ -400,7 +400,7 @@ export const mastra = new Mastra({
|
|
|
400
400
|
})
|
|
401
401
|
```
|
|
402
402
|
|
|
403
|
-
> **
|
|
403
|
+
> **Note:** The Datadog Agent must be configured with OTLP ingestion enabled. Add the following to your `datadog.yaml`:
|
|
404
404
|
>
|
|
405
405
|
> ```yaml
|
|
406
406
|
> otlp_config:
|
|
@@ -200,7 +200,7 @@ export const createMastraClient = (accessToken: string) => {
|
|
|
200
200
|
}
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
> **
|
|
203
|
+
> **Note:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
204
204
|
>
|
|
205
205
|
> Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
|
|
206
206
|
|
|
@@ -61,7 +61,7 @@ export const mastra = new Mastra({
|
|
|
61
61
|
})
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
> **
|
|
64
|
+
> **Note:** The default `authorizeUser` method allows all authenticated users. To customize user authorization, provide a custom `authorizeUser` function when constructing the provider.
|
|
65
65
|
>
|
|
66
66
|
> Visit [MastraAuthClerk](https://mastra.ai/reference/auth/clerk) for all available configuration options.
|
|
67
67
|
|
|
@@ -105,7 +105,7 @@ export const mastraClient = new MastraClient({
|
|
|
105
105
|
})
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
> **
|
|
108
|
+
> **Note:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
109
109
|
>
|
|
110
110
|
> Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
|
|
111
111
|
|
|
@@ -200,7 +200,7 @@ export const createMastraClient = (idToken: string) => {
|
|
|
200
200
|
}
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
> **
|
|
203
|
+
> **Note:** The ID token must be prefixed with `Bearer` in the Authorization header.
|
|
204
204
|
>
|
|
205
205
|
> Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
|
|
206
206
|
|
|
@@ -179,16 +179,35 @@ export const mastraClient = new MastraClient({
|
|
|
179
179
|
|
|
180
180
|
### Bearer token
|
|
181
181
|
|
|
182
|
-
You can also pass an Okta
|
|
182
|
+
You can also pass an Okta token as a Bearer token. The token is verified against Okta's JWKS endpoint, and its `aud` claim must match the configured audience. The audience defaults to your client ID, and you can override it with the `audience` option or `OKTA_AUDIENCE`.
|
|
183
|
+
|
|
184
|
+
Okta puts the client ID in the `aud` claim of **ID tokens**, so ID tokens work with the default. **Access tokens** carry the audience of the authorization server that issued them, so set the audience to match:
|
|
185
|
+
|
|
186
|
+
- **Org authorization server** (the default, issuer `https://{domain}`): set the audience to `https://{domain}`.
|
|
187
|
+
- **Custom authorization server** (issuer `https://{domain}/oauth2/{name}`): set the audience to the server's audience value from the Okta Admin Console, for example `api://default`.
|
|
188
|
+
|
|
189
|
+
```env
|
|
190
|
+
OKTA_AUDIENCE=https://dev-123456.okta.com
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Pass an array to accept more than one audience, for example ID tokens from browsers and access tokens from service callers against the same provider:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
new MastraAuthOkta({
|
|
197
|
+
audience: ['your-client-id', 'https://dev-123456.okta.com'],
|
|
198
|
+
})
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
> **Note:** `audience` applies only to Bearer tokens. The ID token exchanged during the SSO login flow is always verified against your client ID.
|
|
183
202
|
|
|
184
203
|
```typescript
|
|
185
204
|
import { MastraClient } from '@mastra/client-js'
|
|
186
205
|
|
|
187
|
-
export const createMastraClient = (
|
|
206
|
+
export const createMastraClient = (token: string) => {
|
|
188
207
|
return new MastraClient({
|
|
189
208
|
baseUrl: 'http://localhost:4111',
|
|
190
209
|
headers: {
|
|
191
|
-
Authorization: `Bearer ${
|
|
210
|
+
Authorization: `Bearer ${token}`,
|
|
192
211
|
},
|
|
193
212
|
})
|
|
194
213
|
}
|
|
@@ -213,7 +232,7 @@ console.log(response)
|
|
|
213
232
|
```bash
|
|
214
233
|
curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
215
234
|
-H "Content-Type: application/json" \
|
|
216
|
-
-H "Authorization: Bearer <your-okta-
|
|
235
|
+
-H "Authorization: Bearer <your-okta-token>" \
|
|
217
236
|
-d '{
|
|
218
237
|
"messages": "Weather in London"
|
|
219
238
|
}'
|
|
@@ -222,6 +241,7 @@ curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
|
222
241
|
## Troubleshooting
|
|
223
242
|
|
|
224
243
|
- **401 on every request**: Verify your Okta domain, client ID, and client secret are correct. Check that the redirect URI in your Okta application matches `OKTA_REDIRECT_URI`.
|
|
244
|
+
- **401 with `unexpected "aud" claim value` in the server logs**: The Bearer token's audience doesn't match the configured audience. This usually means you sent an access token while the audience is still the default client ID. Set `OKTA_AUDIENCE` to the audience of the authorization server that issued the token. See [Bearer token](#bearer-token).
|
|
225
245
|
- **Cookies not sent cross-origin**: Set `credentials: "include"` in `MastraClient` and configure `server.cors` with your frontend origin and `credentials: true`.
|
|
226
246
|
- **Session lost on restart**: Set `OKTA_COOKIE_PASSWORD` to a stable value (at least 32 characters). Without it, an auto-generated key is used that changes on each restart.
|
|
227
247
|
- **RBAC returns empty permissions**: Verify `OKTA_API_TOKEN` is set and the token has permission to list user groups. Check that group names in `roleMapping` match your Okta group names exactly.
|
|
@@ -59,7 +59,7 @@ export const mastra = new Mastra({
|
|
|
59
59
|
})
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
> **
|
|
62
|
+
> **Note:** The default `authorizeUser` method checks the `isAdmin` column in the `users` table in the `public` schema. To customize user authorization, provide a custom `authorizeUser` function when constructing the provider.
|
|
63
63
|
>
|
|
64
64
|
> Visit [MastraAuthSupabase](https://mastra.ai/reference/auth/supabase) for all available configuration options.
|
|
65
65
|
|
|
@@ -101,7 +101,7 @@ export const mastraClient = new MastraClient({
|
|
|
101
101
|
})
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
> **
|
|
104
|
+
> **Note:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
105
105
|
>
|
|
106
106
|
> Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
|
|
107
107
|
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
# Workers
|
|
4
4
|
|
|
5
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
6
|
+
|
|
5
7
|
When workers run in separate processes from the API, they communicate over HTTP. The orchestration worker calls the API's step execution endpoint to run workflow steps on the API server. Push-mode PubSub brokers (like Google Cloud Pub/Sub in push mode) can also deliver events directly to the API's event endpoint. This is a distinct integration path from pull-mode workers, which pull events from the broker themselves. Both HTTP endpoints require authentication when an auth provider is configured.
|
|
6
8
|
|
|
7
9
|
## How it works
|
|
@@ -221,7 +221,7 @@ export const createMastraClient = (accessToken: string) => {
|
|
|
221
221
|
}
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
> **
|
|
224
|
+
> **Note:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
225
225
|
>
|
|
226
226
|
> Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
|
|
227
227
|
|
|
@@ -6,7 +6,7 @@ Create a custom adapter when the prebuilt server adapters (Hono, Express, Fastif
|
|
|
6
6
|
|
|
7
7
|
A custom adapter translates between Mastra's route definitions and your framework's routing system. You'll implement methods that register middleware, handle requests, and send responses using your framework's APIs.
|
|
8
8
|
|
|
9
|
-
> **
|
|
9
|
+
> **Note:** Use any of these prebuilt server adapters:
|
|
10
10
|
>
|
|
11
11
|
> - [@mastra/hono](https://mastra.ai/reference/server/hono-adapter)
|
|
12
12
|
> - [@mastra/express](https://mastra.ai/reference/server/express-adapter)
|
|
@@ -35,6 +35,41 @@ curl http://localhost:4111/my-custom-route
|
|
|
35
35
|
|
|
36
36
|
Each route's handler receives the Hono `Context`. Within the handler you can access the `Mastra` instance to fetch or call agents and workflows.
|
|
37
37
|
|
|
38
|
+
## Schema validation
|
|
39
|
+
|
|
40
|
+
Use [`createRoute()`](https://mastra.ai/reference/server/create-route) in `apiRoutes` to parse and validate path parameters, query parameters, and request bodies with Zod. The schemas also infer the handler parameters and generate OpenAPI metadata.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { Mastra } from '@mastra/core'
|
|
44
|
+
import { createRoute } from '@mastra/server/server-adapter'
|
|
45
|
+
import { z } from 'zod'
|
|
46
|
+
|
|
47
|
+
const createItemRoute = createRoute({
|
|
48
|
+
method: 'POST',
|
|
49
|
+
path: '/items',
|
|
50
|
+
responseType: 'json',
|
|
51
|
+
bodySchema: z.object({
|
|
52
|
+
name: z.string().min(1),
|
|
53
|
+
}),
|
|
54
|
+
responseSchema: z.object({
|
|
55
|
+
id: z.string(),
|
|
56
|
+
name: z.string(),
|
|
57
|
+
}),
|
|
58
|
+
handler: async ({ name }) => ({
|
|
59
|
+
id: crypto.randomUUID(),
|
|
60
|
+
name,
|
|
61
|
+
}),
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
export const mastra = new Mastra({
|
|
65
|
+
server: {
|
|
66
|
+
apiRoutes: [createItemRoute],
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
By default, Mastra returns a `400` response when validation fails. The `onValidationError` callback can override the status and response body. Validated values and the `Mastra` server context are passed directly to the handler.
|
|
72
|
+
|
|
38
73
|
## Middleware
|
|
39
74
|
|
|
40
75
|
To add route-specific middleware pass a `middleware` array when calling `registerApiRoute()`.
|
|
@@ -149,7 +149,7 @@ const testAgent = async () => {
|
|
|
149
149
|
}
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
> **
|
|
152
|
+
> **Note:** You can also call `.generate()` with an array of message objects that include `role` and `content`. Visit the [.generate() reference](https://mastra.ai/reference/client-js/agents) for more information.
|
|
153
153
|
|
|
154
154
|
## Streaming responses
|
|
155
155
|
|
|
@@ -175,7 +175,7 @@ const testAgent = async () => {
|
|
|
175
175
|
}
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
> **
|
|
178
|
+
> **Note:** You can also call `.stream()` with an array of message objects that include `role` and `content`. Visit the [.stream() reference](https://mastra.ai/reference/client-js/agents) for more information.
|
|
179
179
|
|
|
180
180
|
## Configuration options
|
|
181
181
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Mastra runs as an HTTP server that exposes your agents, workflows, and other functionality as API endpoints. The server handles request routing, middleware execution, authentication, and streaming responses.
|
|
6
6
|
|
|
7
|
-
> **
|
|
7
|
+
> **Note:** This page covers the [`server`](https://mastra.ai/reference/configuration) configuration options passed to the `Mastra` constructor. For running Mastra with your own HTTP server (Hono, Express, etc.), visit [Server Adapters](https://mastra.ai/docs/server/server-adapters).
|
|
8
8
|
|
|
9
9
|
## Server features
|
|
10
10
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Dynamic workflows
|
|
4
4
|
|
|
5
|
-
> **Beta:**
|
|
5
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
6
6
|
|
|
7
7
|
Dynamic workflows are workflow definitions expressed as data instead of code. A definition is a JSON document that describes the workflow's schemas and step graph. Mastra validates the definition and registers it as a runnable workflow, then persists it in storage so it survives process restarts.
|
|
8
8
|
|
|
@@ -287,7 +287,7 @@ You can run workflows from agents, tools, the Mastra Client, or the command line
|
|
|
287
287
|
const testWorkflow = mastra.getWorkflow('testWorkflow')
|
|
288
288
|
```
|
|
289
289
|
|
|
290
|
-
> **
|
|
290
|
+
> **Note:** `mastra.getWorkflow()` is preferred over a direct import for two reasons:
|
|
291
291
|
>
|
|
292
292
|
> 1. It provides access to the Mastra instance configuration (logger, telemetry, storage, registered agents, and vector stores)
|
|
293
293
|
> 2. It provides full TypeScript type inference for workflow input and output schemas
|
|
@@ -15,6 +15,8 @@ When you call `timeTravel()` on a workflow run:
|
|
|
15
15
|
3. Execution begins from the specified step with the provided or reconstructed input data
|
|
16
16
|
4. The workflow continues to completion from that point forward
|
|
17
17
|
|
|
18
|
+
If the workflow definition has changed since the run was recorded (for example, a step was renamed), or the recorded run never reached a step that precedes the target, time travel fails with a descriptive error before anything executes, and the stored snapshot is left unchanged.
|
|
19
|
+
|
|
18
20
|
Time travel requires storage to be configured since it relies on persisted workflow snapshots.
|
|
19
21
|
|
|
20
22
|
## Basic usage
|