@mastra/mcp-docs-server 1.0.0-beta.13 → 1.0.0-beta.14
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 +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +98 -98
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +30 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +171 -171
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Frag.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Freact.md +9 -2
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +94 -94
- package/.docs/organized/changelogs/create-mastra.md +3 -3
- package/.docs/organized/changelogs/mastra.md +17 -17
- package/.docs/organized/code-examples/agent-v6.md +151 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +2 -3
- 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 -0
- package/.docs/raw/deployment/web-framework.mdx +4 -6
- 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/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 +386 -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/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/setting-up.mdx +6 -2
- 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 +6 -7
- 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 +2 -2
- 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 +3 -3
- 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 +3 -3
- package/.docs/raw/reference/storage/libsql.mdx +69 -54
- package/.docs/raw/reference/storage/mongodb.mdx +80 -7
- package/.docs/raw/reference/storage/mssql.mdx +4 -4
- package/.docs/raw/{memory → reference}/storage/overview.mdx +12 -110
- package/.docs/raw/reference/storage/postgresql.mdx +78 -7
- 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 +1 -1
- 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/inngest-workflow.mdx +8 -9
- package/.docs/raw/workflows/input-data-mapping.mdx +7 -7
- package/.docs/raw/workflows/overview.mdx +33 -22
- package/.docs/raw/workflows/snapshots.mdx +14 -44
- 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 +9 -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 +4 -4
- 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
|
@@ -22,7 +22,7 @@ If you prefer not to use our automatic CLI tool, you can set up your project you
|
|
|
22
22
|
|
|
23
23
|
Create a new project and change directory:
|
|
24
24
|
|
|
25
|
-
```bash
|
|
25
|
+
```bash
|
|
26
26
|
mkdir my-first-agent && cd my-first-agent
|
|
27
27
|
```
|
|
28
28
|
|
|
@@ -31,7 +31,7 @@ Initialize a TypeScript project and install the following dependencies:
|
|
|
31
31
|
<Tabs>
|
|
32
32
|
<TabItem value="npm" label="npm">
|
|
33
33
|
|
|
34
|
-
```bash
|
|
34
|
+
```bash
|
|
35
35
|
npm init -y
|
|
36
36
|
npm install -D typescript @types/node mastra@beta
|
|
37
37
|
npm install @mastra/core@beta zod@^4
|
|
@@ -40,7 +40,7 @@ npm install @mastra/core@beta zod@^4
|
|
|
40
40
|
</TabItem>
|
|
41
41
|
<TabItem value="pnpm" label="pnpm">
|
|
42
42
|
|
|
43
|
-
```bash
|
|
43
|
+
```bash
|
|
44
44
|
pnpm init
|
|
45
45
|
pnpm add -D typescript @types/node mastra@beta
|
|
46
46
|
pnpm add @mastra/core@beta zod@^4
|
|
@@ -49,7 +49,7 @@ pnpm add @mastra/core@beta zod@^4
|
|
|
49
49
|
</TabItem>
|
|
50
50
|
<TabItem value="yarn" label="yarn">
|
|
51
51
|
|
|
52
|
-
```bash
|
|
52
|
+
```bash
|
|
53
53
|
yarn init -y
|
|
54
54
|
yarn add -D typescript @types/node mastra@beta
|
|
55
55
|
yarn add @mastra/core@beta zod@^4
|
|
@@ -58,7 +58,7 @@ yarn add @mastra/core@beta zod@^4
|
|
|
58
58
|
</TabItem>
|
|
59
59
|
<TabItem value="bun" label="bun">
|
|
60
60
|
|
|
61
|
-
```bash
|
|
61
|
+
```bash
|
|
62
62
|
bun init -y
|
|
63
63
|
bun add -d typescript @types/node mastra@beta
|
|
64
64
|
bun add @mastra/core@beta zod@^4
|
|
@@ -69,7 +69,7 @@ bun add @mastra/core@beta zod@^4
|
|
|
69
69
|
|
|
70
70
|
Add `dev` and `build` scripts to your `package.json` file:
|
|
71
71
|
|
|
72
|
-
```json title="package.json"
|
|
72
|
+
```json title="package.json" /,/ /"dev": "mastra dev",/ /"build": "mastra build"/
|
|
73
73
|
{
|
|
74
74
|
"scripts": {
|
|
75
75
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -85,13 +85,13 @@ Add `dev` and `build` scripts to your `package.json` file:
|
|
|
85
85
|
|
|
86
86
|
Create a `tsconfig.json` file:
|
|
87
87
|
|
|
88
|
-
```bash
|
|
88
|
+
```bash
|
|
89
89
|
touch tsconfig.json
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
Add the following configuration:
|
|
93
93
|
|
|
94
|
-
```json title="tsconfig.json"
|
|
94
|
+
```json title="tsconfig.json"
|
|
95
95
|
{
|
|
96
96
|
"compilerOptions": {
|
|
97
97
|
"target": "ES2022",
|
|
@@ -120,13 +120,13 @@ Mastra requires modern `module` and `moduleResolution` settings. Using `CommonJS
|
|
|
120
120
|
|
|
121
121
|
Create an `.env` file:
|
|
122
122
|
|
|
123
|
-
```bash
|
|
123
|
+
```bash
|
|
124
124
|
touch .env
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
Add your API key:
|
|
128
128
|
|
|
129
|
-
```bash title=".env"
|
|
129
|
+
```bash title=".env"
|
|
130
130
|
GOOGLE_GENERATIVE_AI_API_KEY=<your-api-key>
|
|
131
131
|
```
|
|
132
132
|
|
|
@@ -142,13 +142,13 @@ This guide uses Google Gemini, but you can use any supported [model provider](/m
|
|
|
142
142
|
|
|
143
143
|
Create a `weather-tool.ts` file:
|
|
144
144
|
|
|
145
|
-
```bash
|
|
145
|
+
```bash
|
|
146
146
|
mkdir -p src/mastra/tools && touch src/mastra/tools/weather-tool.ts
|
|
147
147
|
```
|
|
148
148
|
|
|
149
149
|
Add the following code:
|
|
150
150
|
|
|
151
|
-
```ts title="src/mastra/tools/weather-tool.ts"
|
|
151
|
+
```ts title="src/mastra/tools/weather-tool.ts"
|
|
152
152
|
import { createTool } from "@mastra/core/tools";
|
|
153
153
|
import { z } from "zod";
|
|
154
154
|
|
|
@@ -181,13 +181,13 @@ We've shortened and simplified the `weatherTool` example here. You can see the c
|
|
|
181
181
|
|
|
182
182
|
Create a `weather-agent.ts` file:
|
|
183
183
|
|
|
184
|
-
```bash
|
|
184
|
+
```bash
|
|
185
185
|
mkdir -p src/mastra/agents && touch src/mastra/agents/weather-agent.ts
|
|
186
186
|
```
|
|
187
187
|
|
|
188
188
|
Add the following code:
|
|
189
189
|
|
|
190
|
-
```ts title="src/mastra/agents/weather-agent.ts"
|
|
190
|
+
```ts title="src/mastra/agents/weather-agent.ts"
|
|
191
191
|
import { Agent } from "@mastra/core/agent";
|
|
192
192
|
import { weatherTool } from "../tools/weather-tool";
|
|
193
193
|
|
|
@@ -217,13 +217,13 @@ export const weatherAgent = new Agent({
|
|
|
217
217
|
|
|
218
218
|
Create the Mastra entry point and register your agent:
|
|
219
219
|
|
|
220
|
-
```bash
|
|
220
|
+
```bash
|
|
221
221
|
touch src/mastra/index.ts
|
|
222
222
|
```
|
|
223
223
|
|
|
224
224
|
Add the following code:
|
|
225
225
|
|
|
226
|
-
```ts title="src/mastra/index.ts"
|
|
226
|
+
```ts title="src/mastra/index.ts"
|
|
227
227
|
import { Mastra } from "@mastra/core";
|
|
228
228
|
import { weatherAgent } from "./agents/weather-agent";
|
|
229
229
|
|
|
@@ -241,28 +241,28 @@ You can now launch [Studio](/docs/v1/getting-started/studio) and test your agent
|
|
|
241
241
|
<Tabs>
|
|
242
242
|
<TabItem value="npm" label="npm">
|
|
243
243
|
|
|
244
|
-
```bash
|
|
244
|
+
```bash
|
|
245
245
|
npm run dev
|
|
246
246
|
```
|
|
247
247
|
|
|
248
248
|
</TabItem>
|
|
249
249
|
<TabItem value="pnpm" label="pnpm">
|
|
250
250
|
|
|
251
|
-
```bash
|
|
251
|
+
```bash
|
|
252
252
|
pnpm run dev
|
|
253
253
|
```
|
|
254
254
|
|
|
255
255
|
</TabItem>
|
|
256
256
|
<TabItem value="yarn" label="yarn">
|
|
257
257
|
|
|
258
|
-
```bash
|
|
258
|
+
```bash
|
|
259
259
|
yarn run dev
|
|
260
260
|
```
|
|
261
261
|
|
|
262
262
|
</TabItem>
|
|
263
263
|
<TabItem value="bun" label="bun">
|
|
264
264
|
|
|
265
|
-
```bash
|
|
265
|
+
```bash
|
|
266
266
|
bun run dev
|
|
267
267
|
```
|
|
268
268
|
|
|
@@ -25,7 +25,7 @@ During the interactive [create-mastra](/reference/v1/cli/create-mastra) wizard,
|
|
|
25
25
|
|
|
26
26
|
If there are no specific instructions for your tool below, you may be able to add the MCP server with this common JSON configuration anyways.
|
|
27
27
|
|
|
28
|
-
```json
|
|
28
|
+
```json
|
|
29
29
|
{
|
|
30
30
|
"mcpServers": {
|
|
31
31
|
"mastra": {
|
|
@@ -41,7 +41,7 @@ If there are no specific instructions for your tool below, you may be able to ad
|
|
|
41
41
|
|
|
42
42
|
Install using the terminal command:
|
|
43
43
|
|
|
44
|
-
```bash
|
|
44
|
+
```bash
|
|
45
45
|
claude mcp add mastra -- npx -y @mastra/mcp-docs-server@beta
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -49,7 +49,7 @@ Install `@mastra/ai-sdk` to begin using the `withMastra()` function.
|
|
|
49
49
|
|
|
50
50
|
Processors let you transform messages before they're sent to the model (`processInput`) and after responses are received (`processOutputResult`). This example creates a logging processor that logs message counts at each stage, then wraps an OpenAI model with it.
|
|
51
51
|
|
|
52
|
-
```typescript title="src/example.ts"
|
|
52
|
+
```typescript title="src/example.ts"
|
|
53
53
|
import { openai } from '@ai-sdk/openai';
|
|
54
54
|
import { generateText } from 'ai';
|
|
55
55
|
import { withMastra } from '@mastra/ai-sdk';
|
|
@@ -80,9 +80,9 @@ const { text } = await generateText({
|
|
|
80
80
|
|
|
81
81
|
### With Memory
|
|
82
82
|
|
|
83
|
-
Memory automatically loads previous messages from storage before the LLM call and saves new messages after. This example configures a
|
|
83
|
+
Memory automatically loads previous messages from storage before the LLM call and saves new messages after. This example configures a libSQL storage backend to persist conversation history, loading the last 10 messages for context.
|
|
84
84
|
|
|
85
|
-
```typescript title="src/memory-example.ts"
|
|
85
|
+
```typescript title="src/memory-example.ts"
|
|
86
86
|
import { openai } from '@ai-sdk/openai';
|
|
87
87
|
import { generateText } from 'ai';
|
|
88
88
|
import { withMastra } from '@mastra/ai-sdk';
|
|
@@ -113,7 +113,7 @@ const { text } = await generateText({
|
|
|
113
113
|
|
|
114
114
|
You can combine processors and memory together. Input processors run after memory loads historical messages, and output processors run before memory saves the response.
|
|
115
115
|
|
|
116
|
-
```typescript title="src/combined-example.ts"
|
|
116
|
+
```typescript title="src/combined-example.ts"
|
|
117
117
|
import { openai } from '@ai-sdk/openai';
|
|
118
118
|
import { generateText } from 'ai';
|
|
119
119
|
import { withMastra } from '@mastra/ai-sdk';
|
|
@@ -80,7 +80,7 @@ You can use [`chatRoute()`](/reference/v1/ai-sdk/chat-route), [`workflowRoute()`
|
|
|
80
80
|
|
|
81
81
|
This example shows how to set up a chat route at the `/chat` endpoint that uses an agent with the ID `weatherAgent`.
|
|
82
82
|
|
|
83
|
-
```typescript title="src/mastra/index.ts"
|
|
83
|
+
```typescript title="src/mastra/index.ts"
|
|
84
84
|
import { Mastra } from "@mastra/core";
|
|
85
85
|
import { chatRoute } from "@mastra/ai-sdk";
|
|
86
86
|
|
|
@@ -104,7 +104,7 @@ You can also use dynamic agent routing, see the [`chatRoute()` reference documen
|
|
|
104
104
|
|
|
105
105
|
This example shows how to set up a workflow route at the `/workflow` endpoint that uses a workflow with the ID `weatherWorkflow`.
|
|
106
106
|
|
|
107
|
-
```typescript title="src/mastra/index.ts"
|
|
107
|
+
```typescript title="src/mastra/index.ts"
|
|
108
108
|
import { Mastra } from "@mastra/core";
|
|
109
109
|
import { workflowRoute } from "@mastra/ai-sdk";
|
|
110
110
|
|
|
@@ -136,7 +136,7 @@ See [Workflow Streaming](/docs/v1/streaming/workflow-streaming#streaming-agent-t
|
|
|
136
136
|
|
|
137
137
|
This example shows how to set up a network route at the `/network` endpoint that uses an agent with the ID `weatherAgent`.
|
|
138
138
|
|
|
139
|
-
```typescript title="src/mastra/index.ts"
|
|
139
|
+
```typescript title="src/mastra/index.ts"
|
|
140
140
|
import { Mastra } from "@mastra/core";
|
|
141
141
|
import { networkRoute } from "@mastra/ai-sdk";
|
|
142
142
|
|
|
@@ -172,7 +172,7 @@ The examples below show you how to use them with Next.js App Router.
|
|
|
172
172
|
|
|
173
173
|
This example shows how to set up a chat route at the `/chat` endpoint that uses an agent with the ID `weatherAgent`.
|
|
174
174
|
|
|
175
|
-
```typescript title="app/chat/route.ts"
|
|
175
|
+
```typescript title="app/chat/route.ts"
|
|
176
176
|
import { handleChatStream } from '@mastra/ai-sdk';
|
|
177
177
|
import { createUIMessageStreamResponse } from 'ai';
|
|
178
178
|
import { mastra } from '@/src/mastra';
|
|
@@ -194,7 +194,7 @@ export async function POST(req: Request) {
|
|
|
194
194
|
|
|
195
195
|
This example shows how to set up a workflow route at the `/workflow` endpoint that uses a workflow with the ID `weatherWorkflow`.
|
|
196
196
|
|
|
197
|
-
```typescript title="app/workflow/route.ts"
|
|
197
|
+
```typescript title="app/workflow/route.ts"
|
|
198
198
|
import { handleWorkflowStream } from '@mastra/ai-sdk';
|
|
199
199
|
import { createUIMessageStreamResponse } from 'ai';
|
|
200
200
|
import { mastra } from '@/src/mastra';
|
|
@@ -216,7 +216,7 @@ export async function POST(req: Request) {
|
|
|
216
216
|
|
|
217
217
|
This example shows how to set up a network route at the `/network` endpoint that uses an agent with the ID `routingAgent`.
|
|
218
218
|
|
|
219
|
-
```typescript title="app/network/route.ts"
|
|
219
|
+
```typescript title="app/network/route.ts"
|
|
220
220
|
import { handleNetworkStream } from '@mastra/ai-sdk';
|
|
221
221
|
import { createUIMessageStreamResponse } from 'ai';
|
|
222
222
|
import { mastra } from '@/src/mastra';
|
|
@@ -279,7 +279,7 @@ The `useCompletion()` hook handles single-turn completions between your frontend
|
|
|
279
279
|
|
|
280
280
|
Your frontend could look like this:
|
|
281
281
|
|
|
282
|
-
```typescript title="app/page.tsx"
|
|
282
|
+
```typescript title="app/page.tsx"
|
|
283
283
|
import { useCompletion } from '@ai-sdk/react';
|
|
284
284
|
|
|
285
285
|
export default function Page() {
|
|
@@ -308,7 +308,7 @@ Below are two approaches to implementing the backend:
|
|
|
308
308
|
|
|
309
309
|
<TabItem value="mastra-server" label="Mastra Server">
|
|
310
310
|
|
|
311
|
-
```ts title="src/mastra/index.ts"
|
|
311
|
+
```ts title="src/mastra/index.ts"
|
|
312
312
|
import { Mastra } from '@mastra/core/mastra';
|
|
313
313
|
import { registerApiRoute } from '@mastra/core/server';
|
|
314
314
|
import { handleChatStream } from '@mastra/ai-sdk';
|
|
@@ -353,7 +353,7 @@ export const mastra = new Mastra({
|
|
|
353
353
|
|
|
354
354
|
<TabItem value="nextjs" label="Next.js">
|
|
355
355
|
|
|
356
|
-
```ts title="app/completion/route.ts"
|
|
356
|
+
```ts title="app/completion/route.ts"
|
|
357
357
|
import { handleChatStream } from '@mastra/ai-sdk';
|
|
358
358
|
import { createUIMessageStreamResponse } from 'ai';
|
|
359
359
|
import { mastra } from '@/src/mastra';
|
|
@@ -433,7 +433,7 @@ Here's an example of rendering a weather tool's output as a custom `WeatherCard`
|
|
|
433
433
|
|
|
434
434
|
Define a tool with an `outputSchema` so the frontend knows the shape of the data to render.
|
|
435
435
|
|
|
436
|
-
```typescript title="src/mastra/tools/weather-tool.ts" {10-17}
|
|
436
|
+
```typescript title="src/mastra/tools/weather-tool.ts" {10-17}
|
|
437
437
|
import { createTool } from "@mastra/core/tools";
|
|
438
438
|
import { z } from "zod";
|
|
439
439
|
|
|
@@ -474,7 +474,7 @@ export const weatherTool = createTool({
|
|
|
474
474
|
|
|
475
475
|
Check for `tool-{toolKey}` parts in the message and render a custom component based on the tool's state and output.
|
|
476
476
|
|
|
477
|
-
```typescript title="src/components/chat.tsx" {24-35}
|
|
477
|
+
```typescript title="src/components/chat.tsx" {24-35}
|
|
478
478
|
import { useChat } from "@ai-sdk/react";
|
|
479
479
|
import { DefaultChatTransport } from "ai";
|
|
480
480
|
import { WeatherCard } from "./weather-card";
|
|
@@ -540,7 +540,7 @@ When using `workflowRoute()` or `handleWorkflowStream()`, Mastra emits `data-wor
|
|
|
540
540
|
|
|
541
541
|
Define a workflow with multiple steps that will emit `data-workflow` parts as it executes.
|
|
542
542
|
|
|
543
|
-
```typescript title="src/mastra/workflows/activities-workflow.ts"
|
|
543
|
+
```typescript title="src/mastra/workflows/activities-workflow.ts"
|
|
544
544
|
import { createStep, createWorkflow } from "@mastra/core/workflows";
|
|
545
545
|
import { z } from "zod";
|
|
546
546
|
|
|
@@ -594,7 +594,7 @@ activitiesWorkflow.commit();
|
|
|
594
594
|
|
|
595
595
|
Register the workflow with Mastra and expose it via `workflowRoute()` to stream workflow events to the frontend.
|
|
596
596
|
|
|
597
|
-
```typescript title="src/mastra/index.ts"
|
|
597
|
+
```typescript title="src/mastra/index.ts"
|
|
598
598
|
import { Mastra } from "@mastra/core";
|
|
599
599
|
import { workflowRoute } from "@mastra/ai-sdk";
|
|
600
600
|
|
|
@@ -617,7 +617,7 @@ export const mastra = new Mastra({
|
|
|
617
617
|
|
|
618
618
|
Check for `data-workflow` parts and render each step's status and output using the `WorkflowDataPart` type for type safety.
|
|
619
619
|
|
|
620
|
-
```typescript title="src/components/workflow-chat.tsx" {3,5,45-47}
|
|
620
|
+
```typescript title="src/components/workflow-chat.tsx" {3,5,45-47}
|
|
621
621
|
import { useChat } from "@ai-sdk/react";
|
|
622
622
|
import { DefaultChatTransport } from "ai";
|
|
623
623
|
import type { WorkflowDataPart } from "@mastra/ai-sdk";
|
|
@@ -706,7 +706,7 @@ When using `networkRoute()` or `handleNetworkStream()`, Mastra emits `data-netwo
|
|
|
706
706
|
|
|
707
707
|
Register agents with Mastra and expose the routing agent via `networkRoute()` to stream network execution events to the frontend.
|
|
708
708
|
|
|
709
|
-
```typescript title="src/mastra/index.ts"
|
|
709
|
+
```typescript title="src/mastra/index.ts"
|
|
710
710
|
import { Mastra } from "@mastra/core";
|
|
711
711
|
import { networkRoute } from "@mastra/ai-sdk";
|
|
712
712
|
|
|
@@ -729,7 +729,7 @@ export const mastra = new Mastra({
|
|
|
729
729
|
|
|
730
730
|
Check for `data-network` parts and render each agent's execution step using the `NetworkDataPart` type for type safety.
|
|
731
731
|
|
|
732
|
-
```typescript title="src/components/network-chat.tsx" {3,5,42-44}
|
|
732
|
+
```typescript title="src/components/network-chat.tsx" {3,5,42-44}
|
|
733
733
|
import { useChat } from "@ai-sdk/react";
|
|
734
734
|
import { DefaultChatTransport } from "ai";
|
|
735
735
|
import type { NetworkDataPart } from "@mastra/ai-sdk";
|
|
@@ -823,7 +823,7 @@ You must `await` the `writer.custom()` call, otherwise you may encounter a `Writ
|
|
|
823
823
|
|
|
824
824
|
Use `writer.custom()` inside the tool's `execute()` function to emit custom `data-` prefixed events at different stages of execution.
|
|
825
825
|
|
|
826
|
-
```typescript title="src/mastra/tools/task-tool.ts" {18-24,30-36}
|
|
826
|
+
```typescript title="src/mastra/tools/task-tool.ts" {18-24,30-36}
|
|
827
827
|
import { createTool } from "@mastra/core/tools";
|
|
828
828
|
import { z } from "zod";
|
|
829
829
|
|
|
@@ -875,7 +875,7 @@ export const taskTool = createTool({
|
|
|
875
875
|
|
|
876
876
|
Filter message parts for your custom event type and render a progress indicator that updates as new events arrive.
|
|
877
877
|
|
|
878
|
-
```typescript title="src/components/task-chat.tsx" {31-41,45}
|
|
878
|
+
```typescript title="src/components/task-chat.tsx" {31-41,45}
|
|
879
879
|
import { useChat } from "@ai-sdk/react";
|
|
880
880
|
import { DefaultChatTransport } from "ai";
|
|
881
881
|
import { useMemo } from "react";
|
|
@@ -969,7 +969,7 @@ When loading messages from Mastra's memory to display in a chat UI, use [`toAISd
|
|
|
969
969
|
|
|
970
970
|
Here's an example of the frontend code:
|
|
971
971
|
|
|
972
|
-
```typescript {15-25}
|
|
972
|
+
```typescript {15-25}
|
|
973
973
|
import { useChat } from "@ai-sdk/react";
|
|
974
974
|
import { useState } from "react";
|
|
975
975
|
import { DefaultChatTransport } from 'ai';
|
|
@@ -1016,7 +1016,7 @@ Two examples on how to implement the backend portion of it.
|
|
|
1016
1016
|
|
|
1017
1017
|
Add a `chatRoute()` to your Mastra configuration like shown above. Then, add a server-level middleware:
|
|
1018
1018
|
|
|
1019
|
-
```typescript title="src/mastra/index.ts"
|
|
1019
|
+
```typescript title="src/mastra/index.ts"
|
|
1020
1020
|
import { Mastra } from "@mastra/core";
|
|
1021
1021
|
|
|
1022
1022
|
export const mastra = new Mastra({
|
|
@@ -1052,7 +1052,7 @@ You can access this data in your tools via the `requestContext` parameter. See t
|
|
|
1052
1052
|
|
|
1053
1053
|
<TabItem value="nextjs" label="Next.js">
|
|
1054
1054
|
|
|
1055
|
-
```typescript title="app/chat-extra/route.ts"
|
|
1055
|
+
```typescript title="app/chat-extra/route.ts"
|
|
1056
1056
|
import { handleChatStream } from '@mastra/ai-sdk';
|
|
1057
1057
|
import { RequestContext } from "@mastra/core/request-context";
|
|
1058
1058
|
import { createUIMessageStreamResponse } from 'ai';
|
|
@@ -1101,7 +1101,7 @@ The workflow uses:
|
|
|
1101
1101
|
|
|
1102
1102
|
Create a workflow step that suspends for approval. The step checks `resumeData` to determine if it's resuming, and calls `suspend()` on first execution.
|
|
1103
1103
|
|
|
1104
|
-
```typescript title="src/mastra/workflows/approval-workflow.ts"
|
|
1104
|
+
```typescript title="src/mastra/workflows/approval-workflow.ts"
|
|
1105
1105
|
import { createStep, createWorkflow } from "@mastra/core/workflows";
|
|
1106
1106
|
import { z } from "zod";
|
|
1107
1107
|
|
|
@@ -1158,7 +1158,7 @@ approvalWorkflow.commit();
|
|
|
1158
1158
|
|
|
1159
1159
|
Register the workflow. Storage is required for suspend/resume to persist state.
|
|
1160
1160
|
|
|
1161
|
-
```typescript title="src/mastra/index.ts"
|
|
1161
|
+
```typescript title="src/mastra/index.ts"
|
|
1162
1162
|
import { Mastra } from "@mastra/core";
|
|
1163
1163
|
import { workflowRoute } from "@mastra/ai-sdk";
|
|
1164
1164
|
import { LibSQLStore } from "@mastra/libsql";
|
|
@@ -1182,7 +1182,7 @@ export const mastra = new Mastra({
|
|
|
1182
1182
|
|
|
1183
1183
|
Detect when the workflow is suspended and send resume data with `runId`, `step`, and `resumeData`.
|
|
1184
1184
|
|
|
1185
|
-
```typescript title="src/components/approval-workflow.tsx"
|
|
1185
|
+
```typescript title="src/components/approval-workflow.tsx"
|
|
1186
1186
|
import { useChat } from "@ai-sdk/react";
|
|
1187
1187
|
import { DefaultChatTransport } from "ai";
|
|
1188
1188
|
import { useMemo, useState } from "react";
|
|
@@ -1292,7 +1292,7 @@ The pattern uses:
|
|
|
1292
1292
|
|
|
1293
1293
|
Create a tool that calls an agent and pipes its stream to the tool's writer.
|
|
1294
1294
|
|
|
1295
|
-
```typescript title="src/mastra/tools/nested-agent-tool.ts"
|
|
1295
|
+
```typescript title="src/mastra/tools/nested-agent-tool.ts"
|
|
1296
1296
|
import { createTool } from "@mastra/core/tools";
|
|
1297
1297
|
import { z } from "zod";
|
|
1298
1298
|
|
|
@@ -1325,7 +1325,7 @@ export const nestedAgentTool = createTool({
|
|
|
1325
1325
|
|
|
1326
1326
|
Create an agent that uses this tool.
|
|
1327
1327
|
|
|
1328
|
-
```typescript title="src/mastra/agents/forecast-agent.ts"
|
|
1328
|
+
```typescript title="src/mastra/agents/forecast-agent.ts"
|
|
1329
1329
|
import { Agent } from "@mastra/core/agent";
|
|
1330
1330
|
import { nestedAgentTool } from "../tools/nested-agent-tool";
|
|
1331
1331
|
|
|
@@ -1343,7 +1343,7 @@ export const forecastAgent = new Agent({
|
|
|
1343
1343
|
|
|
1344
1344
|
Handle `data-tool-agent` parts to display the nested agent's streamed output.
|
|
1345
1345
|
|
|
1346
|
-
```typescript title="src/components/nested-agent-chat.tsx"
|
|
1346
|
+
```typescript title="src/components/nested-agent-chat.tsx"
|
|
1347
1347
|
import { useChat } from "@ai-sdk/react";
|
|
1348
1348
|
import { DefaultChatTransport } from "ai";
|
|
1349
1349
|
import { useState } from "react";
|
|
@@ -1417,7 +1417,7 @@ The pattern uses:
|
|
|
1417
1417
|
|
|
1418
1418
|
Create a workflow step that streams an agent's response by piping to the step's `writer`.
|
|
1419
1419
|
|
|
1420
|
-
```typescript title="src/mastra/workflows/weather-workflow.ts"
|
|
1420
|
+
```typescript title="src/mastra/workflows/weather-workflow.ts"
|
|
1421
1421
|
import { createStep, createWorkflow } from "@mastra/core/workflows";
|
|
1422
1422
|
import { z } from "zod";
|
|
1423
1423
|
import { weatherAgent } from "../agents/weather-agent";
|
|
@@ -1464,7 +1464,7 @@ weatherWorkflow.commit();
|
|
|
1464
1464
|
|
|
1465
1465
|
Register the workflow with a `workflowRoute()`. Text streaming is enabled by default.
|
|
1466
1466
|
|
|
1467
|
-
```typescript title="src/mastra/index.ts"
|
|
1467
|
+
```typescript title="src/mastra/index.ts"
|
|
1468
1468
|
import { Mastra } from "@mastra/core";
|
|
1469
1469
|
import { workflowRoute } from "@mastra/ai-sdk";
|
|
1470
1470
|
|
|
@@ -1485,7 +1485,7 @@ export const mastra = new Mastra({
|
|
|
1485
1485
|
|
|
1486
1486
|
Render both `text` parts (streaming agent output) and `data-workflow` parts (step progress).
|
|
1487
1487
|
|
|
1488
|
-
```typescript title="src/components/weather-workflow.tsx"
|
|
1488
|
+
```typescript title="src/components/weather-workflow.tsx"
|
|
1489
1489
|
import { useChat } from "@ai-sdk/react";
|
|
1490
1490
|
import { DefaultChatTransport } from "ai";
|
|
1491
1491
|
import { useState } from "react";
|
|
@@ -44,7 +44,7 @@ project-root
|
|
|
44
44
|
|
|
45
45
|
Bootstrap your Mastra server:
|
|
46
46
|
|
|
47
|
-
```bash
|
|
47
|
+
```bash
|
|
48
48
|
npx create-mastra@beta
|
|
49
49
|
```
|
|
50
50
|
|
|
@@ -52,7 +52,7 @@ This command will launch an interactive wizard to help you scaffold a new Mastra
|
|
|
52
52
|
|
|
53
53
|
Navigate to your newly created Mastra server directory:
|
|
54
54
|
|
|
55
|
-
```bash
|
|
55
|
+
```bash
|
|
56
56
|
cd mastra-server # Replace with the actual directory name you provided
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -84,13 +84,13 @@ Ensure that you have set the appropriate environment variables for your LLM prov
|
|
|
84
84
|
|
|
85
85
|
Create a chat route for the Assistant UI frontend by using the `chatRoute()` helper from `@mastra/ai-sdk`. Add it to your Mastra project:
|
|
86
86
|
|
|
87
|
-
```bash
|
|
87
|
+
```bash
|
|
88
88
|
npm install @mastra/ai-sdk@beta
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
In your `src/mastra/index.ts` file, register the chat route:
|
|
92
92
|
|
|
93
|
-
```typescript
|
|
93
|
+
```typescript title="src/mastra/index.ts" {2,7-13}
|
|
94
94
|
import { Mastra } from '@mastra/core/mastra';
|
|
95
95
|
import { chatRoute } from '@mastra/ai-sdk';
|
|
96
96
|
// Rest of the imports...
|
|
@@ -115,7 +115,7 @@ This will make all agents available in AI SDK-compatible formats, including the
|
|
|
115
115
|
|
|
116
116
|
Run the Mastra server using the following command:
|
|
117
117
|
|
|
118
|
-
```bash
|
|
118
|
+
```bash
|
|
119
119
|
npm run dev
|
|
120
120
|
```
|
|
121
121
|
|
|
@@ -127,13 +127,13 @@ By default, the Mastra server will run on `http://localhost:4111`. Keep this ser
|
|
|
127
127
|
|
|
128
128
|
Go up one directory to your project root.
|
|
129
129
|
|
|
130
|
-
```bash
|
|
130
|
+
```bash
|
|
131
131
|
cd ..
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
Create a new `assistant-ui` project with the following command.
|
|
135
135
|
|
|
136
|
-
```bash
|
|
136
|
+
```bash
|
|
137
137
|
npx assistant-ui@latest create
|
|
138
138
|
```
|
|
139
139
|
|
|
@@ -175,7 +175,7 @@ Now, the Assistant UI frontend will send chat requests directly to your running
|
|
|
175
175
|
|
|
176
176
|
You're ready to connect the pieces! Make sure both the Mastra server and the Assistant UI frontend are running. Start the Next.js development server:
|
|
177
177
|
|
|
178
|
-
```bash
|
|
178
|
+
```bash
|
|
179
179
|
npm run dev
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -48,7 +48,7 @@ project-root
|
|
|
48
48
|
|
|
49
49
|
Bootstrap your Mastra server:
|
|
50
50
|
|
|
51
|
-
```bash
|
|
51
|
+
```bash
|
|
52
52
|
npx create-mastra@latest
|
|
53
53
|
```
|
|
54
54
|
|
|
@@ -56,7 +56,7 @@ This command will launch an interactive wizard to help you scaffold a new Mastra
|
|
|
56
56
|
|
|
57
57
|
Navigate to your newly created Mastra server directory:
|
|
58
58
|
|
|
59
|
-
```bash
|
|
59
|
+
```bash
|
|
60
60
|
cd mastra-server # Replace with the actual directory name you provided
|
|
61
61
|
```
|
|
62
62
|
|
|
@@ -88,13 +88,13 @@ Ensure that you have set the appropriate environment variables for your LLM prov
|
|
|
88
88
|
|
|
89
89
|
Create a chat route for the CopilotKit frontend by using the `registerCopilotKit()` helper from `@ag-ui/mastra`. Add it to your Mastra project (and its peer dependencies):
|
|
90
90
|
|
|
91
|
-
```bash
|
|
91
|
+
```bash
|
|
92
92
|
npm install --legacy-peer-deps @ag-ui/mastra @copilotkit/runtime @ag-ui/core @ag-ui/client @ag-ui/encoder @ag-ui/langgraph @ag-ui/proto
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
In your `src/mastra/index.ts` file, register the chat route:
|
|
96
96
|
|
|
97
|
-
```typescript
|
|
97
|
+
```typescript title="src/mastra/index.ts" {2,7-19}
|
|
98
98
|
import { Mastra } from '@mastra/core/mastra';
|
|
99
99
|
import { registerCopilotKit } from '@ag-ui/mastra/copilotkit';
|
|
100
100
|
// Rest of the imports...
|
|
@@ -125,7 +125,7 @@ This will make the `weatherAgent` available at `/chat` in a CopilotKit-compatibl
|
|
|
125
125
|
|
|
126
126
|
Run the Mastra server using the following command:
|
|
127
127
|
|
|
128
|
-
```bash
|
|
128
|
+
```bash
|
|
129
129
|
npm run dev
|
|
130
130
|
```
|
|
131
131
|
|
|
@@ -137,19 +137,19 @@ By default, the Mastra server will run on `http://localhost:4111`. Keep this ser
|
|
|
137
137
|
|
|
138
138
|
Go up one directory to your project root.
|
|
139
139
|
|
|
140
|
-
```bash
|
|
140
|
+
```bash
|
|
141
141
|
cd ..
|
|
142
142
|
```
|
|
143
143
|
|
|
144
144
|
Create a new Next.js project with the name `my-copilot-app`:
|
|
145
145
|
|
|
146
|
-
```bash
|
|
146
|
+
```bash
|
|
147
147
|
npx create-next-app@latest my-copilot-app
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
Navigate to your newly created Next.js project directory:
|
|
151
151
|
|
|
152
|
-
```bash
|
|
152
|
+
```bash
|
|
153
153
|
cd my-copilot-app
|
|
154
154
|
```
|
|
155
155
|
|
|
@@ -159,13 +159,13 @@ cd my-copilot-app
|
|
|
159
159
|
|
|
160
160
|
Install the CopilotKit UI packages which you'll use to display a chat interface:
|
|
161
161
|
|
|
162
|
-
```bash
|
|
162
|
+
```bash
|
|
163
163
|
npm install @copilotkit/react-ui @copilotkit/react-core
|
|
164
164
|
```
|
|
165
165
|
|
|
166
166
|
Open the home route of the Next.js app (usually `app/page.tsx` or `src/app/page.tsx`) and replace the existing contents with the following code to set up a basic CopilotKit chat interface:
|
|
167
167
|
|
|
168
|
-
```typescript
|
|
168
|
+
```typescript title="app/page.tsx"
|
|
169
169
|
import { CopilotChat } from "@copilotkit/react-ui";
|
|
170
170
|
import { CopilotKit } from "@copilotkit/react-core";
|
|
171
171
|
import "@copilotkit/react-ui/styles.css";
|
|
@@ -193,7 +193,7 @@ export default function Home() {
|
|
|
193
193
|
|
|
194
194
|
You're ready to connect the pieces! Make sure both the Mastra server and the CopilotKit frontend are running. Start the Next.js development server:
|
|
195
195
|
|
|
196
|
-
```bash
|
|
196
|
+
```bash
|
|
197
197
|
npm run dev
|
|
198
198
|
```
|
|
199
199
|
|