@mastra/mcp-docs-server 1.2.14 → 1.2.15-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/.docs/docs/agents/a2a.md +75 -2
  2. package/.docs/docs/agents/processors.md +2 -0
  3. package/.docs/docs/agents/skills.md +15 -1
  4. package/.docs/docs/capabilities/channels/overview.md +19 -0
  5. package/.docs/docs/capabilities/subagents.md +23 -5
  6. package/.docs/docs/connections/overview.md +94 -0
  7. package/.docs/docs/datasets/running-experiments.md +18 -0
  8. package/.docs/docs/evals/overview.md +16 -4
  9. package/.docs/docs/harness/agent-controller.md +6 -0
  10. package/.docs/docs/harness/overview.md +26 -0
  11. package/.docs/docs/index.md +1 -1
  12. package/.docs/docs/mcp/overview.md +10 -0
  13. package/.docs/docs/memory/multi-user-threads.md +1 -1
  14. package/.docs/docs/memory/observational-memory.md +1 -1
  15. package/.docs/docs/memory/semantic-recall.md +2 -1
  16. package/.docs/docs/memory/working-memory.md +1 -0
  17. package/.docs/docs/observability/feedback.md +16 -0
  18. package/.docs/docs/observability/integrations/exporters/mastra-storage.md +1 -0
  19. package/.docs/docs/server/auth.md +2 -0
  20. package/.docs/docs/server/mastra-client.md +11 -11
  21. package/.docs/docs/storage/overview.md +1 -0
  22. package/.docs/docs/workflows/agents-and-tools.md +2 -2
  23. package/.docs/docs/workflows/{stored-workflows.md → dynamic-workflows.md} +23 -23
  24. package/.docs/docs/workflows/snapshots.md +3 -1
  25. package/.docs/guides/build-your-ui/ai-sdk-ui.md +25 -14
  26. package/.docs/guides/getting-started/quickstart.md +1 -1
  27. package/.docs/guides/rag/overview.md +1 -1
  28. package/.docs/guides/rag/retrieval.md +17 -0
  29. package/.docs/guides/rag/vector-databases.md +41 -0
  30. package/.docs/guides/voice/realtime-voice.md +28 -2
  31. package/.docs/models/gateways/neon.md +20 -14
  32. package/.docs/models/gateways/netlify.md +1 -2
  33. package/.docs/models/gateways/openrouter.md +4 -2
  34. package/.docs/models/gateways/vercel.md +10 -3
  35. package/.docs/models/index.md +1 -1
  36. package/.docs/models/providers/anthropic.md +2 -2
  37. package/.docs/models/providers/cortecs.md +2 -1
  38. package/.docs/models/providers/deepinfra.md +6 -3
  39. package/.docs/models/providers/digitalocean.md +6 -5
  40. package/.docs/models/providers/empiriolabs.md +6 -4
  41. package/.docs/models/providers/friendli.md +8 -9
  42. package/.docs/models/providers/huggingface.md +4 -1
  43. package/.docs/models/providers/hyper.md +5 -6
  44. package/.docs/models/providers/kilo.md +11 -9
  45. package/.docs/models/providers/llmgateway.md +3 -3
  46. package/.docs/models/providers/meta.md +7 -5
  47. package/.docs/models/providers/minimax.md +25 -23
  48. package/.docs/models/providers/nano-gpt.md +7 -4
  49. package/.docs/models/providers/neuralwatt.md +2 -1
  50. package/.docs/models/providers/ofox.md +74 -16
  51. package/.docs/models/providers/openai.md +28 -26
  52. package/.docs/models/providers/opencode-go.md +1 -1
  53. package/.docs/models/providers/opencode.md +2 -3
  54. package/.docs/models/providers/perplexity-agent.md +24 -24
  55. package/.docs/models/providers/pioneer.md +27 -1
  56. package/.docs/models/providers/regolo-ai.md +25 -20
  57. package/.docs/models/providers/upstage.md +3 -2
  58. package/.docs/models/providers/vivgrid.md +4 -2
  59. package/.docs/models/providers/wandb.md +1 -1
  60. package/.docs/reference/agents/channels.md +22 -1
  61. package/.docs/reference/agents/generate.md +1 -1
  62. package/.docs/reference/ai-sdk/chat-route.md +2 -0
  63. package/.docs/reference/browser/agent-browser.md +1 -1
  64. package/.docs/reference/browser/mastra-browser.md +1 -1
  65. package/.docs/reference/browser/stagehand-browser.md +1 -1
  66. package/.docs/reference/channels/slack-provider.md +2 -0
  67. package/.docs/reference/client-js/observability.md +22 -0
  68. package/.docs/reference/client-js/workflows.md +32 -19
  69. package/.docs/reference/configuration.md +26 -1
  70. package/.docs/reference/core/{addStoredWorkflow.md → addDynamicWorkflow.md} +10 -10
  71. package/.docs/reference/core/{addStoredWorkflows.md → addDynamicWorkflows.md} +9 -9
  72. package/.docs/reference/editor/tool-provider.md +26 -1
  73. package/.docs/reference/file-based-agents/config.md +22 -21
  74. package/.docs/reference/file-based-agents/instructions.md +42 -17
  75. package/.docs/reference/file-based-agents/schedules.md +232 -0
  76. package/.docs/reference/index.md +7 -3
  77. package/.docs/reference/observability/metrics/automatic-metrics.md +10 -8
  78. package/.docs/reference/rag/metadata-filters.md +13 -4
  79. package/.docs/reference/server/register-api-route.md +2 -0
  80. package/.docs/reference/server/routes.md +38 -24
  81. package/.docs/reference/storage/composite.md +58 -0
  82. package/.docs/reference/storage/oracledb.md +239 -0
  83. package/.docs/reference/storage/overview.md +9 -9
  84. package/.docs/reference/storage/retention.md +1 -1
  85. package/.docs/reference/streaming/agents/stream.md +1 -1
  86. package/.docs/reference/tools/bedrock-kb-tool.md +117 -0
  87. package/.docs/reference/tools/mcp-client.md +54 -0
  88. package/.docs/reference/vectors/oracledb.md +347 -0
  89. package/.docs/reference/voice/google.md +19 -3
  90. package/.docs/reference/workflows/{stored-workflow-definition.md → dynamic-workflow-definition.md} +7 -7
  91. package/.docs/reference/workflows/step.md +40 -0
  92. package/.docs/reference/workflows/workflow-methods/agent.md +3 -3
  93. package/.docs/reference/workflows/workflow-methods/tool.md +3 -3
  94. package/.docs/reference/workspace/daytona-sandbox.md +21 -0
  95. package/.docs/reference/workspace/workspace-class.md +2 -0
  96. package/CHANGELOG.md +51 -0
  97. package/package.json +6 -6
