@mastra/mcp-docs-server 1.1.46-alpha.3 → 1.1.46
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/agent-builder/browser.md +1 -1
- package/.docs/docs/agent-builder/channels.md +1 -1
- package/.docs/docs/agent-builder/integrations.md +73 -0
- package/.docs/docs/agent-builder/overview.md +1 -0
- package/.docs/docs/agents/adding-voice.md +1 -1
- package/.docs/docs/agents/agent-approval.md +2 -2
- package/.docs/docs/agents/background-tasks.md +1 -1
- package/.docs/docs/agents/channels.md +2 -2
- package/.docs/docs/agents/code-mode.md +20 -56
- package/.docs/docs/agents/overview.md +1 -0
- package/.docs/docs/agents/sdk-agents.md +165 -1
- package/.docs/docs/agents/supervisor-agents.md +40 -2
- package/.docs/docs/agents/using-tools.md +59 -1
- package/.docs/docs/browser/agent-browser.md +1 -1
- package/.docs/docs/browser/browser-viewer.md +22 -15
- package/.docs/docs/browser/overview.md +1 -1
- package/.docs/docs/browser/stagehand.md +1 -1
- package/.docs/docs/editor/overview.md +6 -6
- package/.docs/docs/editor/prompts.md +3 -3
- package/.docs/docs/editor/tools.md +2 -2
- package/.docs/docs/evals/evals-with-memory.md +8 -8
- package/.docs/docs/mastra-platform/observability.md +1 -1
- package/.docs/docs/mastra-platform/server.md +1 -1
- package/.docs/docs/mcp/mcp-apps.md +4 -4
- package/.docs/docs/memory/observational-memory.md +1 -1
- package/.docs/docs/memory/working-memory.md +2 -2
- package/.docs/docs/observability/integrations/bridges/datadog.md +1 -1
- package/.docs/docs/observability/integrations/bridges/otel.md +1 -1
- package/.docs/docs/observability/integrations/exporters/laminar.md +1 -1
- package/.docs/docs/observability/integrations/exporters/langfuse.md +26 -1
- package/.docs/docs/observability/integrations/exporters/mastra-platform.md +1 -1
- package/.docs/docs/observability/integrations/exporters/mastra-storage.md +4 -4
- package/.docs/docs/observability/integrations/exporters/otel.md +1 -1
- package/.docs/docs/observability/integrations/overview.md +1 -1
- package/.docs/docs/observability/logging.md +1 -1
- package/.docs/docs/observability/metrics/overview.md +3 -3
- package/.docs/docs/observability/metrics/querying.md +2 -2
- package/.docs/docs/observability/storage.md +2 -2
- package/.docs/docs/observability/tracing/overview.md +1 -1
- package/.docs/docs/server/auth/fga.md +15 -15
- package/.docs/docs/server/auth/okta.md +2 -2
- package/.docs/docs/server/auth/workos.md +1 -1
- package/.docs/docs/server/custom-api-routes.md +1 -1
- package/.docs/docs/server/pubsub.md +4 -4
- package/.docs/docs/studio/auth.md +1 -1
- package/.docs/docs/studio/observability.md +3 -1
- package/.docs/docs/workflows/scheduled-workflows.md +13 -13
- package/.docs/docs/workspace/filesystem.md +1 -1
- package/.docs/docs/workspace/lsp.md +1 -1
- package/.docs/docs/workspace/overview.md +35 -1
- package/.docs/docs/workspace/sandbox.md +4 -3
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +2 -2
- package/.docs/guides/deployment/aws-bedrock-agentcore.md +3 -3
- package/.docs/guides/deployment/inngest.md +5 -5
- package/.docs/guides/deployment/temporal.md +3 -3
- package/.docs/guides/getting-started/nestjs.md +1 -1
- package/.docs/guides/migrations/mastra-cloud.md +3 -3
- package/.docs/guides/migrations/upgrade-to-v1/overview.md +1 -1
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +1 -1
- package/.docs/reference/acp/acp-agent.md +2 -2
- package/.docs/reference/agents/agent.md +44 -0
- package/.docs/reference/agents/channels.md +1 -1
- package/.docs/reference/agents/durable-agent.md +2 -2
- package/.docs/reference/agents/generate.md +2 -0
- package/.docs/reference/agents/generateLegacy.md +2 -0
- package/.docs/reference/ai-sdk/handle-chat-stream.md +1 -1
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +1 -1
- package/.docs/reference/auth/okta.md +1 -1
- package/.docs/reference/auth/workos.md +1 -1
- package/.docs/reference/browser/agent-browser.md +1 -1
- package/.docs/reference/browser/browser-viewer.md +11 -9
- package/.docs/reference/browser/stagehand-browser.md +1 -1
- package/.docs/reference/cli/mastra.md +3 -1
- package/.docs/reference/client-js/responses.md +2 -2
- package/.docs/reference/client-js/workflows.md +1 -1
- package/.docs/reference/configuration.md +1 -1
- package/.docs/reference/core/removeWorkspace.md +26 -0
- package/.docs/reference/editor/browser-provider.md +1 -1
- package/.docs/reference/editor/storage-browser-ref.md +3 -3
- package/.docs/reference/editor/storage-workspace-ref.md +1 -1
- package/.docs/reference/evals/rubric.md +113 -0
- package/.docs/reference/evals/trajectory-accuracy.md +3 -3
- package/.docs/reference/harness/harness-class.md +81 -62
- package/.docs/reference/index.md +5 -0
- package/.docs/reference/memory/serialized-memory-config.md +1 -1
- package/.docs/reference/observability/metrics/automatic-metrics.md +3 -3
- package/.docs/reference/observability/tracing/bridges/datadog.md +1 -1
- package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +3 -3
- package/.docs/reference/observability/tracing/exporters/default-exporter.md +1 -1
- package/.docs/reference/observability/tracing/exporters/mastra-platform-exporter.md +5 -5
- package/.docs/reference/observability/tracing/exporters/mastra-storage-exporter.md +1 -1
- package/.docs/reference/observability/tracing/exporters/otel.md +1 -1
- package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +2 -2
- package/.docs/reference/processors/cost-guard-processor.md +2 -2
- package/.docs/reference/processors/processor-interface.md +4 -4
- package/.docs/reference/processors/response-cache.md +2 -2
- package/.docs/reference/processors/skill-search-processor.md +3 -3
- package/.docs/reference/processors/tool-search-processor.md +108 -4
- package/.docs/reference/pubsub/base.md +1 -1
- package/.docs/reference/pubsub/caching-pubsub.md +2 -2
- package/.docs/reference/pubsub/event-emitter.md +3 -3
- package/.docs/reference/pubsub/google-cloud-pubsub.md +1 -1
- package/.docs/reference/pubsub/redis-streams.md +1 -1
- package/.docs/reference/pubsub/unix-socket-pubsub.md +1 -1
- package/.docs/reference/server/nestjs-adapter.md +2 -2
- package/.docs/reference/signals/task-signal-provider.md +62 -0
- package/.docs/reference/storage/clickhouse.md +49 -4
- package/.docs/reference/storage/composite.md +33 -1
- package/.docs/reference/storage/convex.md +2 -2
- package/.docs/reference/storage/dsql.md +7 -7
- package/.docs/reference/storage/duckdb.md +3 -3
- package/.docs/reference/storage/redis.md +3 -3
- package/.docs/reference/storage/spanner.md +7 -7
- package/.docs/reference/streaming/agents/stream.md +2 -0
- package/.docs/reference/streaming/agents/streamLegacy.md +2 -0
- package/.docs/reference/streaming/agents/streamUntilIdle.md +1 -1
- package/.docs/reference/tools/brightdata.md +3 -3
- package/.docs/reference/tools/create-code-mode.md +124 -0
- package/.docs/reference/tools/create-tool.md +1 -1
- package/.docs/reference/tools/mcp-client.md +5 -5
- package/.docs/reference/tools/mcp-server.md +45 -0
- package/.docs/reference/tools/perplexity.md +4 -4
- package/.docs/reference/tools/tavily.md +3 -3
- package/.docs/reference/voice/aws-nova-sonic.md +1 -1
- package/.docs/reference/voice/google-gemini-live.md +1 -1
- package/.docs/reference/voice/inworld-realtime.md +5 -5
- package/.docs/reference/voice/inworld.md +1 -1
- package/.docs/reference/voice/sarvam.md +1 -1
- package/.docs/reference/workspace/agentcore-runtime-sandbox.md +7 -7
- package/.docs/reference/workspace/azure-blob-filesystem.md +2 -2
- package/.docs/reference/workspace/files-sdk-filesystem.md +3 -3
- package/.docs/reference/workspace/google-drive-filesystem.md +7 -7
- package/.docs/reference/workspace/modal-sandbox.md +1 -1
- package/.docs/reference/workspace/railway-sandbox.md +230 -0
- package/.docs/reference/workspace/vercel-microvm-sandbox.md +1 -1
- package/.docs/reference/workspace/vercel.md +2 -2
- package/.docs/reference/workspace/workspace-class.md +39 -3
- package/CHANGELOG.md +20 -0
- package/dist/chunk-GLPCVXXO.js +2075 -0
- package/dist/chunk-GLPCVXXO.js.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/stdio.js +1 -2070
- package/dist/stdio.js.map +1 -1
- package/package.json +6 -6
|
@@ -8,7 +8,7 @@ ClickHouse is most commonly used as the dedicated observability backend in a [co
|
|
|
8
8
|
|
|
9
9
|
Production observability for traces, logs, metrics, scores, and feedback.
|
|
10
10
|
|
|
11
|
-
For local development, use a composite store that combines [LibSQL](https://mastra.ai/reference/storage/libsql) (for memory and workflows) and `@mastra/duckdb` (for observability). Neither alone covers a development setup: LibSQL
|
|
11
|
+
For local development, use a composite store that combines [LibSQL](https://mastra.ai/reference/storage/libsql) (for memory and workflows) and `@mastra/duckdb` (for observability). Neither alone covers a development setup: LibSQL doesn't implement the observability domain, and DuckDB doesn't implement the other domains. See the [observability overview](https://mastra.ai/docs/observability/overview) for an example.
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
@@ -44,7 +44,7 @@ You will also need a running ClickHouse server. See [Hosting options](#hosting-o
|
|
|
44
44
|
|
|
45
45
|
`ObservabilityStorageClickhouseVNext` is the current observability domain implementation. It uses an insert-only schema backed by `ReplacingMergeTree` and is optimized for the volume produced by traces, logs, metrics, scores, and feedback.
|
|
46
46
|
|
|
47
|
-
Compose it with another storage adapter so observability writes
|
|
47
|
+
Compose it with another storage adapter so observability writes don't contend with your application data:
|
|
48
48
|
|
|
49
49
|
```typescript
|
|
50
50
|
import { Mastra } from '@mastra/core'
|
|
@@ -85,7 +85,7 @@ export const mastra = new Mastra({
|
|
|
85
85
|
|
|
86
86
|
### Observability with the legacy domain
|
|
87
87
|
|
|
88
|
-
`ObservabilityStorageClickhouse` is the original observability adapter and remains supported for projects that
|
|
88
|
+
`ObservabilityStorageClickhouse` is the original observability adapter and remains supported for projects that haven't migrated to the vNext schema. The configuration shape is the same as the vNext class.
|
|
89
89
|
|
|
90
90
|
```typescript
|
|
91
91
|
import { ObservabilityStorageClickhouse } from '@mastra/clickhouse'
|
|
@@ -182,10 +182,55 @@ The same `client` form is accepted by `ObservabilityStorageClickhouse` and `Obse
|
|
|
182
182
|
|
|
183
183
|
**ttl** (`object`): Per-table TTL configuration applied at table creation time. Accepts row-level and column-level TTLs in interval units from \`NANOSECOND\` through \`YEAR\`.
|
|
184
184
|
|
|
185
|
+
**replication** (`{ cluster?: string; zookeeperPath?: string; replicaName?: string }`): Opt-in replicated table configuration for multi-replica ClickHouse clusters. When set, Mastra creates replicated MergeTree tables. When \`cluster\` is set, Mastra also adds \`ON CLUSTER\` to Mastra-owned data definition language (DDL).
|
|
186
|
+
|
|
185
187
|
**disableInit** (`boolean`): When \`true\`, the store does not run table creation or migrations on first use. Call \`storage.init()\` explicitly from your deployment scripts. (Default: `false`)
|
|
186
188
|
|
|
187
189
|
`ClickhouseStore` also accepts every option from `ClickHouseClientConfigOptions` (such as `database`, `request_timeout`, `compression`, `keep_alive`, and `max_open_connections`).
|
|
188
190
|
|
|
191
|
+
### Replicated clusters
|
|
192
|
+
|
|
193
|
+
Use `replication` when Mastra writes to a multi-replica ClickHouse cluster through a load balancer.
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const storage = new ClickhouseStoreVNext({
|
|
197
|
+
id: 'clickhouse-storage',
|
|
198
|
+
url: process.env.CLICKHOUSE_URL!,
|
|
199
|
+
username: process.env.CLICKHOUSE_USERNAME!,
|
|
200
|
+
password: process.env.CLICKHOUSE_PASSWORD!,
|
|
201
|
+
replication: {
|
|
202
|
+
cluster: 'company_cluster',
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
When `replication` is set, Mastra rewrites its `MergeTree` and `ReplacingMergeTree` table engines to `ReplicatedMergeTree` and `ReplicatedReplacingMergeTree`. The default engine arguments are:
|
|
208
|
+
|
|
209
|
+
- `zookeeperPath`: `'/clickhouse/tables/{shard}/{database}/{table}'`
|
|
210
|
+
- `replicaName`: `'{replica}'`
|
|
211
|
+
|
|
212
|
+
The defaults match the most common self-managed convention. If your cluster's existing tables use a different layout (for example `/clickhouse/tables/{shard}/{table}` without the `{database}` segment), set `zookeeperPath` explicitly to match. Mastra does not read your cluster's convention from Keeper, so a mismatched default writes Mastra's metadata to a separate branch from the rest of the cluster.
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
new ClickhouseStoreVNext({
|
|
216
|
+
url: process.env.CLICKHOUSE_URL!,
|
|
217
|
+
username: process.env.CLICKHOUSE_USERNAME!,
|
|
218
|
+
password: process.env.CLICKHOUSE_PASSWORD!,
|
|
219
|
+
replication: {
|
|
220
|
+
cluster: 'company_cluster',
|
|
221
|
+
zookeeperPath: '/clickhouse/tables/{shard}/{table}',
|
|
222
|
+
},
|
|
223
|
+
})
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Set `cluster` to add `ON CLUSTER` to Mastra-owned DDL such as table creation, materialized view creation, column migrations, TTL changes, and table drops.
|
|
227
|
+
|
|
228
|
+
Manual maintenance such as `optimizeTable()` and `materializeTtl()` runs on every replica when `cluster` is set. These operations can be expensive on a large cluster. Prefer running them outside peak hours, and let routine merges happen on the background merge queue rather than triggering them on every restart.
|
|
229
|
+
|
|
230
|
+
If existing Mastra tables use local `MergeTree` or `ReplacingMergeTree` engines, initialization fails while `replication` is enabled. Mastra refuses to silently convert local tables because copy-and-swap is unsafe across replicas. To migrate, recreate the affected tables as `Replicated*` before enabling replication. The typical sequence is: rename the local table, run `CREATE TABLE ... ENGINE = ReplicatedMergeTree(...) ON CLUSTER ...`, run `INSERT INTO ... SELECT * FROM <renamed_local>`, then drop the renamed local table.
|
|
231
|
+
|
|
232
|
+
Do not set `replication` on ClickHouse Cloud. Cloud rewrites `MergeTree` to `SharedMergeTree` server-side, and explicit `ReplicatedMergeTree` engines produce incorrect DDL. `replication` is only for self-managed multi-replica clusters.
|
|
233
|
+
|
|
189
234
|
### Observability domain options
|
|
190
235
|
|
|
191
236
|
`ObservabilityStorageClickhouse` and `ObservabilityStorageClickhouseVNext` accept the same connection options as `ClickhouseStore` (`url`, `username`, `password`, or a pre-configured `client`).
|
|
@@ -261,7 +306,7 @@ Two ways to provision the database:
|
|
|
261
306
|
|
|
262
307
|
The same approach applies to other hosts with ephemeral filesystems. For application data that should also live off-host, pair this setup with a managed PostgreSQL or LibSQL/Turso instance for the `default` storage.
|
|
263
308
|
|
|
264
|
-
> **Warning:**
|
|
309
|
+
> **Warning:** Don't point an embedded backend like DuckDB at a path inside an ephemeral container filesystem. Data written there is lost when the container restarts, and on some platforms the path is read-only.
|
|
265
310
|
|
|
266
311
|
## Initialization
|
|
267
312
|
|
|
@@ -240,6 +240,38 @@ const storage = new MastraCompositeStore({
|
|
|
240
240
|
})
|
|
241
241
|
```
|
|
242
242
|
|
|
243
|
-
> **Note:** `ObservabilityStorageClickhouseVNext` is the current observability domain implementation. The legacy `ObservabilityStorageClickhouse` class is also exported and remains supported for projects that
|
|
243
|
+
> **Note:** `ObservabilityStorageClickhouseVNext` is the current observability domain implementation. The legacy `ObservabilityStorageClickhouse` class is also exported and remains supported for projects that haven't migrated. See the [ClickHouse storage reference](https://mastra.ai/reference/storage/clickhouse) for details.
|
|
244
|
+
|
|
245
|
+
### Replicated ClickHouse for multi-replica clusters
|
|
246
|
+
|
|
247
|
+
For self-managed ClickHouse clusters with multiple replicas, set `replication` so Mastra emits `ReplicatedMergeTree` engines and applies `ON CLUSTER` to its DDL:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
251
|
+
import { MemoryPG, WorkflowsPG, ScoresPG } from '@mastra/pg'
|
|
252
|
+
import { ObservabilityStorageClickhouseVNext } from '@mastra/clickhouse'
|
|
253
|
+
|
|
254
|
+
const storage = new MastraCompositeStore({
|
|
255
|
+
id: 'composite',
|
|
256
|
+
domains: {
|
|
257
|
+
memory: new MemoryPG({ connectionString: process.env.DATABASE_URL }),
|
|
258
|
+
workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
|
|
259
|
+
scores: new ScoresPG({ connectionString: process.env.DATABASE_URL }),
|
|
260
|
+
observability: new ObservabilityStorageClickhouseVNext({
|
|
261
|
+
url: process.env.CLICKHOUSE_URL,
|
|
262
|
+
username: process.env.CLICKHOUSE_USERNAME,
|
|
263
|
+
password: process.env.CLICKHOUSE_PASSWORD,
|
|
264
|
+
replication: {
|
|
265
|
+
cluster: 'production_cluster',
|
|
266
|
+
// Optional (defaults shown):
|
|
267
|
+
// zookeeperPath: '/clickhouse/tables/{shard}/{database}/{table}',
|
|
268
|
+
// replicaName: '{replica}',
|
|
269
|
+
},
|
|
270
|
+
}),
|
|
271
|
+
},
|
|
272
|
+
})
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Do not set `replication` on ClickHouse Cloud. Cloud rewrites `MergeTree` to `SharedMergeTree` server-side. See the [ClickHouse storage reference](https://mastra.ai/reference/storage/clickhouse) for the full config shape and operator notes.
|
|
244
276
|
|
|
245
277
|
> **Info:** This approach is also required when using storage providers that don't support observability (like Convex, DynamoDB, or Cloudflare). See the [MastraStorageExporter documentation](https://mastra.ai/docs/observability/integrations/exporters/mastra-storage) for the full list of supported providers.
|
|
@@ -176,13 +176,13 @@ For very large cache namespaces, clear incrementally or use narrower prefixes to
|
|
|
176
176
|
|
|
177
177
|
During batched cleanup, cache metadata can temporarily use an internal `deleted` state. The next cleanup pass removes those rows. Avoid writing new values with the same prefix until `clear()` finishes.
|
|
178
178
|
|
|
179
|
-
`clear()` only removes rows whose stored `keyPrefix` exactly matches the configured `keyPrefix`. It
|
|
179
|
+
`clear()` only removes rows whose stored `keyPrefix` exactly matches the configured `keyPrefix`. It doesn't clear nested prefixes by string prefix matching. Each `listPush()` refreshes the list TTL using the cache's configured `ttlMs`.
|
|
180
180
|
|
|
181
181
|
Use a non-empty `keyPrefix` unless you intentionally want `clear()` to remove every cache key in the deployment. Expired list rows are reclaimed incrementally during reads and writes; `clear()` removes all rows for the prefix.
|
|
182
182
|
|
|
183
183
|
`ConvexServerCache` works best for durable replay of moderate-frequency events. For high-frequency token streams, prefer batching events or using a lower-latency cache backend.
|
|
184
184
|
|
|
185
|
-
`ConvexServerCache`
|
|
185
|
+
`ConvexServerCache` doesn't replace a distributed pub/sub transport. If your app needs live cross-process event delivery, configure a production pub/sub backend separately.
|
|
186
186
|
|
|
187
187
|
## Additional notes
|
|
188
188
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The Aurora DSQL storage implementation provides storage using Amazon Aurora DSQL with IAM authentication.
|
|
4
4
|
|
|
5
|
-
Aurora DSQL
|
|
5
|
+
Aurora DSQL doesn't support PostgreSQL extensions (`CREATE EXTENSION`), including `pgvector`. For vector storage, use a separate vector store such as `@mastra/s3vectors`.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -170,7 +170,7 @@ const memoryStore = await storage.getStore('memory')
|
|
|
170
170
|
const thread = await memoryStore?.getThreadById({ threadId: '...' })
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
> **Warning:** If `init()`
|
|
173
|
+
> **Warning:** If `init()` isn't called, tables won't be created and storage operations will fail silently or throw errors.
|
|
174
174
|
|
|
175
175
|
### Direct Database and Pool Access
|
|
176
176
|
|
|
@@ -193,7 +193,7 @@ This approach is intended for advanced scenarios where low-level access is requi
|
|
|
193
193
|
|
|
194
194
|
#### IAM-only authentication
|
|
195
195
|
|
|
196
|
-
Connections are authenticated with IAM.
|
|
196
|
+
Connections are authenticated with IAM. No database passwords are required. `@mastra/dsql` uses `@aws/aurora-dsql-node-postgres-connector` to generate short-lived auth tokens. You can provide a custom credentials provider via `customCredentialsProvider`.
|
|
197
197
|
|
|
198
198
|
#### Single database, schema-based isolation
|
|
199
199
|
|
|
@@ -201,7 +201,7 @@ Each cluster exposes a single database named `postgres`. Logical separation is d
|
|
|
201
201
|
|
|
202
202
|
#### No PostgreSQL extensions
|
|
203
203
|
|
|
204
|
-
`CREATE EXTENSION`
|
|
204
|
+
`CREATE EXTENSION` isn't supported. This includes `pgvector`, `PostGIS`, and others. For vector storage, use a separate store such as `@mastra/s3vectors` alongside `DSQLStore`.
|
|
205
205
|
|
|
206
206
|
#### JSON stored as text
|
|
207
207
|
|
|
@@ -209,7 +209,7 @@ JSON/JSONB are available as query types but not as column types. `@mastra/dsql`
|
|
|
209
209
|
|
|
210
210
|
#### Schema and DDL constraints
|
|
211
211
|
|
|
212
|
-
Some PostgreSQL features
|
|
212
|
+
Some PostgreSQL features aren't available:
|
|
213
213
|
|
|
214
214
|
- Foreign key constraints
|
|
215
215
|
- `TRUNCATE`
|
|
@@ -219,7 +219,7 @@ Indexes are created asynchronously using `CREATE INDEX ASYNC`. The store's `init
|
|
|
219
219
|
|
|
220
220
|
#### Transactions and optimistic concurrency
|
|
221
221
|
|
|
222
|
-
Aurora DSQL uses optimistic concurrency control (OCC) and may return retriable OCC errors under contention.
|
|
222
|
+
Aurora DSQL uses optimistic concurrency control (OCC) and may return retriable OCC errors under contention. Limits exist on transaction duration and size. Large bulk operations should be split into smaller batches at the application level.
|
|
223
223
|
|
|
224
224
|
#### Connection lifetime
|
|
225
225
|
|
|
@@ -332,7 +332,7 @@ await storage.createIndex({
|
|
|
332
332
|
})
|
|
333
333
|
```
|
|
334
334
|
|
|
335
|
-
Aurora DSQL
|
|
335
|
+
Aurora DSQL doesn't allow `ASC`/`DESC` in `CREATE INDEX ASYNC`. If you include them, they will be automatically stripped.
|
|
336
336
|
|
|
337
337
|
### Index Options
|
|
338
338
|
|
|
@@ -6,11 +6,11 @@ For vector search, see the [DuckDB vector store reference](https://mastra.ai/ref
|
|
|
6
6
|
|
|
7
7
|
## When to use DuckDB
|
|
8
8
|
|
|
9
|
-
Local development of observability features. DuckDB is embedded and file-based, so it
|
|
9
|
+
Local development of observability features. DuckDB is embedded and file-based, so it doesn't require a server and starts instantly. It supports the same observability signals as ClickHouse, which makes it useful for testing dashboards and trace exploration before deploying to a production backend.
|
|
10
10
|
|
|
11
11
|
DuckDB currently implements only the `observability` domain. Pair it with another storage adapter (such as [LibSQL](https://mastra.ai/reference/storage/libsql)) for `memory` and `workflows` in a [composite storage](https://mastra.ai/reference/storage/composite) setup.
|
|
12
12
|
|
|
13
|
-
> **Warning:** DuckDB is for development and not recommended for production. It runs in-process, persists to a single local file, and
|
|
13
|
+
> **Warning:** DuckDB is for development and not recommended for production. It runs in-process, persists to a single local file, and doesn't work on platforms with ephemeral filesystems (such as Railway, Fly.io, Render, Heroku, or serverless containers). For production observability, use [ClickHouse](https://mastra.ai/reference/storage/clickhouse).
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -110,7 +110,7 @@ const duckdb = new DuckDBStore({ path: ':memory:' })
|
|
|
110
110
|
|
|
111
111
|
### Lower-level types
|
|
112
112
|
|
|
113
|
-
`@mastra/duckdb` also exports `DuckDBConnection` for sharing a single underlying database across multiple Mastra storage instances, and the corresponding `DuckDBStorageConfig` type. Most applications
|
|
113
|
+
`@mastra/duckdb` also exports `DuckDBConnection` for sharing a single underlying database across multiple Mastra storage instances, and the corresponding `DuckDBStorageConfig` type. Most applications won't need these directly.
|
|
114
114
|
|
|
115
115
|
## Supported domains
|
|
116
116
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Redis Storage
|
|
2
2
|
|
|
3
|
-
The Redis storage implementation provides a high-performance storage solution using direct Redis connections via [node-redis](https://github.com/redis/node-redis) (the official Redis client for Node.js). It supports standalone Redis, and through custom client configuration, Redis Sentinel and Cluster deployments.
|
|
3
|
+
The Redis storage implementation provides a high-performance storage solution using direct Redis connections via [`node-redis`](https://github.com/redis/node-redis) (the official Redis client for Node.js). It supports standalone Redis, and through custom client configuration, Redis Sentinel and Cluster deployments.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -41,7 +41,7 @@ await storage.init()
|
|
|
41
41
|
|
|
42
42
|
### Using Pre-configured Client
|
|
43
43
|
|
|
44
|
-
For advanced configurations like Sentinel or Cluster, you can pass a pre-configured
|
|
44
|
+
For advanced configurations like Sentinel or Cluster, you can pass a pre-configured Redis client:
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
47
|
import { RedisStore } from '@mastra/redis'
|
|
@@ -142,7 +142,7 @@ const storage = new RedisStore({
|
|
|
142
142
|
|
|
143
143
|
### Accessing the Underlying Client
|
|
144
144
|
|
|
145
|
-
You can access the underlying
|
|
145
|
+
You can access the underlying Redis client for custom operations:
|
|
146
146
|
|
|
147
147
|
```typescript
|
|
148
148
|
const storage = new RedisStore({
|
|
@@ -138,7 +138,7 @@ Two tables also carry Spanner-specific `STORED` generated columns that the adapt
|
|
|
138
138
|
|
|
139
139
|
Both are added via `ALTER TABLE ... ADD COLUMN IF NOT EXISTS` during `init()` and skipped under `initMode: 'validate'` (where the schema is owned externally). When the column is absent, the adapter falls back to a `JSON_VALUE` filter at runtime.
|
|
140
140
|
|
|
141
|
-
The adapter
|
|
141
|
+
The adapter doesn't create or use named schemas; use a dedicated database for isolation.
|
|
142
142
|
|
|
143
143
|
### Initialization
|
|
144
144
|
|
|
@@ -160,7 +160,7 @@ const mastra = new Mastra({
|
|
|
160
160
|
})
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
-
If you use storage directly, call `init()` once before the first operation. Spanner
|
|
163
|
+
If you use storage directly, call `init()` once before the first operation. Spanner doesn't allow concurrent schema changes, so `SpannerStore.init()` runs each domain's setup sequentially.
|
|
164
164
|
|
|
165
165
|
```typescript
|
|
166
166
|
const storage = new SpannerStore({
|
|
@@ -175,18 +175,18 @@ const memory = await storage.getStore('memory')
|
|
|
175
175
|
const thread = await memory?.getThreadById({ threadId: '...' })
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
> **Warning:** If `init()`
|
|
178
|
+
> **Warning:** If `init()` isn't called and `disableInit` is true, the required tables won't exist and storage operations will fail.
|
|
179
179
|
|
|
180
180
|
### GoogleSQL specifics
|
|
181
181
|
|
|
182
182
|
A few behaviors differ from other relational adapters:
|
|
183
183
|
|
|
184
|
-
- Upserts use `INSERT OR UPDATE`. Spanner
|
|
185
|
-
-
|
|
184
|
+
- Upserts use `INSERT OR UPDATE`. Spanner doesn't provide a `RETURNING` clause for upserts, so callers needing the post-write state must read it back.
|
|
185
|
+
- No `TRUNCATE` exists; `dangerouslyClearAll()` issues `DELETE WHERE TRUE`.
|
|
186
186
|
- Identifiers are quoted with backticks.
|
|
187
187
|
- DDL is applied through `database.updateSchema(...)`, which is asynchronous (long-running operation).
|
|
188
|
-
- `NULLS FIRST/LAST`
|
|
189
|
-
- JSON containment
|
|
188
|
+
- `NULLS FIRST/LAST` isn't supported. Ordering with NULL handling is emulated through an `IS NULL` ordering key.
|
|
189
|
+
- JSON containment isn't supported natively. `listTraces` `metadata` and `scope` filters compile to per-key `JSON_VALUE(...) = @v` equality checks, and `tags` filters compile to `EXISTS` over `JSON_QUERY_ARRAY(...)`. This differs from Postgres' `@>` containment operator (which can match nested structure in a single index scan) — most one-shot lookups still work but deeply nested structural matches aren't expressible.
|
|
190
190
|
|
|
191
191
|
### Direct database access
|
|
192
192
|
|
|
@@ -168,6 +168,8 @@ const stream = await agent.stream('message for agent')
|
|
|
168
168
|
|
|
169
169
|
**options.clientTools** (`ToolsInput`): Tools that are executed on the 'client' side of the request. These tools do not have execute functions in the definition.
|
|
170
170
|
|
|
171
|
+
**options.hooks** (`ToolHooks`): Per-execution hooks that run before and after tool calls. Overrides matching agent-level hooks for this execution. \`beforeToolCall\` can return \`{ proceed: false, output }\` to skip the tool call.
|
|
172
|
+
|
|
171
173
|
**options.savePerStep** (`boolean`): Save messages incrementally after each stream step completes (default: false).
|
|
172
174
|
|
|
173
175
|
**options.requireToolApproval** (`boolean`): When true, all tool calls require explicit approval before execution. The stream will emit \`tool-call-approval\` chunks and pause until \`approveToolCall()\` or \`declineToolCall()\` is called.
|
|
@@ -82,6 +82,8 @@ await agent.streamLegacy('message for agent')
|
|
|
82
82
|
|
|
83
83
|
**options.clientTools** (`ToolsInput`): Tools that are executed on the 'client' side of the request. These tools do not have execute functions in the definition.
|
|
84
84
|
|
|
85
|
+
**options.hooks** (`ToolHooks`): Per-execution hooks that run before and after tool calls. Overrides matching agent-level hooks for this execution. \`beforeToolCall\` can return \`{ proceed: false, output }\` to skip the tool call.
|
|
86
|
+
|
|
85
87
|
**options.savePerStep** (`boolean`): Save messages incrementally after each stream step completes (default: false).
|
|
86
88
|
|
|
87
89
|
**options.providerOptions** (`Record<string, Record<string, JSONValue>>`): Additional provider-specific options that are passed through to the underlying LLM provider. The structure is \`{ providerName: { optionKey: value } }\`. For example: \`{ openai: { reasoningEffort: 'high' }, anthropic: { maxTokens: 1000 } }\`.
|
|
@@ -62,7 +62,7 @@ Internally, `streamUntilIdle()`:
|
|
|
62
62
|
|
|
63
63
|
1. Runs the initial turn via `agent.stream(...)` and pipes its `fullStream` into the outer stream.
|
|
64
64
|
2. Subscribes to background-task completion events for the resolved memory scope.
|
|
65
|
-
3. Queues each terminal event (`background-task-completed`, `background-task-failed`, `background-task-cancelled`) and, when the outer wrapper is idle between turns, re-invokes `agent.stream([], ...)` with a directive listing the
|
|
65
|
+
3. Queues each terminal event (`background-task-completed`, `background-task-failed`, `background-task-cancelled`) and, when the outer wrapper is idle between turns, re-invokes `agent.stream([], ...)` with a directive listing the completed `toolCallId`s. The continuation turn flows into the same outer stream.
|
|
66
66
|
4. Closes the outer stream once no tasks are running and no completions are queued.
|
|
67
67
|
|
|
68
68
|
## Extended usage example
|
|
@@ -155,9 +155,9 @@ const agent = new Agent({
|
|
|
155
155
|
|
|
156
156
|
## Environment variables
|
|
157
157
|
|
|
158
|
-
| Variable | Description
|
|
159
|
-
| ---------------------- |
|
|
160
|
-
| `BRIGHTDATA_API_TOKEN` | Your Bright Data API token. Used as the default when `apiKey`
|
|
158
|
+
| Variable | Description |
|
|
159
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------- |
|
|
160
|
+
| `BRIGHTDATA_API_TOKEN` | Your Bright Data API token. Used as the default when `apiKey` isn't passed to a factory function. |
|
|
161
161
|
|
|
162
162
|
## Related
|
|
163
163
|
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# createCodeMode()
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.38.0`
|
|
4
|
+
|
|
5
|
+
The `createCodeMode()` function returns a tool and generated instructions that let an agent run multi-tool computations as one TypeScript function. The generated code runs in a workspace sandbox, and each `external_*` call runs the real tool on the host with validation, request context, and tracing.
|
|
6
|
+
|
|
7
|
+
For a conceptual overview, see [Code mode](https://mastra.ai/docs/agents/code-mode).
|
|
8
|
+
|
|
9
|
+
## Usage example
|
|
10
|
+
|
|
11
|
+
Create a code mode tool, add its generated instructions to the agent, and register the returned tool with the same id.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Agent } from '@mastra/core/agent'
|
|
15
|
+
import { createCodeMode, createTool } from '@mastra/core/tools'
|
|
16
|
+
import { LocalSandbox } from '@mastra/core/workspace'
|
|
17
|
+
import { z } from 'zod'
|
|
18
|
+
|
|
19
|
+
const getTopProducts = createTool({
|
|
20
|
+
id: 'getTopProducts',
|
|
21
|
+
description: 'Get top selling products',
|
|
22
|
+
inputSchema: z.object({ limit: z.number() }),
|
|
23
|
+
outputSchema: z.object({
|
|
24
|
+
products: z.array(z.object({ id: z.string(), name: z.string(), totalSales: z.number() })),
|
|
25
|
+
}),
|
|
26
|
+
execute: async ({ limit }) => fetchTopProducts(limit),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const getProductRatings = createTool({
|
|
30
|
+
id: 'getProductRatings',
|
|
31
|
+
description: 'Get ratings for a product',
|
|
32
|
+
inputSchema: z.object({ productId: z.string() }),
|
|
33
|
+
outputSchema: z.object({ ratings: z.array(z.object({ score: z.number() })) }),
|
|
34
|
+
execute: async ({ productId }) => fetchRatings(productId),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const { tool, instructions } = createCodeMode({
|
|
38
|
+
tools: { getTopProducts, getProductRatings },
|
|
39
|
+
sandbox: new LocalSandbox(),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
export const shopAgent = new Agent({
|
|
43
|
+
name: 'shop-assistant',
|
|
44
|
+
instructions: ['You are a helpful shopping assistant.', instructions],
|
|
45
|
+
model: 'openai/gpt-5.5',
|
|
46
|
+
tools: { execute_typescript: tool },
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Parameters
|
|
51
|
+
|
|
52
|
+
**config** (`CodeModeConfig`): Configuration for the code mode tool and generated instructions.
|
|
53
|
+
|
|
54
|
+
**config.tools** (`ToolsInput`): Tools exposed to the generated code as \`external\_\<id>\` functions. Only these tools can be called.
|
|
55
|
+
|
|
56
|
+
**config.sandbox** (`WorkspaceSandbox`): Sandbox used to execute the generated code. Required unless the agent runs in a workspace that provides a sandbox. Pass \`new LocalSandbox()\` to run on the host explicitly.
|
|
57
|
+
|
|
58
|
+
**config.timeout** (`number`): Execution timeout in milliseconds.
|
|
59
|
+
|
|
60
|
+
**config.id** (`string`): The generated tool id.
|
|
61
|
+
|
|
62
|
+
**transport** (`CodeModeTransport`): Optional transport implementation used to run the generated code in the sandbox. The default transport uses stdio JSON-RPC over the workspace sandbox process API.
|
|
63
|
+
|
|
64
|
+
## Returns
|
|
65
|
+
|
|
66
|
+
Returns a `CodeModeResult` object.
|
|
67
|
+
|
|
68
|
+
**tool** (`Tool<any, any>`): The generated code mode tool. By default, its id is \`execute\_typescript\`.
|
|
69
|
+
|
|
70
|
+
**instructions** (`string`): Generated model instructions with typed \`external\_\*\` declarations for the configured tools.
|
|
71
|
+
|
|
72
|
+
## CodeModeToolResult
|
|
73
|
+
|
|
74
|
+
The generated tool returns a `CodeModeToolResult`.
|
|
75
|
+
|
|
76
|
+
**success** (`boolean`): Whether the generated code ran to completion without throwing.
|
|
77
|
+
|
|
78
|
+
**result** (`unknown`): The value returned by the generated code.
|
|
79
|
+
|
|
80
|
+
**logs** (`string[]`): Captured console output from \`console.log\`, \`console.info\`, \`console.warn\`, and \`console.error\`, in order.
|
|
81
|
+
|
|
82
|
+
**error** (`{ message: string; name?: string; line?: number }`): Error details when the generated code throws or fails to execute.
|
|
83
|
+
|
|
84
|
+
**error.message** (`string`): Error message.
|
|
85
|
+
|
|
86
|
+
**error.name** (`string`): Error name, when available.
|
|
87
|
+
|
|
88
|
+
**error.line** (`number`): Line number associated with the failure, when available.
|
|
89
|
+
|
|
90
|
+
## Inspecting instructions
|
|
91
|
+
|
|
92
|
+
Use `createCodeModeInstructions()` to inspect the exact prompt content generated for a set of tools.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { createCodeModeInstructions } from '@mastra/core/tools'
|
|
96
|
+
|
|
97
|
+
console.log(
|
|
98
|
+
createCodeModeInstructions({
|
|
99
|
+
tools: { getTopProducts, getProductRatings },
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The instructions include the usage contract and one typed `declare function external_<id>(...)` line for each configured tool. Tool ids are sanitized into valid TypeScript function names, and conflicting sanitized names throw an error.
|
|
105
|
+
|
|
106
|
+
## createCodeModeTool()
|
|
107
|
+
|
|
108
|
+
Use `createCodeModeTool()` when you only need the tool and want to manage instructions separately. Most agents should use `createCodeMode()` so the tool and matching instructions stay together.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { createCodeModeTool } from '@mastra/core/tools'
|
|
112
|
+
import { LocalSandbox } from '@mastra/core/workspace'
|
|
113
|
+
|
|
114
|
+
export const codeModeTool = createCodeModeTool({
|
|
115
|
+
tools: { getTopProducts, getProductRatings },
|
|
116
|
+
sandbox: new LocalSandbox(),
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Related
|
|
121
|
+
|
|
122
|
+
- [Code mode](https://mastra.ai/docs/agents/code-mode)
|
|
123
|
+
- [createTool()](https://mastra.ai/reference/tools/create-tool)
|
|
124
|
+
- [Workspace overview](https://mastra.ai/docs/workspace/overview)
|
|
@@ -125,7 +125,7 @@ export const weatherTool = createTool({
|
|
|
125
125
|
})
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
Mastra forwards `strict: true` to model adapters that support strict tool calling. On adapters that
|
|
128
|
+
Mastra forwards `strict: true` to model adapters that support strict tool calling. On adapters that don't support strict tool calling, Mastra ignores this option.
|
|
129
129
|
|
|
130
130
|
## Example with `toModelOutput`
|
|
131
131
|
|
|
@@ -153,7 +153,7 @@ const agent = new Agent({
|
|
|
153
153
|
})
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
-
When `forwardInstructions` is omitted (the default), instructions are still cached and can be inspected via [`getServerInstructions()`](#getserverinstructions), but
|
|
156
|
+
When `forwardInstructions` is omitted (the default), instructions are still cached and can be inspected via [`getServerInstructions()`](#getserverinstructions), but aren't added to any agent's system prompt.
|
|
157
157
|
|
|
158
158
|
> **Security note:** server instructions are forwarded verbatim (subject only to length truncation) into the agent's system prompt. A malicious or compromised MCP server can use them to inject instructions the agent will treat as trusted system guidance. Only enable `forwardInstructions` for servers you trust, and prefer reviewing instructions with `getServerInstructions()` before forwarding instructions from third-party servers.
|
|
159
159
|
|
|
@@ -179,7 +179,7 @@ const res = await agent.stream(prompt, {
|
|
|
179
179
|
|
|
180
180
|
### `getServerInstructions()`
|
|
181
181
|
|
|
182
|
-
Returns the instructions currently known for each configured MCP server. Servers that
|
|
182
|
+
Returns the instructions currently known for each configured MCP server. Servers that haven't connected yet, or don't advertise instructions, return `undefined`.
|
|
183
183
|
|
|
184
184
|
```typescript
|
|
185
185
|
getServerInstructions(): Record<string, string | undefined>
|
|
@@ -1065,9 +1065,9 @@ await agent.generate('Hello!', {
|
|
|
1065
1065
|
|
|
1066
1066
|
## Handling auth failures inside custom fetch
|
|
1067
1067
|
|
|
1068
|
-
A custom `fetch`
|
|
1068
|
+
A custom `fetch` shouldn't `throw` when authentication is unavailable. The Streamable HTTP transport in the MCP SDK opens a long-lived `GET /mcp` "standalone listener" stream in the background to receive server-pushed notifications. Errors on that stream are retried with exponential backoff, and a thrown `fetch` or a cleanly-closed stream can produce an indefinite reconnect loop at roughly one attempt per second.
|
|
1069
1069
|
|
|
1070
|
-
Return a synthetic `Response` instead. The [MCP Streamable HTTP specification](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports) defines `405 Method Not Allowed` as the signal a server returns when it
|
|
1070
|
+
Return a synthetic `Response` instead. The [MCP Streamable HTTP specification](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports) defines `405 Method Not Allowed` as the signal a server returns when it doesn't offer the GET SSE stream, and the SDK honors it as a terminal status that stops the listener cleanly. Use this to disable the listener when your server doesn't push notifications.
|
|
1071
1071
|
|
|
1072
1072
|
The following pattern waits for an auth token on POST requests, attaches it to outgoing headers, and short-circuits the GET listener with a synthetic 405:
|
|
1073
1073
|
|
|
@@ -1108,7 +1108,7 @@ const mcpClient = new MCPClient({
|
|
|
1108
1108
|
})
|
|
1109
1109
|
```
|
|
1110
1110
|
|
|
1111
|
-
Return `405` for the GET listener only when your server
|
|
1111
|
+
Return `405` for the GET listener only when your server doesn't push notifications back to the client. If your server uses the standalone GET stream, attach the auth token on `GET` requests as well and let the request through.
|
|
1112
1112
|
|
|
1113
1113
|
## Using SSE request headers
|
|
1114
1114
|
|
|
@@ -69,6 +69,8 @@ The constructor accepts an `MCPServerConfig` object with the following propertie
|
|
|
69
69
|
|
|
70
70
|
**mapAuthInfoToUser** (`({ authInfo, extra, requestContext }) => unknown | null | undefined | Promise<unknown | null | undefined>`): Maps MCP transport auth data from \`extra.authInfo\` into the \`user\` value used by Mastra FGA checks. Use this when an OAuth-protected MCP server is registered on a Mastra instance with an FGA provider.
|
|
71
71
|
|
|
72
|
+
**fga** (`{ resourceMapping?: Partial<Record<'tool' | 'tools', { fgaResourceType: string; deriveId?: ({ user, resourceId, requestContext }) => string | undefined }>>; permissionMapping?: Record<string, string> }`): Overrides resource and permission mappings for this MCP server's \`tools/list\` and \`tools/call\` FGA checks. Use this when MCP authorization should be scoped differently from internal agent or workflow tool execution.
|
|
73
|
+
|
|
72
74
|
**repository** (`Repository`): Optional repository information for the server's source code.
|
|
73
75
|
|
|
74
76
|
**releaseDate** (`string`): Optional release date of this server version (ISO 8601 string). Defaults to the time of instantiation if not provided.
|
|
@@ -1129,6 +1131,49 @@ const server = new MCPServer({
|
|
|
1129
1131
|
})
|
|
1130
1132
|
```
|
|
1131
1133
|
|
|
1134
|
+
### Scope MCP tool FGA separately
|
|
1135
|
+
|
|
1136
|
+
Use `fga.resourceMapping` and `fga.permissionMapping` when MCP clients need a different authorization scope than internal agent or workflow tool execution. The override applies only to `tools/list` and `tools/call` checks for this MCP server.
|
|
1137
|
+
|
|
1138
|
+
```typescript
|
|
1139
|
+
import { MastraFGAPermissions } from '@mastra/core/auth/ee'
|
|
1140
|
+
|
|
1141
|
+
const server = new MCPServer({
|
|
1142
|
+
id: 'my-server',
|
|
1143
|
+
name: 'My Server',
|
|
1144
|
+
version: '1.0.0',
|
|
1145
|
+
tools: { getUserData },
|
|
1146
|
+
mapAuthInfoToUser: ({ authInfo }) => {
|
|
1147
|
+
const user = authInfo as {
|
|
1148
|
+
extra?: {
|
|
1149
|
+
userId?: string
|
|
1150
|
+
organizationMembershipId?: string
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
if (!user.extra?.userId) {
|
|
1155
|
+
return null
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
return {
|
|
1159
|
+
id: user.extra.userId,
|
|
1160
|
+
organizationMembershipId: user.extra.organizationMembershipId,
|
|
1161
|
+
}
|
|
1162
|
+
},
|
|
1163
|
+
fga: {
|
|
1164
|
+
resourceMapping: {
|
|
1165
|
+
tool: {
|
|
1166
|
+
fgaResourceType: 'user',
|
|
1167
|
+
deriveId: ({ user }) => (user as { id: string }).id,
|
|
1168
|
+
},
|
|
1169
|
+
},
|
|
1170
|
+
permissionMapping: {
|
|
1171
|
+
[MastraFGAPermissions.TOOLS_EXECUTE]: 'read',
|
|
1172
|
+
},
|
|
1173
|
+
},
|
|
1174
|
+
})
|
|
1175
|
+
```
|
|
1176
|
+
|
|
1132
1177
|
### Setting Up Authentication Middleware
|
|
1133
1178
|
|
|
1134
1179
|
To pass data to your tools, populate `req.auth` on the Node.js request object in your HTTP server middleware before calling `server.startHTTP()`.
|
|
@@ -139,10 +139,10 @@ const agent = new Agent({
|
|
|
139
139
|
|
|
140
140
|
## Environment variables
|
|
141
141
|
|
|
142
|
-
| Variable | Description
|
|
143
|
-
| -------------------- |
|
|
144
|
-
| `PERPLEXITY_API_KEY` | Your Perplexity API key. Used as the default when `apiKey`
|
|
145
|
-
| `PPLX_API_KEY` | Fallback used when `PERPLEXITY_API_KEY` is unset.
|
|
142
|
+
| Variable | Description |
|
|
143
|
+
| -------------------- | ---------------------------------------------------------------------------------------------- |
|
|
144
|
+
| `PERPLEXITY_API_KEY` | Your Perplexity API key. Used as the default when `apiKey` isn't passed to a factory function. |
|
|
145
|
+
| `PPLX_API_KEY` | Fallback used when `PERPLEXITY_API_KEY` is unset. |
|
|
146
146
|
|
|
147
147
|
## Related
|
|
148
148
|
|
|
@@ -295,9 +295,9 @@ const agent = new Agent({
|
|
|
295
295
|
|
|
296
296
|
## Environment variables
|
|
297
297
|
|
|
298
|
-
| Variable | Description
|
|
299
|
-
| ---------------- |
|
|
300
|
-
| `TAVILY_API_KEY` | Your Tavily API key. Used as the default when `apiKey`
|
|
298
|
+
| Variable | Description |
|
|
299
|
+
| ---------------- | ------------------------------------------------------------------------------------------ |
|
|
300
|
+
| `TAVILY_API_KEY` | Your Tavily API key. Used as the default when `apiKey` isn't passed to a factory function. |
|
|
301
301
|
|
|
302
302
|
## Related
|
|
303
303
|
|
|
@@ -150,7 +150,7 @@ Returns: `Promise<void>`
|
|
|
150
150
|
|
|
151
151
|
### `endAudioInput()`
|
|
152
152
|
|
|
153
|
-
Signals the end of the current audio turn so the model can finalize its response. Call this when the user stops speaking and the provider
|
|
153
|
+
Signals the end of the current audio turn so the model can finalize its response. Call this when the user stops speaking and the provider isn't configured for server-side turn detection.
|
|
154
154
|
|
|
155
155
|
Returns: `Promise<void>`
|
|
156
156
|
|