@mastra/mcp-docs-server 1.1.5 → 1.1.6-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/docs/agents/adding-voice.md +349 -0
- package/.docs/docs/agents/agent-approval.md +558 -0
- package/.docs/docs/agents/agent-memory.md +209 -0
- package/.docs/docs/agents/guardrails.md +374 -0
- package/.docs/docs/agents/network-approval.md +275 -0
- package/.docs/docs/agents/networks.md +299 -0
- package/.docs/docs/agents/overview.md +304 -0
- package/.docs/docs/agents/processors.md +622 -0
- package/.docs/docs/agents/structured-output.md +273 -0
- package/.docs/docs/agents/supervisor-agents.md +304 -0
- package/.docs/docs/agents/using-tools.md +214 -0
- package/.docs/docs/build-with-ai/mcp-docs-server.md +238 -0
- package/.docs/docs/build-with-ai/skills.md +35 -0
- package/.docs/docs/community/contributing-templates.md +3 -0
- package/.docs/docs/community/discord.md +9 -0
- package/.docs/docs/community/licensing.md +66 -0
- package/.docs/docs/deployment/cloud-providers.md +15 -0
- package/.docs/docs/deployment/mastra-server.md +122 -0
- package/.docs/docs/deployment/monorepo.md +142 -0
- package/.docs/docs/deployment/overview.md +62 -0
- package/.docs/docs/deployment/studio.md +239 -0
- package/.docs/docs/deployment/web-framework.md +52 -0
- package/.docs/docs/deployment/workflow-runners.md +9 -0
- package/.docs/docs/evals/built-in-scorers.md +47 -0
- package/.docs/docs/evals/custom-scorers.md +519 -0
- package/.docs/docs/evals/overview.md +141 -0
- package/.docs/docs/evals/running-in-ci.md +124 -0
- package/.docs/docs/getting-started/build-with-ai.md +68 -0
- package/.docs/docs/getting-started/manual-install.md +226 -0
- package/.docs/docs/getting-started/project-structure.md +60 -0
- package/.docs/docs/getting-started/start.md +28 -0
- package/.docs/docs/getting-started/studio.md +101 -0
- package/.docs/docs/index.md +43 -0
- package/.docs/docs/mastra-cloud/deployment.md +77 -0
- package/.docs/docs/mastra-cloud/observability.md +38 -0
- package/.docs/docs/mastra-cloud/overview.md +23 -0
- package/.docs/docs/mastra-cloud/setup.md +42 -0
- package/.docs/docs/mastra-cloud/studio.md +24 -0
- package/.docs/docs/mastra-code/configuration.md +299 -0
- package/.docs/docs/mastra-code/customization.md +228 -0
- package/.docs/docs/mastra-code/modes.md +104 -0
- package/.docs/docs/mastra-code/overview.md +135 -0
- package/.docs/docs/mastra-code/tools.md +229 -0
- package/.docs/docs/mcp/overview.md +373 -0
- package/.docs/docs/mcp/publishing-mcp-server.md +95 -0
- package/.docs/docs/memory/memory-processors.md +314 -0
- package/.docs/docs/memory/message-history.md +260 -0
- package/.docs/docs/memory/observational-memory.md +248 -0
- package/.docs/docs/memory/overview.md +45 -0
- package/.docs/docs/memory/semantic-recall.md +272 -0
- package/.docs/docs/memory/storage.md +261 -0
- package/.docs/docs/memory/working-memory.md +400 -0
- package/.docs/docs/observability/datasets/overview.md +198 -0
- package/.docs/docs/observability/datasets/running-experiments.md +274 -0
- package/.docs/docs/observability/logging.md +99 -0
- package/.docs/docs/observability/overview.md +70 -0
- package/.docs/docs/observability/tracing/bridges/otel.md +209 -0
- package/.docs/docs/observability/tracing/exporters/arize.md +272 -0
- package/.docs/docs/observability/tracing/exporters/braintrust.md +111 -0
- package/.docs/docs/observability/tracing/exporters/cloud.md +127 -0
- package/.docs/docs/observability/tracing/exporters/datadog.md +187 -0
- package/.docs/docs/observability/tracing/exporters/default.md +209 -0
- package/.docs/docs/observability/tracing/exporters/laminar.md +100 -0
- package/.docs/docs/observability/tracing/exporters/langfuse.md +213 -0
- package/.docs/docs/observability/tracing/exporters/langsmith.md +198 -0
- package/.docs/docs/observability/tracing/exporters/otel.md +476 -0
- package/.docs/docs/observability/tracing/exporters/posthog.md +148 -0
- package/.docs/docs/observability/tracing/exporters/sentry.md +208 -0
- package/.docs/docs/observability/tracing/overview.md +1112 -0
- package/.docs/docs/observability/tracing/processors/sensitive-data-filter.md +300 -0
- package/.docs/docs/rag/chunking-and-embedding.md +183 -0
- package/.docs/docs/rag/graph-rag.md +215 -0
- package/.docs/docs/rag/overview.md +72 -0
- package/.docs/docs/rag/retrieval.md +515 -0
- package/.docs/docs/rag/vector-databases.md +645 -0
- package/.docs/docs/server/auth/auth0.md +220 -0
- package/.docs/docs/server/auth/better-auth.md +203 -0
- package/.docs/docs/server/auth/clerk.md +132 -0
- package/.docs/docs/server/auth/composite-auth.md +234 -0
- package/.docs/docs/server/auth/custom-auth-provider.md +513 -0
- package/.docs/docs/server/auth/firebase.md +272 -0
- package/.docs/docs/server/auth/jwt.md +110 -0
- package/.docs/docs/server/auth/simple-auth.md +180 -0
- package/.docs/docs/server/auth/supabase.md +117 -0
- package/.docs/docs/server/auth/workos.md +186 -0
- package/.docs/docs/server/auth.md +38 -0
- package/.docs/docs/server/custom-adapters.md +378 -0
- package/.docs/docs/server/custom-api-routes.md +267 -0
- package/.docs/docs/server/mastra-client.md +243 -0
- package/.docs/docs/server/mastra-server.md +71 -0
- package/.docs/docs/server/middleware.md +225 -0
- package/.docs/docs/server/request-context.md +471 -0
- package/.docs/docs/server/server-adapters.md +547 -0
- package/.docs/docs/streaming/events.md +237 -0
- package/.docs/docs/streaming/overview.md +175 -0
- package/.docs/docs/streaming/tool-streaming.md +175 -0
- package/.docs/docs/streaming/workflow-streaming.md +109 -0
- package/.docs/docs/voice/overview.md +959 -0
- package/.docs/docs/voice/speech-to-speech.md +102 -0
- package/.docs/docs/voice/speech-to-text.md +79 -0
- package/.docs/docs/voice/text-to-speech.md +83 -0
- package/.docs/docs/workflows/agents-and-tools.md +166 -0
- package/.docs/docs/workflows/control-flow.md +822 -0
- package/.docs/docs/workflows/error-handling.md +360 -0
- package/.docs/docs/workflows/human-in-the-loop.md +215 -0
- package/.docs/docs/workflows/overview.md +370 -0
- package/.docs/docs/workflows/snapshots.md +238 -0
- package/.docs/docs/workflows/suspend-and-resume.md +205 -0
- package/.docs/docs/workflows/time-travel.md +309 -0
- package/.docs/docs/workflows/workflow-state.md +181 -0
- package/.docs/docs/workspace/filesystem.md +164 -0
- package/.docs/docs/workspace/overview.md +239 -0
- package/.docs/docs/workspace/sandbox.md +63 -0
- package/.docs/docs/workspace/search.md +243 -0
- package/.docs/docs/workspace/skills.md +169 -0
- package/.docs/guides/agent-frameworks/ai-sdk.md +140 -0
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +1499 -0
- package/.docs/guides/build-your-ui/assistant-ui.md +156 -0
- package/.docs/guides/build-your-ui/copilotkit.md +289 -0
- package/.docs/guides/deployment/amazon-ec2.md +130 -0
- package/.docs/guides/deployment/aws-lambda.md +248 -0
- package/.docs/guides/deployment/azure-app-services.md +114 -0
- package/.docs/guides/deployment/cloudflare.md +99 -0
- package/.docs/guides/deployment/digital-ocean.md +168 -0
- package/.docs/guides/deployment/inngest.md +682 -0
- package/.docs/guides/deployment/netlify.md +77 -0
- package/.docs/guides/deployment/vercel.md +101 -0
- package/.docs/guides/getting-started/astro.md +398 -0
- package/.docs/guides/getting-started/electron.md +504 -0
- package/.docs/guides/getting-started/express.md +251 -0
- package/.docs/guides/getting-started/hono.md +190 -0
- package/.docs/guides/getting-started/next-js.md +347 -0
- package/.docs/guides/getting-started/nuxt.md +497 -0
- package/.docs/guides/getting-started/quickstart.md +67 -0
- package/.docs/guides/getting-started/sveltekit.md +296 -0
- package/.docs/guides/getting-started/vite-react.md +425 -0
- package/.docs/guides/guide/ai-recruiter.md +226 -0
- package/.docs/guides/guide/chef-michel.md +211 -0
- package/.docs/guides/guide/code-review-bot.md +226 -0
- package/.docs/guides/guide/dev-assistant.md +307 -0
- package/.docs/guides/guide/docs-manager.md +238 -0
- package/.docs/guides/guide/github-actions-pr-description.md +236 -0
- package/.docs/guides/guide/notes-mcp-server.md +416 -0
- package/.docs/guides/guide/research-assistant.md +348 -0
- package/.docs/guides/guide/research-coordinator.md +416 -0
- package/.docs/guides/guide/stock-agent.md +132 -0
- package/.docs/guides/guide/web-search.md +320 -0
- package/.docs/guides/guide/whatsapp-chat-bot.md +405 -0
- package/.docs/guides/index.md +3 -0
- package/.docs/guides/migrations/agentnetwork.md +97 -0
- package/.docs/guides/migrations/ai-sdk-v4-to-v5.md +112 -0
- package/.docs/guides/migrations/network-to-supervisor.md +261 -0
- package/.docs/guides/migrations/upgrade-to-v1/agent.md +404 -0
- package/.docs/guides/migrations/upgrade-to-v1/cli.md +57 -0
- package/.docs/guides/migrations/upgrade-to-v1/client.md +337 -0
- package/.docs/guides/migrations/upgrade-to-v1/deployment.md +37 -0
- package/.docs/guides/migrations/upgrade-to-v1/evals.md +239 -0
- package/.docs/guides/migrations/upgrade-to-v1/mastra.md +143 -0
- package/.docs/guides/migrations/upgrade-to-v1/mcp.md +97 -0
- package/.docs/guides/migrations/upgrade-to-v1/memory.md +285 -0
- package/.docs/guides/migrations/upgrade-to-v1/overview.md +119 -0
- package/.docs/guides/migrations/upgrade-to-v1/processors.md +68 -0
- package/.docs/guides/migrations/upgrade-to-v1/rag.md +42 -0
- package/.docs/guides/migrations/upgrade-to-v1/storage.md +553 -0
- package/.docs/guides/migrations/upgrade-to-v1/tools.md +180 -0
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +412 -0
- package/.docs/guides/migrations/upgrade-to-v1/vectors.md +87 -0
- package/.docs/guides/migrations/upgrade-to-v1/voice.md +30 -0
- package/.docs/guides/migrations/upgrade-to-v1/workflows.md +341 -0
- package/.docs/guides/migrations/vnext-to-standard-apis.md +362 -0
- package/.docs/models/embeddings.md +161 -0
- package/.docs/models/gateways/azure-openai.md +128 -0
- package/.docs/models/gateways/custom-gateways.md +545 -0
- package/.docs/models/gateways/netlify.md +88 -0
- package/.docs/models/gateways/openrouter.md +219 -0
- package/.docs/models/gateways/vercel.md +225 -0
- package/.docs/models/gateways.md +14 -0
- package/.docs/models/index.md +286 -0
- package/.docs/models/providers/302ai.md +134 -0
- package/.docs/models/providers/abacus.md +125 -0
- package/.docs/models/providers/agentrouter.md +90 -0
- package/.docs/models/providers/aihubmix.md +107 -0
- package/.docs/models/providers/alibaba-cn.md +135 -0
- package/.docs/models/providers/alibaba.md +111 -0
- package/.docs/models/providers/amazon-bedrock.md +33 -0
- package/.docs/models/providers/anthropic.md +153 -0
- package/.docs/models/providers/azure.md +33 -0
- package/.docs/models/providers/bailing.md +72 -0
- package/.docs/models/providers/baseten.md +77 -0
- package/.docs/models/providers/berget.md +78 -0
- package/.docs/models/providers/cerebras.md +101 -0
- package/.docs/models/providers/chutes.md +136 -0
- package/.docs/models/providers/cloudflare-ai-gateway.md +33 -0
- package/.docs/models/providers/cloudflare-workers-ai.md +109 -0
- package/.docs/models/providers/cohere.md +33 -0
- package/.docs/models/providers/cortecs.md +91 -0
- package/.docs/models/providers/deepinfra.md +112 -0
- package/.docs/models/providers/deepseek.md +88 -0
- package/.docs/models/providers/fastrouter.md +84 -0
- package/.docs/models/providers/fireworks-ai.md +89 -0
- package/.docs/models/providers/firmware.md +85 -0
- package/.docs/models/providers/friendli.md +78 -0
- package/.docs/models/providers/github-models.md +125 -0
- package/.docs/models/providers/google-vertex.md +33 -0
- package/.docs/models/providers/google.md +159 -0
- package/.docs/models/providers/groq.md +107 -0
- package/.docs/models/providers/helicone.md +161 -0
- package/.docs/models/providers/huggingface.md +90 -0
- package/.docs/models/providers/iflowcn.md +84 -0
- package/.docs/models/providers/inception.md +72 -0
- package/.docs/models/providers/inference.md +79 -0
- package/.docs/models/providers/io-intelligence.md +87 -0
- package/.docs/models/providers/io-net.md +87 -0
- package/.docs/models/providers/jiekou.md +131 -0
- package/.docs/models/providers/kilo.md +333 -0
- package/.docs/models/providers/kimi-for-coding.md +100 -0
- package/.docs/models/providers/kuae-cloud-coding-plan.md +71 -0
- package/.docs/models/providers/llama.md +77 -0
- package/.docs/models/providers/lmstudio.md +73 -0
- package/.docs/models/providers/lucidquery.md +72 -0
- package/.docs/models/providers/minimax-cn-coding-plan.md +102 -0
- package/.docs/models/providers/minimax-cn.md +102 -0
- package/.docs/models/providers/minimax-coding-plan.md +102 -0
- package/.docs/models/providers/minimax.md +104 -0
- package/.docs/models/providers/mistral.md +124 -0
- package/.docs/models/providers/moark.md +72 -0
- package/.docs/models/providers/modelscope.md +77 -0
- package/.docs/models/providers/moonshotai-cn.md +76 -0
- package/.docs/models/providers/moonshotai.md +76 -0
- package/.docs/models/providers/morph.md +73 -0
- package/.docs/models/providers/nano-gpt.md +103 -0
- package/.docs/models/providers/nebius.md +116 -0
- package/.docs/models/providers/nova.md +72 -0
- package/.docs/models/providers/novita-ai.md +154 -0
- package/.docs/models/providers/nvidia.md +141 -0
- package/.docs/models/providers/ollama-cloud.md +103 -0
- package/.docs/models/providers/ollama.md +33 -0
- package/.docs/models/providers/openai.md +193 -0
- package/.docs/models/providers/opencode.md +100 -0
- package/.docs/models/providers/ovhcloud.md +83 -0
- package/.docs/models/providers/perplexity.md +100 -0
- package/.docs/models/providers/poe.md +183 -0
- package/.docs/models/providers/privatemode-ai.md +75 -0
- package/.docs/models/providers/requesty.md +90 -0
- package/.docs/models/providers/scaleway.md +84 -0
- package/.docs/models/providers/siliconflow-cn.md +138 -0
- package/.docs/models/providers/siliconflow.md +140 -0
- package/.docs/models/providers/stackit.md +78 -0
- package/.docs/models/providers/stepfun.md +73 -0
- package/.docs/models/providers/submodel.md +79 -0
- package/.docs/models/providers/synthetic.md +96 -0
- package/.docs/models/providers/togetherai.md +115 -0
- package/.docs/models/providers/upstage.md +73 -0
- package/.docs/models/providers/venice.md +95 -0
- package/.docs/models/providers/vivgrid.md +106 -0
- package/.docs/models/providers/vultr.md +75 -0
- package/.docs/models/providers/wandb.md +80 -0
- package/.docs/models/providers/xai.md +141 -0
- package/.docs/models/providers/xiaomi.md +71 -0
- package/.docs/models/providers/zai-coding-plan.md +80 -0
- package/.docs/models/providers/zai.md +79 -0
- package/.docs/models/providers/zenmux.md +161 -0
- package/.docs/models/providers/zhipuai-coding-plan.md +79 -0
- package/.docs/models/providers/zhipuai.md +79 -0
- package/.docs/models/providers.md +81 -0
- package/.docs/reference/agents/agent.md +141 -0
- package/.docs/reference/agents/generate.md +186 -0
- package/.docs/reference/agents/generateLegacy.md +173 -0
- package/.docs/reference/agents/getDefaultGenerateOptions.md +36 -0
- package/.docs/reference/agents/getDefaultOptions.md +34 -0
- package/.docs/reference/agents/getDefaultStreamOptions.md +36 -0
- package/.docs/reference/agents/getDescription.md +21 -0
- package/.docs/reference/agents/getInstructions.md +34 -0
- package/.docs/reference/agents/getLLM.md +37 -0
- package/.docs/reference/agents/getMemory.md +34 -0
- package/.docs/reference/agents/getModel.md +34 -0
- package/.docs/reference/agents/getTools.md +29 -0
- package/.docs/reference/agents/getVoice.md +34 -0
- package/.docs/reference/agents/listAgents.md +35 -0
- package/.docs/reference/agents/listScorers.md +34 -0
- package/.docs/reference/agents/listTools.md +34 -0
- package/.docs/reference/agents/listWorkflows.md +34 -0
- package/.docs/reference/agents/network.md +133 -0
- package/.docs/reference/ai-sdk/chat-route.md +82 -0
- package/.docs/reference/ai-sdk/handle-chat-stream.md +53 -0
- package/.docs/reference/ai-sdk/handle-network-stream.md +37 -0
- package/.docs/reference/ai-sdk/handle-workflow-stream.md +55 -0
- package/.docs/reference/ai-sdk/network-route.md +74 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +231 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-v4-messages.md +79 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-v5-messages.md +76 -0
- package/.docs/reference/ai-sdk/with-mastra.md +59 -0
- package/.docs/reference/ai-sdk/workflow-route.md +79 -0
- package/.docs/reference/auth/auth0.md +73 -0
- package/.docs/reference/auth/better-auth.md +71 -0
- package/.docs/reference/auth/clerk.md +36 -0
- package/.docs/reference/auth/firebase.md +80 -0
- package/.docs/reference/auth/jwt.md +26 -0
- package/.docs/reference/auth/supabase.md +33 -0
- package/.docs/reference/auth/workos.md +84 -0
- package/.docs/reference/cli/create-mastra.md +137 -0
- package/.docs/reference/cli/mastra.md +336 -0
- package/.docs/reference/client-js/agents.md +437 -0
- package/.docs/reference/client-js/error-handling.md +16 -0
- package/.docs/reference/client-js/logs.md +24 -0
- package/.docs/reference/client-js/mastra-client.md +63 -0
- package/.docs/reference/client-js/memory.md +221 -0
- package/.docs/reference/client-js/observability.md +72 -0
- package/.docs/reference/client-js/telemetry.md +20 -0
- package/.docs/reference/client-js/tools.md +44 -0
- package/.docs/reference/client-js/vectors.md +79 -0
- package/.docs/reference/client-js/workflows.md +199 -0
- package/.docs/reference/configuration.md +752 -0
- package/.docs/reference/core/addGateway.md +42 -0
- package/.docs/reference/core/getAgent.md +21 -0
- package/.docs/reference/core/getAgentById.md +21 -0
- package/.docs/reference/core/getDeployer.md +22 -0
- package/.docs/reference/core/getGateway.md +38 -0
- package/.docs/reference/core/getGatewayById.md +41 -0
- package/.docs/reference/core/getLogger.md +22 -0
- package/.docs/reference/core/getMCPServer.md +47 -0
- package/.docs/reference/core/getMCPServerById.md +55 -0
- package/.docs/reference/core/getMemory.md +50 -0
- package/.docs/reference/core/getScorer.md +54 -0
- package/.docs/reference/core/getScorerById.md +54 -0
- package/.docs/reference/core/getServer.md +22 -0
- package/.docs/reference/core/getStorage.md +22 -0
- package/.docs/reference/core/getStoredAgentById.md +89 -0
- package/.docs/reference/core/getTelemetry.md +22 -0
- package/.docs/reference/core/getVector.md +22 -0
- package/.docs/reference/core/getWorkflow.md +42 -0
- package/.docs/reference/core/listAgents.md +21 -0
- package/.docs/reference/core/listGateways.md +40 -0
- package/.docs/reference/core/listLogs.md +38 -0
- package/.docs/reference/core/listLogsByRunId.md +36 -0
- package/.docs/reference/core/listMCPServers.md +55 -0
- package/.docs/reference/core/listMemory.md +56 -0
- package/.docs/reference/core/listScorers.md +29 -0
- package/.docs/reference/core/listStoredAgents.md +93 -0
- package/.docs/reference/core/listVectors.md +22 -0
- package/.docs/reference/core/listWorkflows.md +21 -0
- package/.docs/reference/core/mastra-class.md +66 -0
- package/.docs/reference/core/mastra-model-gateway.md +153 -0
- package/.docs/reference/core/setLogger.md +26 -0
- package/.docs/reference/core/setStorage.md +27 -0
- package/.docs/reference/datasets/addItem.md +37 -0
- package/.docs/reference/datasets/addItems.md +35 -0
- package/.docs/reference/datasets/compareExperiments.md +52 -0
- package/.docs/reference/datasets/create.md +51 -0
- package/.docs/reference/datasets/dataset.md +82 -0
- package/.docs/reference/datasets/datasets-manager.md +94 -0
- package/.docs/reference/datasets/delete.md +25 -0
- package/.docs/reference/datasets/deleteExperiment.md +27 -0
- package/.docs/reference/datasets/deleteItem.md +27 -0
- package/.docs/reference/datasets/deleteItems.md +29 -0
- package/.docs/reference/datasets/get.md +31 -0
- package/.docs/reference/datasets/getDetails.md +47 -0
- package/.docs/reference/datasets/getExperiment.md +30 -0
- package/.docs/reference/datasets/getItem.md +33 -0
- package/.docs/reference/datasets/getItemHistory.md +31 -0
- package/.docs/reference/datasets/list.md +31 -0
- package/.docs/reference/datasets/listExperimentResults.md +39 -0
- package/.docs/reference/datasets/listExperiments.md +33 -0
- package/.docs/reference/datasets/listItems.md +46 -0
- package/.docs/reference/datasets/listVersions.md +33 -0
- package/.docs/reference/datasets/startExperiment.md +62 -0
- package/.docs/reference/datasets/startExperimentAsync.md +43 -0
- package/.docs/reference/datasets/update.md +48 -0
- package/.docs/reference/datasets/updateItem.md +38 -0
- package/.docs/reference/deployer/cloudflare.md +79 -0
- package/.docs/reference/deployer/netlify.md +80 -0
- package/.docs/reference/deployer/vercel.md +91 -0
- package/.docs/reference/deployer.md +100 -0
- package/.docs/reference/evals/answer-relevancy.md +105 -0
- package/.docs/reference/evals/answer-similarity.md +99 -0
- package/.docs/reference/evals/bias.md +120 -0
- package/.docs/reference/evals/completeness.md +136 -0
- package/.docs/reference/evals/content-similarity.md +101 -0
- package/.docs/reference/evals/context-precision.md +196 -0
- package/.docs/reference/evals/context-relevance.md +531 -0
- package/.docs/reference/evals/create-scorer.md +270 -0
- package/.docs/reference/evals/faithfulness.md +114 -0
- package/.docs/reference/evals/hallucination.md +213 -0
- package/.docs/reference/evals/keyword-coverage.md +128 -0
- package/.docs/reference/evals/mastra-scorer.md +123 -0
- package/.docs/reference/evals/noise-sensitivity.md +675 -0
- package/.docs/reference/evals/prompt-alignment.md +614 -0
- package/.docs/reference/evals/run-evals.md +179 -0
- package/.docs/reference/evals/scorer-utils.md +326 -0
- package/.docs/reference/evals/textual-difference.md +113 -0
- package/.docs/reference/evals/tone-consistency.md +119 -0
- package/.docs/reference/evals/tool-call-accuracy.md +533 -0
- package/.docs/reference/evals/toxicity.md +123 -0
- package/.docs/reference/harness/harness-class.md +708 -0
- package/.docs/reference/index.md +277 -0
- package/.docs/reference/logging/pino-logger.md +117 -0
- package/.docs/reference/mastra-code/createMastraCode.md +108 -0
- package/.docs/reference/memory/clone-utilities.md +199 -0
- package/.docs/reference/memory/cloneThread.md +130 -0
- package/.docs/reference/memory/createThread.md +68 -0
- package/.docs/reference/memory/deleteMessages.md +38 -0
- package/.docs/reference/memory/getThreadById.md +24 -0
- package/.docs/reference/memory/listThreads.md +145 -0
- package/.docs/reference/memory/memory-class.md +147 -0
- package/.docs/reference/memory/observational-memory.md +565 -0
- package/.docs/reference/memory/recall.md +91 -0
- package/.docs/reference/observability/tracing/bridges/otel.md +131 -0
- package/.docs/reference/observability/tracing/configuration.md +178 -0
- package/.docs/reference/observability/tracing/exporters/arize.md +141 -0
- package/.docs/reference/observability/tracing/exporters/braintrust.md +93 -0
- package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +163 -0
- package/.docs/reference/observability/tracing/exporters/console-exporter.md +138 -0
- package/.docs/reference/observability/tracing/exporters/datadog.md +116 -0
- package/.docs/reference/observability/tracing/exporters/default-exporter.md +174 -0
- package/.docs/reference/observability/tracing/exporters/laminar.md +78 -0
- package/.docs/reference/observability/tracing/exporters/langfuse.md +134 -0
- package/.docs/reference/observability/tracing/exporters/langsmith.md +108 -0
- package/.docs/reference/observability/tracing/exporters/otel.md +199 -0
- package/.docs/reference/observability/tracing/exporters/posthog.md +92 -0
- package/.docs/reference/observability/tracing/exporters/sentry.md +184 -0
- package/.docs/reference/observability/tracing/instances.md +107 -0
- package/.docs/reference/observability/tracing/interfaces.md +743 -0
- package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +144 -0
- package/.docs/reference/observability/tracing/spans.md +224 -0
- package/.docs/reference/processors/batch-parts-processor.md +61 -0
- package/.docs/reference/processors/language-detector.md +82 -0
- package/.docs/reference/processors/message-history-processor.md +85 -0
- package/.docs/reference/processors/moderation-processor.md +104 -0
- package/.docs/reference/processors/pii-detector.md +108 -0
- package/.docs/reference/processors/processor-interface.md +521 -0
- package/.docs/reference/processors/prompt-injection-detector.md +72 -0
- package/.docs/reference/processors/semantic-recall-processor.md +117 -0
- package/.docs/reference/processors/system-prompt-scrubber.md +80 -0
- package/.docs/reference/processors/token-limiter-processor.md +115 -0
- package/.docs/reference/processors/tool-call-filter.md +85 -0
- package/.docs/reference/processors/tool-search-processor.md +111 -0
- package/.docs/reference/processors/unicode-normalizer.md +62 -0
- package/.docs/reference/processors/working-memory-processor.md +152 -0
- package/.docs/reference/rag/chunk.md +221 -0
- package/.docs/reference/rag/database-config.md +261 -0
- package/.docs/reference/rag/document.md +114 -0
- package/.docs/reference/rag/embeddings.md +92 -0
- package/.docs/reference/rag/extract-params.md +168 -0
- package/.docs/reference/rag/graph-rag.md +111 -0
- package/.docs/reference/rag/metadata-filters.md +216 -0
- package/.docs/reference/rag/rerank.md +75 -0
- package/.docs/reference/rag/rerankWithScorer.md +80 -0
- package/.docs/reference/server/create-route.md +262 -0
- package/.docs/reference/server/express-adapter.md +176 -0
- package/.docs/reference/server/fastify-adapter.md +90 -0
- package/.docs/reference/server/hono-adapter.md +162 -0
- package/.docs/reference/server/koa-adapter.md +127 -0
- package/.docs/reference/server/mastra-server.md +298 -0
- package/.docs/reference/server/register-api-route.md +249 -0
- package/.docs/reference/server/routes.md +306 -0
- package/.docs/reference/storage/cloudflare-d1.md +218 -0
- package/.docs/reference/storage/cloudflare.md +88 -0
- package/.docs/reference/storage/composite.md +235 -0
- package/.docs/reference/storage/convex.md +161 -0
- package/.docs/reference/storage/dynamodb.md +282 -0
- package/.docs/reference/storage/lance.md +131 -0
- package/.docs/reference/storage/libsql.md +135 -0
- package/.docs/reference/storage/mongodb.md +262 -0
- package/.docs/reference/storage/mssql.md +157 -0
- package/.docs/reference/storage/overview.md +121 -0
- package/.docs/reference/storage/postgresql.md +526 -0
- package/.docs/reference/storage/upstash.md +160 -0
- package/.docs/reference/streaming/ChunkType.md +292 -0
- package/.docs/reference/streaming/agents/MastraModelOutput.md +182 -0
- package/.docs/reference/streaming/agents/stream.md +221 -0
- package/.docs/reference/streaming/agents/streamLegacy.md +142 -0
- package/.docs/reference/streaming/workflows/observeStream.md +42 -0
- package/.docs/reference/streaming/workflows/resumeStream.md +61 -0
- package/.docs/reference/streaming/workflows/stream.md +88 -0
- package/.docs/reference/streaming/workflows/timeTravelStream.md +142 -0
- package/.docs/reference/templates/overview.md +194 -0
- package/.docs/reference/tools/create-tool.md +237 -0
- package/.docs/reference/tools/document-chunker-tool.md +89 -0
- package/.docs/reference/tools/graph-rag-tool.md +182 -0
- package/.docs/reference/tools/mcp-client.md +954 -0
- package/.docs/reference/tools/mcp-server.md +1271 -0
- package/.docs/reference/tools/vector-query-tool.md +459 -0
- package/.docs/reference/vectors/astra.md +121 -0
- package/.docs/reference/vectors/chroma.md +264 -0
- package/.docs/reference/vectors/convex.md +300 -0
- package/.docs/reference/vectors/couchbase.md +226 -0
- package/.docs/reference/vectors/duckdb.md +318 -0
- package/.docs/reference/vectors/elasticsearch.md +189 -0
- package/.docs/reference/vectors/lance.md +220 -0
- package/.docs/reference/vectors/libsql.md +305 -0
- package/.docs/reference/vectors/mongodb.md +295 -0
- package/.docs/reference/vectors/opensearch.md +99 -0
- package/.docs/reference/vectors/pg.md +408 -0
- package/.docs/reference/vectors/pinecone.md +168 -0
- package/.docs/reference/vectors/qdrant.md +222 -0
- package/.docs/reference/vectors/s3vectors.md +277 -0
- package/.docs/reference/vectors/turbopuffer.md +157 -0
- package/.docs/reference/vectors/upstash.md +294 -0
- package/.docs/reference/vectors/vectorize.md +147 -0
- package/.docs/reference/voice/azure.md +148 -0
- package/.docs/reference/voice/cloudflare.md +83 -0
- package/.docs/reference/voice/composite-voice.md +121 -0
- package/.docs/reference/voice/deepgram.md +79 -0
- package/.docs/reference/voice/elevenlabs.md +98 -0
- package/.docs/reference/voice/google-gemini-live.md +378 -0
- package/.docs/reference/voice/google.md +228 -0
- package/.docs/reference/voice/mastra-voice.md +311 -0
- package/.docs/reference/voice/murf.md +122 -0
- package/.docs/reference/voice/openai-realtime.md +203 -0
- package/.docs/reference/voice/openai.md +88 -0
- package/.docs/reference/voice/playai.md +80 -0
- package/.docs/reference/voice/sarvam.md +126 -0
- package/.docs/reference/voice/speechify.md +75 -0
- package/.docs/reference/voice/voice.addInstructions.md +55 -0
- package/.docs/reference/voice/voice.addTools.md +67 -0
- package/.docs/reference/voice/voice.answer.md +54 -0
- package/.docs/reference/voice/voice.close.md +51 -0
- package/.docs/reference/voice/voice.connect.md +94 -0
- package/.docs/reference/voice/voice.events.md +37 -0
- package/.docs/reference/voice/voice.getSpeakers.md +129 -0
- package/.docs/reference/voice/voice.listen.md +164 -0
- package/.docs/reference/voice/voice.off.md +54 -0
- package/.docs/reference/voice/voice.on.md +111 -0
- package/.docs/reference/voice/voice.send.md +65 -0
- package/.docs/reference/voice/voice.speak.md +157 -0
- package/.docs/reference/voice/voice.updateConfig.md +60 -0
- package/.docs/reference/workflows/run-methods/cancel.md +86 -0
- package/.docs/reference/workflows/run-methods/restart.md +33 -0
- package/.docs/reference/workflows/run-methods/resume.md +59 -0
- package/.docs/reference/workflows/run-methods/start.md +58 -0
- package/.docs/reference/workflows/run-methods/startAsync.md +67 -0
- package/.docs/reference/workflows/run-methods/timeTravel.md +142 -0
- package/.docs/reference/workflows/run.md +59 -0
- package/.docs/reference/workflows/step.md +119 -0
- package/.docs/reference/workflows/workflow-methods/branch.md +25 -0
- package/.docs/reference/workflows/workflow-methods/commit.md +17 -0
- package/.docs/reference/workflows/workflow-methods/create-run.md +63 -0
- package/.docs/reference/workflows/workflow-methods/dountil.md +25 -0
- package/.docs/reference/workflows/workflow-methods/dowhile.md +25 -0
- package/.docs/reference/workflows/workflow-methods/foreach.md +118 -0
- package/.docs/reference/workflows/workflow-methods/map.md +93 -0
- package/.docs/reference/workflows/workflow-methods/parallel.md +21 -0
- package/.docs/reference/workflows/workflow-methods/sleep.md +35 -0
- package/.docs/reference/workflows/workflow-methods/sleepUntil.md +35 -0
- package/.docs/reference/workflows/workflow-methods/then.md +21 -0
- package/.docs/reference/workflows/workflow.md +157 -0
- package/.docs/reference/workspace/e2b-sandbox.md +289 -0
- package/.docs/reference/workspace/filesystem.md +255 -0
- package/.docs/reference/workspace/gcs-filesystem.md +174 -0
- package/.docs/reference/workspace/local-filesystem.md +343 -0
- package/.docs/reference/workspace/local-sandbox.md +301 -0
- package/.docs/reference/workspace/s3-filesystem.md +175 -0
- package/.docs/reference/workspace/sandbox.md +87 -0
- package/.docs/reference/workspace/workspace-class.md +244 -0
- package/CHANGELOG.md +8 -0
- package/package.json +5 -5
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# MastraAuthAuth0 Class
|
|
2
|
+
|
|
3
|
+
The `MastraAuthAuth0` class provides authentication for Mastra using Auth0. It verifies incoming requests using Auth0-issued JWT tokens and integrates with the Mastra server using the `auth` option.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
This example uses Auth0 authentication. Make sure to:
|
|
8
|
+
|
|
9
|
+
1. Create an Auth0 account at [auth0.com](https://auth0.com/)
|
|
10
|
+
2. Set up an Application in your Auth0 Dashboard
|
|
11
|
+
3. Configure an API in your Auth0 Dashboard with an identifier (audience)
|
|
12
|
+
4. Configure your application's allowed callback URLs, web origins, and logout URLs
|
|
13
|
+
|
|
14
|
+
```env
|
|
15
|
+
AUTH0_DOMAIN=your-tenant.auth0.com
|
|
16
|
+
AUTH0_AUDIENCE=your-api-identifier
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
> **Note:** You can find your domain in the Auth0 Dashboard under Applications > Settings. The audience is the identifier of your API configured in Auth0 Dashboard > APIs.
|
|
20
|
+
>
|
|
21
|
+
> For detailed setup instructions, refer to the [Auth0 quickstarts](https://auth0.com/docs/quickstarts) for your specific platform.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
Before you can use the `MastraAuthAuth0` class you have to install the `@mastra/auth-auth0` package.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @mastra/auth-auth0@latest
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage examples
|
|
32
|
+
|
|
33
|
+
### Basic usage with environment variables
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { Mastra } from '@mastra/core'
|
|
37
|
+
import { MastraAuthAuth0 } from '@mastra/auth-auth0'
|
|
38
|
+
|
|
39
|
+
export const mastra = new Mastra({
|
|
40
|
+
server: {
|
|
41
|
+
auth: new MastraAuthAuth0(),
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Custom configuration
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Mastra } from '@mastra/core'
|
|
50
|
+
import { MastraAuthAuth0 } from '@mastra/auth-auth0'
|
|
51
|
+
|
|
52
|
+
export const mastra = new Mastra({
|
|
53
|
+
server: {
|
|
54
|
+
auth: new MastraAuthAuth0({
|
|
55
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
56
|
+
audience: process.env.AUTH0_AUDIENCE,
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Configuration
|
|
63
|
+
|
|
64
|
+
### User Authorization
|
|
65
|
+
|
|
66
|
+
By default, `MastraAuthAuth0` allows all authenticated users who have valid Auth0 tokens for the specified audience. The token verification ensures that:
|
|
67
|
+
|
|
68
|
+
1. The token is properly signed by Auth0
|
|
69
|
+
2. The token is not expired
|
|
70
|
+
3. The token audience matches your configured audience
|
|
71
|
+
4. The token issuer matches your Auth0 domain
|
|
72
|
+
|
|
73
|
+
To customize user authorization, provide a custom `authorizeUser` function:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { MastraAuthAuth0 } from '@mastra/auth-auth0'
|
|
77
|
+
|
|
78
|
+
const auth0Provider = new MastraAuthAuth0({
|
|
79
|
+
authorizeUser: async user => {
|
|
80
|
+
// Custom authorization logic
|
|
81
|
+
return user.email?.endsWith('@yourcompany.com') || false
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
> **Info:** Visit [MastraAuthAuth0](https://mastra.ai/reference/auth/auth0) for all available configuration options.
|
|
87
|
+
|
|
88
|
+
## Client-side setup
|
|
89
|
+
|
|
90
|
+
When using Auth0 auth, you'll need to set up the Auth0 React SDK, authenticate users, and retrieve their access tokens to pass to your Mastra requests.
|
|
91
|
+
|
|
92
|
+
### Setting up Auth0 React SDK
|
|
93
|
+
|
|
94
|
+
First, install and configure the Auth0 React SDK in your application:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm install @auth0/auth0-react
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import React from 'react'
|
|
102
|
+
import { Auth0Provider } from '@auth0/auth0-react'
|
|
103
|
+
|
|
104
|
+
const Auth0ProviderWithHistory = ({ children }) => {
|
|
105
|
+
return (
|
|
106
|
+
<Auth0Provider
|
|
107
|
+
domain={process.env.REACT_APP_AUTH0_DOMAIN}
|
|
108
|
+
clientId={process.env.REACT_APP_AUTH0_CLIENT_ID}
|
|
109
|
+
authorizationParams={{
|
|
110
|
+
redirect_uri: window.location.origin,
|
|
111
|
+
audience: process.env.REACT_APP_AUTH0_AUDIENCE,
|
|
112
|
+
scope: 'read:current_user update:current_user_metadata',
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
{children}
|
|
116
|
+
</Auth0Provider>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default Auth0ProviderWithHistory
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Retrieving access tokens
|
|
124
|
+
|
|
125
|
+
Use the Auth0 React SDK to authenticate users and retrieve their access tokens:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { useAuth0 } from '@auth0/auth0-react'
|
|
129
|
+
|
|
130
|
+
export const useAuth0Token = () => {
|
|
131
|
+
const { getAccessTokenSilently } = useAuth0()
|
|
132
|
+
|
|
133
|
+
const getAccessToken = async () => {
|
|
134
|
+
const token = await getAccessTokenSilently()
|
|
135
|
+
return token
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return { getAccessToken }
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
> **Note:** Refer to the [Auth0 React SDK documentation](https://auth0.com/docs/libraries/auth0-react) for more authentication methods and configuration options.
|
|
143
|
+
|
|
144
|
+
## Configuring `MastraClient`
|
|
145
|
+
|
|
146
|
+
When `auth` is enabled, all requests made with `MastraClient` must include a valid Auth0 access token in the `Authorization` header:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { MastraClient } from '@mastra/client-js'
|
|
150
|
+
|
|
151
|
+
export const createMastraClient = (accessToken: string) => {
|
|
152
|
+
return new MastraClient({
|
|
153
|
+
baseUrl: 'https://<mastra-api-url>',
|
|
154
|
+
headers: {
|
|
155
|
+
Authorization: `Bearer ${accessToken}`,
|
|
156
|
+
},
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
> **Info:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
162
|
+
>
|
|
163
|
+
> Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
|
|
164
|
+
|
|
165
|
+
### Making authenticated requests
|
|
166
|
+
|
|
167
|
+
Once `MastraClient` is configured with the Auth0 access token, you can send authenticated requests:
|
|
168
|
+
|
|
169
|
+
**React**:
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
import React, { useState } from 'react'
|
|
173
|
+
import { useAuth0 } from '@auth0/auth0-react'
|
|
174
|
+
import { MastraClient } from '@mastra/client-js'
|
|
175
|
+
|
|
176
|
+
export const MastraApiTest = () => {
|
|
177
|
+
const { getAccessTokenSilently } = useAuth0()
|
|
178
|
+
const [result, setResult] = useState(null)
|
|
179
|
+
|
|
180
|
+
const callMastraApi = async () => {
|
|
181
|
+
const token = await getAccessTokenSilently()
|
|
182
|
+
|
|
183
|
+
const mastra = new MastraClient({
|
|
184
|
+
baseUrl: 'http://localhost:4111',
|
|
185
|
+
headers: {
|
|
186
|
+
Authorization: `Bearer ${token}`,
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
const weatherAgent = mastra.getAgent('weatherAgent')
|
|
191
|
+
const response = await weatherAgent.generate("What's the weather like in New York")
|
|
192
|
+
|
|
193
|
+
setResult(response.text)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<div>
|
|
198
|
+
<button onClick={callMastraApi}>Test Mastra API</button>
|
|
199
|
+
|
|
200
|
+
{result && (
|
|
201
|
+
<div className="result">
|
|
202
|
+
<h6>Result:</h6>
|
|
203
|
+
<pre>{result}</pre>
|
|
204
|
+
</div>
|
|
205
|
+
)}
|
|
206
|
+
</div>
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**cURL**:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
215
|
+
-H "Content-Type: application/json" \
|
|
216
|
+
-H "Authorization: Bearer <your-auth0-access-token>" \
|
|
217
|
+
-d '{
|
|
218
|
+
"messages": "Weather in London"
|
|
219
|
+
}'
|
|
220
|
+
```
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# MastraAuthBetterAuth Class
|
|
2
|
+
|
|
3
|
+
The `MastraAuthBetterAuth` class provides authentication for Mastra using Better Auth. It verifies incoming requests using your Better Auth instance and integrates with the Mastra server via the `server.auth` option.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
This example uses Better Auth. Make sure your Better Auth instance is configured and your environment variables are set.
|
|
8
|
+
|
|
9
|
+
```env
|
|
10
|
+
# Required by Better Auth
|
|
11
|
+
BETTER_AUTH_SECRET=... # at least 32 chars
|
|
12
|
+
BETTER_AUTH_URL=http://localhost:3000
|
|
13
|
+
|
|
14
|
+
# Example DB URL used by the snippet below (adjust for your setup)
|
|
15
|
+
DATABASE_URL=postgres://...
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
> **Note:** Better Auth recommends setting `baseURL` explicitly (or via `BETTER_AUTH_URL`) for security and stability.
|
|
19
|
+
|
|
20
|
+
If you haven't mounted Better Auth's handler yet (so your app can sign users in / create sessions), follow the [Better Auth installation guide](https://www.better-auth.com/docs/installation) to mount the `/api/auth/*` route (or your configured base path).
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
Install the `@mastra/auth-better-auth` package:
|
|
25
|
+
|
|
26
|
+
**npm**:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @mastra/auth-better-auth
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**pnpm**:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm add @mastra/auth-better-auth
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Yarn**:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
yarn add @mastra/auth-better-auth
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Bun**:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
bun add @mastra/auth-better-auth
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage example
|
|
51
|
+
|
|
52
|
+
First, create your Better Auth instance:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { betterAuth } from 'better-auth'
|
|
56
|
+
|
|
57
|
+
export const auth = betterAuth({
|
|
58
|
+
database: {
|
|
59
|
+
provider: 'postgresql',
|
|
60
|
+
url: process.env.DATABASE_URL!,
|
|
61
|
+
},
|
|
62
|
+
emailAndPassword: {
|
|
63
|
+
enabled: true,
|
|
64
|
+
},
|
|
65
|
+
baseURL: process.env.BETTER_AUTH_URL,
|
|
66
|
+
secret: process.env.BETTER_AUTH_SECRET,
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Then, use it with Mastra:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { Mastra } from '@mastra/core'
|
|
74
|
+
import { MastraAuthBetterAuth } from '@mastra/auth-better-auth'
|
|
75
|
+
import { auth } from '@/lib/auth'
|
|
76
|
+
|
|
77
|
+
const mastraAuth = new MastraAuthBetterAuth({
|
|
78
|
+
auth,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
export const mastra = new Mastra({
|
|
82
|
+
server: {
|
|
83
|
+
auth: mastraAuth,
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
> **Info:** Visit [MastraAuthBetterAuth](https://mastra.ai/reference/auth/better-auth) for all available configuration options.
|
|
89
|
+
|
|
90
|
+
## Custom authorization
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
const mastraAuth = new MastraAuthBetterAuth({
|
|
94
|
+
auth,
|
|
95
|
+
async authorizeUser(user) {
|
|
96
|
+
// Example: only allow verified emails
|
|
97
|
+
return user?.user?.emailVerified === true
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Route configuration
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const mastraAuth = new MastraAuthBetterAuth({
|
|
106
|
+
auth,
|
|
107
|
+
public: ['/health', '/api/status'],
|
|
108
|
+
protected: ['/api/*', '/admin/*'],
|
|
109
|
+
})
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Matching rules
|
|
113
|
+
|
|
114
|
+
- `public` and `protected` accept exact paths, wildcard patterns (like `/api/*`), and path params (like `/users/:id`).
|
|
115
|
+
- For method-specific rules, use tuples like `["/api/agents", ["GET", "POST"]]`.
|
|
116
|
+
- If a route matches both `public` and `protected`, `public` wins and no auth is required.
|
|
117
|
+
- If neither matches, routes are treated as protected by default (unless a route is explicitly marked `requiresAuth: false`).
|
|
118
|
+
|
|
119
|
+
## Client-side setup
|
|
120
|
+
|
|
121
|
+
When auth is enabled, requests to Mastra's built-in routes require authentication. In practice, that means your client needs to send whatever credential your Better Auth setup uses for authenticated requests.
|
|
122
|
+
|
|
123
|
+
### Cookie session (recommended)
|
|
124
|
+
|
|
125
|
+
If your Better Auth setup uses cookies, configure the client to send credentials and ensure your Mastra server CORS allows credentials for cross-origin requests.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { MastraClient } from '@mastra/client-js'
|
|
129
|
+
|
|
130
|
+
export const mastraClient = new MastraClient({
|
|
131
|
+
baseUrl: 'http://localhost:4111',
|
|
132
|
+
credentials: 'include',
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
If you are calling the API directly, include credentials in `fetch` as well:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
await fetch('http://localhost:4111/api/agents/weatherAgent/generate', {
|
|
140
|
+
method: 'POST',
|
|
141
|
+
headers: {
|
|
142
|
+
'Content-Type': 'application/json',
|
|
143
|
+
},
|
|
144
|
+
credentials: 'include',
|
|
145
|
+
body: JSON.stringify({ messages: 'Weather in London' }),
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Bearer token
|
|
150
|
+
|
|
151
|
+
If your Better Auth setup issues bearer tokens, include them in the `Authorization` header:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { MastraClient } from '@mastra/client-js'
|
|
155
|
+
|
|
156
|
+
export const mastraClient = new MastraClient({
|
|
157
|
+
baseUrl: 'http://localhost:4111',
|
|
158
|
+
headers: {
|
|
159
|
+
Authorization: `Bearer ${accessToken}`,
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
> **Info:** Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
|
|
165
|
+
|
|
166
|
+
### Making authenticated requests
|
|
167
|
+
|
|
168
|
+
**React**:
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { mastraClient } from '../lib/mastra-client'
|
|
172
|
+
|
|
173
|
+
export const TestAgent = () => {
|
|
174
|
+
async function handleClick() {
|
|
175
|
+
const agent = mastraClient.getAgent('weatherAgent')
|
|
176
|
+
|
|
177
|
+
const response = await agent.generate('Weather in London')
|
|
178
|
+
|
|
179
|
+
console.log(response)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return <button onClick={handleClick}>Test Agent</button>
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**cURL**:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
190
|
+
-H "Content-Type: application/json" \
|
|
191
|
+
-H "Authorization: Bearer <your-token>" \
|
|
192
|
+
-d '{
|
|
193
|
+
"messages": "Weather in London"
|
|
194
|
+
}'
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Troubleshooting
|
|
198
|
+
|
|
199
|
+
- **401/403 on every request**: confirm your Better Auth handler is mounted and your app can create a valid session/token.
|
|
200
|
+
- **Cookies not sent**: set `credentials: "include"` in `MastraClient` and enable CORS credentials on the Mastra server.
|
|
201
|
+
- **Authorization header missing**: ensure the client attaches `Authorization: Bearer <token>` when using bearer tokens.
|
|
202
|
+
- **Base URL issues**: set `baseURL` in `betterAuth({ ... })` or set `BETTER_AUTH_URL`.
|
|
203
|
+
- **DB connection errors**: verify `DATABASE_URL` and database provider configuration.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# MastraAuthClerk Class
|
|
2
|
+
|
|
3
|
+
The `MastraAuthClerk` class provides authentication for Mastra using Clerk. It verifies incoming requests using Clerk's authentication system and integrates with the Mastra server using the `auth` option.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
This example uses Clerk authentication. Make sure to add your Clerk credentials to your `.env` file and ensure your Clerk project is properly configured.
|
|
8
|
+
|
|
9
|
+
```env
|
|
10
|
+
CLERK_PUBLISHABLE_KEY=pk_test_...
|
|
11
|
+
CLERK_SECRET_KEY=sk_test_...
|
|
12
|
+
CLERK_JWKS_URI=https://your-clerk-domain.clerk.accounts.dev/.well-known/jwks.json
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
> **Note:** You can find these keys in your Clerk Dashboard under "API Keys".
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Before you can use the `MastraAuthClerk` class you have to install the `@mastra/auth-clerk` package.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @mastra/auth-clerk@latest
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage example
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Mastra } from '@mastra/core'
|
|
29
|
+
import { MastraAuthClerk } from '@mastra/auth-clerk'
|
|
30
|
+
|
|
31
|
+
export const mastra = new Mastra({
|
|
32
|
+
server: {
|
|
33
|
+
auth: new MastraAuthClerk({
|
|
34
|
+
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
|
|
35
|
+
secretKey: process.env.CLERK_SECRET_KEY,
|
|
36
|
+
jwksUri: process.env.CLERK_JWKS_URI,
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
> **Info:** The default `authorizeUser` method allows all authenticated users. To customize user authorization, provide a custom `authorizeUser` function when constructing the provider.
|
|
43
|
+
>
|
|
44
|
+
> Visit [MastraAuthClerk](https://mastra.ai/reference/auth/clerk) for all available configuration options.
|
|
45
|
+
|
|
46
|
+
## Client-side setup
|
|
47
|
+
|
|
48
|
+
When using Clerk auth, you'll need to retrieve the access token from Clerk on the client side and pass it to your Mastra requests.
|
|
49
|
+
|
|
50
|
+
### Retrieving the access token
|
|
51
|
+
|
|
52
|
+
Use the Clerk React hooks to authenticate users and retrieve their access token:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { useAuth } from '@clerk/nextjs'
|
|
56
|
+
|
|
57
|
+
export const useClerkAuth = () => {
|
|
58
|
+
const { getToken } = useAuth()
|
|
59
|
+
|
|
60
|
+
const getAccessToken = async () => {
|
|
61
|
+
const token = await getToken()
|
|
62
|
+
return token
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { getAccessToken }
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
> **Info:** Refer to the [Clerk documentation](https://clerk.com/docs) for more information.
|
|
70
|
+
|
|
71
|
+
## Configuring `MastraClient`
|
|
72
|
+
|
|
73
|
+
When `auth` is enabled, all requests made with `MastraClient` must include a valid Clerk access token in the `Authorization` header:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { MastraClient } from '@mastra/client-js'
|
|
77
|
+
|
|
78
|
+
export const mastraClient = new MastraClient({
|
|
79
|
+
baseUrl: 'https://<mastra-api-url>',
|
|
80
|
+
headers: {
|
|
81
|
+
Authorization: `Bearer ${accessToken}`,
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
> **Info:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
87
|
+
>
|
|
88
|
+
> Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
|
|
89
|
+
|
|
90
|
+
### Making authenticated requests
|
|
91
|
+
|
|
92
|
+
Once `MastraClient` is configured with the Clerk access token, you can send authenticated requests:
|
|
93
|
+
|
|
94
|
+
**React**:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
'use client'
|
|
98
|
+
|
|
99
|
+
import { useAuth } from '@clerk/nextjs'
|
|
100
|
+
import { MastraClient } from '@mastra/client-js'
|
|
101
|
+
|
|
102
|
+
export const TestAgent = () => {
|
|
103
|
+
const { getToken } = useAuth()
|
|
104
|
+
|
|
105
|
+
async function handleClick() {
|
|
106
|
+
const token = await getToken()
|
|
107
|
+
|
|
108
|
+
const client = new MastraClient({
|
|
109
|
+
baseUrl: 'http://localhost:4111',
|
|
110
|
+
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const weatherAgent = client.getAgent('weatherAgent')
|
|
114
|
+
const response = await weatherAgent.generate("What's the weather like in New York")
|
|
115
|
+
|
|
116
|
+
console.log({ response })
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return <button onClick={handleClick}>Test Agent</button>
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**cURL**:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
127
|
+
-H "Content-Type: application/json" \
|
|
128
|
+
-H "Authorization: Bearer <your-clerk-access-token>" \
|
|
129
|
+
-d '{
|
|
130
|
+
"messages": "Weather in London"
|
|
131
|
+
}'
|
|
132
|
+
```
|