@mastra/core 1.0.0-beta.21 → 1.0.0-beta.22
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/CHANGELOG.md +356 -0
- package/dist/action/index.d.ts +7 -7
- package/dist/action/index.d.ts.map +1 -1
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent.d.ts +100 -18
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +22 -18
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +13 -13
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/adapters/AIV4Adapter.d.ts.map +1 -1
- package/dist/agent/message-list/index.cjs +18 -18
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/message-list.d.ts +2 -1
- package/dist/agent/message-list/message-list.d.ts.map +1 -1
- package/dist/agent/trip-wire.d.ts +1 -2
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/types.d.ts +9 -10
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +7 -42
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +6 -118
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +7 -11
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +4 -68
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +3 -45
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/schema.d.ts +10 -10
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +2 -8
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/{chunk-HJXEZSNI.js → chunk-3XY64RAM.js} +5 -5
- package/dist/{chunk-HJXEZSNI.js.map → chunk-3XY64RAM.js.map} +1 -1
- package/dist/{chunk-XSJNTLM7.js → chunk-453NPBJ7.js} +479 -47
- package/dist/chunk-453NPBJ7.js.map +1 -0
- package/dist/{chunk-3CZ42NBZ.js → chunk-5UVSKF5L.js} +17 -14
- package/dist/chunk-5UVSKF5L.js.map +1 -0
- package/dist/{chunk-XKDVT3ZH.cjs → chunk-67ZKOPA4.cjs} +480 -48
- package/dist/chunk-67ZKOPA4.cjs.map +1 -0
- package/dist/{chunk-YLP5IWH2.js → chunk-7IYWOBLG.js} +4 -4
- package/dist/{chunk-YLP5IWH2.js.map → chunk-7IYWOBLG.js.map} +1 -1
- package/dist/{chunk-3RCMDLCG.cjs → chunk-ALQFYWAR.cjs} +12 -12
- package/dist/{chunk-3RCMDLCG.cjs.map → chunk-ALQFYWAR.cjs.map} +1 -1
- package/dist/{chunk-PC3FBUWH.js → chunk-C4CIC3LZ.js} +2 -2
- package/dist/chunk-C4CIC3LZ.js.map +1 -0
- package/dist/{chunk-7JGQWNV5.js → chunk-CPLRD2VP.js} +3 -3
- package/dist/{chunk-7JGQWNV5.js.map → chunk-CPLRD2VP.js.map} +1 -1
- package/dist/{chunk-AHN7K3VE.js → chunk-CQ2E577C.js} +5 -5
- package/dist/chunk-CQ2E577C.js.map +1 -0
- package/dist/{chunk-A4MCHA5L.cjs → chunk-CVLIEFWM.cjs} +100 -819
- package/dist/chunk-CVLIEFWM.cjs.map +1 -0
- package/dist/{chunk-XBZWAUZ3.js → chunk-IFPQ2MLB.js} +25 -12
- package/dist/chunk-IFPQ2MLB.js.map +1 -0
- package/dist/{chunk-DVJZZAZA.cjs → chunk-IHD36QFA.cjs} +7 -7
- package/dist/{chunk-DVJZZAZA.cjs.map → chunk-IHD36QFA.cjs.map} +1 -1
- package/dist/{chunk-WMJEP45F.cjs → chunk-J4KVR4DZ.cjs} +25 -18
- package/dist/chunk-J4KVR4DZ.cjs.map +1 -0
- package/dist/{chunk-3RFSIHFR.js → chunk-K2LPTKSY.js} +4 -720
- package/dist/chunk-K2LPTKSY.js.map +1 -0
- package/dist/{chunk-FY3PYSMK.cjs → chunk-KHO4KFXW.cjs} +5 -5
- package/dist/{chunk-FY3PYSMK.cjs.map → chunk-KHO4KFXW.cjs.map} +1 -1
- package/dist/{chunk-W7R7GPNN.cjs → chunk-MGPIVG2O.cjs} +9 -9
- package/dist/chunk-MGPIVG2O.cjs.map +1 -0
- package/dist/{chunk-KGE3KAM7.js → chunk-N3PAHTKU.js} +23 -3
- package/dist/chunk-N3PAHTKU.js.map +1 -0
- package/dist/{chunk-O4H44CMA.js → chunk-N7TDP7ZE.js} +586 -117
- package/dist/chunk-N7TDP7ZE.js.map +1 -0
- package/dist/{chunk-I5GMA5UM.cjs → chunk-NPIYNC5A.cjs} +9 -9
- package/dist/{chunk-I5GMA5UM.cjs.map → chunk-NPIYNC5A.cjs.map} +1 -1
- package/dist/{chunk-AW7FISLD.cjs → chunk-OZ75PBBK.cjs} +27 -7
- package/dist/chunk-OZ75PBBK.cjs.map +1 -0
- package/dist/{chunk-JMAPJWVG.cjs → chunk-OZCUIZRA.cjs} +2021 -1426
- package/dist/chunk-OZCUIZRA.cjs.map +1 -0
- package/dist/{chunk-6OPEMI2Q.cjs → chunk-PM3UIIBK.cjs} +2 -3
- package/dist/{chunk-6OPEMI2Q.cjs.map → chunk-PM3UIIBK.cjs.map} +1 -1
- package/dist/{chunk-CISH55FP.js → chunk-PSIJ6OSV.js} +16 -9
- package/dist/chunk-PSIJ6OSV.js.map +1 -0
- package/dist/{chunk-UOZ3GJY2.cjs → chunk-PTK74KG4.cjs} +2 -2
- package/dist/chunk-PTK74KG4.cjs.map +1 -0
- package/dist/{chunk-O5IPTMEH.cjs → chunk-Q5QQDMSD.cjs} +32 -29
- package/dist/chunk-Q5QQDMSD.cjs.map +1 -0
- package/dist/{chunk-UVHSM2GU.cjs → chunk-SMM2C4KH.cjs} +6 -4
- package/dist/chunk-SMM2C4KH.cjs.map +1 -0
- package/dist/{chunk-UXLQEGIN.cjs → chunk-SVPXZEU7.cjs} +35 -22
- package/dist/chunk-SVPXZEU7.cjs.map +1 -0
- package/dist/{chunk-SOSXN7X4.cjs → chunk-TU6MNGBB.cjs} +619 -151
- package/dist/chunk-TU6MNGBB.cjs.map +1 -0
- package/dist/{chunk-EK7E4ETB.js → chunk-TX5GUG5Q.js} +3 -3
- package/dist/{chunk-EK7E4ETB.js.map → chunk-TX5GUG5Q.js.map} +1 -1
- package/dist/{chunk-SQ7T6FWC.cjs → chunk-UAH236P2.cjs} +13 -13
- package/dist/{chunk-SQ7T6FWC.cjs.map → chunk-UAH236P2.cjs.map} +1 -1
- package/dist/{chunk-AIJ6HPJG.js → chunk-UL7TJCKA.js} +4 -4
- package/dist/{chunk-AIJ6HPJG.js.map → chunk-UL7TJCKA.js.map} +1 -1
- package/dist/{chunk-IC2MIQBW.js → chunk-UVOQLIWL.js} +1922 -1326
- package/dist/chunk-UVOQLIWL.js.map +1 -0
- package/dist/{chunk-IMLORTHO.js → chunk-WANKWENG.js} +5 -5
- package/dist/{chunk-IMLORTHO.js.map → chunk-WANKWENG.js.map} +1 -1
- package/dist/{chunk-ICU4Z5MO.cjs → chunk-X7DR353F.cjs} +8 -8
- package/dist/{chunk-ICU4Z5MO.cjs.map → chunk-X7DR353F.cjs.map} +1 -1
- package/dist/{chunk-6TBWJV35.js → chunk-Y22QMA7S.js} +6 -4
- package/dist/chunk-Y22QMA7S.js.map +1 -0
- package/dist/{chunk-FT7DFPAL.js → chunk-YYNZEEOO.js} +5 -5
- package/dist/{chunk-FT7DFPAL.js.map → chunk-YYNZEEOO.js.map} +1 -1
- package/dist/di/index.cjs +4 -4
- package/dist/di/index.js +1 -1
- package/dist/docs/README.md +6 -5
- package/dist/docs/SKILL.md +6 -5
- package/dist/docs/SOURCE_MAP.json +288 -293
- package/dist/docs/agents/01-overview.md +2 -2
- package/dist/docs/agents/02-using-tools.md +5 -0
- package/dist/docs/agents/04-structured-output.md +24 -4
- package/dist/docs/agents/06-processors.md +65 -1
- package/dist/docs/agents/08-agent-approval.md +5 -6
- package/dist/docs/agents/09-network-approval.md +274 -0
- package/dist/docs/agents/{10-reference.md → 11-reference.md} +1 -1
- package/dist/docs/ai-sdk/01-reference.md +1 -1
- package/dist/docs/cli/01-reference.md +1 -1
- package/dist/docs/client-js/01-reference.md +10 -5
- package/dist/docs/configuration.mdx/01-reference.md +750 -0
- package/dist/docs/core/01-reference.md +9 -35
- package/dist/docs/deployer/01-reference.md +19 -6
- package/dist/docs/evals/01-overview.md +5 -5
- package/dist/docs/evals/02-custom-scorers.md +49 -6
- package/dist/docs/evals/04-reference.md +10 -4
- package/dist/docs/mcp/01-overview.md +26 -16
- package/dist/docs/mcp/02-publishing-mcp-server.md +2 -2
- package/dist/docs/memory/01-overview.md +2 -2
- package/dist/docs/memory/02-storage.md +59 -25
- package/dist/docs/memory/03-working-memory.md +10 -6
- package/dist/docs/memory/04-semantic-recall.md +2 -4
- package/dist/docs/memory/05-memory-processors.md +2 -3
- package/dist/docs/memory/06-reference.md +2 -4
- package/dist/docs/observability/01-overview.md +1 -1
- package/dist/docs/observability/02-logging.md +4 -5
- package/dist/docs/observability/03-overview.md +69 -13
- package/dist/docs/observability/09-datadog.md +169 -0
- package/dist/docs/observability/10-laminar.md +95 -0
- package/dist/docs/observability/{11-otel.md → 13-otel.md} +12 -7
- package/dist/docs/observability/{13-reference.md → 15-reference.md} +125 -1
- package/dist/docs/processors/01-reference.md +23 -0
- package/dist/docs/rag/01-overview.md +1 -1
- package/dist/docs/rag/02-chunking-and-embedding.md +0 -1
- package/dist/docs/rag/03-vector-databases.md +10 -5
- package/dist/docs/rag/04-retrieval.md +5 -6
- package/dist/docs/rag/06-reference.md +4 -5
- package/dist/docs/server/01-mastra-server.md +32 -49
- package/dist/docs/server/02-custom-adapters.md +5 -2
- package/dist/docs/server/04-request-context.md +50 -11
- package/dist/docs/server/05-custom-api-routes.md +1 -1
- package/dist/docs/server/06-mastra-client.md +2 -2
- package/dist/docs/storage/01-reference.md +99 -23
- package/dist/docs/streaming/04-reference.md +6 -1
- package/dist/docs/tools/01-reference.md +380 -25
- package/dist/docs/tools-mcp/01-mcp-overview.md +10 -2
- package/dist/docs/tools-mcp/02-overview.md +4 -4
- package/dist/docs/vectors/01-reference.md +24 -11
- package/dist/docs/voice/01-overview.md +2 -2
- package/dist/docs/voice/05-reference.md +2 -2
- package/dist/docs/workflows/01-overview.md +5 -5
- package/dist/docs/workflows/04-agents-and-tools.md +4 -6
- package/dist/docs/workflows/06-suspend-and-resume.md +5 -7
- package/dist/docs/workflows/11-reference.md +1 -91
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +20 -20
- package/dist/evals/index.js +3 -3
- package/dist/evals/scoreTraces/index.cjs +5 -5
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts +4 -67
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/integration/index.cjs +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.cjs +9 -9
- package/dist/llm/index.js +2 -2
- package/dist/llm/model/model.loop.d.ts +1 -2
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +1 -2
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +224 -18
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/loop/loop.d.ts +1 -2
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/network/index.d.ts +21 -80
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/network/run-command-tool.d.ts +14 -11
- package/dist/loop/network/run-command-tool.d.ts.map +1 -1
- package/dist/loop/network/validation.d.ts +3 -4
- package/dist/loop/network/validation.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/types.d.ts +4 -5
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +31 -804
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +22 -539
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +13 -294
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +2 -41
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +32 -805
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +90 -91
- package/dist/loop/workflows/schema.d.ts.map +1 -1
- package/dist/loop/workflows/stream.d.ts +1 -2
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +28 -9
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +11 -11
- package/dist/memory/index.js +1 -1
- package/dist/memory/memory.d.ts +4 -2
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/observability/index.cjs +11 -11
- package/dist/observability/index.js +1 -1
- package/dist/observability/types/tracing.d.ts +45 -7
- package/dist/observability/types/tracing.d.ts.map +1 -1
- package/dist/processors/index.cjs +38 -38
- package/dist/processors/index.d.ts +3 -3
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/memory/semantic-recall.d.ts +2 -0
- package/dist/processors/memory/semantic-recall.d.ts.map +1 -1
- package/dist/processors/processors/structured-output.d.ts +2 -2
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/processors/processors/token-limiter.d.ts +16 -10
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +4 -4
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +66 -67
- package/dist/processors/step-schema.d.ts.map +1 -1
- package/dist/provider-registry-C3IAGLLU.js +3 -0
- package/dist/{provider-registry-6DWM3X3I.js.map → provider-registry-C3IAGLLU.js.map} +1 -1
- package/dist/provider-registry-YH4FCTT2.cjs +40 -0
- package/dist/{provider-registry-DCECMUCQ.cjs.map → provider-registry-YH4FCTT2.cjs.map} +1 -1
- package/dist/provider-registry.json +477 -45
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/request-context/index.cjs +4 -4
- package/dist/request-context/index.d.ts +10 -9
- package/dist/request-context/index.d.ts.map +1 -1
- package/dist/request-context/index.js +1 -1
- package/dist/server/types.d.ts +1 -1
- package/dist/storage/constants.cjs +14 -14
- package/dist/storage/constants.d.ts +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/observability/types.d.ts +90 -90
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +93 -93
- package/dist/storage/index.js +2 -2
- package/dist/stream/MastraAgentNetworkStream.d.ts +8 -12
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +2 -3
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts +2 -3
- package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
- package/dist/stream/base/output-format-handlers.d.ts +2 -2
- package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +76 -50
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/base/schema.d.ts +7 -2
- package/dist/stream/base/schema.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -15
- package/dist/stream/index.d.ts +2 -2
- package/dist/stream/index.d.ts.map +1 -1
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +72 -26
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +4 -4
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.d.ts +1 -1
- package/dist/tool-loop-agent/index.d.ts.map +1 -1
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/tool-loop-agent/tool-loop-processor.d.ts +1 -2
- package/dist/tool-loop-agent/tool-loop-processor.d.ts.map +1 -1
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts +27 -14
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +76 -20
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/ui-types.d.ts +3 -4
- package/dist/tools/ui-types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +4 -4
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/types/dynamic-argument.d.ts +61 -1
- package/dist/types/dynamic-argument.d.ts.map +1 -1
- package/dist/types/zod-compat.d.ts +3 -11
- package/dist/types/zod-compat.d.ts.map +1 -1
- package/dist/utils.cjs +22 -22
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/index.cjs +2 -2
- package/dist/vector/index.js +1 -1
- package/dist/voice/index.cjs +6 -6
- package/dist/voice/index.js +1 -1
- package/dist/workflows/default.d.ts +114 -2
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/utils.d.ts +1 -1
- package/dist/workflows/evented/workflow.d.ts +74 -21
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/handlers/control-flow.d.ts +2 -2
- package/dist/workflows/handlers/control-flow.d.ts.map +1 -1
- package/dist/workflows/handlers/sleep.d.ts.map +1 -1
- package/dist/workflows/handlers/step.d.ts +1 -1
- package/dist/workflows/handlers/step.d.ts.map +1 -1
- package/dist/workflows/index.cjs +23 -23
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +28 -24
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +91 -54
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +165 -118
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/llm/model/provider-types.generated.d.ts +224 -18
- package/dist/chunk-3CZ42NBZ.js.map +0 -1
- package/dist/chunk-3RFSIHFR.js.map +0 -1
- package/dist/chunk-6TBWJV35.js.map +0 -1
- package/dist/chunk-A4MCHA5L.cjs.map +0 -1
- package/dist/chunk-AHN7K3VE.js.map +0 -1
- package/dist/chunk-AW7FISLD.cjs.map +0 -1
- package/dist/chunk-CISH55FP.js.map +0 -1
- package/dist/chunk-IC2MIQBW.js.map +0 -1
- package/dist/chunk-JMAPJWVG.cjs.map +0 -1
- package/dist/chunk-KGE3KAM7.js.map +0 -1
- package/dist/chunk-O4H44CMA.js.map +0 -1
- package/dist/chunk-O5IPTMEH.cjs.map +0 -1
- package/dist/chunk-PC3FBUWH.js.map +0 -1
- package/dist/chunk-SOSXN7X4.cjs.map +0 -1
- package/dist/chunk-UOZ3GJY2.cjs.map +0 -1
- package/dist/chunk-UVHSM2GU.cjs.map +0 -1
- package/dist/chunk-UXLQEGIN.cjs.map +0 -1
- package/dist/chunk-W7R7GPNN.cjs.map +0 -1
- package/dist/chunk-WMJEP45F.cjs.map +0 -1
- package/dist/chunk-XBZWAUZ3.js.map +0 -1
- package/dist/chunk-XKDVT3ZH.cjs.map +0 -1
- package/dist/chunk-XSJNTLM7.js.map +0 -1
- package/dist/provider-registry-6DWM3X3I.js +0 -3
- package/dist/provider-registry-DCECMUCQ.cjs +0 -40
- package/dist/stream/aisdk/v5/output.d.ts +0 -121
- package/dist/stream/aisdk/v5/output.d.ts.map +0 -1
- /package/dist/docs/agents/{09-adding-voice.md → 10-adding-voice.md} +0 -0
- /package/dist/docs/observability/{09-langfuse.md → 11-langfuse.md} +0 -0
- /package/dist/docs/observability/{10-langsmith.md → 12-langsmith.md} +0 -0
- /package/dist/docs/observability/{12-posthog.md → 14-posthog.md} +0 -0
|
@@ -200,6 +200,43 @@ export const tool = createTool({
|
|
|
200
200
|
});
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
+
## Example with MCP Annotations
|
|
204
|
+
|
|
205
|
+
When exposing tools via MCP (Model Context Protocol), you can add annotations to describe tool behavior and customize how clients display the tool. These MCP-specific properties are grouped under the `mcp` property:
|
|
206
|
+
|
|
207
|
+
```typescript title="src/mastra/tools/weather-tool.ts"
|
|
208
|
+
import { createTool } from "@mastra/core/tools";
|
|
209
|
+
import { z } from "zod";
|
|
210
|
+
|
|
211
|
+
export const weatherTool = createTool({
|
|
212
|
+
id: "get-weather",
|
|
213
|
+
description: "Get current weather for a location",
|
|
214
|
+
inputSchema: z.object({
|
|
215
|
+
location: z.string().describe("City name or coordinates"),
|
|
216
|
+
}),
|
|
217
|
+
// MCP-specific properties
|
|
218
|
+
mcp: {
|
|
219
|
+
// Annotations for client behavior hints
|
|
220
|
+
annotations: {
|
|
221
|
+
title: "Weather Lookup", // Human-readable display name
|
|
222
|
+
readOnlyHint: true, // Tool doesn't modify environment
|
|
223
|
+
destructiveHint: false, // Tool doesn't perform destructive updates
|
|
224
|
+
idempotentHint: true, // Same args = same result
|
|
225
|
+
openWorldHint: true, // Interacts with external API
|
|
226
|
+
},
|
|
227
|
+
// Custom metadata for client-specific functionality
|
|
228
|
+
_meta: {
|
|
229
|
+
version: "1.0.0",
|
|
230
|
+
category: "weather",
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
execute: async (inputData) => {
|
|
234
|
+
const weather = await fetchWeather(inputData.location);
|
|
235
|
+
return { weather };
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
203
240
|
## Parameters
|
|
204
241
|
|
|
205
242
|
## Returns
|
|
@@ -306,6 +343,23 @@ Additionally:
|
|
|
306
343
|
|
|
307
344
|
Hook errors are caught and logged automatically, but do not prevent tool execution from continuing. If a hook throws an error, it will be logged to the console but will not fail the tool call.
|
|
308
345
|
|
|
346
|
+
## MCP Tool Annotations
|
|
347
|
+
|
|
348
|
+
When exposing tools via the Model Context Protocol (MCP), you can provide annotations that describe tool behavior. These annotations help MCP clients like OpenAI Apps SDK understand how to present and handle your tools.
|
|
349
|
+
|
|
350
|
+
MCP-specific properties are grouped under the `mcp` property, which includes `annotations` and `_meta`:
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
mcp: {
|
|
354
|
+
annotations: { /* behavior hints */ },
|
|
355
|
+
_meta: { /* custom metadata */ },
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### ToolAnnotations Properties
|
|
360
|
+
|
|
361
|
+
These annotations follow the [MCP specification](https://spec.modelcontextprotocol.io/specification/2025-03-26/server/tools/#tool-annotations) and are passed through when tools are listed via MCP.
|
|
362
|
+
|
|
309
363
|
## Related
|
|
310
364
|
|
|
311
365
|
- [MCP Overview](https://mastra.ai/docs/v1/mcp/overview)
|
|
@@ -793,7 +847,7 @@ Retrieves all tools from all configured servers, with tool names namespaced by t
|
|
|
793
847
|
Intended to be passed onto an Agent definition.
|
|
794
848
|
|
|
795
849
|
```ts
|
|
796
|
-
new Agent({ tools: await mcp.listTools() });
|
|
850
|
+
new Agent({ id: "agent", tools: await mcp.listTools() });
|
|
797
851
|
```
|
|
798
852
|
|
|
799
853
|
### listToolsets()
|
|
@@ -1338,6 +1392,104 @@ await mcpClient.elicitation.onRequest("interactiveServer", async (request) => {
|
|
|
1338
1392
|
- **Clear UI**: Make it obvious what information is being requested and why
|
|
1339
1393
|
- **Security**: Never auto-accept requests for sensitive information
|
|
1340
1394
|
|
|
1395
|
+
## OAuth Authentication
|
|
1396
|
+
|
|
1397
|
+
For connecting to MCP servers that require OAuth authentication per the [MCP Auth Specification](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization), use the `MCPOAuthClientProvider`:
|
|
1398
|
+
|
|
1399
|
+
```typescript
|
|
1400
|
+
import { MCPClient, MCPOAuthClientProvider } from "@mastra/mcp";
|
|
1401
|
+
|
|
1402
|
+
// Create an OAuth provider
|
|
1403
|
+
const oauthProvider = new MCPOAuthClientProvider({
|
|
1404
|
+
redirectUrl: "http://localhost:3000/oauth/callback",
|
|
1405
|
+
clientMetadata: {
|
|
1406
|
+
redirect_uris: ["http://localhost:3000/oauth/callback"],
|
|
1407
|
+
client_name: "My MCP Client",
|
|
1408
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
1409
|
+
response_types: ["code"],
|
|
1410
|
+
},
|
|
1411
|
+
onRedirectToAuthorization: (url) => {
|
|
1412
|
+
// Handle authorization redirect (open browser, redirect response, etc.)
|
|
1413
|
+
console.log(`Please visit: ${url}`);
|
|
1414
|
+
},
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1417
|
+
// Use the provider with MCPClient
|
|
1418
|
+
const client = new MCPClient({
|
|
1419
|
+
servers: {
|
|
1420
|
+
protectedServer: {
|
|
1421
|
+
url: new URL("https://mcp.example.com/mcp"),
|
|
1422
|
+
authProvider: oauthProvider,
|
|
1423
|
+
},
|
|
1424
|
+
},
|
|
1425
|
+
});
|
|
1426
|
+
```
|
|
1427
|
+
|
|
1428
|
+
### Quick Token Provider
|
|
1429
|
+
|
|
1430
|
+
For testing or when you already have a valid access token:
|
|
1431
|
+
|
|
1432
|
+
```typescript
|
|
1433
|
+
import { MCPClient, createSimpleTokenProvider } from "@mastra/mcp";
|
|
1434
|
+
|
|
1435
|
+
const provider = createSimpleTokenProvider("your-access-token", {
|
|
1436
|
+
redirectUrl: "http://localhost:3000/callback",
|
|
1437
|
+
clientMetadata: {
|
|
1438
|
+
redirect_uris: ["http://localhost:3000/callback"],
|
|
1439
|
+
client_name: "Test Client",
|
|
1440
|
+
},
|
|
1441
|
+
});
|
|
1442
|
+
|
|
1443
|
+
const client = new MCPClient({
|
|
1444
|
+
servers: {
|
|
1445
|
+
testServer: {
|
|
1446
|
+
url: new URL("https://mcp.example.com/mcp"),
|
|
1447
|
+
authProvider: provider,
|
|
1448
|
+
},
|
|
1449
|
+
},
|
|
1450
|
+
});
|
|
1451
|
+
```
|
|
1452
|
+
|
|
1453
|
+
### Custom Token Storage
|
|
1454
|
+
|
|
1455
|
+
For persistent token storage across sessions, implement the `OAuthStorage` interface:
|
|
1456
|
+
|
|
1457
|
+
```typescript
|
|
1458
|
+
import { MCPOAuthClientProvider, OAuthStorage } from "@mastra/mcp";
|
|
1459
|
+
|
|
1460
|
+
class DatabaseOAuthStorage implements OAuthStorage {
|
|
1461
|
+
constructor(private db: Database, private userId: string) {}
|
|
1462
|
+
|
|
1463
|
+
async set(key: string, value: string): Promise<void> {
|
|
1464
|
+
await this.db.query(
|
|
1465
|
+
"INSERT INTO oauth_tokens (user_id, key, value) VALUES (?, ?, ?) ON CONFLICT DO UPDATE SET value = ?",
|
|
1466
|
+
[this.userId, key, value, value]
|
|
1467
|
+
);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
async get(key: string): Promise<string | undefined> {
|
|
1471
|
+
const result = await this.db.query(
|
|
1472
|
+
"SELECT value FROM oauth_tokens WHERE user_id = ? AND key = ?",
|
|
1473
|
+
[this.userId, key]
|
|
1474
|
+
);
|
|
1475
|
+
return result?.[0]?.value;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
async delete(key: string): Promise<void> {
|
|
1479
|
+
await this.db.query(
|
|
1480
|
+
"DELETE FROM oauth_tokens WHERE user_id = ? AND key = ?",
|
|
1481
|
+
[this.userId, key]
|
|
1482
|
+
);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
const provider = new MCPOAuthClientProvider({
|
|
1487
|
+
redirectUrl: "http://localhost:3000/callback",
|
|
1488
|
+
clientMetadata: { /* ... */ },
|
|
1489
|
+
storage: new DatabaseOAuthStorage(db, "user-123"),
|
|
1490
|
+
});
|
|
1491
|
+
```
|
|
1492
|
+
|
|
1341
1493
|
## Examples
|
|
1342
1494
|
|
|
1343
1495
|
### Static Tool Configuration
|
|
@@ -1369,6 +1521,7 @@ const mcp = new MCPClient({
|
|
|
1369
1521
|
|
|
1370
1522
|
// Create an agent with access to all tools
|
|
1371
1523
|
const agent = new Agent({
|
|
1524
|
+
id: "multi-tool-agent",
|
|
1372
1525
|
name: "Multi-tool Agent",
|
|
1373
1526
|
instructions: "You have access to multiple tool servers.",
|
|
1374
1527
|
model: "openai/gpt-5.1",
|
|
@@ -1424,6 +1577,7 @@ import { MCPClient } from "@mastra/mcp";
|
|
|
1424
1577
|
|
|
1425
1578
|
// Create the agent first, without any tools
|
|
1426
1579
|
const agent = new Agent({
|
|
1580
|
+
id: "multi-tool-agent",
|
|
1427
1581
|
name: "Multi-tool Agent",
|
|
1428
1582
|
instructions: "You help users check stocks and weather.",
|
|
1429
1583
|
model: "openai/gpt-5.1",
|
|
@@ -2507,44 +2661,245 @@ type ElicitResult = {
|
|
|
2507
2661
|
};
|
|
2508
2662
|
```
|
|
2509
2663
|
|
|
2664
|
+
## OAuth Protection
|
|
2665
|
+
|
|
2666
|
+
To protect your MCP server with OAuth authentication per the [MCP Auth Specification](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization), use the `createOAuthMiddleware` function:
|
|
2667
|
+
|
|
2668
|
+
```typescript
|
|
2669
|
+
import http from "node:http";
|
|
2670
|
+
import { MCPServer, createOAuthMiddleware, createStaticTokenValidator } from "@mastra/mcp";
|
|
2671
|
+
|
|
2672
|
+
const mcpServer = new MCPServer({
|
|
2673
|
+
id: "protected-server",
|
|
2674
|
+
name: "Protected MCP Server",
|
|
2675
|
+
version: "1.0.0",
|
|
2676
|
+
tools: { /* your tools */ },
|
|
2677
|
+
});
|
|
2678
|
+
|
|
2679
|
+
// Create OAuth middleware
|
|
2680
|
+
const oauthMiddleware = createOAuthMiddleware({
|
|
2681
|
+
oauth: {
|
|
2682
|
+
resource: "https://mcp.example.com/mcp",
|
|
2683
|
+
authorizationServers: ["https://auth.example.com"],
|
|
2684
|
+
scopesSupported: ["mcp:read", "mcp:write"],
|
|
2685
|
+
resourceName: "My Protected MCP Server",
|
|
2686
|
+
validateToken: createStaticTokenValidator(["allowed-token-1"]),
|
|
2687
|
+
},
|
|
2688
|
+
mcpPath: "/mcp",
|
|
2689
|
+
});
|
|
2690
|
+
|
|
2691
|
+
// Create HTTP server with OAuth protection
|
|
2692
|
+
const httpServer = http.createServer(async (req, res) => {
|
|
2693
|
+
const url = new URL(req.url || "", "https://mcp.example.com");
|
|
2694
|
+
|
|
2695
|
+
// Apply OAuth middleware first
|
|
2696
|
+
const result = await oauthMiddleware(req, res, url);
|
|
2697
|
+
if (!result.proceed) return; // Middleware handled response (401, metadata, etc.)
|
|
2698
|
+
|
|
2699
|
+
// Token is valid, proceed to MCP handler
|
|
2700
|
+
await mcpServer.startHTTP({ url, httpPath: "/mcp", req, res });
|
|
2701
|
+
});
|
|
2702
|
+
|
|
2703
|
+
httpServer.listen(3000);
|
|
2704
|
+
```
|
|
2705
|
+
|
|
2706
|
+
The middleware automatically:
|
|
2707
|
+
|
|
2708
|
+
- Serves **Protected Resource Metadata** at `/.well-known/oauth-protected-resource` (RFC 9728)
|
|
2709
|
+
- Returns `401 Unauthorized` with proper `WWW-Authenticate` headers when authentication is required
|
|
2710
|
+
- Validates bearer tokens using your provided validator
|
|
2711
|
+
|
|
2712
|
+
### Token Validation
|
|
2713
|
+
|
|
2714
|
+
For production, use proper token validation:
|
|
2715
|
+
|
|
2716
|
+
```typescript
|
|
2717
|
+
import { createOAuthMiddleware, createIntrospectionValidator } from "@mastra/mcp";
|
|
2718
|
+
|
|
2719
|
+
// Option 1: Token introspection (RFC 7662)
|
|
2720
|
+
const middleware = createOAuthMiddleware({
|
|
2721
|
+
oauth: {
|
|
2722
|
+
resource: "https://mcp.example.com/mcp",
|
|
2723
|
+
authorizationServers: ["https://auth.example.com"],
|
|
2724
|
+
validateToken: createIntrospectionValidator(
|
|
2725
|
+
"https://auth.example.com/oauth/introspect",
|
|
2726
|
+
{ clientId: "mcp-server", clientSecret: "secret" }
|
|
2727
|
+
),
|
|
2728
|
+
},
|
|
2729
|
+
});
|
|
2730
|
+
|
|
2731
|
+
// Option 2: Custom validation (JWT, database lookup, etc.)
|
|
2732
|
+
const customMiddleware = createOAuthMiddleware({
|
|
2733
|
+
oauth: {
|
|
2734
|
+
resource: "https://mcp.example.com/mcp",
|
|
2735
|
+
authorizationServers: ["https://auth.example.com"],
|
|
2736
|
+
validateToken: async (token, resource) => {
|
|
2737
|
+
const decoded = await verifyJWT(token);
|
|
2738
|
+
if (!decoded) {
|
|
2739
|
+
return { valid: false, error: "invalid_token" };
|
|
2740
|
+
}
|
|
2741
|
+
return {
|
|
2742
|
+
valid: true,
|
|
2743
|
+
scopes: decoded.scope?.split(" ") || [],
|
|
2744
|
+
subject: decoded.sub,
|
|
2745
|
+
};
|
|
2746
|
+
},
|
|
2747
|
+
},
|
|
2748
|
+
});
|
|
2749
|
+
```
|
|
2750
|
+
|
|
2751
|
+
### OAuth Middleware Options
|
|
2752
|
+
|
|
2510
2753
|
## Authentication Context
|
|
2511
2754
|
|
|
2512
|
-
Tools can access request metadata via `context.mcp.extra` when using HTTP-based transports
|
|
2755
|
+
Tools can access request metadata via `context.mcp.extra` when using HTTP-based transports. This allows you to pass authentication info, user context, or any custom data from your HTTP middleware to your MCP tools.
|
|
2756
|
+
|
|
2757
|
+
### How It Works
|
|
2758
|
+
|
|
2759
|
+
Whatever you set on `req.auth` in your HTTP middleware becomes available as `context.mcp.extra.authInfo` in your tools:
|
|
2760
|
+
|
|
2761
|
+
```
|
|
2762
|
+
req.auth = { ... } → context?.mcp?.extra?.authInfo.extra = { ... }
|
|
2763
|
+
```
|
|
2764
|
+
|
|
2765
|
+
### Setting Up Authentication Middleware
|
|
2766
|
+
|
|
2767
|
+
To pass data to your tools, populate `req.auth` on the Node.js request object in your HTTP server middleware before calling `server.startHTTP()`.
|
|
2768
|
+
|
|
2769
|
+
```typescript
|
|
2770
|
+
import express from "express";
|
|
2771
|
+
|
|
2772
|
+
const app = express();
|
|
2773
|
+
|
|
2774
|
+
// Auth middleware - set req.auth before the MCP handler
|
|
2775
|
+
app.use("/mcp", (req, res, next) => {
|
|
2776
|
+
const token = req.headers.authorization?.replace("Bearer ", "");
|
|
2777
|
+
const user = verifyToken(token);
|
|
2778
|
+
|
|
2779
|
+
// This entire object becomes context.mcp.extra.authInfo
|
|
2780
|
+
// @ts-ignore - req.auth is read by the MCP SDK
|
|
2781
|
+
req.auth = {
|
|
2782
|
+
token,
|
|
2783
|
+
userId: user.userId,
|
|
2784
|
+
email: user.email,
|
|
2785
|
+
};
|
|
2786
|
+
next();
|
|
2787
|
+
});
|
|
2788
|
+
|
|
2789
|
+
app.all("/mcp", async (req, res) => {
|
|
2790
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
2791
|
+
await server.startHTTP({ url, httpPath: "/mcp", req, res });
|
|
2792
|
+
});
|
|
2793
|
+
```
|
|
2794
|
+
|
|
2795
|
+
### Accessing Auth Data in Tools
|
|
2796
|
+
|
|
2797
|
+
The `req.auth` object is available as `context.mcp.extra.authInfo` in your tool's execute function:
|
|
2513
2798
|
|
|
2514
2799
|
```typescript
|
|
2515
2800
|
execute: async (inputData, context) => {
|
|
2516
|
-
|
|
2517
|
-
|
|
2801
|
+
// Access the auth data you set in middleware
|
|
2802
|
+
const authInfo = context?.mcp?.extra?.authInfo;
|
|
2803
|
+
|
|
2804
|
+
if (!authInfo?.extra?.userId) {
|
|
2805
|
+
return { error: "Authentication required" };
|
|
2518
2806
|
}
|
|
2519
2807
|
|
|
2520
|
-
// Use the auth
|
|
2808
|
+
// Use the auth data
|
|
2809
|
+
console.log("User ID:", authInfo.extra.userId);
|
|
2810
|
+
console.log("Email:", authInfo.extra.email);
|
|
2811
|
+
|
|
2521
2812
|
const response = await fetch("/api/data", {
|
|
2522
|
-
headers: { Authorization: `Bearer ${
|
|
2523
|
-
signal: context
|
|
2813
|
+
headers: { Authorization: `Bearer ${authInfo.token}` },
|
|
2814
|
+
signal: context?.mcp?.extra?.signal,
|
|
2524
2815
|
});
|
|
2525
2816
|
|
|
2526
2817
|
return response.json();
|
|
2527
2818
|
};
|
|
2528
2819
|
```
|
|
2529
2820
|
|
|
2530
|
-
The `extra`
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2821
|
+
### The `extra` Object
|
|
2822
|
+
|
|
2823
|
+
The full `context.mcp.extra` object contains:
|
|
2824
|
+
|
|
2825
|
+
| Property | Description |
|
|
2826
|
+
|----------|-------------|
|
|
2827
|
+
| `authInfo` | Whatever you set on `req.auth` in your middleware |
|
|
2828
|
+
| `sessionId` | Session identifier for the MCP connection |
|
|
2829
|
+
| `signal` | AbortSignal for request cancellation |
|
|
2830
|
+
| `sendNotification` | MCP protocol function for sending notifications |
|
|
2831
|
+
| `sendRequest` | MCP protocol function for sending requests |
|
|
2832
|
+
|
|
2833
|
+
### Complete Example
|
|
2834
|
+
|
|
2835
|
+
Here's a complete example showing the data flow from middleware to tool:
|
|
2836
|
+
|
|
2837
|
+
```typescript
|
|
2838
|
+
import express from "express";
|
|
2839
|
+
import { MCPServer } from "@mastra/mcp";
|
|
2840
|
+
import { createTool } from "@mastra/core/tools";
|
|
2841
|
+
import { z } from "zod";
|
|
2842
|
+
|
|
2843
|
+
const verifyToken = (token: string) => {
|
|
2844
|
+
// TODO: Implement token verification
|
|
2845
|
+
return {
|
|
2846
|
+
userId: "123",
|
|
2847
|
+
email: "test@test.com",
|
|
2848
|
+
};
|
|
2849
|
+
};
|
|
2850
|
+
|
|
2851
|
+
// 1. Define your tool that uses auth context
|
|
2852
|
+
const getUserData = createTool({
|
|
2853
|
+
id: "get-user-data",
|
|
2854
|
+
description: "Fetches data for the authenticated user",
|
|
2855
|
+
inputSchema: z.object({}),
|
|
2856
|
+
execute: async (inputData, context) => {
|
|
2857
|
+
const authInfo = context?.mcp?.extra?.authInfo;
|
|
2858
|
+
|
|
2859
|
+
if (!authInfo?.extra?.userId) {
|
|
2860
|
+
return { error: "Authentication required" };
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
// Access the data you set in middleware
|
|
2864
|
+
return {
|
|
2865
|
+
userId: authInfo.extra.userId,
|
|
2866
|
+
email: authInfo.extra.email,
|
|
2867
|
+
};
|
|
2868
|
+
},
|
|
2869
|
+
});
|
|
2870
|
+
|
|
2871
|
+
// 2. Create the MCP server with your tools
|
|
2872
|
+
const server = new MCPServer({
|
|
2873
|
+
id: "my-server",
|
|
2874
|
+
name: "My Server",
|
|
2875
|
+
version: "1.0.0",
|
|
2876
|
+
tools: { getUserData },
|
|
2877
|
+
});
|
|
2878
|
+
|
|
2879
|
+
// 3. Set up Express with auth middleware
|
|
2880
|
+
const app = express();
|
|
2881
|
+
|
|
2882
|
+
app.use("/mcp", (req, res, next) => {
|
|
2883
|
+
const token = req.headers.authorization?.replace("Bearer ", "");
|
|
2884
|
+
const user = verifyToken(token);
|
|
2885
|
+
|
|
2886
|
+
// This entire object becomes context.mcp.extra.authInfo
|
|
2887
|
+
// @ts-ignore - req.auth is read by the MCP SDK
|
|
2888
|
+
req.auth = {
|
|
2889
|
+
token,
|
|
2890
|
+
userId: user.userId,
|
|
2891
|
+
email: user.email,
|
|
2892
|
+
};
|
|
2893
|
+
next();
|
|
2894
|
+
});
|
|
2895
|
+
|
|
2896
|
+
app.all("/mcp", async (req, res) => {
|
|
2897
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
2898
|
+
await server.startHTTP({ url, httpPath: "/mcp", req, res });
|
|
2899
|
+
});
|
|
2900
|
+
|
|
2901
|
+
app.listen(3000);
|
|
2902
|
+
```
|
|
2548
2903
|
|
|
2549
2904
|
## Related Information
|
|
2550
2905
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
> Learn about the Model Context Protocol (MCP), how to use third-party tools via MCPClient, connect to registries, and share your own tools using MCPServer.
|
|
2
2
|
|
|
3
3
|
> **Code References:**
|
|
4
|
-
- `Agent`: dist/agent/agent.d.ts → dist/chunk-
|
|
5
|
-
- `Mastra`: dist/mastra/index.d.ts → dist/chunk-
|
|
4
|
+
- `Agent`: dist/agent/agent.d.ts → dist/chunk-UVOQLIWL.js:16630
|
|
5
|
+
- `Mastra`: dist/mastra/index.d.ts → dist/chunk-IFPQ2MLB.js:24
|
|
6
6
|
|
|
7
7
|
# MCP Overview
|
|
8
8
|
|
|
@@ -50,6 +50,10 @@ export const testMcpClient = new MCPClient({
|
|
|
50
50
|
|
|
51
51
|
Visit [MCPClient](https://mastra.ai/reference/v1/tools/mcp-client) for a full list of configuration options.
|
|
52
52
|
|
|
53
|
+
> **Note:** Authentication
|
|
54
|
+
|
|
55
|
+
For connecting to OAuth-protected MCP servers, see the [OAuth Authentication](https://mastra.ai/reference/v1/tools/mcp-client#oauth-authentication) section.
|
|
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 `.listTools()` in the `tools` parameter. This loads from the defined MCP servers, making them available to the agent.
|
|
@@ -103,6 +107,10 @@ export const testMcpServer = new MCPServer({
|
|
|
103
107
|
|
|
104
108
|
Visit [MCPServer](https://mastra.ai/reference/v1/tools/mcp-server) for a full list of configuration options.
|
|
105
109
|
|
|
110
|
+
> **Note:** Authentication
|
|
111
|
+
|
|
112
|
+
To protect your MCP server with OAuth, see the [OAuth Protection](https://mastra.ai/reference/v1/tools/mcp-server#oauth-protection) section.
|
|
113
|
+
|
|
106
114
|
### Serverless deployments
|
|
107
115
|
|
|
108
116
|
`MCPServer` can be deployed in serverless environments (Cloudflare Workers, Vercel Edge Functions, AWS Lambda, etc.) by enabling the `serverless: true` option in `startHTTP()`. This runs the server in stateless mode, where each request is handled independently without session management.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
> Understand what tools are in Mastra, how to add them to agents, and best practices for designing effective tools.
|
|
2
2
|
|
|
3
3
|
> **Code References:**
|
|
4
|
-
- `createTool`: dist/tools/index.d.ts → dist/chunk-
|
|
5
|
-
- `Tool`: dist/tools/tool.d.ts → dist/chunk-
|
|
4
|
+
- `createTool`: dist/tools/index.d.ts → dist/chunk-N3PAHTKU.js:305
|
|
5
|
+
- `Tool`: dist/tools/tool.d.ts → dist/chunk-N3PAHTKU.js:115
|
|
6
6
|
|
|
7
7
|
# Using Tools
|
|
8
8
|
|
|
@@ -69,8 +69,8 @@ const advancedTools = () => {};
|
|
|
69
69
|
const baseTools = () => {};
|
|
70
70
|
|
|
71
71
|
export const testTool = createTool({
|
|
72
|
-
execute: async (
|
|
73
|
-
const userTier = requestContext
|
|
72
|
+
execute: async (inputData, context) => {
|
|
73
|
+
const userTier = context?.requestContext?.get("user-tier") as UserTier["user-tier"];
|
|
74
74
|
|
|
75
75
|
return userTier === "enterprise" ? advancedTools : baseTools;
|
|
76
76
|
},
|
|
@@ -26,7 +26,7 @@ import { LibSQLVector } from "@mastra/libsql";
|
|
|
26
26
|
// Create a new vector store instance
|
|
27
27
|
const store = new LibSQLVector({
|
|
28
28
|
id: 'libsql-vector',
|
|
29
|
-
|
|
29
|
+
url: process.env.DATABASE_URL,
|
|
30
30
|
// Optional: for Turso cloud databases
|
|
31
31
|
authToken: process.env.DATABASE_AUTH_TOKEN,
|
|
32
32
|
});
|
|
@@ -193,7 +193,7 @@ export const libsqlAgent = new Agent({
|
|
|
193
193
|
}),
|
|
194
194
|
vector: new LibSQLVector({
|
|
195
195
|
id: 'libsql-agent-vector',
|
|
196
|
-
|
|
196
|
+
url: "file:libsql-agent.db",
|
|
197
197
|
}),
|
|
198
198
|
embedder: fastembed,
|
|
199
199
|
options: {
|
|
@@ -202,9 +202,7 @@ export const libsqlAgent = new Agent({
|
|
|
202
202
|
topK: 3,
|
|
203
203
|
messageRange: 2,
|
|
204
204
|
},
|
|
205
|
-
|
|
206
|
-
generateTitle: true, // Explicitly enable automatic title generation
|
|
207
|
-
},
|
|
205
|
+
generateTitle: true, // Explicitly enable automatic title generation
|
|
208
206
|
},
|
|
209
207
|
}),
|
|
210
208
|
});
|
|
@@ -235,8 +233,23 @@ import { MongoDBVector } from "@mastra/mongodb";
|
|
|
235
233
|
|
|
236
234
|
const store = new MongoDBVector({
|
|
237
235
|
id: 'mongodb-vector',
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
uri: process.env.MONGODB_URI,
|
|
237
|
+
dbName: process.env.MONGODB_DATABASE,
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Custom Embedding Field Path
|
|
242
|
+
|
|
243
|
+
If you need to store embeddings in a nested field structure (e.g., to integrate with existing MongoDB collections), use the `embeddingFieldPath` option:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import { MongoDBVector } from "@mastra/mongodb";
|
|
247
|
+
|
|
248
|
+
const store = new MongoDBVector({
|
|
249
|
+
id: 'mongodb-vector',
|
|
250
|
+
uri: process.env.MONGODB_URI,
|
|
251
|
+
dbName: process.env.MONGODB_DATABASE,
|
|
252
|
+
embeddingFieldPath: 'text.contentEmbedding', // Store embeddings at text.contentEmbedding
|
|
240
253
|
});
|
|
241
254
|
```
|
|
242
255
|
|
|
@@ -370,10 +383,12 @@ export const mongodbAgent = new Agent({
|
|
|
370
383
|
model: "openai/gpt-5.1",
|
|
371
384
|
memory: new Memory({
|
|
372
385
|
storage: new MongoDBStore({
|
|
373
|
-
|
|
386
|
+
id: 'mongodb-storage',
|
|
387
|
+
uri: process.env.MONGODB_URI!,
|
|
374
388
|
dbName: process.env.MONGODB_DB_NAME!,
|
|
375
389
|
}),
|
|
376
390
|
vector: new MongoDBVector({
|
|
391
|
+
id: 'mongodb-vector',
|
|
377
392
|
uri: process.env.MONGODB_URI!,
|
|
378
393
|
dbName: process.env.MONGODB_DB_NAME!,
|
|
379
394
|
}),
|
|
@@ -384,9 +399,7 @@ export const mongodbAgent = new Agent({
|
|
|
384
399
|
topK: 3,
|
|
385
400
|
messageRange: 2,
|
|
386
401
|
},
|
|
387
|
-
|
|
388
|
-
generateTitle: true, // generates descriptive thread titles automatically
|
|
389
|
-
},
|
|
402
|
+
generateTitle: true, // generates descriptive thread titles automatically
|
|
390
403
|
},
|
|
391
404
|
}),
|
|
392
405
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
> Overview of voice capabilities in Mastra, including text-to-speech, speech-to-text, and real-time speech-to-speech interactions.
|
|
2
2
|
|
|
3
3
|
> **Code References:**
|
|
4
|
-
- `Agent`: dist/agent/agent.d.ts → dist/chunk-
|
|
5
|
-
- `CompositeVoice`: dist/voice/index.d.ts → dist/chunk-
|
|
4
|
+
- `Agent`: dist/agent/agent.d.ts → dist/chunk-UVOQLIWL.js:16630
|
|
5
|
+
- `CompositeVoice`: dist/voice/index.d.ts → dist/chunk-TX5GUG5Q.js:192
|
|
6
6
|
|
|
7
7
|
# Voice in Mastra
|
|
8
8
|
|
|
@@ -595,7 +595,7 @@ import { CompositeVoice } from "@mastra/core/voice";
|
|
|
595
595
|
import { OpenAIRealtimeVoice } from "@mastra/voice-openai-realtime";
|
|
596
596
|
const realtimeVoice = new OpenAIRealtimeVoice();
|
|
597
597
|
const voice = new CompositeVoice({
|
|
598
|
-
|
|
598
|
+
realtime: realtimeVoice,
|
|
599
599
|
});
|
|
600
600
|
// This will use the OpenAIRealtimeVoice provider
|
|
601
601
|
await voice.connect();
|
|
@@ -880,7 +880,7 @@ const speaker = new Speaker({
|
|
|
880
880
|
|
|
881
881
|
const realtimeVoice = new OpenAIRealtimeVoice();
|
|
882
882
|
const voice = new CompositeVoice({
|
|
883
|
-
|
|
883
|
+
realtime: realtimeVoice,
|
|
884
884
|
});
|
|
885
885
|
|
|
886
886
|
// Connect to the real-time service
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
> Workflows in Mastra help you orchestrate complex sequences of tasks with features like branching, parallel execution, resource suspension, and more.
|
|
2
2
|
|
|
3
3
|
> **Code References:**
|
|
4
|
-
- `createStep`: dist/workflows/index.d.ts → dist/chunk-
|
|
5
|
-
- `createWorkflow`: dist/workflows/index.d.ts → dist/chunk-
|
|
6
|
-
- `cloneWorkflow`: dist/workflows/index.d.ts → dist/chunk-
|
|
7
|
-
- `Mastra`: dist/mastra/index.d.ts → dist/chunk-
|
|
8
|
-
- `Workflow`: dist/workflows/workflow.d.ts → dist/chunk-
|
|
4
|
+
- `createStep`: dist/workflows/index.d.ts → dist/chunk-UVOQLIWL.js:7570
|
|
5
|
+
- `createWorkflow`: dist/workflows/index.d.ts → dist/chunk-UVOQLIWL.js:8230
|
|
6
|
+
- `cloneWorkflow`: dist/workflows/index.d.ts → dist/chunk-UVOQLIWL.js:8233
|
|
7
|
+
- `Mastra`: dist/mastra/index.d.ts → dist/chunk-IFPQ2MLB.js:24
|
|
8
|
+
- `Workflow`: dist/workflows/workflow.d.ts → dist/chunk-UVOQLIWL.js:8246
|
|
9
9
|
|
|
10
10
|
# Workflows overview
|
|
11
11
|
|
|
@@ -131,12 +131,10 @@ const step2 = createStep({
|
|
|
131
131
|
execute: async ({ inputData, requestContext }) => {
|
|
132
132
|
const { formatted } = inputData;
|
|
133
133
|
|
|
134
|
-
const response = await testTool.execute(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
requestContext,
|
|
139
|
-
});
|
|
134
|
+
const response = await testTool.execute(
|
|
135
|
+
{ text: formatted },
|
|
136
|
+
{ requestContext },
|
|
137
|
+
);
|
|
140
138
|
|
|
141
139
|
return {
|
|
142
140
|
emphasized: response.emphasized,
|