@mastra/mcp-docs-server 1.3.12 → 1.3.13-alpha.2
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 +2 -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 +66 -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 +6 -6
- 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/observability/tracing/overview.md +0 -2
- package/.docs/docs/server/custom-adapters.md +4 -0
- 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/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/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/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/voice/openai.md +40 -0
- package/.docs/integrations.md +40 -1
- package/.docs/models/gateways/custom-gateways.md +2 -0
- package/.docs/models/gateways/netlify.md +8 -3
- package/.docs/models/gateways/openrouter.md +7 -8
- package/.docs/models/gateways/vercel.md +418 -418
- package/.docs/models/index.md +46 -2
- package/.docs/models/providers/aiand.md +1 -1
- package/.docs/models/providers/baseten.md +2 -1
- package/.docs/models/providers/chutes.md +2 -1
- package/.docs/models/providers/edenai.md +5 -9
- package/.docs/models/providers/empiriolabs.md +3 -3
- package/.docs/models/providers/hyper.md +7 -13
- package/.docs/models/providers/inceptron.md +3 -3
- package/.docs/models/providers/kilo.md +20 -25
- package/.docs/models/providers/llmgateway-providers.md +22 -10
- package/.docs/models/providers/llmgateway.md +5 -5
- package/.docs/models/providers/modular.md +6 -6
- package/.docs/models/providers/nano-gpt.md +18 -21
- package/.docs/models/providers/opencode-go.md +3 -1
- package/.docs/models/providers/opencode.md +3 -2
- package/.docs/models/providers/ovhcloud.md +1 -2
- package/.docs/models/providers/prime.md +1 -1
- 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 +2 -2
- package/.docs/models/providers/togetherai.md +2 -1
- package/.docs/models/providers/wandb.md +5 -4
- package/.docs/reference/agents/agent.md +3 -1
- package/.docs/reference/agents/channels.md +38 -1
- package/.docs/reference/agents/durable-agent.md +37 -26
- 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/auth/better-auth.md +2 -2
- package/.docs/reference/auth/neon.md +24 -15
- 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/connect/channels.md +55 -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/evals/completeness.md +0 -1
- package/.docs/reference/evals/content-similarity.md +1 -3
- package/.docs/reference/evals/create-scorer.md +5 -3
- 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/index.md +7 -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/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/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/semantic-recall-processor.md +1 -1
- 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/redis-streams.md +2 -0
- 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 +6 -4
- 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 +4 -0
- package/.docs/reference/tools/mcp-server.md +6 -2
- package/.docs/reference/tools/vector-query-tool.md +3 -3
- package/.docs/reference/workflows/run-methods/start.md +1 -1
- package/.docs/reference/workflows/run-methods/timeTravel.md +1 -1
- package/.docs/reference/workflows/workflow.md +2 -0
- package/.docs/reference/workspace/sandbox.md +1 -1
- 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 -4
- 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/dist/src-BDrEqwuY.js.map +0 -1
|
@@ -108,7 +108,7 @@ The agent now has humanlike long-term memory that persists across conversations.
|
|
|
108
108
|
const memory = new Memory({
|
|
109
109
|
options: {
|
|
110
110
|
observationalMemory: {
|
|
111
|
-
model: 'deepseek/deepseek-
|
|
111
|
+
model: 'deepseek/deepseek-flash',
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
114
|
})
|
|
@@ -154,7 +154,7 @@ export const agent = new Agent({
|
|
|
154
154
|
memory: new Memory({
|
|
155
155
|
options: {
|
|
156
156
|
observationalMemory: {
|
|
157
|
-
model: '
|
|
157
|
+
model: 'auto',
|
|
158
158
|
temporalMarkers: true,
|
|
159
159
|
},
|
|
160
160
|
},
|
|
@@ -180,7 +180,7 @@ import { Memory } from '@mastra/memory'
|
|
|
180
180
|
const memory = new Memory({
|
|
181
181
|
options: {
|
|
182
182
|
observationalMemory: {
|
|
183
|
-
model: '
|
|
183
|
+
model: 'auto',
|
|
184
184
|
activateAfterIdle: 'auto',
|
|
185
185
|
activateOnProviderChange: true,
|
|
186
186
|
},
|
|
@@ -196,7 +196,7 @@ import { Memory } from '@mastra/memory'
|
|
|
196
196
|
const memory = new Memory({
|
|
197
197
|
options: {
|
|
198
198
|
observationalMemory: {
|
|
199
|
-
model: '
|
|
199
|
+
model: 'auto',
|
|
200
200
|
activateAfterIdle: '5m',
|
|
201
201
|
observation: {
|
|
202
202
|
activateAfterIdle: false,
|
|
@@ -455,7 +455,7 @@ new Agent({
|
|
|
455
455
|
options: {
|
|
456
456
|
observationalMemory: {
|
|
457
457
|
observation: {
|
|
458
|
-
model: 'deepseek/deepseek-
|
|
458
|
+
model: 'deepseek/deepseek-flash',
|
|
459
459
|
observeAttachments: false,
|
|
460
460
|
},
|
|
461
461
|
},
|
|
@@ -522,7 +522,7 @@ Set `retrieval: true` to enable the recall tool for browsing raw messages. No ve
|
|
|
522
522
|
const memory = new Memory({
|
|
523
523
|
options: {
|
|
524
524
|
observationalMemory: {
|
|
525
|
-
model: '
|
|
525
|
+
model: 'auto',
|
|
526
526
|
retrieval: true,
|
|
527
527
|
},
|
|
528
528
|
},
|
|
@@ -540,7 +540,7 @@ const memory = new Memory({
|
|
|
540
540
|
embedder: myEmbedder,
|
|
541
541
|
options: {
|
|
542
542
|
observationalMemory: {
|
|
543
|
-
model: '
|
|
543
|
+
model: 'auto',
|
|
544
544
|
retrieval: { vector: true },
|
|
545
545
|
},
|
|
546
546
|
},
|
|
@@ -557,7 +557,7 @@ By default, the recall tool scope is `'resource'`, the agent can list threads an
|
|
|
557
557
|
const memory = new Memory({
|
|
558
558
|
options: {
|
|
559
559
|
observationalMemory: {
|
|
560
|
-
model: '
|
|
560
|
+
model: 'auto',
|
|
561
561
|
retrieval: { vector: true, scope: 'thread' },
|
|
562
562
|
},
|
|
563
563
|
},
|
|
@@ -572,7 +572,7 @@ Mastra injects scope-aware instructions that teach the agent when to search, lis
|
|
|
572
572
|
const memory = new Memory({
|
|
573
573
|
options: {
|
|
574
574
|
observationalMemory: {
|
|
575
|
-
model: '
|
|
575
|
+
model: 'auto',
|
|
576
576
|
retrieval: {
|
|
577
577
|
vector: true,
|
|
578
578
|
instructions: `
|
|
@@ -641,13 +641,13 @@ const memory = new Memory({
|
|
|
641
641
|
|
|
642
642
|
Mastra recommends using a model that has a large context window (128K+ tokens) and is fast enough to run in the background without slowing down your actions.
|
|
643
643
|
|
|
644
|
-
To pin a model instead, set a concrete model ID. We've also successfully tested `openai/gpt-6-luna`, `anthropic/claude-haiku-5-5`,
|
|
644
|
+
To pin a model instead, set a concrete model ID. We've also successfully tested `openai/gpt-6-luna`, `anthropic/claude-haiku-5-5`, and `deepseek/deepseek-flash`.
|
|
645
645
|
|
|
646
646
|
```typescript
|
|
647
647
|
const memory = new Memory({
|
|
648
648
|
options: {
|
|
649
649
|
observationalMemory: {
|
|
650
|
-
model: 'deepseek/deepseek-
|
|
650
|
+
model: 'deepseek/deepseek-flash',
|
|
651
651
|
},
|
|
652
652
|
},
|
|
653
653
|
})
|
|
@@ -655,9 +655,9 @@ const memory = new Memory({
|
|
|
655
655
|
|
|
656
656
|
See [model configuration](https://mastra.ai/reference/memory/observational-memory) for using different models per agent.
|
|
657
657
|
|
|
658
|
-
> **Note:** `google/gemini-2.5-flash`
|
|
658
|
+
> **Note:** Some models preserve detail in long output unusually well. In testing, `google/gemini-2.5-flash` did this. Other models may behave differently. With such a model, the Reflector can produce reflections that stay above the configured `reflection.observationTokens` threshold even after the maximum compression retry. When this happens, the Reflector returns the smallest non-degenerate candidate produced during retries so the loop terminates instead of running forever.
|
|
659
659
|
>
|
|
660
|
-
> If you'd rather have more aggressive compression on the Reflector,
|
|
660
|
+
> If you'd rather have more aggressive compression on the Reflector, pick a model that condenses more readily, such as `deepseek/deepseek-flash`. You can use a detail-preserving model for the Observer and a condensing one for the Reflector. See [different models per agent](https://mastra.ai/reference/memory/observational-memory).
|
|
661
661
|
|
|
662
662
|
### Token-tiered model selection
|
|
663
663
|
|
|
@@ -678,7 +678,7 @@ const memory = new Memory({
|
|
|
678
678
|
5_000: 'openrouter/mistralai/ministral-8b-2512',
|
|
679
679
|
20_000: 'openrouter/mistralai/mistral-small-2603',
|
|
680
680
|
40_000: 'openai/gpt-6-luna',
|
|
681
|
-
1_000_000: 'google/gemini-3.
|
|
681
|
+
1_000_000: 'google/gemini-3.8-flash',
|
|
682
682
|
},
|
|
683
683
|
}),
|
|
684
684
|
},
|
|
@@ -686,7 +686,7 @@ const memory = new Memory({
|
|
|
686
686
|
model: new ModelByInputTokens({
|
|
687
687
|
upTo: {
|
|
688
688
|
20_000: 'openai/gpt-6-luna',
|
|
689
|
-
100_000: '
|
|
689
|
+
100_000: 'deepseek/deepseek-flash',
|
|
690
690
|
},
|
|
691
691
|
}),
|
|
692
692
|
},
|
|
@@ -709,7 +709,7 @@ Each thread has its own observations. This scope is well tested and works well a
|
|
|
709
709
|
const memory = new Memory({
|
|
710
710
|
options: {
|
|
711
711
|
observationalMemory: {
|
|
712
|
-
model: '
|
|
712
|
+
model: 'auto',
|
|
713
713
|
scope: 'thread',
|
|
714
714
|
},
|
|
715
715
|
},
|
|
@@ -728,7 +728,7 @@ In resource scope, observations are shared across all threads for a resource (ty
|
|
|
728
728
|
- **Agent understanding:** Each thread sees a mix of observations from every thread for the resource. Every new thread starts with context from earlier threads, and the agent may continue work that another thread started but didn't finish.
|
|
729
729
|
- **Performance:** Unobserved messages across _all_ threads are processed together, which is slow for users with many existing threads.
|
|
730
730
|
|
|
731
|
-
|
|
731
|
+
[Knowledge](https://mastra.ai/docs/knowledge/overview), now in alpha, gives agents shared information across threads and is planned to replace resource scope. Until it's stable, use the alternatives below.
|
|
732
732
|
|
|
733
733
|
#### Cross-thread continuity without resource scope
|
|
734
734
|
|
|
@@ -743,7 +743,7 @@ Use thread scope with one or both of these features instead:
|
|
|
743
743
|
const memory = new Memory({
|
|
744
744
|
options: {
|
|
745
745
|
observationalMemory: {
|
|
746
|
-
model: '
|
|
746
|
+
model: 'auto',
|
|
747
747
|
retrieval: true,
|
|
748
748
|
},
|
|
749
749
|
workingMemory: {
|
|
@@ -762,7 +762,7 @@ OM uses token thresholds to decide when to observe and reflect. See [token budge
|
|
|
762
762
|
const memory = new Memory({
|
|
763
763
|
options: {
|
|
764
764
|
observationalMemory: {
|
|
765
|
-
model: '
|
|
765
|
+
model: 'auto',
|
|
766
766
|
observation: {
|
|
767
767
|
// when to run the Observer (default: 30,000)
|
|
768
768
|
messageTokens: 30_000,
|
|
@@ -873,7 +873,7 @@ With `"auto"`, Mastra chooses an idle activation TTL from the active model provi
|
|
|
873
873
|
const memory = new Memory({
|
|
874
874
|
options: {
|
|
875
875
|
observationalMemory: {
|
|
876
|
-
model: '
|
|
876
|
+
model: 'auto',
|
|
877
877
|
activateAfterIdle: 'auto',
|
|
878
878
|
activateOnProviderChange: true,
|
|
879
879
|
},
|
|
@@ -893,7 +893,7 @@ Changing models or providers mid-thread will invalidate the prompt cache. If you
|
|
|
893
893
|
const memory = new Memory({
|
|
894
894
|
options: {
|
|
895
895
|
observationalMemory: {
|
|
896
|
-
model: '
|
|
896
|
+
model: 'auto',
|
|
897
897
|
activateAfterIdle: { default: 'auto', anthropic: '1h' },
|
|
898
898
|
},
|
|
899
899
|
},
|
|
@@ -917,7 +917,7 @@ To disable async buffering and use synchronous observation/reflection instead:
|
|
|
917
917
|
const memory = new Memory({
|
|
918
918
|
options: {
|
|
919
919
|
observationalMemory: {
|
|
920
|
-
model: '
|
|
920
|
+
model: 'auto',
|
|
921
921
|
observation: {
|
|
922
922
|
bufferTokens: false,
|
|
923
923
|
},
|
|
@@ -940,7 +940,7 @@ Set `observation.previousObserverTokens` to limit how many tokens of previous ob
|
|
|
940
940
|
const memory = new Memory({
|
|
941
941
|
options: {
|
|
942
942
|
observationalMemory: {
|
|
943
|
-
model: '
|
|
943
|
+
model: 'auto',
|
|
944
944
|
observation: {
|
|
945
945
|
previousObserverTokens: 10_000, // keep only ~10k tokens of recent observations
|
|
946
946
|
},
|
|
@@ -9,8 +9,7 @@ Memory gives your agent access to earlier messages and tool results. The agent c
|
|
|
9
9
|
Mastra agents can be configured to store [message history](https://mastra.ai/docs/memory/message-history). Additionally, you can enable:
|
|
10
10
|
|
|
11
11
|
- [Observational Memory](https://mastra.ai/docs/memory/observational-memory) (Recommended): Uses background agents to maintain a dense observation log that replaces raw message history as it grows. This keeps the context window small while preserving long-term memory.
|
|
12
|
-
- [Working memory](https://mastra.ai/docs/memory/working-memory): Stores persistent, structured user
|
|
13
|
-
- [Semantic recall](https://mastra.ai/docs/memory/semantic-recall): Retrieves relevant past messages based on semantic meaning rather than exact keywords.
|
|
12
|
+
- [Working memory](https://mastra.ai/docs/memory/working-memory): Stores persistent, structured information about the user, the application, or the task, such as names, preferences, and goals.
|
|
14
13
|
- [Multi-user threads](https://mastra.ai/docs/memory/multi-user-threads): Share one thread between multiple users.
|
|
15
14
|
|
|
16
15
|
If the combined memory exceeds the model's context limit, [memory processors](https://mastra.ai/docs/memory/memory-processors) can filter, trim, or prioritize content so the most relevant information is preserved.
|
|
@@ -161,7 +160,7 @@ const response = await memoryAgent.generate('Remember my favorite color is blue.
|
|
|
161
160
|
})
|
|
162
161
|
```
|
|
163
162
|
|
|
164
|
-
Scopes can also come from the
|
|
163
|
+
Scopes can also come from the request context and from the agent. Scopes from the call and the request context arrive first. The agent's `scopes` option then adds a list to them, or a function receives them and returns the run's final set:
|
|
165
164
|
|
|
166
165
|
```typescript
|
|
167
166
|
import { Agent } from '@mastra/core/agent'
|
|
@@ -170,10 +169,10 @@ import { Memory } from '@mastra/memory'
|
|
|
170
169
|
export const memoryAgent = new Agent({
|
|
171
170
|
id: 'memory-agent',
|
|
172
171
|
name: 'Memory Agent',
|
|
173
|
-
scopes: ({ requestContext }) => {
|
|
172
|
+
scopes: ({ scopes, requestContext }) => {
|
|
174
173
|
// Set by your auth middleware. Request bodies can fill unreserved keys.
|
|
175
174
|
const orgId = requestContext.get('org-id')
|
|
176
|
-
return orgId ? [`org:${orgId}`] :
|
|
175
|
+
return orgId ? [...scopes, `org:${orgId}`] : scopes
|
|
177
176
|
},
|
|
178
177
|
memory: new Memory(),
|
|
179
178
|
})
|
|
@@ -181,7 +180,7 @@ export const memoryAgent = new Agent({
|
|
|
181
180
|
|
|
182
181
|
The resolver's inputs must come from the server, not the client: a request body can set any request context key that isn't reserved. Trusted server middleware can also set scopes directly with the `MASTRA_SCOPES_KEY` request context key. Visit [Request Context](https://mastra.ai/docs/server/request-context) for details. Clients can't send scopes in a request body.
|
|
183
182
|
|
|
184
|
-
You can mix scopes with `memory.resource`, `memory.thread`, or the resource and thread request context keys, as long as they agree. If a `resource:` or `thread:` scope names a different value than another source, the call throws an error.
|
|
183
|
+
You can mix scopes with `memory.resource`, `memory.thread`, or the resource and thread request context keys, as long as they agree. If a `resource:` or `thread:` scope names a different value than another source, the call throws an error. A `scopes` function must also return every `resource:` and `thread:` scope it receives. Dropping one throws an error.
|
|
185
184
|
|
|
186
185
|
Tools, processors, and subagents receive the run's other scopes, but not its `resource:` and `thread:` scopes. Each nested agent call picks its own resource and thread.
|
|
187
186
|
|
|
@@ -189,6 +188,8 @@ Tools, processors, and subagents receive the run's other scopes, but not its `re
|
|
|
189
188
|
|
|
190
189
|
Long conversations can fill the context window with raw message history and reduce agent performance. [Observational Memory](https://mastra.ai/docs/memory/observational-memory) uses background agents to compress older messages into observations. This reduces the context used by message history while retaining information for later turns.
|
|
191
190
|
|
|
191
|
+
Compression loses exact wording, so Observational Memory can register a `recall` tool that goes back to the original messages. The tool is off by default: set `retrieval: true` to enable browsing, which lists earlier messages across the resource's threads unless you pass `scope: 'thread'`. With `retrieval: { vector: true }` plus a vector store and embedder on `Memory`, it can also search by meaning. That search matches observation groups rather than raw messages, so a detail the summary dropped may not turn up, and each hit links back to the messages it came from. See [retrieval mode](https://mastra.ai/docs/memory/observational-memory).
|
|
192
|
+
|
|
192
193
|
**For AI agents:** Using Observational Memory requires a storage provider! You either need to set it on the Mastra instance at `src/mastra/index.ts` or pass it to the Agent constructor.
|
|
193
194
|
|
|
194
195
|
```typescript
|
|
@@ -302,4 +303,15 @@ Visit [Request Context](https://mastra.ai/docs/server/request-context) for more
|
|
|
302
303
|
- [`Memory` reference](https://mastra.ai/reference/memory/memory-class)
|
|
303
304
|
- [Tracing](https://mastra.ai/docs/observability/tracing/overview)
|
|
304
305
|
- [Request Context](https://mastra.ai/docs/server/request-context)
|
|
305
|
-
- [Mastra Code](https://code.mastra.ai/): A coding agent using Mastra's memory system
|
|
306
|
+
- [Mastra Code](https://code.mastra.ai/): A coding agent using Mastra's memory system
|
|
307
|
+
|
|
308
|
+
**For AI agents:** Observational Memory has a few failure modes that cause real problems.
|
|
309
|
+
|
|
310
|
+
- Thread scope requires a `threadId` when you call the agent. Without one, Observational Memory throws.
|
|
311
|
+
- On an existing thread, the first turn loads every stored message until the first observation completes. A large thread pays a one-time context cost.
|
|
312
|
+
- `lastMessages` does nothing under Observational Memory. It replaces raw history itself, so the MessageHistory processor is skipped.
|
|
313
|
+
- Leave `observation.observeOnContextOverflow` at its default `true`. When the main model's context overflows, it can activate buffered observations, observe pending messages, and retry the request. It skips read-only requests and only retries when it observed or activated something. With it off, the overflowing request fails.
|
|
314
|
+
- Some invalid options are validated on first use, not when you construct `Memory`. For example, `shareTokenBudget: true` with async buffering enabled fails on the first memory operation. Read the error instead of retrying.
|
|
315
|
+
- With async buffering, work continues in the background. Call `await memory.settled()` before closing storage or shutting down, or that work is lost.
|
|
316
|
+
- The observation mutex only works inside one process. Across processes, coordination comes from a shared PubSub backend and storage: the agent loop uses a backend with leases to run one loop per thread, and the Observer runs inside that loop. Configure every process with the same backend with leases and the same storage. See [Running across processes](https://mastra.ai/docs/signals/running-across-processes).
|
|
317
|
+
- Debug with `OM_DEBUG=1`, which writes `om-debug.log`, plus `getStatus()` and the `onDebugEvent` callback.
|
|
@@ -62,8 +62,6 @@ If the configured failure policy lets the main execution continue, it can still
|
|
|
62
62
|
|
|
63
63
|
Model inference spans (`MODEL_INFERENCE`) measure provider execution and record usage. Model chunk spans (`MODEL_CHUNK`) capture content after output processors have accepted or transformed it. Chunks belong to the logical step (`MODEL_STEP`), so buffered output can arrive after provider execution ends without outliving its parent. In the agent streaming paths, inference spans no longer capture response output; use the processed chunk spans or the generation output instead.
|
|
64
64
|
|
|
65
|
-
When durable execution finishes on another worker, the original termination cause may be unavailable. Normal completion and step-limit exits can then report `unknown`. Separate resumed-segment tracing isn't supported on Inngest. A caller-side Inngest deadline may also be missing from worker-owned outcomes. Core durable resume tracing also requires the workers to share live tracing state. Span identity and finalization across workers aren't yet guaranteed.
|
|
66
|
-
|
|
67
65
|
## Sampling strategies
|
|
68
66
|
|
|
69
67
|
Sampling allows you to control which traces are collected, helping you balance between observability needs and resource costs.
|
|
@@ -334,6 +334,10 @@ constructor(options: {
|
|
|
334
334
|
bodyLimitOptions?: BodyLimitOptions;
|
|
335
335
|
streamOptions?: StreamOptions;
|
|
336
336
|
customRouteAuthConfig?: Map<string, boolean>;
|
|
337
|
+
tools?: ToolsInput;
|
|
338
|
+
taskStore?: InMemoryTaskStore;
|
|
339
|
+
customApiRoutes?: ApiRoute[];
|
|
340
|
+
mcpOptions?: MCPOptions;
|
|
337
341
|
}) {
|
|
338
342
|
super(options);
|
|
339
343
|
}
|
|
@@ -290,12 +290,12 @@ requestContext.set(MASTRA_RESOURCE_ID_KEY, user.id)
|
|
|
290
290
|
requestContext.set(MASTRA_THREAD_ID_KEY, threadId)
|
|
291
291
|
```
|
|
292
292
|
|
|
293
|
-
| Key | Purpose
|
|
294
|
-
| --------------------------- |
|
|
295
|
-
| `MASTRA_RESOURCE_ID_KEY` | Forces all memory operations to use this resource ID. The server validates that accessed threads belong to this resource and returns 403 if not.
|
|
296
|
-
| `MASTRA_THREAD_ID_KEY` | Forces thread operations to use this thread ID, overriding client-provided values
|
|
297
|
-
| `MASTRA_SCOPES_KEY` | Sets the [scopes](https://mastra.ai/docs/memory/overview) the agent run acts as, as an array of `<type>:<value>` strings. Combined with the agent's `scopes` and
|
|
298
|
-
| `MASTRA_MESSAGE_AUTHOR_KEY` | Names who sent a user message as `{ id, name?, avatarUrl? }`. Agent-controller sessions persist it at `content.metadata.signal.author` and mirror it to `providerMetadata.mastra.author` for compatibility, so a thread shared by several people can show who wrote what.
|
|
293
|
+
| Key | Purpose |
|
|
294
|
+
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
295
|
+
| `MASTRA_RESOURCE_ID_KEY` | Forces all memory operations to use this resource ID. The server validates that accessed threads belong to this resource and returns 403 if not. |
|
|
296
|
+
| `MASTRA_THREAD_ID_KEY` | Forces thread operations to use this thread ID, overriding client-provided values |
|
|
297
|
+
| `MASTRA_SCOPES_KEY` | Sets the [scopes](https://mastra.ai/docs/memory/overview) the agent run acts as, as an array of `<type>:<value>` strings. Combined with per-call `scopes`; the agent's `scopes` list adds to them, and a `scopes` function replaces them. A `resource:` or `thread:` scope that conflicts with another resource or thread value returns a 400 error. |
|
|
298
|
+
| `MASTRA_MESSAGE_AUTHOR_KEY` | Names who sent a user message as `{ id, name?, avatarUrl? }`. Agent-controller sessions persist it at `content.metadata.signal.author` and mirror it to `providerMetadata.mastra.author` for compatibility, so a thread shared by several people can show who wrote what. |
|
|
299
299
|
|
|
300
300
|
Server ownership checks read only `MASTRA_RESOURCE_ID_KEY` and `MASTRA_THREAD_ID_KEY`. If your middleware sets identity through `MASTRA_SCOPES_KEY` and you want those checks, set `MASTRA_RESOURCE_ID_KEY` too:
|
|
301
301
|
|
|
@@ -594,12 +594,13 @@ When using server adapters, configuration comes from two places: the Mastra `ser
|
|
|
594
594
|
|
|
595
595
|
The adapter reads these settings from `mastra.getServer()`:
|
|
596
596
|
|
|
597
|
-
| Option | Description
|
|
598
|
-
| --------------- |
|
|
599
|
-
| `auth` | Authentication config, used by `registerAuthMiddleware()`.
|
|
600
|
-
| `
|
|
601
|
-
| `
|
|
602
|
-
| `
|
|
597
|
+
| Option | Description |
|
|
598
|
+
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
599
|
+
| `auth` | Authentication config, used by `registerAuthMiddleware()`. |
|
|
600
|
+
| `apiRoutes` | Custom [`registerApiRoute()`](https://mastra.ai/reference/server/register-api-route) routes, registered by `registerCustomApiRoutes()` and added to the OpenAPI spec when `openapiPath` is set. The adapter constructor `customApiRoutes` option overrides this list. |
|
|
601
|
+
| `bodySizeLimit` | Default body size limit in bytes. Can be overridden per-adapter via `bodyLimitOptions`. |
|
|
602
|
+
| `onError` | Custom error handler called when an unhandled error occurs in a route handler. See [server.onError](https://mastra.ai/reference/configuration). |
|
|
603
|
+
| `middleware` | User [middleware](https://mastra.ai/docs/server/middleware), registered by `registerUserMiddleware()`. Hono-based adapters run it; Elysia, Express, Fastify, Koa, and NestJS log a warning because Hono handlers can't run there. |
|
|
603
604
|
|
|
604
605
|
### Adapter constructor only
|
|
605
606
|
|
|
@@ -618,12 +619,11 @@ These options are passed directly to the adapter constructor and aren't read fro
|
|
|
618
619
|
|
|
619
620
|
These `server` config options are only used by `mastra build` and have no effect when using adapters directly:
|
|
620
621
|
|
|
621
|
-
| Option | Used by
|
|
622
|
-
| -------------- |
|
|
623
|
-
| `port`, `host` | `mastra dev`, `mastra build`
|
|
624
|
-
| `cors` | `mastra build` adds CORS middleware
|
|
625
|
-
| `timeout` | `mastra build`
|
|
626
|
-
| `apiRoutes` | `registerApiRoute()` for `mastra build` |
|
|
622
|
+
| Option | Used by |
|
|
623
|
+
| -------------- | ----------------------------------- |
|
|
624
|
+
| `port`, `host` | `mastra dev`, `mastra build` |
|
|
625
|
+
| `cors` | `mastra build` adds CORS middleware |
|
|
626
|
+
| `timeout` | `mastra build` |
|
|
627
627
|
|
|
628
628
|
When using adapters, configure these features directly with your framework. For example, add CORS middleware using Hono's or Express's built-in CORS packages, and set the port when calling your framework's listen function.
|
|
629
629
|
|
|
@@ -119,7 +119,9 @@ if (action === 'persist') {
|
|
|
119
119
|
|
|
120
120
|
Only idle threads persist here. An active thread still delivers to the running run, so `persisted` is set only when the action is `persist`.
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
Message and signal sends return an `accepted` promise. It resolves when Mastra decides what to do, not when a run finishes. `sendNotificationSignal()` includes `accepted` only when its delivery policy emits a signal, so check `decision` first. `sendStateSignal()` omits it when it skips an unchanged snapshot.
|
|
123
|
+
|
|
124
|
+
The `accepted` promise resolves with one of these actions:
|
|
123
125
|
|
|
124
126
|
- `wake`: this process started a run for the input.
|
|
125
127
|
- `deliver`: the input was sent to a run, or another process accepted responsibility for starting one.
|
|
@@ -4,43 +4,59 @@
|
|
|
4
4
|
|
|
5
5
|
# Knowledge
|
|
6
6
|
|
|
7
|
-
Studio
|
|
7
|
+
Studio's Knowledge page shows what your agents know: every scope and page, how they link, and who wrote what. Use it to check content you loaded and to watch agents' edits as they happen. It's read-only.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
The routes that feed it are **off by default**. Until you enable them, the Knowledge page in Studio shows an explainer saying Knowledge browsing isn't enabled.
|
|
9
|
+
> **Alpha:** Knowledge is in alpha. Its API may change between releases.
|
|
12
10
|
|
|
13
11
|
## Enable the routes
|
|
14
12
|
|
|
15
|
-
Register the Knowledge routes
|
|
13
|
+
The Knowledge routes are **off by default**. Until you enable them, Studio's Knowledge page says browsing isn't enabled. Register the Knowledge instance on `Mastra` and add the routes:
|
|
16
14
|
|
|
17
15
|
```typescript
|
|
18
|
-
import { Mastra } from '@mastra/core'
|
|
16
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
19
17
|
import { KNOWLEDGE_ROUTES } from '@mastra/server/server-adapter'
|
|
18
|
+
import { knowledge } from './knowledge'
|
|
19
|
+
import { supportAgent } from './agents/support-agent'
|
|
20
20
|
|
|
21
21
|
export const mastra = new Mastra({
|
|
22
|
+
agents: { supportAgent },
|
|
23
|
+
knowledge: { company: knowledge },
|
|
22
24
|
server: { apiRoutes: [...KNOWLEDGE_ROUTES] },
|
|
23
25
|
})
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
The routes mount under your server's API prefix, `/api/knowledge` by default, and need `@mastra/core` 1.81.0 or later. With 1.81.0, Studio counts links only among the pages it has loaded. [Server routes](https://mastra.ai/reference/server/routes) lists each route, its parameters and its errors.
|
|
29
|
+
|
|
30
|
+
## What you see
|
|
31
|
+
|
|
32
|
+
- **Tree**: every scope and the pages inside it, nested the way your agents organized them.
|
|
33
|
+
- **Graph**: the same pages and how they connect. Lines show each page's parent, the pages its notes mention, the links written in its body, and which scopes grant access to which. A legend names each kind of line. Select a page in either view to open it.
|
|
34
|
+
- **Page**: the body, version and who last updated it, its notes with their authors, its child pages, the notes on other pages that mention it, and who it's pinned for.
|
|
35
|
+
- **Activity**: each page's history of creates, edits, moves, merges, notes and pins, with the author and time of each.
|
|
36
|
+
- **Search**: over page names, descriptions, bodies and note text.
|
|
37
|
+
|
|
38
|
+
On narrow screens the tree and graph share one panel, with a toggle between them that keeps the selected page.
|
|
39
|
+
|
|
40
|
+
When an agent writes, the tree, graph and open page update as it happens, without a reload. Studio follows writes made through the Knowledge instance registered with Mastra. Writes from another process or another instance on the same storage show up after a reload.
|
|
27
41
|
|
|
28
|
-
|
|
29
|
-
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
30
|
-
| `GET /knowledge` | The Knowledge instances you can read |
|
|
31
|
-
| `GET /knowledge/:knowledgeKey/tree` | The root scopes, or the child scopes and pages under `parentId` |
|
|
32
|
-
| `GET /knowledge/:knowledgeKey/pages/:pageId` | One page with its ancestors, notes, pin and referenced pages |
|
|
33
|
-
| `GET /knowledge/:knowledgeKey/graph` | A bounded graph of pages with parent and mention edges |
|
|
34
|
-
| `GET /knowledge/:knowledgeKey/search` | Pages and notes matching a query |
|
|
35
|
-
| `GET /knowledge/:knowledgeKey/activity` | Recent changes, optionally for one scope or page |
|
|
36
|
-
| `GET /knowledge/:knowledgeKey/events` | A Server-Sent Events stream of the writes the caller can read, which Studio follows to show changes as they happen |
|
|
42
|
+

|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
Hover over or select a page in the graph to draw its links: solid green lines for the pages it links to, dashed orange lines for the pages that link to it.
|
|
45
|
+
|
|
46
|
+

|
|
47
|
+
|
|
48
|
+
Focus a page to see only it, its parent and its child pages.
|
|
49
|
+
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
In an agent's chat, Knowledge tool calls show the pages they read or wrote, and pinned pages show what the run received. Both link to the page in this view.
|
|
53
|
+
|
|
54
|
+
## Control who sees what
|
|
39
55
|
|
|
40
56
|
What the routes return depends on whether your app configures auth (`server.auth` or `studio.auth`):
|
|
41
57
|
|
|
42
|
-
- **No auth:** the routes read as the instance owner and return every scope, page and note.
|
|
43
|
-
- **Auth:** the routes return only what the signed-in
|
|
58
|
+
- **No auth:** the routes read as the instance owner and return every scope, page and note to anyone who can reach the server. Use this only for a local or test project, and add auth before you deploy.
|
|
59
|
+
- **Auth:** the routes return only what the signed-in user can read. In `authorize`, set the request context key `MASTRA_KNOWLEDGE_PRINCIPALS_KEY` to the user's Knowledge scopes. Knowledge applies the same access rules agents use. In the alpha, these rules aren't an [isolation boundary](https://mastra.ai/docs/knowledge/scopes-and-access), so don't store content that must never reach another user.
|
|
44
60
|
|
|
45
61
|
```typescript
|
|
46
62
|
import { Mastra } from '@mastra/core/mastra'
|
|
@@ -69,13 +85,18 @@ export const mastra = new Mastra({
|
|
|
69
85
|
})
|
|
70
86
|
```
|
|
71
87
|
|
|
88
|
+
If you set a different prefix, change the `/api/knowledge` check in `authorize` to match. Otherwise the key isn't set and the routes return `403`.
|
|
89
|
+
|
|
72
90
|
An `authorize` function replaces the server's rules and role checks for every route, so keep your app's existing decision for the other paths, as above. Returning `true` for everything would let any signed-in user call any route.
|
|
73
91
|
|
|
74
|
-
Set the value to
|
|
92
|
+
Set the value to an array of scopes, or `'all'` for someone who should see the whole instance. An empty array reads nothing. See [Knowledge access and errors](https://mastra.ai/reference/server/routes) for what other values return. If you configure `studio.auth`, Studio requests use it instead of `server.auth`, so set the key in that `authorize`.
|
|
75
93
|
|
|
76
|
-
|
|
94
|
+
### Deployment notes
|
|
77
95
|
|
|
78
|
-
- **No auth configured:** the routes are open to anyone who can reach the server and read the whole instance. Enable them only where Studio itself is private.
|
|
79
96
|
- **No RBAC provider:** the `knowledge:read` check is skipped, so any authenticated user with a principal mapping can read the pages those principals cover, in every instance.
|
|
80
|
-
- **With an FGA provider:** Knowledge
|
|
81
|
-
- **NestJS:** the NestJS adapter doesn't serve the Knowledge routes yet.
|
|
97
|
+
- **With an FGA provider:** each Knowledge instance is checked separately with `knowledge:read`. A user sees only the instances you grant. See [Knowledge access and errors](https://mastra.ai/reference/server/routes).
|
|
98
|
+
- **NestJS:** the NestJS adapter doesn't serve the Knowledge routes yet.
|
|
99
|
+
|
|
100
|
+
## Build your own view
|
|
101
|
+
|
|
102
|
+
To show Knowledge changes in your own app, subscribe with [`knowledge.onChange()`](https://mastra.ai/reference/knowledge/knowledge-class). Events carry IDs, not content. Read the page again under the user's scopes before you show it to them. A `page` `delete` event can't be read again, so remove the page from your view. A `page` `merge` event's `pageId` is the target, so also remove the merged-away page in `sourceId`. A `scope` event is sent for a new scope only, not for its child scopes or template pages, so list the scope again to find them.
|
|
@@ -63,6 +63,8 @@ CSV exports contain plain cell text, including link labels rather than URLs. Foo
|
|
|
63
63
|
|
|
64
64
|
You can also attach [scorers](#scorers) to measure and compare response quality over time.
|
|
65
65
|
|
|
66
|
+
To ask about part of a response, select the text in the message and choose **Add to chat**, or press Tab to reach it from the keyboard. Each passage you add gets a numbered comment bubble in the chat, and the message box counts them, for example **2 annotations**. Select a bubble to write a comment on that passage or remove it, or open the count to find a passage in the chat. When you send, the agent receives a numbered list of the passages, each quoted with its comment, ahead of what you type. You can also send the annotations without typing anything. A selection that spans two messages doesn't offer **Add to chat**.
|
|
67
|
+
|
|
66
68
|
You can send a follow-up message in the same thread during an agent response stream. Studio shows the message as pending until the stream confirms it, then continues the response below that follow-up. Other Studio tabs that have the same thread open can observe the active stream.
|
|
67
69
|
|
|
68
70
|
Use [Editor](https://mastra.ai/docs/studio/editor) to let non-technical team members iterate on agents and version every change, plus run experiments without redeploying.
|
|
@@ -73,7 +75,7 @@ Use [Agent Builder](https://agent-builder.mastra.ai) to create and manage fully
|
|
|
73
75
|
|
|
74
76
|
Open an agent's **Models** panel to view its primary model and fallback models in priority order. For static model lists, you can reorder models, enable or disable fallbacks, and change the provider or model. The panel stays synchronized when Studio refetches the agent.
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
When the agent sets `editor: { model: true }`, these edits are saved through [Editor](https://mastra.ai/docs/studio/editor). This requires a configured `MastraEditor` and agent storage; without either, saving fails with HTTP 500. Otherwise they change the running server's in-memory agent and are lost when the server restarts. Persistent editing for other agents is tracked in [GitHub issue #27089](https://github.com/mastra-ai/mastra/issues/27089).
|
|
77
79
|
|
|
78
80
|
Function-valued model lists can vary by request context, so Studio displays them as read-only. Change a dynamic model list in code instead.
|
|
79
81
|
|
|
@@ -4,9 +4,48 @@
|
|
|
4
4
|
|
|
5
5
|
# Clerk
|
|
6
6
|
|
|
7
|
+
Use Clerk with Mastra in two ways:
|
|
8
|
+
|
|
9
|
+
- **Agent tools** let an agent manage Clerk users, organizations, and sessions through [Mastra Connect](https://mastra.ai/docs/mastra-platform/connect).
|
|
10
|
+
- **[Server authentication](#server-authentication)** verifies requests to your Mastra server with Clerk, using the `@mastra/auth-clerk` package.
|
|
11
|
+
|
|
12
|
+
## Connect
|
|
13
|
+
|
|
14
|
+
Before you start, complete the [Connect setup](https://mastra.ai/docs/mastra-platform/connect) to install `@mastra/connect` and configure your platform project.
|
|
15
|
+
|
|
16
|
+
### Agent tools
|
|
17
|
+
|
|
18
|
+
Give agents tools to manage users, organizations, memberships, invitations, roles, and sessions in Clerk.
|
|
19
|
+
|
|
20
|
+
Connect an account with the `clerk` provider ID. Run this command from the directory that contains your `.env` file:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
mastra connect add clerk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Then pass [`tools()`](https://mastra.ai/reference/connect/tools) to the agent and select the provider:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { Agent } from '@mastra/core/agent'
|
|
30
|
+
import { tools } from '@mastra/connect'
|
|
31
|
+
|
|
32
|
+
export const clerkAgent = new Agent({
|
|
33
|
+
id: 'clerk-agent',
|
|
34
|
+
name: 'Clerk agent',
|
|
35
|
+
instructions:
|
|
36
|
+
'You help people manage users, organizations, memberships, invitations, roles, and sessions in Clerk.',
|
|
37
|
+
model: '__GATEWAY_OPENAI_MODEL_LUNA__',
|
|
38
|
+
tools: tools({ providers: ['clerk'] }),
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The agent gets 42 Clerk tools, with keys such as `clerk_assign_organization_role_permission`. See [Clerk tools](https://mastra.ai/reference/connect/providers) for the full list, and the [`tools()` parameters](https://mastra.ai/reference/connect/tools) to restrict tools or require approval before a call runs.
|
|
43
|
+
|
|
44
|
+
## Server authentication
|
|
45
|
+
|
|
7
46
|
The `@mastra/auth-clerk` package 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.
|
|
8
47
|
|
|
9
|
-
|
|
48
|
+
### Prerequisites
|
|
10
49
|
|
|
11
50
|
This example uses Clerk authentication. Make sure to add your Clerk credentials to your `.env` file and ensure your Clerk project is properly configured.
|
|
12
51
|
|
|
@@ -18,7 +57,7 @@ CLERK_JWKS_URI=https://your-clerk-domain.clerk.accounts.dev/.well-known/jwks.jso
|
|
|
18
57
|
|
|
19
58
|
> **Note:** You can find these keys in your Clerk Dashboard under "API Keys".
|
|
20
59
|
|
|
21
|
-
|
|
60
|
+
### Installation
|
|
22
61
|
|
|
23
62
|
Before you can use the `MastraAuthClerk` class you have to install the `@mastra/auth-clerk` package.
|
|
24
63
|
|
|
@@ -46,7 +85,7 @@ yarn add @mastra/auth-clerk@latest
|
|
|
46
85
|
bun add @mastra/auth-clerk@latest
|
|
47
86
|
```
|
|
48
87
|
|
|
49
|
-
|
|
88
|
+
### Usage example
|
|
50
89
|
|
|
51
90
|
```typescript
|
|
52
91
|
import { Mastra } from '@mastra/core'
|
|
@@ -67,11 +106,11 @@ export const mastra = new Mastra({
|
|
|
67
106
|
>
|
|
68
107
|
> Visit [MastraAuthClerk](https://mastra.ai/reference/auth/clerk) for all available configuration options.
|
|
69
108
|
|
|
70
|
-
|
|
109
|
+
### Client-side setup
|
|
71
110
|
|
|
72
111
|
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.
|
|
73
112
|
|
|
74
|
-
|
|
113
|
+
#### Retrieving the access token
|
|
75
114
|
|
|
76
115
|
Use the Clerk React hooks to authenticate users and retrieve their access token:
|
|
77
116
|
|
|
@@ -92,7 +131,7 @@ export const useClerkAuth = () => {
|
|
|
92
131
|
|
|
93
132
|
Refer to the [Clerk documentation](https://clerk.com/docs) for more information.
|
|
94
133
|
|
|
95
|
-
|
|
134
|
+
### Configuring `MastraClient`
|
|
96
135
|
|
|
97
136
|
When `auth` is enabled, all requests made with `MastraClient` must include a valid Clerk access token in the `Authorization` header:
|
|
98
137
|
|
|
@@ -111,7 +150,7 @@ export const mastraClient = new MastraClient({
|
|
|
111
150
|
>
|
|
112
151
|
> Visit [Mastra Client SDK](https://mastra.ai/docs/server/mastra-client) for more configuration options.
|
|
113
152
|
|
|
114
|
-
|
|
153
|
+
#### Making authenticated requests
|
|
115
154
|
|
|
116
155
|
Once `MastraClient` is configured with the Clerk access token, you can send authenticated requests:
|
|
117
156
|
|