@mastra/mcp-docs-server 1.3.12 → 1.3.13-alpha.10
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/resumable-streams.md +140 -0
- package/.docs/docs/agents/tools.md +3 -2
- package/.docs/docs/auth/overview.md +1 -0
- package/.docs/docs/auth/simple-auth.md +8 -8
- package/.docs/docs/channels.md +34 -1
- package/.docs/docs/connections/mcp.md +73 -7
- package/.docs/docs/deployment/mastra-server.md +10 -2
- package/.docs/docs/deployment/workers.md +3 -1
- package/.docs/docs/guides/authentication-identity.md +4 -0
- package/.docs/docs/harness/background-tasks.md +2 -1
- package/.docs/docs/harness/durable-agents.md +106 -8
- package/.docs/docs/harness/goals.md +1 -1
- package/.docs/docs/harness/schedules.md +2 -0
- package/.docs/docs/knowledge/agents-and-tools.md +122 -0
- package/.docs/docs/knowledge/load-your-content.md +86 -0
- package/.docs/docs/knowledge/overview.md +106 -0
- package/.docs/docs/knowledge/patterns.md +167 -0
- package/.docs/docs/knowledge/pinned-context.md +177 -0
- package/.docs/docs/knowledge/scopes-and-access.md +202 -0
- package/.docs/docs/knowledge/search.md +63 -0
- package/.docs/docs/mastra-platform/connect.md +231 -0
- package/.docs/docs/mastra-platform/overview.md +1 -1
- package/.docs/docs/memory/observational-memory.md +23 -23
- package/.docs/docs/memory/overview.md +19 -7
- package/.docs/docs/memory/semantic-recall.md +26 -1
- package/.docs/docs/observability/integrations/exporters/mastra-storage.md +41 -0
- package/.docs/docs/observability/tracing/overview.md +0 -2
- package/.docs/docs/sandbox/skills.md +32 -3
- package/.docs/docs/server/custom-adapters.md +44 -11
- package/.docs/docs/server/middleware.md +1 -1
- package/.docs/docs/server/request-context.md +6 -6
- package/.docs/docs/server/server-adapters.md +12 -12
- package/.docs/docs/signals/sending-signals.md +3 -1
- package/.docs/docs/studio/knowledge.md +45 -24
- package/.docs/docs/studio/overview.md +3 -1
- package/.docs/docs/workflows/overview.md +12 -0
- package/.docs/docs/workflows/suspend-and-resume.md +1 -1
- package/.docs/integrations/agentic-ui/ai-sdk-ui.md +46 -0
- package/.docs/integrations/auth/clerk.md +46 -7
- package/.docs/integrations/auth/neon.md +217 -0
- package/.docs/integrations/auth/supabase.md +46 -7
- package/.docs/integrations/auth/workos.md +54 -15
- package/.docs/integrations/channels/discord.md +84 -6
- package/.docs/integrations/channels/github.md +63 -24
- package/.docs/integrations/channels/slack.md +89 -8
- package/.docs/integrations/channels/teams.md +79 -5
- package/.docs/integrations/channels/telegram.md +47 -6
- package/.docs/integrations/crm/attio.md +42 -0
- package/.docs/integrations/crm/clay.md +42 -0
- package/.docs/integrations/crm/hubspot.md +41 -0
- package/.docs/integrations/databases/neon.md +37 -1
- package/.docs/integrations/databases/postgresql.md +46 -0
- package/.docs/integrations/deploy/render.md +59 -18
- package/.docs/integrations/deploy/temporal.md +74 -0
- package/.docs/integrations/documents/google-docs.md +41 -0
- package/.docs/integrations/documents/google-sheet.md +41 -0
- package/.docs/integrations/documents/microsoft-excel.md +43 -0
- package/.docs/integrations/documents/microsoft-powerpoint.md +41 -0
- package/.docs/integrations/documents/microsoft-word.md +41 -0
- package/.docs/integrations/documents/notion.md +41 -0
- package/.docs/integrations/documents/one-drive.md +41 -0
- package/.docs/integrations/documents/sharepoint-online.md +41 -0
- package/.docs/integrations/email-calendar/google-calendar.md +41 -0
- package/.docs/integrations/email-calendar/google-mail.md +41 -0
- package/.docs/integrations/email-calendar/outlook.md +41 -0
- package/.docs/integrations/file-storage/amazon-s3.md +1 -1
- package/.docs/integrations/file-storage/google-drive.md +54 -15
- package/.docs/integrations/observability/arize.md +1 -1
- package/.docs/integrations/observability/posthog.md +50 -11
- package/.docs/integrations/other/canva.md +42 -0
- package/.docs/integrations/other/fireflies.md +41 -0
- package/.docs/integrations/other/incident-io.md +41 -0
- package/.docs/integrations/other/resend.md +43 -0
- package/.docs/integrations/other/robinhood.md +44 -0
- package/.docs/integrations/other/sanity.md +42 -0
- package/.docs/integrations/other/snowflake.md +41 -0
- package/.docs/integrations/project-management/jira.md +41 -0
- package/.docs/integrations/project-management/linear.md +41 -0
- package/.docs/integrations/sandboxes/e2b.md +1 -1
- package/.docs/integrations/voice/openai.md +40 -0
- package/.docs/integrations.md +40 -1
- package/.docs/models/environment-variables.md +1 -1
- package/.docs/models/gateways/azure-openai.md +61 -2
- package/.docs/models/gateways/custom-gateways.md +2 -0
- package/.docs/models/gateways/merge-gateway.md +3 -1
- package/.docs/models/gateways/netlify.md +13 -7
- package/.docs/models/gateways/openrouter.md +13 -12
- package/.docs/models/gateways/requesty.md +221 -0
- package/.docs/models/gateways/vercel.md +423 -419
- package/.docs/models/gateways.md +7 -1
- package/.docs/models/index.md +46 -3
- package/.docs/models/providers/aiand.md +1 -1
- package/.docs/models/providers/aihubmix.md +2 -0
- package/.docs/models/providers/amazon-bedrock.md +4 -0
- package/.docs/models/providers/anthropic.md +2 -1
- package/.docs/models/providers/azure.md +4 -0
- package/.docs/models/providers/baseten.md +2 -1
- package/.docs/models/providers/chutes.md +6 -4
- package/.docs/models/providers/cloudflare-ai-gateway.md +2 -0
- package/.docs/models/providers/cloudflare-workers-ai.md +0 -13
- package/.docs/models/providers/cohere.md +2 -0
- package/.docs/models/providers/crossmodel.md +5 -1
- package/.docs/models/providers/deepinfra.md +2 -1
- package/.docs/models/providers/edenai.md +12 -13
- package/.docs/models/providers/empiriolabs.md +3 -3
- package/.docs/models/providers/fireworks-ai.md +30 -28
- package/.docs/models/providers/google-vertex.md +2 -0
- package/.docs/models/providers/google.md +4 -3
- package/.docs/models/providers/hyper.md +8 -14
- package/.docs/models/providers/inceptron.md +3 -3
- package/.docs/models/providers/kilo.md +36 -40
- package/.docs/models/providers/llmgateway-providers.md +448 -423
- package/.docs/models/providers/llmgateway.md +10 -6
- package/.docs/models/providers/meta.md +5 -4
- package/.docs/models/providers/modular.md +6 -6
- package/.docs/models/providers/morph.md +2 -1
- package/.docs/models/providers/nano-gpt.md +55 -62
- package/.docs/models/providers/novita-ai.md +4 -2
- package/.docs/models/providers/ollama-cloud.md +2 -1
- package/.docs/models/providers/ollama.md +2 -0
- package/.docs/models/providers/opencode-go.md +3 -1
- package/.docs/models/providers/opencode.md +11 -5
- package/.docs/models/providers/ovhcloud.md +1 -2
- package/.docs/models/providers/prime.md +4 -4
- package/.docs/models/providers/qvac.md +2 -0
- package/.docs/models/providers/tencent-token-plan.md +2 -1
- package/.docs/models/providers/tencent-tokenhub.md +2 -1
- package/.docs/models/providers/tinfoil.md +4 -3
- package/.docs/models/providers/togetherai.md +2 -1
- package/.docs/models/providers/wandb.md +6 -5
- package/.docs/models/providers.md +0 -1
- package/.docs/reference/agent-controller/agent-controller-class.md +4 -2
- package/.docs/reference/agent-controller/session.md +1 -1
- package/.docs/reference/agents/agent.md +3 -1
- package/.docs/reference/agents/channels.md +117 -1
- package/.docs/reference/agents/durable-agent.md +42 -29
- package/.docs/reference/agents/generate.md +1 -1
- package/.docs/reference/agents/getLLM.md +1 -1
- package/.docs/reference/agents/getMetadata.md +1 -1
- package/.docs/reference/agents/getModel.md +4 -2
- package/.docs/reference/agents/getSkill.md +1 -1
- package/.docs/reference/agents/listScorers.md +1 -1
- package/.docs/reference/agents/listTools.md +1 -1
- package/.docs/reference/ai-sdk/chat-route.md +33 -2
- package/.docs/reference/auth/better-auth.md +2 -2
- package/.docs/reference/auth/neon.md +24 -15
- package/.docs/reference/build-with-ai.md +12 -2
- package/.docs/reference/channels/slack-provider.md +1 -1
- package/.docs/reference/cli/mastra.md +10 -1
- package/.docs/reference/client-js/agents.md +4 -4
- package/.docs/reference/client-js/observability.md +90 -3
- package/.docs/reference/code-sdk/mount-agent-controller.md +5 -1
- package/.docs/reference/connect/channels.md +55 -1
- package/.docs/reference/connect/credential.md +2 -1
- package/.docs/reference/connect/providers.md +5 -3
- package/.docs/reference/connect/tools.md +34 -3
- package/.docs/reference/core/addDynamicWorkflow.md +1 -1
- package/.docs/reference/core/addGateway.md +1 -1
- package/.docs/reference/core/getAgent.md +4 -2
- package/.docs/reference/core/getEditor.md +1 -1
- package/.docs/reference/core/getGateway.md +1 -1
- package/.docs/reference/core/getGatewayById.md +14 -1
- package/.docs/reference/core/getMemory.md +2 -2
- package/.docs/reference/core/getStorage.md +1 -1
- package/.docs/reference/core/listMemory.md +3 -3
- package/.docs/reference/core/listScorers.md +2 -2
- package/.docs/reference/core/listVectors.md +1 -1
- package/.docs/reference/core/mastra-class.md +1 -1
- package/.docs/reference/evals/completeness.md +0 -1
- package/.docs/reference/evals/content-similarity.md +1 -3
- package/.docs/reference/evals/create-scorer.md +8 -4
- package/.docs/reference/evals/faithfulness.md +1 -1
- package/.docs/reference/evals/hallucination.md +2 -2
- package/.docs/reference/evals/noise-sensitivity.md +8 -1
- package/.docs/reference/evals/scorer-utils.md +1 -1
- package/.docs/reference/file-based-agents/tools.md +3 -3
- package/.docs/reference/index.md +8 -0
- package/.docs/reference/knowledge/knowledge-class.md +296 -0
- package/.docs/reference/knowledge/knowledge-memory-scopes.md +78 -0
- package/.docs/reference/knowledge/knowledge-tools.md +299 -0
- package/.docs/reference/knowledge/limits.md +44 -0
- package/.docs/reference/knowledge/scope-declarations.md +275 -0
- package/.docs/reference/knowledge/tool-instructions.md +56 -0
- package/.docs/reference/logging/pino-logger.md +1 -1
- package/.docs/reference/memory/memory-class.md +1 -1
- package/.docs/reference/memory/observational-memory.md +9 -7
- package/.docs/reference/observability/feedback.md +3 -1
- package/.docs/reference/observability/tracing/advanced-queries.md +47 -58
- package/.docs/reference/observability/tracing/configuration.md +3 -0
- package/.docs/reference/observability/tracing/exporters/mastra-platform-exporter.md +33 -0
- package/.docs/reference/observability/tracing/exporters/mastra-storage-exporter.md +30 -0
- package/.docs/reference/observability/tracing/interfaces.md +2 -0
- package/.docs/reference/processors/batch-parts-processor.md +0 -2
- package/.docs/reference/processors/message-history-processor.md +1 -1
- package/.docs/reference/processors/moderation-processor.md +1 -1
- package/.docs/reference/processors/processor-interface.md +1 -1
- package/.docs/reference/processors/semantic-recall-processor.md +8 -4
- package/.docs/reference/processors/skill-search-processor.md +3 -0
- package/.docs/reference/processors/skills-processor.md +84 -0
- package/.docs/reference/processors/stream-error-retry-processor.md +1 -1
- package/.docs/reference/processors/token-limiter-processor.md +1 -1
- package/.docs/reference/processors/tool-search-processor.md +1 -1
- package/.docs/reference/pubsub/lease-provider.md +4 -2
- package/.docs/reference/pubsub/redis-streams.md +3 -1
- package/.docs/reference/rag/graph-rag.md +2 -2
- package/.docs/reference/rag/rerank.md +1 -1
- package/.docs/reference/rag/rerankWithScorer.md +1 -1
- package/.docs/reference/schedules/overview.md +3 -3
- package/.docs/reference/server/invoke-route.md +86 -0
- package/.docs/reference/server/koa-adapter.md +1 -1
- package/.docs/reference/server/routes.md +63 -0
- package/.docs/reference/streaming/ChunkType.md +3 -1
- package/.docs/reference/streaming/agents/MastraModelOutput.md +13 -12
- package/.docs/reference/streaming/agents/stream.md +1 -1
- package/.docs/reference/streaming/workflows/resumeStream.md +1 -1
- package/.docs/reference/tools/mcp-client.md +30 -7
- package/.docs/reference/tools/mcp-server.md +6 -2
- package/.docs/reference/tools/vector-query-tool.md +3 -3
- package/.docs/reference/workers/overview.md +2 -2
- package/.docs/reference/workflows/run-methods/resume.md +1 -1
- package/.docs/reference/workflows/run-methods/start.md +1 -1
- package/.docs/reference/workflows/run-methods/timeTravel.md +1 -1
- package/.docs/reference/workflows/run.md +1 -1
- package/.docs/reference/workflows/workflow.md +2 -0
- package/.docs/reference/workspace/factory-sandbox.md +24 -8
- package/.docs/reference/workspace/platform-sandbox.md +22 -7
- package/.docs/reference/workspace/sandbox.md +1 -1
- package/.docs/reference/workspace/workspace-class.md +5 -5
- package/dist/index.js +1 -1
- package/dist/{src-BDrEqwuY.js → src-CwUXyWAK.js} +3 -3
- package/dist/src-CwUXyWAK.js.map +1 -0
- package/dist/stdio.js +1 -1
- package/dist/tools/embedded-docs.d.ts.map +1 -1
- package/package.json +4 -5
- package/.docs/docs/mastra-platform/connect/channels.md +0 -165
- package/.docs/docs/mastra-platform/connect/overview.md +0 -102
- package/.docs/docs/mastra-platform/connect/providers.md +0 -66
- package/.docs/docs/mastra-platform/connect/tools.md +0 -151
- package/.docs/models/providers/requesty.md +0 -261
- package/dist/src-BDrEqwuY.js.map +0 -1
|
@@ -128,7 +128,7 @@ const result = await agent.generate('message for agent')
|
|
|
128
128
|
|
|
129
129
|
**options.output** (`Zod schema | JsonSchema7`): \*\*Deprecated.\*\* Use structuredOutput without a model to achieve the same thing. Defines the expected structure of the output. Can be a JSON Schema object or a Zod schema.
|
|
130
130
|
|
|
131
|
-
**options.scopes** (`string[]`): Scopes the run acts as, written as \<type>:\<value> (for example org:acme, resource:user-123, thread:conversation-123). Memory reads its resource and thread from resource: and thread: scopes. Other scopes are passed to tools and processors. Combined with the agent's scopes
|
|
131
|
+
**options.scopes** (`string[]`): Scopes the run acts as, written as \<type>:\<value> (for example org:acme, resource:user-123, thread:conversation-123). Memory reads its resource and thread from resource: and thread: scopes. Other scopes are passed to tools and processors. Combined with defaultOptions.scopes and the mastra__scopes request context key, then passed through the agent's scopes option: a list adds to them, a function replaces them. Throws if a resource: or thread: scope conflicts with another resource or thread value.
|
|
132
132
|
|
|
133
133
|
**options.memory** (`object`): Memory configuration for conversation persistence and retrieval.
|
|
134
134
|
|
|
@@ -28,7 +28,7 @@ await agent.getLLM({
|
|
|
28
28
|
|
|
29
29
|
## Returns
|
|
30
30
|
|
|
31
|
-
**llm** (`MastraLLMV1 | Promise<MastraLLMV1>`): The language model instance configured for the agent, either as a direct instance or a promise that resolves to the LLM.
|
|
31
|
+
**llm** (`MastraLLMV1 | MastraLLMVNext | Promise<MastraLLMV1 | MastraLLMVNext>`): The language model instance configured for the agent, either as a direct instance or a promise that resolves to the LLM.
|
|
32
32
|
|
|
33
33
|
## Extended usage example
|
|
34
34
|
|
|
@@ -20,7 +20,7 @@ await agent.getMetadata()
|
|
|
20
20
|
|
|
21
21
|
## Returns
|
|
22
22
|
|
|
23
|
-
**metadata** (`Record<string, unknown> | Promise<Record<string, unknown
|
|
23
|
+
**metadata** (`Record<string, unknown> | undefined | Promise<Record<string, unknown> | undefined>`): The metadata configured for the agent, or undefined if no metadata was configured. Returns either directly or as a promise that resolves to the metadata when defined as a function.
|
|
24
24
|
|
|
25
25
|
## Extended usage example
|
|
26
26
|
|
|
@@ -14,13 +14,15 @@ await agent.getModel()
|
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
16
16
|
|
|
17
|
-
**options** (`{ requestContext?: RequestContext }`): Optional configuration object containing request context. (Default: `{}`)
|
|
17
|
+
**options** (`{ requestContext?: RequestContext; modelConfig?: DynamicArgument<MastraModelConfig | ModelWithRetries[]> | ModelFallbacks }`): Optional configuration object containing request context and an optional model override. (Default: `{}`)
|
|
18
18
|
|
|
19
19
|
**options.requestContext** (`RequestContext`): Request Context for dependency injection and contextual information.
|
|
20
20
|
|
|
21
|
+
**options.modelConfig** (`DynamicArgument<MastraModelConfig | ModelWithRetries[]> | ModelFallbacks`): Model configuration to resolve instead of the agent model. Can also be a function that receives the request context.
|
|
22
|
+
|
|
21
23
|
## Returns
|
|
22
24
|
|
|
23
|
-
**model** (`
|
|
25
|
+
**model** (`Promise<MastraLanguageModel | MastraLegacyLanguageModel>`): A promise that resolves to the language model configured for the agent. Always await the result.
|
|
24
26
|
|
|
25
27
|
## Extended usage example
|
|
26
28
|
|
|
@@ -54,7 +54,7 @@ interface Skill {
|
|
|
54
54
|
}
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
`source` describes where Mastra discovered the skill. Skills from a path with a `node_modules` segment are `external`, skills under `.mastra/skills` are `managed`, and all other skills, including those created with [`createSkill()`](https://mastra.ai/reference/agents/createSkill), are `local`.
|
|
57
|
+
`source` describes where Mastra discovered the skill. Skills from a path with a `node_modules` segment are `external`, skills from a path under `.mastra/skills` are `managed`, and all other skills, including those created with [`createSkill()`](https://mastra.ai/reference/agents/createSkill), are `local`.
|
|
58
58
|
|
|
59
59
|
## Merging behavior
|
|
60
60
|
|
|
@@ -20,7 +20,7 @@ await agent.listScorers()
|
|
|
20
20
|
|
|
21
21
|
## Returns
|
|
22
22
|
|
|
23
|
-
**scorers** (`
|
|
23
|
+
**scorers** (`Promise<MastraScorers>`): A promise that resolves to the scoring configuration configured for the agent.
|
|
24
24
|
|
|
25
25
|
## Extended usage example
|
|
26
26
|
|
|
@@ -20,7 +20,7 @@ await agent.listTools()
|
|
|
20
20
|
|
|
21
21
|
## Returns
|
|
22
22
|
|
|
23
|
-
**tools** (`
|
|
23
|
+
**tools** (`Promise<TTools>`): A promise that resolves to the tools configured for the agent.
|
|
24
24
|
|
|
25
25
|
## Extended usage example
|
|
26
26
|
|
|
@@ -10,9 +10,9 @@ Use [`handleChatStream()`](https://mastra.ai/reference/ai-sdk/handle-chat-stream
|
|
|
10
10
|
|
|
11
11
|
`chatRoute()` keeps the existing AI SDK v5/default behavior. If your app is typed against AI SDK v6, pass `version: 'v6'`.
|
|
12
12
|
|
|
13
|
-
> **Disconnect behavior:** `chatRoute()` forwards the incoming request's `AbortSignal` to `agent.stream()`. If the client disconnects, Mastra aborts the in-flight generation.
|
|
13
|
+
> **Disconnect behavior:** By default, `chatRoute()` forwards the incoming request's `AbortSignal` to `agent.stream()`. If the client disconnects, Mastra aborts the in-flight generation.
|
|
14
14
|
>
|
|
15
|
-
>
|
|
15
|
+
> Set `resumable: true` to let the generation continue after a disconnect and allow AI SDK UI to reconnect to the active stream. Resumable chats don't support abort-based cancellation because `useChat().stop()` is indistinguishable from a refresh or network interruption at the server.
|
|
16
16
|
|
|
17
17
|
## Usage example
|
|
18
18
|
|
|
@@ -61,6 +61,8 @@ export const mastra = new Mastra({
|
|
|
61
61
|
|
|
62
62
|
**agentVersion** (`{ versionId: string } | { status?: 'draft' | 'published' }`): Selects a specific agent version. Pass { versionId: '\<id>' } to target an exact version, or { status: 'draft' } / { status: 'published' } to resolve by status. When the route is called, query parameters ?versionId=\<id> or ?status=draft|published take precedence over this static value. Requires the Editor to be configured.
|
|
63
63
|
|
|
64
|
+
**resumable** (`boolean`): Enables AI SDK UI stream resumption. Returns the POST route and a GET \<path>/:chatId/stream route, uses the AI SDK chat ID as the Mastra thread ID, and lets generation continue after the POST connection closes. (Default: `false`)
|
|
65
|
+
|
|
64
66
|
**defaultOptions** (`AgentExecutionOptions`): Default options passed to agent execution. These can include instructions, memory configuration, maxSteps, and other execution settings.
|
|
65
67
|
|
|
66
68
|
**sendStart** (`boolean`): Whether to send start events in the stream. (Default: `true`)
|
|
@@ -77,6 +79,35 @@ export const mastra = new Mastra({
|
|
|
77
79
|
|
|
78
80
|
**heartbeatMs** (`number`): Interval in milliseconds for SSE heartbeats that keep connections active through infrastructure with idle timeouts.
|
|
79
81
|
|
|
82
|
+
## Resumable streams
|
|
83
|
+
|
|
84
|
+
Set `resumable: true` on `chatRoute()` and `resume: true` on AI SDK UI's `useChat()` to reconnect after a refresh or network interruption. The route factory returns a two-item array containing:
|
|
85
|
+
|
|
86
|
+
- `POST <path>`: Starts the agent run. The request's AI SDK chat ID becomes the Mastra memory thread ID.
|
|
87
|
+
- `GET <path>/:chatId/stream`: Replays cached events and follows the active run. The route returns `204` when the run is finished, unavailable, expired, or outside the caller's scope.
|
|
88
|
+
|
|
89
|
+
Pass the returned array as one entry in `server.apiRoutes`. Mastra flattens nested route arrays during server configuration.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { Mastra } from '@mastra/core'
|
|
93
|
+
import { chatRoute } from '@mastra/ai-sdk'
|
|
94
|
+
|
|
95
|
+
export const mastra = new Mastra({
|
|
96
|
+
server: {
|
|
97
|
+
apiRoutes: [
|
|
98
|
+
chatRoute({
|
|
99
|
+
path: '/chat/:agentId',
|
|
100
|
+
resumable: true,
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Active-run discovery is process-local. A reconnect request must reach the same running server process that started the generation. Resumable mode doesn't forward the request `AbortSignal`, so `useChat().stop()` closes the client connection without cancelling the agent run.
|
|
108
|
+
|
|
109
|
+
If the chat uses a resource ID, set `MASTRA_RESOURCE_ID_KEY` in the request context through authentication middleware. Don't send the resource ID only as `memory.resource` in the POST body: the reconnecting GET request has no body, so `chatRoute()` rejects that configuration with `400`.
|
|
110
|
+
|
|
80
111
|
## Additional configuration
|
|
81
112
|
|
|
82
113
|
You can use [`prepareSendMessagesRequest`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#transport.default-chat-transport.prepare-send-messages-request) to customize the request sent to the chat route, for example to pass additional configuration to the agent:
|
|
@@ -71,8 +71,8 @@ The `Session` and `User` types are exported by the Better Auth package.
|
|
|
71
71
|
|
|
72
72
|
- `public` and `protected` accept exact paths, wildcard patterns (like `/api/*`), and path params (like `/users/:id`).
|
|
73
73
|
- For method-specific rules, use tuples like `["/api/agents", ["GET", "POST"]]`.
|
|
74
|
-
- If a route matches both `public` and `protected`, `public` wins and no auth is required.
|
|
75
|
-
- If neither matches,
|
|
74
|
+
- If a route matches both `public` and `protected`, `public` wins and no auth is required, unless the route is marked `requiresAuth: true`. Those routes still authenticate.
|
|
75
|
+
- If neither matches, a route requires auth when it's under `/api/*` (the built-in default `protected` pattern) or is a custom route registered with `registerApiRoute()` that isn't marked `requiresAuth: false`, and other paths don't require auth.
|
|
76
76
|
|
|
77
77
|
## Related
|
|
78
78
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# `MastraAuthNeon` and `MastraRBACNeon`
|
|
6
6
|
|
|
7
|
-
[`MastraAuthNeon`](https://github.com/mastra-ai/mastra/tree/main/auth/neon) connects Mastra authentication to [Neon Auth](https://neon.com/docs/guides/neon-auth). It
|
|
7
|
+
[`MastraAuthNeon`](https://github.com/mastra-ai/mastra/tree/main/auth/neon) connects Mastra authentication to [Neon Auth](https://neon.com/docs/guides/neon-auth). It verifies Neon Auth JWTs sent as bearer tokens with Neon Auth's JWKS endpoint and validates Neon Auth session cookies through its session API. The provider also supports email-and-password sign-in, sign-up, and session management.
|
|
8
8
|
|
|
9
9
|
`MastraRBACNeon` maps Neon Auth organization roles to Mastra permissions. Register it separately when your application uses Neon Auth organization memberships for role-based access control.
|
|
10
10
|
|
|
@@ -34,7 +34,9 @@ export const mastra = new Mastra({
|
|
|
34
34
|
})
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
Set `NEON_AUTH_BASE_URL` to
|
|
37
|
+
Set `NEON_AUTH_BASE_URL` to the Neon Auth URL shown in the Neon Console, for example `https://ep-example-123456.neonauth.us-east-2.aws.neon.tech/neondb/auth`. You can also pass `baseUrl` directly to both constructors.
|
|
38
|
+
|
|
39
|
+
Visit the [Neon integration guide](https://mastra.ai/integrations/auth/neon) for setup steps.
|
|
38
40
|
|
|
39
41
|
## `MastraAuthNeon`
|
|
40
42
|
|
|
@@ -42,13 +44,13 @@ Set `NEON_AUTH_BASE_URL` to your Neon Auth service URL. You can also pass `baseU
|
|
|
42
44
|
|
|
43
45
|
The `MastraAuthNeon` constructor accepts an optional `MastraAuthNeonOptions` object.
|
|
44
46
|
|
|
45
|
-
**baseUrl** (`string`): Neon Auth
|
|
47
|
+
**baseUrl** (`string`): Neon Auth URL, including the database path (for example /neondb/auth). Falls back to the NEON_AUTH_BASE_URL environment variable. Trailing slashes are removed. The JWT issuer and audience must equal the origin of this URL.
|
|
46
48
|
|
|
47
|
-
**jwksUrl** (`string`): JWKS endpoint used to verify bearer tokens. Falls back to NEON_AUTH_JWKS_URL, then \<baseUrl
|
|
49
|
+
**jwksUrl** (`string`): JWKS endpoint used to verify bearer tokens. Falls back to NEON_AUTH_JWKS_URL, then \<baseUrl>/.well-known/jwks.json.
|
|
48
50
|
|
|
49
|
-
**sessionCookieName** (`string`): Name of the Neon Auth session cookie. Defaults to
|
|
51
|
+
**sessionCookieName** (`string`): Name of the Neon Auth session cookie. Defaults to \_\_Secure-neon-auth.session_token.
|
|
50
52
|
|
|
51
|
-
**signUpEnabled** (`boolean`): Whether credentials-based sign-up is enabled. Defaults to true.
|
|
53
|
+
**signUpEnabled** (`boolean`): Whether credentials-based sign-up is enabled. When false, signUp() throws and no Neon Auth account is created. Defaults to true.
|
|
52
54
|
|
|
53
55
|
**name** (`string`): Provider name. Defaults to neon.
|
|
54
56
|
|
|
@@ -74,7 +76,9 @@ The `MastraAuthNeon` constructor accepts an optional `MastraAuthNeonOptions` obj
|
|
|
74
76
|
await auth.authenticateToken(token, request)
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
Verifies
|
|
79
|
+
Verifies a JWT-shaped token against the configured JWKS endpoint, checking its signature, issuer, audience, and expiry. Otherwise, validates the Neon Auth session cookie from the request through the session API. If JWT verification fails, the session cookie is still accepted, so an expired bearer token doesn't sign out a client that also sends cookies. When the request has no session cookie, a non-JWT token is treated as the session cookie value. Returns the authenticated `NeonAuthUser`, or `null` when validation fails.
|
|
80
|
+
|
|
81
|
+
`NeonAuthUser` contains the top-level `id`, `email`, and `name`, the Neon Auth `user` object, and either the `session` (cookie authentication) or the verified `jwt` claims (bearer authentication).
|
|
78
82
|
|
|
79
83
|
#### `authorizeUser()`
|
|
80
84
|
|
|
@@ -92,7 +96,7 @@ Runs the configured custom authorization function when one is provided. Otherwis
|
|
|
92
96
|
const result = await auth.signIn(email, password, request)
|
|
93
97
|
```
|
|
94
98
|
|
|
95
|
-
Authenticates email-and-password credentials through Neon Auth. Returns the authenticated user,
|
|
99
|
+
Authenticates email-and-password credentials through Neon Auth. Returns the authenticated user, a Neon Auth JWT as `token`, and the Neon Auth session cookies. Neon Auth must trust the origin of the incoming request.
|
|
96
100
|
|
|
97
101
|
#### `signUp()`
|
|
98
102
|
|
|
@@ -100,7 +104,7 @@ Authenticates email-and-password credentials through Neon Auth. Returns the auth
|
|
|
100
104
|
const result = await auth.signUp(email, password, name, request)
|
|
101
105
|
```
|
|
102
106
|
|
|
103
|
-
Creates a Neon Auth account using email-and-password credentials. `name` is optional
|
|
107
|
+
Creates a Neon Auth account using email-and-password credentials. `name` is optional. When omitted, the provider derives a display name from the email address. Returns the same result as `signIn()`.
|
|
104
108
|
|
|
105
109
|
#### `isSignUpEnabled()`
|
|
106
110
|
|
|
@@ -139,10 +143,13 @@ Validates the session through Neon Auth. Neon Auth refreshes sessions automatica
|
|
|
139
143
|
#### `destroySession()`
|
|
140
144
|
|
|
141
145
|
```typescript
|
|
142
|
-
|
|
146
|
+
const sessionId = auth.getSessionIdFromRequest(request)
|
|
147
|
+
if (sessionId) await auth.destroySession(sessionId)
|
|
143
148
|
```
|
|
144
149
|
|
|
145
|
-
|
|
150
|
+
Pass the signed session cookie value from `getSessionIdFromRequest()`, not the `id` returned by `validateSession()`. `destroySession()` attempts to revoke that session through the Neon Auth sign-out endpoint. A network error or non-2xx response can leave the session active, and the method doesn't throw for these failures. When Mastra sends the header from `getClearSessionHeaders()`, it clears the matching cookie on the Mastra host, not a cookie on a separate Neon Auth host. A separate Neon Auth session can remain active after Studio sign-out.
|
|
151
|
+
|
|
152
|
+
Revoking a session doesn't invalidate an already-issued JWT. Bearer tokens that pass JWT verification can still authenticate because verification doesn't check the Neon Auth session. JWT verification doesn't require an expiration claim, so a token without one may remain usable after sign-out.
|
|
146
153
|
|
|
147
154
|
## `MastraRBACNeon`
|
|
148
155
|
|
|
@@ -152,11 +159,11 @@ The `MastraRBACNeon` constructor accepts a `MastraRBACNeonOptions` object.
|
|
|
152
159
|
|
|
153
160
|
**roleMapping** (`RoleMapping`): Maps Neon Auth role names to Mastra permission patterns. Use \_default to define permissions for unmapped roles.
|
|
154
161
|
|
|
155
|
-
**baseUrl** (`string`): Neon Auth
|
|
162
|
+
**baseUrl** (`string`): Neon Auth URL. Falls back to the NEON_AUTH_BASE_URL environment variable. Trailing slashes are removed.
|
|
156
163
|
|
|
157
|
-
**organizationId** (`string`):
|
|
164
|
+
**organizationId** (`string`): Organization whose membership role is used. Defaults to the active organization of the session.
|
|
158
165
|
|
|
159
|
-
**getUserRoles** (`(user: NeonAuthUser) => Promise<string[]> | string[]`): Custom function
|
|
166
|
+
**getUserRoles** (`(user: NeonAuthUser) => Promise<string[]> | string[]`): Custom function that returns role names for a user. Use it to assign roles to bearer JWT requests, which carry no organization roles.
|
|
160
167
|
|
|
161
168
|
**cache** (`{ ttlMs?: number; maxSize?: number }`): Role lookup cache configuration. The defaults are 60,000 ms and 1,000 entries.
|
|
162
169
|
|
|
@@ -168,7 +175,9 @@ The `MastraRBACNeon` constructor accepts a `MastraRBACNeonOptions` object.
|
|
|
168
175
|
const roles = await rbac.getRoles(user)
|
|
169
176
|
```
|
|
170
177
|
|
|
171
|
-
Returns roles from the configured `getUserRoles` function, the user's
|
|
178
|
+
Returns roles from the configured `getUserRoles` function when provided. Otherwise, when `organizationId` is set or the session has an active organization, returns the user's role in that organization, read from Neon Auth with the user's session cookie. Non-members get no roles. Without an organization, returns the user's Neon Auth role, such as `user` or `admin`.
|
|
179
|
+
|
|
180
|
+
Bearer JWT requests have no session, so they get no roles unless `getUserRoles` is provided. The JWT `role` claim (`authenticated`) is never used as a Mastra role.
|
|
172
181
|
|
|
173
182
|
#### `hasRole()`
|
|
174
183
|
|
|
@@ -18,9 +18,19 @@ Each `dist/docs` includes:
|
|
|
18
18
|
|
|
19
19
|
## Context files
|
|
20
20
|
|
|
21
|
-
Mastra provides a root [`llms.txt`](https://mastra.ai/llms.txt) file that contains an overview of all available documentation pages.
|
|
21
|
+
Mastra provides a root [`llms.txt`](https://mastra.ai/llms.txt) file that contains an overview of all available documentation pages.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
To load many pages in one request, use the `llms-full.txt` bundles. They contain the full Markdown of every page in sidebar order:
|
|
24
|
+
|
|
25
|
+
- [`/llms-full.txt`](https://mastra.ai/llms-full.txt): All documentation
|
|
26
|
+
- [`/docs/llms-full.txt`](https://mastra.ai/docs/llms-full.txt): Docs
|
|
27
|
+
- [`/models/llms-full.txt`](https://mastra.ai/models/llms-full.txt): Models
|
|
28
|
+
- [`/integrations/llms-full.txt`](https://mastra.ai/integrations/llms-full.txt): Integrations
|
|
29
|
+
- [`/reference/llms-full.txt`](https://mastra.ai/reference/llms-full.txt): Reference
|
|
30
|
+
|
|
31
|
+
The full bundle is large, so prefer a section bundle or individual pages when you only need part of the documentation.
|
|
32
|
+
|
|
33
|
+
Each documentation page also has its own `llms.txt` file. These files are streamlined markdown files. At the end of each docs page you'll find a link to the corresponding `llms.txt` file.
|
|
24
34
|
|
|
25
35
|
Add `/llms.txt` to any Mastra docs URL to access it. You can also request it by adding a `.md` extension to the end of the URL.
|
|
26
36
|
|
|
@@ -63,7 +63,7 @@ await slack.configure({
|
|
|
63
63
|
|
|
64
64
|
**toolApprovers** (`'requester' | 'anyone'`): Who can approve or deny tool calls. By default, only the user whose message triggered the call can respond when their identity was recorded; without a recorded requester, another channel member may respond. Set 'anyone' to allow another member of the shared Slack channel to approve or deny even when a requester was recorded. This bypasses only the requester check; the action still requires a pending approval in the same thread. (Default: `'requester'`)
|
|
65
65
|
|
|
66
|
-
**typingStatus** (`boolean | TypingStatusFn`): Show a typing indicator while the agent works. Set false to disable, or pass a function to return custom status text per stream chunk (return
|
|
66
|
+
**typingStatus** (`boolean | TypingStatusFn`): Show a typing indicator while the agent works. Set false to disable, or pass a function to return custom status text per stream chunk (return false, null, or undefined to leave the current status unchanged for that chunk). (Default: `true`)
|
|
67
67
|
|
|
68
68
|
**waitUntil** (`WaitUntilFn`): Returns a waitUntil for the current Slack webhook request. Required on serverless runtimes where Hono can't bridge the platform's ExecutionContext (Vercel, AWS Lambda). Without it, the invocation freezes after the 200 ack and kills the run mid-flight. Pass the bare waitUntil(promise) from your platform SDK (for example, @vercel/functions). Cloudflare Workers and Netlify users typically don't need this.
|
|
69
69
|
|
|
@@ -877,6 +877,8 @@ Manages authentication for Mastra platform. Credentials are stored in `~/.mastra
|
|
|
877
877
|
|
|
878
878
|
Opens a browser for login and stores the credentials locally.
|
|
879
879
|
|
|
880
|
+
When browser sign-in is needed and there's no interactive terminal (in CI, when input or output is piped, or in an agent's shell), the command first prints how to authenticate headless shells, then still waits for browser sign-in. On the same machine, you can run `mastra auth login` once in your own terminal so later commands reuse the saved session. In CI or on another machine, set `MASTRA_API_TOKEN` and `MASTRA_ORG_ID` instead. Create the token from a signed-in terminal with [`mastra auth tokens create`](#mastra-auth-tokens-create) or in the dashboard. If the browser sign-in wait times out, the command exits with status 1. If `MASTRA_API_TOKEN` is already set in a non-interactive shell, the command skips browser sign-in: it verifies the token and checks that an organization is selected (from `MASTRA_ORG_ID` or saved credentials), then exits with status 0. If either check fails, it exits with status 1 and names what's missing.
|
|
881
|
+
|
|
880
882
|
### `mastra auth logout`
|
|
881
883
|
|
|
882
884
|
Removes stored credentials. If `MASTRA_API_TOKEN` is still set in the environment, the CLI warns that it will continue to be used.
|
|
@@ -943,7 +945,7 @@ Connects a provider to the project. When the organization already has connection
|
|
|
943
945
|
|
|
944
946
|
OAuth providers open the provider's consent screen in your browser and print its URL if you need to open it manually. API key and Basic auth providers prompt for credentials in the terminal and verify them before completing the connection. Providers with other auth types open a hosted connect page. The command waits until the connection becomes active before exiting.
|
|
945
947
|
|
|
946
|
-
Credential prompts require an interactive terminal, even with `--yes`. Run the command outside CI or connect through the platform UI.
|
|
948
|
+
Credential prompts require an interactive terminal, even with `--yes`. Run the command outside CI or connect through the platform UI. Each provider's [integration page](https://mastra.ai/docs/mastra-platform/connect) lists its API key and permission requirements.
|
|
947
949
|
|
|
948
950
|
Once a new connection is active, the command offers to set a display name so you can tell connections to the same provider apart. It lists the provider's existing connections, suggests a name that doesn't collide with them, and asks for confirmation if the chosen name duplicates another connection's name. Leave the field blank to skip naming. Setting a display name requires the organization admin role; if naming fails, the connection remains active.
|
|
949
951
|
|
|
@@ -1266,6 +1268,13 @@ Errors are written to `stderr` as JSON and return a non-zero exit code:
|
|
|
1266
1268
|
}
|
|
1267
1269
|
```
|
|
1268
1270
|
|
|
1271
|
+
The exit code reflects whether the request succeeded, not the contents of the response:
|
|
1272
|
+
|
|
1273
|
+
- `0`: The server returned a successful response. This includes empty results and payloads that report existing state, such as a tool result saying a record already exists. A tool that returns an object with an `error` field still exits `0`, so check the `data` payload when the tool reports its own failures.
|
|
1274
|
+
- `1`: The request failed. This includes an unreachable server, invalid JSON input, a missing resource, or a tool that throws an error.
|
|
1275
|
+
|
|
1276
|
+
If the command reading the output exits early, as with `| head`, the exit code still reflects whether the request succeeded.
|
|
1277
|
+
|
|
1269
1278
|
### Target resolution
|
|
1270
1279
|
|
|
1271
1280
|
For runtime commands, the command resolves the target server in this order:
|
|
@@ -914,9 +914,9 @@ const agent = await mastraClient.createStoredAgent({
|
|
|
914
914
|
})
|
|
915
915
|
```
|
|
916
916
|
|
|
917
|
-
####
|
|
917
|
+
#### Resumable streams for stored agents
|
|
918
918
|
|
|
919
|
-
Set `durable` to
|
|
919
|
+
Set `durable` to configure [resumable streams](https://mastra.ai/docs/agents/resumable-streams) on the hydrated plain agent. Pass `true` to enable streams, `false` to disable them, or an object to tune stream cleanup:
|
|
920
920
|
|
|
921
921
|
```typescript
|
|
922
922
|
const agent = await mastraClient.createStoredAgent({
|
|
@@ -927,11 +927,11 @@ const agent = await mastraClient.createStoredAgent({
|
|
|
927
927
|
provider: 'openai',
|
|
928
928
|
name: 'gpt-5.4',
|
|
929
929
|
},
|
|
930
|
-
durable: {
|
|
930
|
+
durable: { cleanupTimeoutMs: 0 },
|
|
931
931
|
})
|
|
932
932
|
```
|
|
933
933
|
|
|
934
|
-
Only serializable options are accepted
|
|
934
|
+
Only serializable options are accepted, with cache and pubsub inherited from the server's `Mastra` instance. Existing stored agents with `durable: true` also use this field for resumable streams only. To retain durable execution and checkpoint recovery, register a code agent wrapped with `createDurableAgent({ agent })`.
|
|
935
935
|
|
|
936
936
|
### `getStoredAgent()`
|
|
937
937
|
|
|
@@ -115,7 +115,7 @@ if (capabilities.spanAggregate) {
|
|
|
115
115
|
|
|
116
116
|
The request and response structure follows `aggregateTraces()`, with direct span predicates and span dimensions such as `spanType`, `name`, and `parentEntityName`. Token and cost measures belong to the span that recorded the usage and aren't added to parent spans. Check `capabilities.spanAggregate` before calling, and `capabilities.spanAggregateModelDimensions` before grouping or counting distinct values by `model` or `provider`. With an older adapter, those requests return `501`.
|
|
117
117
|
|
|
118
|
-
Both `aggregateTraces()` and `aggregateSpans()` accept `timeToFirstToken.*` and `timeToFirstChunk
|
|
118
|
+
Both `aggregateTraces()` and `aggregateSpans()` accept time to first token (TTFT) and time to first chunk (TTFC) measures, `timeToFirstToken.*` and `timeToFirstChunk.*`, when `capabilities.aggregateTimeToFirstMeasures` is `true`. Spans and traces without a recorded value are skipped, never counted as 0. See [Time to first chunk (TTFC)](https://mastra.ai/reference/observability/tracing/advanced-queries) and [Time to first token (TTFT)](https://mastra.ai/reference/observability/tracing/advanced-queries).
|
|
119
119
|
|
|
120
120
|
See [Aggregate spans](https://mastra.ai/reference/observability/tracing/advanced-queries) for selection, dimensions, per-span usage, and how to list the spans behind a group.
|
|
121
121
|
|
|
@@ -403,13 +403,52 @@ const scores = await mastraClient.listScoresBySpan({
|
|
|
403
403
|
})
|
|
404
404
|
```
|
|
405
405
|
|
|
406
|
+
## Get a score by ID
|
|
407
|
+
|
|
408
|
+
Use `getScore()` to retrieve one observability score:
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
const { score } = await mastraClient.getScore('score-id-123')
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
The response is `{ score: record | null }`. A missing score returns HTTP 200 with `{ score: null }`. The return type is `GetScoreResponse`, exported from `@mastra/client-js`.
|
|
415
|
+
|
|
416
|
+
## Creating scores
|
|
417
|
+
|
|
418
|
+
Create a score for a trace, optionally identifying a span within it:
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
const response = await mastraClient.createScore({
|
|
422
|
+
score: {
|
|
423
|
+
traceId: 'trace-123',
|
|
424
|
+
spanId: 'span-456',
|
|
425
|
+
scorerId: 'accuracy',
|
|
426
|
+
score: 0.95,
|
|
427
|
+
},
|
|
428
|
+
})
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
`createScore()` requires a nonblank `score.traceId`, with an optional `spanId`. The client generates a missing `scoreId` and ISO `timestamp` once per call and preserves them across retries. Supply these fields to reuse an existing identity. See [signal write options](#signal-write-options) for context resolution and retry behavior.
|
|
432
|
+
|
|
406
433
|
## Feedback
|
|
407
434
|
|
|
408
|
-
Feedback methods create, list, and query human-in-the-loop signals such as ratings, thumbs, comments, and corrections through the
|
|
435
|
+
Feedback methods create, list, and query human-in-the-loop signals such as ratings, thumbs, comments, and corrections through the configured API server. Create methods support OSS and Platform. Full replacement uses Platform's PUT endpoint. See the [feedback guide](https://mastra.ai/docs/observability/feedback) for examples and the [feedback reference](https://mastra.ai/reference/observability/feedback) for full schemas.
|
|
436
|
+
|
|
437
|
+
### Get feedback by ID
|
|
438
|
+
|
|
439
|
+
Use `getFeedback()` to retrieve one feedback record:
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
const { feedback } = await mastraClient.getFeedback('feedback-id-123')
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
The response is `{ feedback: record | null }`. A missing record returns HTTP 200 with `{ feedback: null }`. The return type is `GetFeedbackResponse`, exported from `@mastra/client-js`.
|
|
446
|
+
|
|
447
|
+
Both getters accept an unencoded ID and encode it as a URL path segment. They use the client's configured API prefix, credentials, and headers. Record timestamps are ISO strings in the JSON response.
|
|
409
448
|
|
|
410
449
|
### Creating feedback
|
|
411
450
|
|
|
412
|
-
Create a feedback record
|
|
451
|
+
Create a feedback record for a trace, optionally identifying a span within it:
|
|
413
452
|
|
|
414
453
|
```typescript
|
|
415
454
|
const response = await mastraClient.createFeedback({
|
|
@@ -424,6 +463,54 @@ const response = await mastraClient.createFeedback({
|
|
|
424
463
|
})
|
|
425
464
|
```
|
|
426
465
|
|
|
466
|
+
`createFeedback()` requires a nonblank `feedback.traceId`, with an optional `spanId`. The client generates a missing `feedbackId` and ISO `timestamp` once per call and preserves them across retries. Set `feedbackUserId` to identify the feedback author. `userId` identifies the span's user. An authenticated OSS user takes precedence over a submitted feedback author.
|
|
467
|
+
|
|
468
|
+
### Signal write options
|
|
469
|
+
|
|
470
|
+
Both create methods accept an optional top-level `contextMode` alongside the `feedback` or `score` wrapper:
|
|
471
|
+
|
|
472
|
+
- `"provided"` uses the record's flattened context fields without looking up spans. Missing context fields aren't enriched.
|
|
473
|
+
- `"resolve"` derives context from the stored root and optional target span. Root tags are inherited. Record metadata overrides matching stored metadata keys. A missing root returns `TRACE_NOT_FOUND`. A missing target returns `SPAN_NOT_FOUND`.
|
|
474
|
+
|
|
475
|
+
Omitting `contextMode` uses the server's default: `"provided"` on OSS and `"resolve"` on Platform. The client preserves omission. Select a mode explicitly when the same behavior is required on both servers. On OSS, each configured trusted scope field overrides caller input. In provided mode, other context fields remain caller-supplied. For example, a trusted organization ID overrides `organizationId` but doesn't clear `resourceId` when no trusted resource scope is configured.
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
const result = await mastraClient.createFeedback({
|
|
479
|
+
contextMode: 'resolve',
|
|
480
|
+
feedback: {
|
|
481
|
+
traceId: 'trace-123',
|
|
482
|
+
feedbackUserId: 'reviewer-1',
|
|
483
|
+
feedbackType: 'thumbs',
|
|
484
|
+
value: 1,
|
|
485
|
+
},
|
|
486
|
+
})
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Use `retries` and `anchorRetryTimeoutMs` in the optional second argument to control retries. Network and server errors use the client's transport retry settings. Only 404s with `TRACE_NOT_FOUND` or `SPAN_NOT_FOUND` receive anchor retries, for at most 30 seconds after the first such response. Set `anchorRetryTimeoutMs` to a shorter window or `0` to disable them. Other 404s and authentication or validation errors are terminal.
|
|
490
|
+
|
|
491
|
+
Create responses contain `success` and optional `data` with the generated or supplied `feedbackId`/`scoreId`, `traceId`, nullable `spanId`, and normalized UTC `timestamp`. The client also accepts success-only responses. Platform success confirms publication. The record may not be immediately visible to reads. Direct OSS HTTP callers can omit the ID and timestamp to have the server generate them.
|
|
492
|
+
|
|
493
|
+
Explicit modes require server support. Older servers may ignore `contextMode`. Deploy Platform's supplied-context support before sending `"provided"` there.
|
|
494
|
+
|
|
495
|
+
### Replacing feedback on Platform
|
|
496
|
+
|
|
497
|
+
`replaceFeedback()` sends a full replacement to `PUT /api/observability/feedback/:feedbackId`. Include the original `feedbackId`, `traceId`, and normalized `timestamp`, along with all feedback fields to retain. This method targets Platform. OSS server doesn't implement this replacement endpoint.
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
await mastraClient.replaceFeedback({
|
|
501
|
+
feedback: {
|
|
502
|
+
feedbackId: 'feedback-1',
|
|
503
|
+
traceId: 'trace-123',
|
|
504
|
+
timestamp: '2026-01-01T00:00:00.123Z',
|
|
505
|
+
feedbackType: 'thumbs',
|
|
506
|
+
value: -1,
|
|
507
|
+
feedbackUserId: 'reviewer-1',
|
|
508
|
+
},
|
|
509
|
+
})
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
Use the normalized timestamp from the create response's `data` when available. A changed timestamp identifies a different Platform record. The client preserves the replacement body across retries, but each accepted PUT retry is a new replacement and can supersede another edit. Pass `{ retries: 0, anchorRetryTimeoutMs: 0 }` as the second argument to disable automatic retries.
|
|
513
|
+
|
|
427
514
|
### Deleting feedback and scores
|
|
428
515
|
|
|
429
516
|
Delete feedback or score records by id. Deletion is idempotent, so missing ids are ignored. Each request accepts at most 1,000 `feedbackIds` or 1,000 `scoreIds`. Optional `organizationId` and `resourceId` fields restrict each deletion to records with matching scope fields:
|
|
@@ -74,7 +74,11 @@ const { controller } = await mountAgentControllerOnMastra({ mastra })
|
|
|
74
74
|
|
|
75
75
|
**disableBuiltinTools** (`BuiltinToolId[]`): Agent controller built-in tools (for example, 'submit_plan') removed from every session. Tool guidance skips disabled tools, and plan mode writes the plan file instead of calling 'submit_plan' when it's disabled.
|
|
76
76
|
|
|
77
|
-
**storage** (`StorageConfig`): Custom storage config instead of the auto-detected default.
|
|
77
|
+
**storage** (`StorageConfig | MastraCompositeStore`): Custom storage config instead of the auto-detected default, or a pre-built store instance. An injected instance has no connection test or LibSQL fallback. In both cases the SDK wraps the store: scorer results are discarded unless disableScoreStorage is false, and local observability goes to a separate DuckDB store only when local tracing is enabled and that store opens; otherwise local observability is disabled. Cloud export runs independently when cloud credentials are configured.
|
|
78
|
+
|
|
79
|
+
**storageBackend** (`'libsql' | 'pg'`): Backend of an injected storage instance. Inferred for LibSQLStore and PostgresStore; required for any other injected store, otherwise mounting throws.
|
|
80
|
+
|
|
81
|
+
**vector** (`MastraVector`): Pre-built vector store for recall search. Skips creating the default vector store. When storage is a pre-built instance, no default vector store is created, so pass vector to keep semantic recall search; without it, recall still browses history but can't search semantically.
|
|
78
82
|
|
|
79
83
|
**workspace** (`AgentControllerConfig["workspace"]`): Override the workspace. (Default: `local filesystem + local sandbox based on the detected project`)
|
|
80
84
|
|
|
@@ -18,7 +18,7 @@ export const mastra = new Mastra({
|
|
|
18
18
|
|
|
19
19
|
Returns: `Promise<ChannelsResolver>`. See [The resolver](#the-resolver).
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Each provider's integration page covers its channel setup: [Slack](https://mastra.ai/integrations/channels/slack), [Telegram](https://mastra.ai/integrations/channels/telegram), [Discord](https://mastra.ai/integrations/channels/discord), and [Microsoft Teams](https://mastra.ai/integrations/channels/teams). Their implementations come from `@mastra/slack`, `@mastra/telegram`, `@mastra/discord`, and `@mastra/teams`, loaded on demand. Use those packages directly to configure a channel outside the platform connection flow.
|
|
22
22
|
|
|
23
23
|
The Teams provider encrypts stored bot secrets with `MASTRA_ENCRYPTION_KEY` when set. When it isn't, the key is derived from the platform access token and a warning is logged while a Teams connection is active. Rotating the platform access token makes stored bot credentials unreadable (disconnect and reconnect to re-provision). Projects without a Teams connection are unaffected.
|
|
24
24
|
|
|
@@ -62,6 +62,60 @@ Providers without an active connection don't appear in the resolved map. Their r
|
|
|
62
62
|
|
|
63
63
|
Failure handling matches [`tools()`](https://mastra.ai/reference/connect/tools): configuration errors (missing project ID, bad `ttlMs`, an unknown or malformed provider ID, both spellings of the Slack key) reject at call time, while per-provider problems (provider construction failure, `needs_reauth`, credential sync failure) are downgraded to warn-and-skip. Several active connections for one provider aren't a skip: the resolver warns and uses the first, and `providers.<id>.connectionId` pins the choice. The initial resolution rejects if its platform fetch fails. A failed background refresh warns and preserves the cached snapshot, while an explicit `refresh()` rejects on fetch failure.
|
|
64
64
|
|
|
65
|
+
## Combine with self-managed channels
|
|
66
|
+
|
|
67
|
+
`channels()` replaces the whole `channels` option, and there is no built-in helper to merge it with providers you construct yourself. To use Connect for some channels and manage another yourself, wrap both in one resolver. The wrapper must stay callable and expose a `getRoutes()` that returns every provider's routes, because Mastra mounts channel routes once at construction:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Mastra } from '@mastra/core'
|
|
71
|
+
import { channels } from '@mastra/connect'
|
|
72
|
+
import { TelegramProvider } from '@mastra/telegram'
|
|
73
|
+
import { assistant } from './agents/assistant'
|
|
74
|
+
|
|
75
|
+
const connectChannels = await channels({ providers: ['slack', 'discord'] })
|
|
76
|
+
const telegram = new TelegramProvider()
|
|
77
|
+
|
|
78
|
+
export const mastra = new Mastra({
|
|
79
|
+
agents: { assistant },
|
|
80
|
+
channels: Object.assign(async () => ({ ...(await connectChannels()), telegram }), {
|
|
81
|
+
getRoutes: () => [...connectChannels.getRoutes(), ...telegram.getRoutes()],
|
|
82
|
+
}),
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Exclude the self-managed channel from the Connect selection, as the array form does here. Mastra doesn't detect two providers that register the same route, so a channel enabled in both places mounts conflicting webhooks. Create the self-managed provider once, outside the wrapper: Mastra attaches each distinct provider instance only once. Configure its credentials as described in the [Telegram provider reference](https://mastra.ai/reference/channels/telegram-provider).
|
|
87
|
+
|
|
88
|
+
## Vary tools by channel
|
|
89
|
+
|
|
90
|
+
Channel messages put a [`ChannelContext`](https://mastra.ai/integrations/channels/slack) on the [request context](https://mastra.ai/docs/server/request-context) under the `channel` key. It includes the platform, whether the conversation is a direct message (`isDM`), channel and thread IDs, and the sender's user ID and name. An agent's `tools` function can read it to filter the record that [`tools()`](https://mastra.ai/reference/connect/tools) resolves:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { Agent } from '@mastra/core/agent'
|
|
94
|
+
import type { ChannelContext } from '@mastra/core/channels'
|
|
95
|
+
import { tools } from '@mastra/connect'
|
|
96
|
+
|
|
97
|
+
const connectTools = tools({ providers: ['linear'] })
|
|
98
|
+
const readTools = new Set(['linear_list_issues'])
|
|
99
|
+
|
|
100
|
+
export const assistant = new Agent({
|
|
101
|
+
id: 'assistant',
|
|
102
|
+
name: 'assistant',
|
|
103
|
+
instructions: 'You help the team track work in Linear from Slack and Discord.',
|
|
104
|
+
model: 'openai/gpt-6-luna',
|
|
105
|
+
tools: async ctx => {
|
|
106
|
+
const channel = ctx.requestContext?.get('channel') as ChannelContext | undefined
|
|
107
|
+
const all = await connectTools(ctx)
|
|
108
|
+
|
|
109
|
+
if (channel?.isDM && ctx.requestContext?.get('role') === 'operator') {
|
|
110
|
+
return all
|
|
111
|
+
}
|
|
112
|
+
return Object.fromEntries(Object.entries(all).filter(([key]) => readTools.has(key)))
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Here, only direct messages from users your application identifies as operators get the full Linear toolset. Other requests get only `linear_list_issues`. Set `role` in trusted server-side code after you verify the sender's identity and permissions. Don't grant write access based on conversation type alone. To filter by options instead of post-processing, see [per-request options](https://mastra.ai/reference/connect/tools).
|
|
118
|
+
|
|
65
119
|
## Discord permissions
|
|
66
120
|
|
|
67
121
|
The Discord bot-invite URL requests the `bot` and `applications.commands` scopes with these permissions:
|
|
@@ -42,7 +42,7 @@ Most applications should prefer [`tools()`](https://mastra.ai/reference/connect/
|
|
|
42
42
|
|
|
43
43
|
**connectionId** (`string`): ID of the connection to fetch credentials for.
|
|
44
44
|
|
|
45
|
-
**options** (`{ client?: ConnectClientOptions }`): Optional platform client overrides (accessToken, orgId, baseUrl, fetch
|
|
45
|
+
**options** (`{ client?: ConnectClientOptions; resourceId?: string }`): Optional platform client overrides (accessToken, orgId, baseUrl, fetch; see ConnectClientOptions in tools()) and the end-user resourceId. Pass resourceId when the connection is scoped to an end user. The value is trimmed and must be 1-256 characters, otherwise invalid_options is thrown before any request is sent. The value is sent as the x-mastra-resource-id header, takes precedence over client.resourceId, and the platform returns not found for a resource-scoped connection when it's missing or doesn't match.
|
|
46
46
|
|
|
47
47
|
## Credential handling
|
|
48
48
|
|
|
@@ -56,6 +56,7 @@ Throws `MastraConnectError` with a `code` property:
|
|
|
56
56
|
|
|
57
57
|
| Code | When |
|
|
58
58
|
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
59
|
+
| `invalid_options` | An option is invalid, for example an empty `resourceId` or one longer than 256 characters after trimming |
|
|
59
60
|
| `missing_access_token` | No platform token configured |
|
|
60
61
|
| `connection_not_found` | The connection doesn't exist or isn't accessible |
|
|
61
62
|
| `unsupported_credential_type` | The connection's credential type can't be returned |
|