@@ -0,0 +1,239 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # OracleDB storage
4
+
5
+ The OracleDB storage provider stores Mastra application state in Oracle Database. It implements Mastra's composite storage interface, so one `OracleStore` instance can back memory, workflow snapshots, observability, scores, scorer definitions, MCP client metadata, and agent registry data.
6
+
7
+ ## Installation
8
+
9
+ **npm**:
10
+
11
+ ```bash
12
+ npm install @mastra/oracledb@latest
13
+ ```
14
+
15
+ **pnpm**:
16
+
17
+ ```bash
18
+ pnpm add @mastra/oracledb@latest
19
+ ```
20
+
21
+ **Yarn**:
22
+
23
+ ```bash
24
+ yarn add @mastra/oracledb@latest
25
+ ```
26
+
27
+ **Bun**:
28
+
29
+ ```bash
30
+ bun add @mastra/oracledb@latest
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```ts
36
+ import { OracleStore } from '@mastra/oracledb'
37
+
38
+ const storage = new OracleStore({
39
+ id: 'oracle-storage',
40
+ user: process.env.ORACLE_DATABASE_USER,
41
+ password: process.env.ORACLE_DATABASE_PASSWORD,
42
+ connectString: process.env.ORACLE_DATABASE_CONNECT_STRING,
43
+ })
44
+ ```
45
+
46
+ Use it with Mastra:
47
+
48
+ ```ts
49
+ import { Mastra } from '@mastra/core/mastra'
50
+
51
+ export const mastra = new Mastra({
52
+ storage,
53
+ })
54
+ ```
55
+
56
+ ## Parameters
57
+
58
+ **id** (`string`): Unique identifier for this storage instance.
59
+
60
+ **user** (`string`): Oracle Database user. Required unless using pool or externalAuth.
61
+
62
+ **password** (`string`): Password for the Oracle Database user. Required unless using pool or externalAuth.
63
+
64
+ **connectString** (`string`): Oracle connect string, service name, TNS alias, or Autonomous Database connect descriptor. Required unless using pool.
65
+
66
+ **pool** (`oracledb.Pool`): Existing Oracle connection pool. When provided, Mastra uses the pool but doesn't close it when store.close() is called.
67
+
68
+ **poolManager** (`OraclePoolManager`): Shared Oracle pool manager. Use this to share one Oracle pool between OracleStore and OracleVector.
69
+
70
+ **schemaName** (`string`): Oracle schema name used to qualify storage tables.
71
+
72
+ **poolMin** (`number`): Minimum number of Oracle pool connections. (Default: `0`)
73
+
74
+ **poolMax** (`number`): Maximum number of Oracle pool connections. (Default: `4`)
75
+
76
+ **poolIncrement** (`number`): Number of connections to add when the pool grows. (Default: `1`)
77
+
78
+ **configDir** (`string`): Directory containing Oracle Network configuration files such as tnsnames.ora.
79
+
80
+ **walletLocation** (`string`): Oracle wallet directory for mTLS connections such as Autonomous Database.
81
+
82
+ **walletPassword** (`string`): Password for the Oracle wallet, when required by the wallet configuration.
83
+
84
+ **externalAuth** (`boolean`): Use Oracle external authentication instead of username/password authentication.
85
+
86
+ **disableInit** (`boolean`): When true, automatic schema initialization is disabled. Use this when schema changes are applied separately before the app starts. (Default: `false`)
87
+
88
+ **messageBatchSize** (`number`): Number of messages sent per Oracle executeMany call when saving messages. The operation still commits once at the transaction boundary. (Default: `200`)
89
+
90
+ **skipDefaultIndexes** (`boolean`): When true, default storage indexes aren't created during initialization.
91
+
92
+ **indexes** (`OracleCreateIndexOptions[]`): Custom Oracle index definitions to create during initialization. Indexes are routed to the storage domain that owns the target table.
93
+
94
+ **migrationTableName** (`string`): Oracle table used to track storage schema migrations. (Default: `'MASTRA_ORACLE_MIGRATIONS'`)
95
+
96
+ **vectorRegistryTableName** (`string`): OracleVector registry table used to discover semantic-recall vector tables when threads or messages are deleted. Set this to match OracleVector's registryTableName when that option is customized.
97
+
98
+ ## Connection examples
99
+
100
+ The basic username/password constructor is shown above. For Autonomous Database, add wallet options to the same constructor:
101
+
102
+ ```ts
103
+ const storage = new OracleStore({
104
+ id: 'oracle-storage',
105
+ user: process.env.ORACLE_DATABASE_USER,
106
+ password: process.env.ORACLE_DATABASE_PASSWORD,
107
+ connectString: process.env.ORACLE_DATABASE_CONNECT_STRING,
108
+ walletLocation: process.env.ORACLE_DATABASE_WALLET_DIR,
109
+ walletPassword: process.env.ORACLE_DATABASE_WALLET_PASSWORD,
110
+ configDir: process.env.ORACLE_DATABASE_CONFIG_DIR,
111
+ })
112
+ ```
113
+
114
+ For external authentication, set `externalAuth: true` and omit `password`. To reuse an existing `oracledb.Pool`, pass it as `pool`. Mastra uses it but doesn't close it.
115
+
116
+ `OracleStore` backs memory, workflow snapshots, observability, scores, scorer definitions, MCP client metadata, and agent registry data. When using the store outside a `Mastra` instance, call `await storage.init()` and access a domain with `await storage.getStore('memory')`.
117
+
118
+ ## Initialization
119
+
120
+ When you pass `OracleStore` to `Mastra`, `init()` is called automatically before storage operations run. If you use `OracleStore` directly, call `init()` before reading or writing:
121
+
122
+ ```ts
123
+ await storage.init()
124
+ ```
125
+
126
+ > **Warning:** If initialization is disabled or skipped, storage operations require the Oracle tables and indexes to already exist.
127
+
128
+ `OracleStore.init()` runs repeatable migrations and records the result in the migration ledger table. The default ledger table is `MASTRA_ORACLE_MIGRATIONS`.
129
+
130
+ ```ts
131
+ await storage.migrate()
132
+ const history = await storage.listMigrations()
133
+ ```
134
+
135
+ Repeatable migrations are idempotent. They reconcile the tables and indexes owned by each storage domain on startup, which lets new domain indexes or compatible schema additions apply without changing application code.
136
+
137
+ Initialization also creates the provider's default indexes for common Mastra query paths. Use `skipDefaultIndexes` when indexes are managed separately, or pass `indexes` for custom Oracle indexes. Custom definitions support Oracle options such as `bitmap`, `online`, `invisible`, `parallel`, `compress`, `noLogging`, and `reverse`, as well as function-based expressions like `JSON_VALUE(...)`.
138
+
139
+ Custom indexes are useful when your app repeatedly filters on JSON metadata or when database administrators (DBAs) want to test an index before the optimizer uses it:
140
+
141
+ ```ts
142
+ const storage = new OracleStore({
143
+ id: 'oracle-storage',
144
+ user,
145
+ password,
146
+ connectString,
147
+ indexes: [
148
+ {
149
+ name: 'idx_messages_status',
150
+ table: 'mastra_messages',
151
+ columns: [
152
+ "JSON_VALUE(metadata, '$.status' RETURNING VARCHAR2(32) NULL ON ERROR)",
153
+ 'thread_id',
154
+ ],
155
+ online: true,
156
+ invisible: true,
157
+ },
158
+ ],
159
+ })
160
+ ```
161
+
162
+ Use `invisible` for staged rollout, then remove it after validating query plans. Use `skipDefaultIndexes: true` only when a DBA-managed indexing strategy replaces the defaults.
163
+
164
+ Use `disableInit: true` when schema changes are applied by a separate deployment step or by a database administrator.
165
+
166
+ ## Schema export
167
+
168
+ Use `exportSchemas()` to generate Oracle DDL without connecting to a database. This is useful when schema changes are reviewed or applied outside application startup.
169
+
170
+ ```ts
171
+ import { exportSchemas } from '@mastra/oracledb'
172
+
173
+ const ddl = exportSchemas({
174
+ schemaName: 'MASTRA_APP',
175
+ domains: [
176
+ 'memory',
177
+ 'workflows',
178
+ 'observability',
179
+ 'scores',
180
+ 'scorerDefinitions',
181
+ 'mcpClients',
182
+ 'agents',
183
+ ],
184
+ })
185
+
186
+ console.log(ddl)
187
+ ```
188
+
189
+ `domains` defaults to every supported domain, including `vector`, when omitted.
190
+
191
+ ## Operational notes
192
+
193
+ Use the same `OraclePoolManager` when `OracleStore` and `OracleVector` should share one Oracle connection lifecycle:
194
+
195
+ ```ts
196
+ import { OracleStore, OracleVector } from '@mastra/oracledb'
197
+
198
+ const storage = new OracleStore({ id: 'oracle-storage', user, password, connectString })
199
+ const vector = new OracleVector({
200
+ id: 'oracle-vector',
201
+ poolManager: storage.getPoolManager(),
202
+ })
203
+ ```
204
+
205
+ `OracleStore` exposes `storage.db` and `await storage.getPool()` for advanced use cases. When using these APIs directly, you're responsible for transaction boundaries and connection lifecycle.
206
+
207
+ JSON metadata, payloads, and snapshots are stored in native Oracle JSON columns and encoded server-side, so the rows are readable directly with standard Oracle JDBC tools such as DBeaver and SQL Developer.
208
+
209
+ ## Usage example
210
+
211
+ ### Adding OracleDB memory to an agent
212
+
213
+ ```ts
214
+ import { Agent } from '@mastra/core/agent'
215
+ import { Memory } from '@mastra/memory'
216
+ import { OracleStore } from '@mastra/oracledb'
217
+
218
+ const storage = new OracleStore({
219
+ id: 'oracle-storage',
220
+ user: process.env.ORACLE_DATABASE_USER,
221
+ password: process.env.ORACLE_DATABASE_PASSWORD,
222
+ connectString: process.env.ORACLE_DATABASE_CONNECT_STRING,
223
+ })
224
+
225
+ export const oracleAgent = new Agent({
226
+ id: 'oracle-agent',
227
+ name: 'Oracle Agent',
228
+ instructions: 'You are an assistant with persistent OracleDB-backed memory.',
229
+ model: 'openai/gpt-5.6-sol',
230
+ memory: new Memory({ storage }),
231
+ })
232
+ ```
233
+
234
+ ## Related
235
+
236
+ - [OracleDB vector store](https://mastra.ai/reference/vectors/oracledb)
237
+ - [Storage overview](https://mastra.ai/reference/storage/overview)
238
+ - [Working memory](https://mastra.ai/docs/memory/working-memory)
239
+ - [Workflow snapshots](https://mastra.ai/docs/workflows/snapshots)
@@ -10,15 +10,15 @@ Mastra storage is organized into domains. Each domain owns a set of tables or co
10
10
 
11
11
  Not every storage adapter implements every domain. Composite storage lets you mix adapters per domain when the adapter packages export the corresponding domain classes.
12
12
 
13
- | Domain | Description |
14
- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
15
- | `memory` | Conversation persistence: messages, threads, and resources (including working memory). |
16
- | `workflows` | Workflow run snapshots used for suspend and resume. |
17
- | `workflowDefinitions` | Persisted [stored workflow](https://mastra.ai/docs/workflows/stored-workflows) definitions (beta). Loaded and live-registered on boot. |
18
- | `scores` | Evaluation score records from eval runs. |
19
- | `observability` | Traces and spans used by observability exporters and Studio. |
20
- | `datasets` | Dataset records, versioned items, and dataset versions used by experiments. |
21
- | `experiments` | Experiment runs and per-item experiment results. |
13
+ | Domain | Description |
14
+ | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
15
+ | `memory` | Conversation persistence: messages, threads, and resources (including working memory). |
16
+ | `workflows` | Workflow run snapshots used for suspend and resume. |
17
+ | `workflowDefinitions` | Persisted [dynamic workflow](https://mastra.ai/docs/workflows/dynamic-workflows) definitions (beta). Loaded and live-registered on boot. |
18
+ | `scores` | Evaluation score records from eval runs. |
19
+ | `observability` | Traces and spans used by observability exporters and Studio. |
20
+ | `datasets` | Dataset records, versioned items, and dataset versions used by experiments. |
21
+ | `experiments` | Experiment runs and per-item experiment results. |
22
22
 
23
23
  The schema definitions below cover the built-in database-backed tables documented for `memory`, `workflows`, `scores`, and `observability`. Other domains, and non-database adapters, use implementation-specific storage structures.
24
24
 
@@ -92,7 +92,7 @@ Each domain declares which of its tables can be age-pruned and which timestamp c
92
92
  > - Experiments prune as whole units: an aged experiment's result rows are deleted together with it (results cascade with their parent), so a run is never left partially deleted. Retention doesn't have a separate `results` key.
93
93
  > - For `schedules`, the growth table is the fire history (`schedule_triggers`, one row per fire): schedule definitions are config and aren't pruned.
94
94
  > - On PostgreSQL, timestamp anchors use the timezone-aware mirror columns (for example `createdAtZ`, `completedAtZ`).
95
- > - LibSQL supports all domains above; PostgreSQL and MongoDB support all except `threadState` and `harness`, which they don't implement.
95
+ > - LibSQL and PostgreSQL support all domains above except `harness`, which PostgreSQL doesn't implement. MongoDB supports all except `threadState` and `harness`.
96
96
  > - The v-next PostgreSQL observability domain stores signal events in day-partitioned tables (`spans`, `metrics`, `logs`, `scores`, `feedback`). For it, `prune()` drops whole day partitions (or TimescaleDB chunks) that are entirely older than the cutoff instead of deleting rows: effective level of detail is one day, and a partition is only dropped once its entire day is past `maxAge`. `PruneResult.deleted` reports the number of rows in the dropped partitions.
97
97
 
98
98
  ## Methods
@@ -66,7 +66,7 @@ const stream = await agent.stream('message for agent')
66
66
 
67
67
  **options.delegation** (`DelegationConfig`): Configuration for subagent delegation. Use this to control and monitor when the agent delegates tasks to other agents, including the ability to modify, reject delegations, and provide feedback to guide the supervisor.
68
68
 
69
- **options.delegation.onDelegationStart** (`(context: DelegationStartContext) => DelegationStartResult | void | Promise<DelegationStartResult | void>`): Called before delegating to a subagent. Use this to modify the delegation parameters or reject the delegation entirely.
69
+ **options.delegation.onDelegationStart** (`(context: DelegationStartContext) => DelegationStartResult | void | Promise<DelegationStartResult | void>`): Called before delegating to a subagent. Use this to modify the delegation parameters, reject the delegation entirely, or mutate context.requestContext to add entries to the subagent run's request context.
70
70
 
71
71
  **options.delegation.onDelegationComplete** (`(context: DelegationCompleteContext) => { feedback?: string } | void | Promise<{ feedback?: string } | void>`): Called after a subagent delegation completes. The context includes a bail() method to stop further execution, and you can return { feedback } to guide the supervisor's next action. Feedback is saved to supervisor memory as an assistant message.
72
72
 
@@ -0,0 +1,117 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # createBedrockKBTool()
4
+
5
+ The `createBedrockKBTool()` function creates a tool that retrieves relevant documents from an Amazon Bedrock Knowledge Base. It supports both managed search configuration and agentic retrieval (query decomposition and managed reranking) with automatic fallback to standard retrieval.
6
+
7
+ ## Usage example
8
+
9
+ ```typescript
10
+ import { createBedrockKBTool } from '@mastra/rag'
11
+
12
+ const kbTool = createBedrockKBTool({
13
+ knowledgeBaseId: 'YOUR_KB_ID',
14
+ region: 'us-west-2',
15
+ numberOfResults: 5,
16
+ useAgenticRetrieval: true,
17
+ })
18
+ ```
19
+
20
+ ### With an Agent
21
+
22
+ ```typescript
23
+ import { Agent } from '@mastra/core/agent'
24
+ import { createBedrockKBTool } from '@mastra/rag'
25
+
26
+ const kbTool = createBedrockKBTool({
27
+ knowledgeBaseId: 'YOUR_KB_ID',
28
+ })
29
+
30
+ const agent = new Agent({
31
+ name: 'KnowledgeAssistant',
32
+ instructions: 'Use the knowledge base tool to answer questions.',
33
+ model: myModel,
34
+ tools: { kb: kbTool },
35
+ })
36
+ ```
37
+
38
+ ## Parameters
39
+
40
+ **knowledgeBaseId** (`string`): The ID of the Amazon Bedrock Knowledge Base to query.
41
+
42
+ **region** (`string`): AWS region where the Knowledge Base is deployed. Defaults to AWS\_REGION environment variable or us-east-1.
43
+
44
+ **numberOfResults** (`number`): Maximum number of results to return. Defaults to 5.
45
+
46
+ **useAgenticRetrieval** (`boolean`): Use AgenticRetrieveStream for complex queries with query decomposition and managed reranking. Falls back to standard Retrieve on failure. Defaults to true (disable with USE\_AGENTIC\_RETRIEVAL=false env var).
47
+
48
+ **userId** (`string`): Default AWS user ID for document-level access control. A userId in the Mastra request context takes precedence.
49
+
50
+ ## Input Schema
51
+
52
+ The tool accepts the following input when called by an agent:
53
+
54
+ **queryText** (`string`): The search query to find relevant documents in the knowledge base.
55
+
56
+ ## Output Schema
57
+
58
+ The tool returns an object with:
59
+
60
+ **results** (`BedrockKBResult[]`): Array of retrieval results. Standard retrieval includes source and score when Bedrock provides them; agentic retrieval may omit those fields.
61
+
62
+ ### BedrockKBResult
63
+
64
+ | Field | Type | Description |
65
+ | ---------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
66
+ | `content` | `string` | The text content of the retrieved passage. |
67
+ | `source` | `string \| undefined` | The source URI when Bedrock provides one. Agentic retrieval only includes this field when the result metadata contains `_source_uri`. |
68
+ | `score` | `number \| undefined` | The relevance score returned by standard retrieval. The agentic API doesn't return a score for result items. |
69
+ | `metadata` | `Record<string, unknown>` | Additional metadata from the retrieval result. |
70
+
71
+ ## Retrieval Modes
72
+
73
+ ### Agentic Retrieval (default)
74
+
75
+ When `useAgenticRetrieval` is `true` (default), the tool uses `AgenticRetrieveStreamCommand` which:
76
+
77
+ - Decomposes complex queries into sub-queries
78
+ - Retrieves across multiple passes
79
+ - Applies managed reranking for better results
80
+
81
+ If agentic retrieval fails (e.g., older SDK, permissions), it automatically falls back to standard managed retrieval.
82
+
83
+ ### Standard Managed Retrieval
84
+
85
+ When `useAgenticRetrieval` is `false`, the tool uses `RetrieveCommand` with `managedSearchConfiguration` for direct single-pass retrieval.
86
+
87
+ ## User-based access control
88
+
89
+ Set `userId` in the Mastra request context to forward it as the Bedrock `userContext.userId`. This supports knowledge bases that enforce document-level access control. The request context value overrides the default `userId` configured on the tool.
90
+
91
+ ```typescript
92
+ import { RequestContext } from '@mastra/core/request-context'
93
+
94
+ const requestContext = new RequestContext()
95
+ requestContext.set('userId', 'user-123')
96
+
97
+ await agent.generate('Find my private documents', { requestContext })
98
+ ```
99
+
100
+ ## Required IAM Permissions
101
+
102
+ ```json
103
+ {
104
+ "Version": "2012-10-17",
105
+ "Statement": [
106
+ {
107
+ "Effect": "Allow",
108
+ "Action": ["bedrock:Retrieve", "bedrock:AgenticRetrieveStream"],
109
+ "Resource": "arn:aws:bedrock:*:*:knowledge-base/*"
110
+ }
111
+ ]
112
+ }
113
+ ```
114
+
115
+ ## SDK Requirements
116
+
117
+ - `@aws-sdk/client-bedrock-agent-runtime` >= 3.1000 (AgenticRetrieveStreamCommand requires \~3.1000+)
@@ -37,6 +37,8 @@ Each server in the `servers` map is configured using the `MastraMCPServerDefinit
37
37
 
