@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
|
@@ -140,7 +140,7 @@ Setup the tool:
|
|
|
140
140
|
|
|
141
141
|
In your `src/mastra/index.ts` file, register the agent:
|
|
142
142
|
|
|
143
|
-
```ts
|
|
143
|
+
```ts title="src/mastra/index.ts" {2, 5}
|
|
144
144
|
import { Mastra } from "@mastra/core";
|
|
145
145
|
import { searchAgent } from "./agents/searchAgent";
|
|
146
146
|
|
|
@@ -155,7 +155,7 @@ export const mastra = new Mastra({
|
|
|
155
155
|
|
|
156
156
|
You can test your agent with [Studio](/docs/v1/getting-started/studio) using the `mastra dev` command:
|
|
157
157
|
|
|
158
|
-
```bash
|
|
158
|
+
```bash
|
|
159
159
|
mastra dev
|
|
160
160
|
```
|
|
161
161
|
|
|
@@ -175,7 +175,7 @@ For more control over search behavior, you can integrate external search APIs as
|
|
|
175
175
|
|
|
176
176
|
Install dependencies
|
|
177
177
|
|
|
178
|
-
```bash
|
|
178
|
+
```bash
|
|
179
179
|
npm install exa-js
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -185,7 +185,7 @@ npm install exa-js
|
|
|
185
185
|
|
|
186
186
|
Create a new file `src/mastra/agents/searchAgent.ts` and define your agent:
|
|
187
187
|
|
|
188
|
-
```ts
|
|
188
|
+
```ts title="src/mastra/agents/searchAgent.ts"
|
|
189
189
|
import { Agent } from "@mastra/core/agent";
|
|
190
190
|
|
|
191
191
|
export const searchAgent = new Agent({
|
|
@@ -203,7 +203,7 @@ export const searchAgent = new Agent({
|
|
|
203
203
|
|
|
204
204
|
Setup the tool
|
|
205
205
|
|
|
206
|
-
```ts
|
|
206
|
+
```ts title="src/mastra/tools/searchTool.ts"
|
|
207
207
|
import { createTool } from "@mastra/core/tools";
|
|
208
208
|
import z from "zod";
|
|
209
209
|
import Exa from "exa-js";
|
|
@@ -246,7 +246,7 @@ export const webSearch = createTool({
|
|
|
246
246
|
|
|
247
247
|
Add to your Agent
|
|
248
248
|
|
|
249
|
-
```ts
|
|
249
|
+
```ts title="src/mastra/agents/searchAgent.ts"
|
|
250
250
|
import { webSearch } from "./tools/searchTool";
|
|
251
251
|
|
|
252
252
|
export const searchAgent = new Agent({
|
|
@@ -267,7 +267,7 @@ export const searchAgent = new Agent({
|
|
|
267
267
|
|
|
268
268
|
In your `src/mastra/index.ts` file, register the agent:
|
|
269
269
|
|
|
270
|
-
```ts
|
|
270
|
+
```ts title="src/mastra/index.ts" {2, 5}
|
|
271
271
|
import { Mastra } from "@mastra/core";
|
|
272
272
|
import { searchAgent } from "./agents/searchAgent";
|
|
273
273
|
|
|
@@ -282,7 +282,7 @@ export const mastra = new Mastra({
|
|
|
282
282
|
|
|
283
283
|
You can test your agent with [Studio](/docs/v1/getting-started/studio) using the `mastra dev` command:
|
|
284
284
|
|
|
285
|
-
```bash
|
|
285
|
+
```bash
|
|
286
286
|
mastra dev
|
|
287
287
|
```
|
|
288
288
|
|
|
@@ -11,7 +11,7 @@ This guide demonstrates how to create a WhatsApp chat bot using Mastra agents an
|
|
|
11
11
|
|
|
12
12
|
This example requires a WhatsApp Business API setup and uses the `anthropic` model. Add these environment variables to your `.env` file:
|
|
13
13
|
|
|
14
|
-
```bash title=".env"
|
|
14
|
+
```bash title=".env"
|
|
15
15
|
ANTHROPIC_API_KEY=<your-anthropic-api-key>
|
|
16
16
|
WHATSAPP_VERIFY_TOKEN=<your-verify-token>
|
|
17
17
|
WHATSAPP_ACCESS_TOKEN=<your-whatsapp-access-token>
|
|
@@ -23,7 +23,7 @@ WHATSAPP_API_VERSION=v22.0
|
|
|
23
23
|
|
|
24
24
|
This client handles sending messages to users via the WhatsApp Business API.
|
|
25
25
|
|
|
26
|
-
```typescript title="src/whatsapp-client.ts"
|
|
26
|
+
```typescript title="src/whatsapp-client.ts"
|
|
27
27
|
// Simple WhatsApp Business API client for sending messages
|
|
28
28
|
|
|
29
29
|
interface SendMessageParams {
|
|
@@ -87,7 +87,7 @@ export async function sendWhatsAppMessage({ to, message }: SendMessageParams) {
|
|
|
87
87
|
|
|
88
88
|
This agent handles the main conversation logic with a friendly, conversational personality.
|
|
89
89
|
|
|
90
|
-
```typescript title="src/mastra/agents/chat-agent.ts"
|
|
90
|
+
```typescript title="src/mastra/agents/chat-agent.ts"
|
|
91
91
|
import { Agent } from "@mastra/core/agent";
|
|
92
92
|
import { Memory } from "@mastra/memory";
|
|
93
93
|
import { LibSQLStore } from "@mastra/libsql";
|
|
@@ -136,7 +136,7 @@ export const chatAgent = new Agent({
|
|
|
136
136
|
|
|
137
137
|
This agent converts longer responses into natural, bite-sized text messages suitable for WhatsApp.
|
|
138
138
|
|
|
139
|
-
```typescript title="src/mastra/agents/text-message-agent.ts"
|
|
139
|
+
```typescript title="src/mastra/agents/text-message-agent.ts"
|
|
140
140
|
import { Agent } from "@mastra/core/agent";
|
|
141
141
|
import { Memory } from "@mastra/memory";
|
|
142
142
|
import { LibSQLStore } from "@mastra/libsql";
|
|
@@ -174,7 +174,7 @@ export const textMessageAgent = new Agent({
|
|
|
174
174
|
|
|
175
175
|
This workflow orchestrates the entire chat process: generating a response, breaking it into messages, and sending them via WhatsApp.
|
|
176
176
|
|
|
177
|
-
```typescript title="src/mastra/workflows/chat-workflow.ts"
|
|
177
|
+
```typescript title="src/mastra/workflows/chat-workflow.ts"
|
|
178
178
|
import { createStep, createWorkflow } from "@mastra/core/workflows";
|
|
179
179
|
import { z } from "zod";
|
|
180
180
|
import { sendWhatsAppMessage } from "../../whatsapp-client";
|
|
@@ -300,7 +300,7 @@ chatWorkflow.commit();
|
|
|
300
300
|
|
|
301
301
|
Configure your Mastra instance with the agents, workflow, and WhatsApp webhook endpoints.
|
|
302
302
|
|
|
303
|
-
```typescript title="src/mastra/index.ts"
|
|
303
|
+
```typescript title="src/mastra/index.ts"
|
|
304
304
|
import { Mastra } from "@mastra/core";
|
|
305
305
|
import { registerApiRoute } from "@mastra/core/server";
|
|
306
306
|
import { PinoLogger } from "@mastra/loggers";
|
|
@@ -365,7 +365,7 @@ export const mastra = new Mastra({
|
|
|
365
365
|
|
|
366
366
|
You can test the chat bot locally by simulating a WhatsApp webhook payload.
|
|
367
367
|
|
|
368
|
-
```typescript title="src/test-whatsapp-bot.ts"
|
|
368
|
+
```typescript title="src/test-whatsapp-bot.ts"
|
|
369
369
|
import "dotenv/config";
|
|
370
370
|
|
|
371
371
|
import { mastra } from "./mastra";
|
|
@@ -45,7 +45,7 @@ When using tools with TypeScript in AI SDK v5, Mastra provides type inference he
|
|
|
45
45
|
|
|
46
46
|
The `InferUITool` type helper infers the input and output types of a single Mastra tool:
|
|
47
47
|
|
|
48
|
-
```typescript title="app/types.ts"
|
|
48
|
+
```typescript title="app/types.ts"
|
|
49
49
|
import { InferUITool, createTool } from "@mastra/core/tools";
|
|
50
50
|
import { z } from "zod";
|
|
51
51
|
|
|
@@ -80,7 +80,7 @@ type WeatherUITool = InferUITool<typeof weatherTool>;
|
|
|
80
80
|
|
|
81
81
|
The `InferUITools` type helper infers the input and output types of multiple tools:
|
|
82
82
|
|
|
83
|
-
```typescript title="app/mastra/tools.ts"
|
|
83
|
+
```typescript title="app/mastra/tools.ts"
|
|
84
84
|
import { InferUITools, createTool } from "@mastra/core/tools";
|
|
85
85
|
import { z } from "zod";
|
|
86
86
|
|
|
@@ -153,7 +153,6 @@ Step `suspendPayload` is now validated for steps that have a `suspendSchema` def
|
|
|
153
153
|
- return suspend({ reason: "Suspension reason" }); // Missing otherReason
|
|
154
154
|
+ return suspend({ reason: "Suspension reason", otherReason: "Other reason" });
|
|
155
155
|
}
|
|
156
|
-
//... continue execution logic
|
|
157
156
|
},
|
|
158
157
|
});
|
|
159
158
|
```
|
|
@@ -334,7 +333,6 @@ createStep({
|
|
|
334
333
|
+ if (!context.resumeData) {
|
|
335
334
|
+ return context.suspend({})
|
|
336
335
|
+ }
|
|
337
|
-
+ //..continue execution logic
|
|
338
336
|
+ }
|
|
339
337
|
});
|
|
340
338
|
+
|
|
@@ -106,7 +106,7 @@ See the following API references for more information:
|
|
|
106
106
|
|
|
107
107
|
No `format` option: Always return AI SDK v4 types
|
|
108
108
|
|
|
109
|
-
```typescript
|
|
109
|
+
```typescript
|
|
110
110
|
// Mastra native format (default)
|
|
111
111
|
const result = await agent.stream(messages);
|
|
112
112
|
```
|
|
@@ -118,7 +118,7 @@ Use `format` option to choose output:
|
|
|
118
118
|
- `'mastra'` (default)
|
|
119
119
|
- `'aisdk'` (AI SDK v5 compatible)
|
|
120
120
|
|
|
121
|
-
```typescript
|
|
121
|
+
```typescript
|
|
122
122
|
// AI SDK v5 compatibility
|
|
123
123
|
const result = await agent.stream(messages, {
|
|
124
124
|
format: "aisdk",
|
|
@@ -131,7 +131,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
131
131
|
|
|
132
132
|
- `format` - Choose between 'mastra' or 'aisdk' output format:
|
|
133
133
|
|
|
134
|
-
```typescript
|
|
134
|
+
```typescript copy
|
|
135
135
|
const result = await agent.stream(messages, {
|
|
136
136
|
format: "aisdk", // or 'mastra' (default)
|
|
137
137
|
});
|
|
@@ -139,7 +139,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
139
139
|
|
|
140
140
|
- `system` - Custom system message (separate from instructions).
|
|
141
141
|
|
|
142
|
-
```typescript
|
|
142
|
+
```typescript copy
|
|
143
143
|
const result = await agent.stream(messages, {
|
|
144
144
|
system: "You are a helpful assistant",
|
|
145
145
|
});
|
|
@@ -153,7 +153,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
153
153
|
- 'error' - throw an error
|
|
154
154
|
- 'fallback' - return a fallback value you provide
|
|
155
155
|
|
|
156
|
-
```typescript
|
|
156
|
+
```typescript copy
|
|
157
157
|
const result = await agent.generate(messages, {
|
|
158
158
|
structuredOutput: {
|
|
159
159
|
schema: z.object({
|
|
@@ -170,7 +170,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
170
170
|
|
|
171
171
|
- `stopWhen` - Flexible stop conditions (step count, token limit, etc).
|
|
172
172
|
|
|
173
|
-
```typescript
|
|
173
|
+
```typescript copy
|
|
174
174
|
const result = await agent.stream(messages, {
|
|
175
175
|
stopWhen: ({ steps, totalTokens }) => steps >= 5 || totalTokens >= 10000,
|
|
176
176
|
});
|
|
@@ -178,7 +178,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
178
178
|
|
|
179
179
|
- `providerOptions` - Provider-specific options (e.g., OpenAI-specific settings)
|
|
180
180
|
|
|
181
|
-
```typescript
|
|
181
|
+
```typescript copy
|
|
182
182
|
const result = await agent.stream(messages, {
|
|
183
183
|
providerOptions: {
|
|
184
184
|
openai: {
|
|
@@ -191,7 +191,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
191
191
|
|
|
192
192
|
- `onChunk` - Callback for each streaming chunk.
|
|
193
193
|
|
|
194
|
-
```typescript
|
|
194
|
+
```typescript copy
|
|
195
195
|
const result = await agent.stream(messages, {
|
|
196
196
|
onChunk: (chunk) => {
|
|
197
197
|
console.log("Received chunk:", chunk);
|
|
@@ -201,7 +201,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
201
201
|
|
|
202
202
|
- `onError` - Error callback.
|
|
203
203
|
|
|
204
|
-
```typescript
|
|
204
|
+
```typescript copy
|
|
205
205
|
const result = await agent.stream(messages, {
|
|
206
206
|
onError: (error) => {
|
|
207
207
|
console.error("Stream error:", error);
|
|
@@ -211,7 +211,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
211
211
|
|
|
212
212
|
- `onAbort` - Abort callback.
|
|
213
213
|
|
|
214
|
-
```typescript
|
|
214
|
+
```typescript copy
|
|
215
215
|
const result = await agent.stream(messages, {
|
|
216
216
|
onAbort: () => {
|
|
217
217
|
console.log("Stream aborted");
|
|
@@ -221,7 +221,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
221
221
|
|
|
222
222
|
- `activeTools` - Specify which tools are active for this execution.
|
|
223
223
|
|
|
224
|
-
```typescript
|
|
224
|
+
```typescript copy
|
|
225
225
|
const result = await agent.stream(messages, {
|
|
226
226
|
activeTools: ["search", "calculator"], // Only these tools will be available
|
|
227
227
|
});
|
|
@@ -229,7 +229,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
229
229
|
|
|
230
230
|
- `abortSignal` - AbortSignal for cancellation.
|
|
231
231
|
|
|
232
|
-
```typescript
|
|
232
|
+
```typescript copy
|
|
233
233
|
const controller = new AbortController();
|
|
234
234
|
const result = await agent.stream(messages, {
|
|
235
235
|
abortSignal: controller.signal,
|
|
@@ -240,7 +240,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
240
240
|
|
|
241
241
|
- `prepareStep` - Callback before each step in multi-step execution.
|
|
242
242
|
|
|
243
|
-
```typescript
|
|
243
|
+
```typescript copy
|
|
244
244
|
const result = await agent.stream(messages, {
|
|
245
245
|
prepareStep: ({ step, state }) => {
|
|
246
246
|
console.log("About to execute step:", step);
|
|
@@ -253,7 +253,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
253
253
|
|
|
254
254
|
- `requireToolApproval` - Require approval for all tool calls.
|
|
255
255
|
|
|
256
|
-
```typescript
|
|
256
|
+
```typescript copy
|
|
257
257
|
const result = await agent.stream(messages, {
|
|
258
258
|
requireToolApproval: true,
|
|
259
259
|
});
|
|
@@ -265,7 +265,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
265
265
|
|
|
266
266
|
Unified in `modelSettings`
|
|
267
267
|
|
|
268
|
-
```typescript
|
|
268
|
+
```typescript copy
|
|
269
269
|
const result = await agent.stream(messages, {
|
|
270
270
|
modelSettings: {
|
|
271
271
|
temperature: 0.7,
|
|
@@ -279,7 +279,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
279
279
|
|
|
280
280
|
Moved to memory object.
|
|
281
281
|
|
|
282
|
-
```typescript
|
|
282
|
+
```typescript copy
|
|
283
283
|
const result = await agent.stream(messages, {
|
|
284
284
|
memory: {
|
|
285
285
|
resource: "user-123",
|
|
@@ -294,7 +294,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
294
294
|
|
|
295
295
|
Use `structuredOutput` instead to allow for tool calls and an object return.
|
|
296
296
|
|
|
297
|
-
```typescript
|
|
297
|
+
```typescript copy
|
|
298
298
|
const result = await agent.generate(messages, {
|
|
299
299
|
structuredOutput: {
|
|
300
300
|
schema: z.object({
|
|
@@ -309,7 +309,7 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
309
309
|
|
|
310
310
|
The `output` property is deprecated in favor of `structuredOutput`, to achieve the same results, omit the model and only pass `structuredOutput.schema`, optionally add `jsonPromptInjection: true` if your model does not natively support `response_format`.
|
|
311
311
|
|
|
312
|
-
```typescript
|
|
312
|
+
```typescript copy
|
|
313
313
|
const result = await agent.generate(messages, {
|
|
314
314
|
structuredOutput: {
|
|
315
315
|
schema: {
|
|
@@ -325,11 +325,9 @@ The following options are available in the standard `.stream()` and `generate()`
|
|
|
325
325
|
|
|
326
326
|
Use `memory` instead.
|
|
327
327
|
|
|
328
|
-
```typescript
|
|
328
|
+
```typescript copy
|
|
329
329
|
const result = await agent.generate(messages, {
|
|
330
|
-
memory: {
|
|
331
|
-
// ...
|
|
332
|
-
},
|
|
330
|
+
memory: {},
|
|
333
331
|
});
|
|
334
332
|
```
|
|
335
333
|
|
|
@@ -350,7 +348,7 @@ See the following API references for more information:
|
|
|
350
348
|
|
|
351
349
|
`toolChoice` uses the AI SDK v5 `ToolChoice` type.
|
|
352
350
|
|
|
353
|
-
```typescript
|
|
351
|
+
```typescript copy
|
|
354
352
|
type ToolChoice<TOOLS extends Record<string, unknown>> =
|
|
355
353
|
| "auto"
|
|
356
354
|
| "none"
|
package/.docs/raw/index.mdx
CHANGED
|
@@ -27,9 +27,9 @@ Some highlights include:
|
|
|
27
27
|
|
|
28
28
|
- [**Workflows**](/docs/v1/workflows/overview) - When you need explicit control over execution, use Mastra's graph-based workflow engine to orchestrate complex multi-step processes. Mastra workflows use an intuitive syntax for control flow (`.then()`, `.branch()`, `.parallel()`).
|
|
29
29
|
|
|
30
|
-
- [**Human-in-the-loop**](/docs/v1/workflows/suspend-and-resume) - Suspend an agent or workflow and await user input or approval before resuming. Mastra uses
|
|
30
|
+
- [**Human-in-the-loop**](/docs/v1/workflows/suspend-and-resume) - Suspend an agent or workflow and await user input or approval before resuming. Mastra uses storage to remember execution state, so you can pause indefinitely and resume where you left off.
|
|
31
31
|
|
|
32
|
-
- **Context management** - Give your agents the right context at the right time. Provide [
|
|
32
|
+
- **Context management** - Give your agents the right context at the right time. Provide [message history](/docs/v1/memory/message-history), [retrieve](/docs/v1/rag/overview) data from your sources (APIs, databases, files), and add human-like [working](/docs/v1/memory/working-memory) and [semantic](/docs/v1/memory/semantic-recall) memory so your agents behave coherently.
|
|
33
33
|
|
|
34
34
|
- **Integrations** - Bundle agents and workflows into existing React, Next.js, or Node.js apps, or ship them as standalone endpoints. When building UIs, integrate with agentic libraries like Vercel's AI SDK UI and CopilotKit to bring your AI assistant to life on the web.
|
|
35
35
|
|
|
@@ -15,7 +15,11 @@ This page explains how to set up a project on [Mastra Cloud](https://mastra.ai/c
|
|
|
15
15
|
- A [Mastra Cloud](https://mastra.ai/cloud) account
|
|
16
16
|
- A GitHub account / repository containing a Mastra application
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
:::info
|
|
19
|
+
|
|
20
|
+
Visit our [Getting started](/guides/v1/getting-started/quickstart) guide to scaffold out a new Mastra project with sensible defaults.
|
|
21
|
+
|
|
22
|
+
:::
|
|
19
23
|
|
|
20
24
|
## Setup and Deploy process
|
|
21
25
|
|
|
@@ -70,7 +74,7 @@ Mastra Cloud automatically detects the right build settings, but you can customi
|
|
|
70
74
|
- **Install command**: Runs pre-build to install project dependencies
|
|
71
75
|
- **Project setup command**: Runs pre-build to prepare any external dependencies
|
|
72
76
|
- **Port**: The network port the server will use
|
|
73
|
-
- **Store settings**: Use Mastra Cloud's built-in [LibSQLStore](/
|
|
77
|
+
- **Store settings**: Use Mastra Cloud's built-in [LibSQLStore](/reference/v1/storage/libsql) storage
|
|
74
78
|
- **Deploy Project**: Starts the deployment process
|
|
75
79
|
|
|
76
80
|
</StepItem>
|
|
@@ -29,7 +29,7 @@ npm install @mastra/mcp@beta
|
|
|
29
29
|
|
|
30
30
|
The `MCPClient` connects Mastra primitives to external MCP servers, which can be local packages (invoked using `npx`) or remote HTTP(S) endpoints. Each server must be configured with either a `command` or a `url`, depending on how it's hosted.
|
|
31
31
|
|
|
32
|
-
```typescript title="src/mastra/mcp/test-mcp-client.ts"
|
|
32
|
+
```typescript title="src/mastra/mcp/test-mcp-client.ts"
|
|
33
33
|
import { MCPClient } from "@mastra/mcp";
|
|
34
34
|
|
|
35
35
|
export const testMcpClient = new MCPClient({
|
|
@@ -48,13 +48,17 @@ export const testMcpClient = new MCPClient({
|
|
|
48
48
|
});
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
:::info
|
|
52
|
+
|
|
53
|
+
Visit [MCPClient](/reference/v1/tools/mcp-client) for a full list of configuration options.
|
|
54
|
+
|
|
55
|
+
:::
|
|
52
56
|
|
|
53
57
|
## Using `MCPClient` with an agent
|
|
54
58
|
|
|
55
59
|
To use tools from an MCP server in an agent, import your `MCPClient` and call `.getTools()` in the `tools` parameter. This loads from the defined MCP servers, making them available to the agent.
|
|
56
60
|
|
|
57
|
-
```typescript {3,15} title="src/mastra/agents/test-agent.ts"
|
|
61
|
+
```typescript {3,15} title="src/mastra/agents/test-agent.ts"
|
|
58
62
|
import { Agent } from "@mastra/core/agent";
|
|
59
63
|
|
|
60
64
|
import { testMcpClient } from "../mcp/test-mcp-client";
|
|
@@ -73,13 +77,17 @@ export const testAgent = new Agent({
|
|
|
73
77
|
});
|
|
74
78
|
```
|
|
75
79
|
|
|
76
|
-
|
|
80
|
+
:::info
|
|
81
|
+
|
|
82
|
+
Visit [Agent Class](/reference/v1/agents/agent) for a full list of configuration options.
|
|
83
|
+
|
|
84
|
+
:::
|
|
77
85
|
|
|
78
86
|
## Configuring `MCPServer`
|
|
79
87
|
|
|
80
88
|
To expose agents, tools, and workflows from your Mastra application to external systems over HTTP(S) use the `MCPServer` class. This makes them accessible to any system or agent that supports the protocol.
|
|
81
89
|
|
|
82
|
-
```typescript title="src/mastra/mcp/test-mcp-server.ts"
|
|
90
|
+
```typescript title="src/mastra/mcp/test-mcp-server.ts"
|
|
83
91
|
import { MCPServer } from "@mastra/mcp";
|
|
84
92
|
|
|
85
93
|
import { testAgent } from "../agents/test-agent";
|
|
@@ -96,19 +104,22 @@ export const testMcpServer = new MCPServer({
|
|
|
96
104
|
});
|
|
97
105
|
```
|
|
98
106
|
|
|
99
|
-
|
|
107
|
+
:::info
|
|
108
|
+
|
|
109
|
+
Visit [MCPServer](/reference/v1/tools/mcp-server) for a full list of configuration options.
|
|
110
|
+
|
|
111
|
+
:::
|
|
100
112
|
|
|
101
113
|
## Registering an `MCPServer`
|
|
102
114
|
|
|
103
115
|
To make an MCP server available to other systems or agents that support the protocol, register it in the main `Mastra` instance using `mcpServers`.
|
|
104
116
|
|
|
105
|
-
```typescript title="src/mastra/index.ts"
|
|
117
|
+
```typescript title="src/mastra/index.ts"
|
|
106
118
|
import { Mastra } from "@mastra/core/mastra";
|
|
107
119
|
|
|
108
120
|
import { testMcpServer } from "./mcp/test-mcp-server";
|
|
109
121
|
|
|
110
122
|
export const mastra = new Mastra({
|
|
111
|
-
// ...
|
|
112
123
|
mcpServers: { testMcpServer },
|
|
113
124
|
});
|
|
114
125
|
```
|
|
@@ -128,15 +139,18 @@ export const mastra = new Mastra({
|
|
|
128
139
|
|
|
129
140
|
Use the `.getTools()` method to fetch tools from all configured MCP servers. This is suitable when configuration (such as API keys) is static and consistent across users or requests. Call it once and pass the result to the `tools` property when defining your agent.
|
|
130
141
|
|
|
131
|
-
|
|
142
|
+
:::info
|
|
143
|
+
|
|
144
|
+
Visit [getTools()](/reference/v1/tools/mcp-client#gettools) for more information.
|
|
145
|
+
|
|
146
|
+
:::
|
|
132
147
|
|
|
133
|
-
```typescript {
|
|
148
|
+
```typescript {6} title="src/mastra/agents/test-agent.ts"
|
|
134
149
|
import { Agent } from "@mastra/core/agent";
|
|
135
150
|
|
|
136
151
|
import { testMcpClient } from "../mcp/test-mcp-client";
|
|
137
152
|
|
|
138
153
|
export const testAgent = new Agent({
|
|
139
|
-
// ...
|
|
140
154
|
tools: await testMcpClient.getTools(),
|
|
141
155
|
});
|
|
142
156
|
```
|
|
@@ -145,7 +159,7 @@ export const testAgent = new Agent({
|
|
|
145
159
|
|
|
146
160
|
Use the `.getToolsets()` method when tool configuration may vary by request or user, such as in a multi-tenant system where each user provides their own API key. This method returns toolsets that can be passed to the `toolsets` option in the agent's `.generate()` or `.stream()` calls.
|
|
147
161
|
|
|
148
|
-
```typescript {5-16,21}
|
|
162
|
+
```typescript {5-16,21}
|
|
149
163
|
import { MCPClient } from "@mastra/mcp";
|
|
150
164
|
import { mastra } from "./mastra";
|
|
151
165
|
|
|
@@ -177,7 +191,11 @@ async function handleRequest(userPrompt: string, userApiKey: string) {
|
|
|
177
191
|
}
|
|
178
192
|
```
|
|
179
193
|
|
|
180
|
-
|
|
194
|
+
:::info
|
|
195
|
+
|
|
196
|
+
Visit [getToolsets()](/reference/v1/tools/mcp-client#gettoolsets) for more information.
|
|
197
|
+
|
|
198
|
+
:::
|
|
181
199
|
|
|
182
200
|
## Connecting to an MCP registry
|
|
183
201
|
|
|
@@ -32,7 +32,7 @@ Create a file for your stdio server, for example, `/src/mastra/stdio.ts`.
|
|
|
32
32
|
|
|
33
33
|
Add the following code to the file. Remember to import your actual Mastra tools and name the server appropriately.
|
|
34
34
|
|
|
35
|
-
```typescript title="src/mastra/stdio.ts"
|
|
35
|
+
```typescript title="src/mastra/stdio.ts"
|
|
36
36
|
#!/usr/bin/env node
|
|
37
37
|
import { MCPServer } from "@mastra/mcp";
|
|
38
38
|
import { weatherTool } from "./tools";
|
|
@@ -55,7 +55,7 @@ server.startStdio().catch((error) => {
|
|
|
55
55
|
|
|
56
56
|
Update your `package.json` to include the `bin` entry pointing to your built server file and a script to build the server with both ESM and CJS outputs.
|
|
57
57
|
|
|
58
|
-
```json title="package.json"
|
|
58
|
+
```json title="package.json"
|
|
59
59
|
{
|
|
60
60
|
"bin": "dist/stdio.mjs",
|
|
61
61
|
"scripts": {
|
|
@@ -7,7 +7,7 @@ description: "Learn how to use memory processors in Mastra to filter, trim, and
|
|
|
7
7
|
|
|
8
8
|
Memory processors transform and filter messages as they pass through an agent with memory enabled. They manage context window limits, remove unnecessary content, and optimize the information sent to the language model.
|
|
9
9
|
|
|
10
|
-
When memory is enabled on an agent, Mastra adds memory processors to the agent's processor pipeline. These processors retrieve
|
|
10
|
+
When memory is enabled on an agent, Mastra adds memory processors to the agent's processor pipeline. These processors retrieve message history, working memory, and semantically relevant messages, then persist new messages after the model responds.
|
|
11
11
|
|
|
12
12
|
Memory processors are [processors](/docs/v1/agents/processors) that operate specifically on memory-related messages and state.
|
|
13
13
|
|
|
@@ -17,7 +17,7 @@ Mastra automatically adds these processors when memory is enabled:
|
|
|
17
17
|
|
|
18
18
|
### MessageHistory
|
|
19
19
|
|
|
20
|
-
Retrieves
|
|
20
|
+
Retrieves message history and persists new messages.
|
|
21
21
|
|
|
22
22
|
**When you configure:**
|
|
23
23
|
|
|
@@ -40,7 +40,7 @@ memory: new Memory({
|
|
|
40
40
|
|
|
41
41
|
**Example:**
|
|
42
42
|
|
|
43
|
-
```typescript
|
|
43
|
+
```typescript
|
|
44
44
|
import { Agent } from "@mastra/core/agent";
|
|
45
45
|
import { Memory } from "@mastra/memory";
|
|
46
46
|
import { LibSQLStore } from "@mastra/libsql";
|
|
@@ -89,7 +89,7 @@ memory: new Memory({
|
|
|
89
89
|
|
|
90
90
|
**Example:**
|
|
91
91
|
|
|
92
|
-
```typescript
|
|
92
|
+
```typescript
|
|
93
93
|
import { Agent } from "@mastra/core/agent";
|
|
94
94
|
import { Memory } from "@mastra/memory";
|
|
95
95
|
import { LibSQLStore } from "@mastra/libsql";
|
|
@@ -145,7 +145,7 @@ memory: new Memory({
|
|
|
145
145
|
|
|
146
146
|
**Example:**
|
|
147
147
|
|
|
148
|
-
```typescript
|
|
148
|
+
```typescript
|
|
149
149
|
import { Agent } from "@mastra/core/agent";
|
|
150
150
|
import { Memory } from "@mastra/memory";
|
|
151
151
|
import { LibSQLStore } from "@mastra/libsql";
|
|
@@ -169,7 +169,7 @@ const agent = new Agent({
|
|
|
169
169
|
|
|
170
170
|
If you manually add a memory processor to `inputProcessors` or `outputProcessors`, Mastra will **not** automatically add it. This gives you full control over processor ordering:
|
|
171
171
|
|
|
172
|
-
```typescript
|
|
172
|
+
```typescript
|
|
173
173
|
import { Agent } from "@mastra/core/agent";
|
|
174
174
|
import { Memory } from "@mastra/memory";
|
|
175
175
|
import { MessageHistory } from "@mastra/memory/processors";
|
|
@@ -211,7 +211,7 @@ Understanding the execution order is important when combining guardrails with me
|
|
|
211
211
|
1. **Memory processors run FIRST**: `WorkingMemory`, `MessageHistory`, `SemanticRecall`
|
|
212
212
|
2. **Your input processors run AFTER**: guardrails, filters, validators
|
|
213
213
|
|
|
214
|
-
This means memory loads
|
|
214
|
+
This means memory loads message history before your processors can validate or filter the input.
|
|
215
215
|
|
|
216
216
|
### Output Processors
|
|
217
217
|
|
|
@@ -236,7 +236,7 @@ Output guardrails run **before** memory processors save messages. If a guardrail
|
|
|
236
236
|
- Memory processors are skipped
|
|
237
237
|
- **No messages are persisted to storage**
|
|
238
238
|
|
|
239
|
-
```typescript
|
|
239
|
+
```typescript
|
|
240
240
|
import { Agent } from "@mastra/core/agent";
|
|
241
241
|
import { Memory } from "@mastra/memory";
|
|
242
242
|
import { openai } from "@ai-sdk/openai";
|
|
@@ -281,7 +281,7 @@ Input guardrails run **after** memory processors load history. If a guardrail ab
|
|
|
281
281
|
- Output processors (including memory persistence) are skipped
|
|
282
282
|
- **No messages are persisted to storage**
|
|
283
283
|
|
|
284
|
-
```typescript
|
|
284
|
+
```typescript
|
|
285
285
|
// Input guardrail that validates user input
|
|
286
286
|
const inputValidator = {
|
|
287
287
|
id: "input-validator",
|