38
38
  **env** (`Record<string, string>`): For Stdio servers: Environment variables to set for the command.
39
39
 
40
+ **inheritDefaultEnv** (`boolean`): For Stdio servers: Whether the subprocess environment starts from the MCP SDK's default inherited environment. The default is a curated whitelist, not the full process environment: on POSIX it inherits HOME, LOGNAME, PATH, SHELL, TERM, and USER; on Windows it inherits APPDATA, HOMEDRIVE, HOMEPATH, LOCALAPPDATA, PATH, PROCESSOR\_ARCHITECTURE, SYSTEMDRIVE, SYSTEMROOT, TEMP, USERNAME, and USERPROFILE. When set to false, only the variables explicitly listed in env are passed to the subprocess. Note that a subprocess without PATH may fail to spawn commands that are not absolute paths. (Default: `true`)
41
+
40
42
  **url** (`URL`): For HTTP servers (Streamable HTTP or SSE): The URL of the server.
41
43
 
42
44
  **requestInit** (`RequestInit`): For HTTP servers: Request configuration for the fetch API.
@@ -45,6 +47,8 @@ Each server in the `servers` map is configured using the `MastraMCPServerDefinit
45
47
 
46
48
  **fetch** (`MastraFetchLike`): For HTTP servers: Custom fetch implementation used for all network requests. Receives an optional third requestContext parameter containing request-scoped data (e.g., authentication cookies, bearer tokens) from the incoming request. When provided, this function will be used for all HTTP requests, allowing you to add dynamic authentication headers, forward request-scoped credentials to the MCP server, customize request behavior per-request, or intercept and modify requests/responses. When fetch is provided, requestInit, eventSourceInit, and authProvider become optional, as you can handle these concerns within your custom fetch function.
47
49
 
50
+ **allowedHosts** (`string[]`): For HTTP servers: Opt-in allowlist of hosts the client may contact on behalf of this server. Each entry is matched against the URL host (hostname plus port when the URL carries a non-default port), for example "api.example.com" or "localhost:8080". Matching is exact and case-insensitive on the hostname; wildcards are not supported and the URL scheme is not checked. An empty array denies all requests. When unset, no restriction is applied. See the Security section below for enforcement details.
51
+
48
52
  **logger** (`LogHandler`): Optional additional handler for logging.
49
53
 
50
54
  **timeout** (`number`): Server-specific timeout in milliseconds.
@@ -159,6 +163,56 @@ When `forwardInstructions` is omitted (the default), instructions are still cach
159
163
 
160
164
  > **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.
161
165
 
166
+ ## Security
167
+
168
+ ### Subprocess environment for Stdio servers
169
+
170
+ Stdio subprocesses don't inherit the full parent process environment. By default the subprocess environment starts from the MCP SDK's curated whitelist (POSIX: `HOME`, `LOGNAME`, `PATH`, `SHELL`, `TERM`, `USER`; Windows: `APPDATA`, `HOMEDRIVE`, `HOMEPATH`, `LOCALAPPDATA`, `PATH`, `PROCESSOR_ARCHITECTURE`, `SYSTEMDRIVE`, `SYSTEMROOT`, `TEMP`, `USERNAME`, `USERPROFILE`), merged with any variables you set in `env`. Sensitive variables such as API keys aren't inherited unless you pass them explicitly.
171
+
172
+ For stricter isolation, set `inheritDefaultEnv: false` so only your configured `env` entries reach the subprocess:
173
+
174
+ ```typescript
175
+ const mcp = new MCPClient({
176
+ servers: {
177
+ myTool: {
178
+ command: '/usr/local/bin/my-mcp-server',
179
+ inheritDefaultEnv: false,
180
+ env: { MY_TOOL_API_KEY: process.env.MY_TOOL_API_KEY! },
181
+ },
182
+ },
183
+ })
184
+ ```
185
+
186
+ Variables you place in `env` are forwarded verbatim, so treat server configurations that come from untrusted sources (for example, user-supplied config files) as untrusted input.
187
+
188
+ ### Restricting outbound hosts with `allowedHosts`
189
+
190
+ When HTTP server URLs come from untrusted configuration, an attacker-controlled URL can point the client at internal services (server-side request forgery). Set `allowedHosts` on such servers to restrict which hosts the client will contact:
191
+
192
+ ```typescript
193
+ const mcp = new MCPClient({
194
+ servers: {
195
+ remote: {
196
+ url: new URL(untrustedConfig.serverUrl),
197
+ allowedHosts: ['api.example.com'],
198
+ },
199
+ },
200
+ })
201
+ ```
202
+
203
+ Enforcement details:
204
+
205
+ - On the default fetch path, requests to disallowed hosts, including every redirect hop, are blocked **before** they're sent. Redirects are followed manually (up to 5 hops) so each hop is validated, and the `Authorization` header isn't carried across hops to a different origin (any scheme, host, or port change drops it, matching standard fetch behavior).
206
+ - When you supply a custom `fetch` (or a custom `eventSourceInit.fetch`), the initial URL is still checked before the request, but redirect hops are validated **after the fact** using `response.url`: the outbound hop may occur, and the response is discarded when its final URL points at a disallowed host. A hand-built `Response` with an empty `response.url` skips this post-hoc check.
207
+ - OAuth requests made through `authProvider` (authorization server metadata discovery, token exchange, refresh) are also validated. If your authorization server runs on a different host than the MCP server, add that host to `allowedHosts` too.
208
+ - A blocked host fails the connection with a clear error and is never retried by the reconnect logic.
209
+
210
+ `allowedHosts` is intentionally minimal: it matches exact hosts and doesn't support wildcards or scheme checks. If you need richer policy (scheme checks, IP-range rules), supply a custom `fetch` implementation, which is invoked for every request the client makes.
211
+
212
+ ### Treat tool responses as untrusted input
213
+
214
+ Tool results returned by MCP servers flow into your agent's context as model input. A malicious or compromised server can use tool output for prompt injection. The transport client doesn't sanitize tool responses: sanitization policy belongs at the agent layer, where Mastra's [input and output processors](https://mastra.ai/docs/agents/processors) let you inspect, transform, or block content before and after it reaches the model. Combine this with `requireToolApproval` and the `forwardInstructions` security note above when working with third-party servers.
215
+
162
216
  ## Methods
163
217
 
164
218
  ### `listTools()`