@mastra/mcp-docs-server 1.1.46-alpha.2 → 1.1.46-alpha.4
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/models/gateways/custom-gateways.md +57 -7
- 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/mastra-model-gateway.md +15 -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 +17 -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 +4 -4
|
@@ -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
|
|
|
@@ -265,7 +265,7 @@ Native-audio Gemini Live models — any model whose ID contains `native-audio`,
|
|
|
265
265
|
- The model's spoken reply is delivered as audio plus an `output_audio_transcription` transcript and surfaced as `writing` with `role: 'assistant'`.
|
|
266
266
|
- The model's internal reasoning is delivered as `modelTurn.parts.text` and surfaced as `thinking`.
|
|
267
267
|
|
|
268
|
-
On non-native-audio models there is no `output_audio_transcription` channel, so `modelTurn.parts.text` is the spoken response itself and is emitted as `writing`; the `thinking` event
|
|
268
|
+
On non-native-audio models there is no `output_audio_transcription` channel, so `modelTurn.parts.text` is the spoken response itself and is emitted as `writing`; the `thinking` event doesn't fire.
|
|
269
269
|
|
|
270
270
|
Input transcription, output transcription, and barge-in detection (`realtime_input_config.activity_handling = 'START_OF_ACTIVITY_INTERRUPTS'`) are enabled automatically in the setup payload — no extra configuration is required.
|
|
271
271
|
|
|
@@ -54,7 +54,7 @@ await voice.send(microphoneStream)
|
|
|
54
54
|
voice.close()
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
> Inworld API keys ship pre-Basic-encoded. Paste them verbatim into `INWORLD_API_KEY`; the package
|
|
57
|
+
> Inworld API keys ship pre-Basic-encoded. Paste them verbatim into `INWORLD_API_KEY`; the package doesn't re-encode them.
|
|
58
58
|
|
|
59
59
|
## Constructor parameters
|
|
60
60
|
|
|
@@ -116,7 +116,7 @@ Use the typed `session` field for documented Inworld realtime options. Fields co
|
|
|
116
116
|
|
|
117
117
|
### `providerData` (Inworld extensions)
|
|
118
118
|
|
|
119
|
-
`providerData` is a typed object for Inworld-specific realtime extensions. It
|
|
119
|
+
`providerData` is a typed object for Inworld-specific realtime extensions. It's sent under `session.providerData` on every `session.update`, and composes with any `session.providerData` you set via the `session` field — the constructor `providerData` wins on key collisions.
|
|
120
120
|
|
|
121
121
|
It has five branches plus two session-level fields:
|
|
122
122
|
|
|
@@ -342,12 +342,12 @@ Any voice ID from [Inworld's voice catalog](https://docs.inworld.ai/quickstart-t
|
|
|
342
342
|
|
|
343
343
|
## Notes
|
|
344
344
|
|
|
345
|
-
- API keys can be provided via constructor options or the `INWORLD_API_KEY` environment variable. Keys are pre-Basic-encoded;
|
|
345
|
+
- API keys can be provided via constructor options or the `INWORLD_API_KEY` environment variable. Keys are pre-Basic-encoded; don't re-encode them.
|
|
346
346
|
- The WebSocket URL appends `?key=<sessionId>&protocol=realtime`. The model is configured via the initial `session.update`, not the URL.
|
|
347
|
-
- Per-call `speak(input, { speaker })` scopes the voice override to a single response (via the flat `response.voice` field) and
|
|
347
|
+
- Per-call `speak(input, { speaker })` scopes the voice override to a single response (via the flat `response.voice` field) and doesn't mutate the session.
|
|
348
348
|
- Audio output defaults to PCM16 at 24 kHz. Telephony `audio/pcmu` and `audio/pcma` at 8 kHz, and `audio/float32`, are also supported via `session.audio.output.format`.
|
|
349
349
|
- Use `connect()` before any send, speak, or listen call. Events sent before the WebSocket is open are queued and flushed once the server acknowledges `session.updated`.
|
|
350
350
|
- The voice instance must be closed with `close()` or `disconnect()` to release the WebSocket.
|
|
351
|
-
- `audio.input.turn_detection` defaults to semantic VAD when `session`
|
|
351
|
+
- `audio.input.turn_detection` defaults to semantic VAD when `session` doesn't supply it. Override with your own object, or pass `null` to disable turn detection entirely.
|
|
352
352
|
- `audio.input.transcription` defaults to `{ model: 'inworld/inworld-stt-1' }`, so user-side `writing` events fire out of the box. Override with your own object, or pass `null` to disable user-side transcription.
|
|
353
353
|
- `on()` and `off()` are typed against `InworldVoiceEventMap` — known event names yield a typed callback payload, unknown names fall back to `unknown`.
|
|
@@ -130,6 +130,6 @@ const speakers = await voice.getSpeakers()
|
|
|
130
130
|
## Notes
|
|
131
131
|
|
|
132
132
|
- The TTS endpoint uses progressive NDJSON streaming, so audio playback can begin before the full response is received.
|
|
133
|
-
- An API key can be provided via the `speechModel` or `listeningModel` config, or the `INWORLD_API_KEY` environment variable. TTS and STT keys are resolved independently: passing distinct `speechModel.apiKey` and `listeningModel.apiKey` values lets each service use its own credential. If only one is provided, it
|
|
133
|
+
- An API key can be provided via the `speechModel` or `listeningModel` config, or the `INWORLD_API_KEY` environment variable. TTS and STT keys are resolved independently: passing distinct `speechModel.apiKey` and `listeningModel.apiKey` values lets each service use its own credential. If only one is provided, it's reused for both services as a fallback before the env var.
|
|
134
134
|
- `inworld-tts-2` is the default flagship model. Use `deliveryMode` (`STABLE` | `BALANCED` | `CREATIVE`) to steer delivery style on this model. The `temperature` option is ignored on `inworld-tts-2`.
|
|
135
135
|
- The `inworld-tts-1.5-mini` model offers lower latency at the cost of reduced voice quality compared to `inworld-tts-1.5-max`.
|
|
@@ -127,4 +127,4 @@ Returns: `Promise<Array<{voiceId: SarvamVoiceId}>>`
|
|
|
127
127
|
- Audio is returned as a stream containing binary audio data
|
|
128
128
|
- Speech recognition supports mp3 and wav audio formats
|
|
129
129
|
- `bulbul:v1`, `saarika:v1`, `saarika:v2`, and `saarika:flash` have been deprecated by Sarvam and are no longer supported. Use `bulbul:v3` (or `bulbul:v2`) for TTS and `saarika:v2.5` (or `saaras:v3`) for STT.
|
|
130
|
-
- Speaker names
|
|
130
|
+
- Speaker names aren't interchangeable between `bulbul:v2` and `bulbul:v3` — each model version has its own speaker catalog.
|
|
@@ -6,7 +6,7 @@ Use `AgentCoreRuntimeSandbox` when your agent already runs in AgentCore Runtime
|
|
|
6
6
|
|
|
7
7
|
> **Info:** For interface details, see [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox).
|
|
8
8
|
|
|
9
|
-
> **Warning:** `AgentCoreRuntimeSandbox` only supports one-shot command execution. It
|
|
9
|
+
> **Warning:** `AgentCoreRuntimeSandbox` only supports one-shot command execution. It doesn't support background process management, stdin, or filesystem mounts. AgentCore Code Interpreter is a separate AWS service and isn't part of this provider.
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
@@ -139,7 +139,7 @@ Returns: `Promise<CommandResult>`.
|
|
|
139
139
|
|
|
140
140
|
#### `start()`
|
|
141
141
|
|
|
142
|
-
Runs the sandbox lifecycle start hook. This provider
|
|
142
|
+
Runs the sandbox lifecycle start hook. This provider doesn't create an AgentCore Runtime session during `start()`.
|
|
143
143
|
|
|
144
144
|
```typescript
|
|
145
145
|
await sandbox.start()
|
|
@@ -157,7 +157,7 @@ await sandbox.stop()
|
|
|
157
157
|
|
|
158
158
|
Explicitly stops the AgentCore Runtime session used by this sandbox.
|
|
159
159
|
|
|
160
|
-
Use this when the sandbox owns the runtime session and you want to clean it up directly. `destroy()`
|
|
160
|
+
Use this when the sandbox owns the runtime session and you want to clean it up directly. `destroy()` doesn't call this method unless `stopSessionOnLifecycle` is `true`, because AgentCore Runtime sessions can be shared with agent invocations outside the Workspace sandbox lifecycle.
|
|
161
161
|
|
|
162
162
|
```typescript
|
|
163
163
|
await sandbox.stopRuntimeSession()
|
|
@@ -188,10 +188,10 @@ Returns: `Promise<SandboxInfo>`.
|
|
|
188
188
|
`AgentCoreRuntimeSandbox` follows AgentCore Runtime command execution semantics:
|
|
189
189
|
|
|
190
190
|
- **One-shot commands**: Each command runs to completion or timeout.
|
|
191
|
-
- **No persistent shell**: Shell state
|
|
192
|
-
- **Background processes
|
|
193
|
-
- **Interactive stdin is unavailable**: Runtime command execution
|
|
194
|
-
- **Workspace filesystem mounts are unsupported**: Workspace filesystem mounting
|
|
191
|
+
- **No persistent shell**: Shell state doesn't carry over between commands. Encode state in each command, for example `cd /workspace && npm test`.
|
|
192
|
+
- **Background processes aren't supported**: The provider doesn't expose a `processes` manager.
|
|
193
|
+
- **Interactive stdin is unavailable**: Runtime command execution doesn't provide an interactive stdin stream through this provider.
|
|
194
|
+
- **Workspace filesystem mounts are unsupported**: Workspace filesystem mounting isn't supported by this provider.
|
|
195
195
|
- **Container-dependent tools**: Commands can only use tools installed in the AgentCore Runtime container image.
|
|
196
196
|
|
|
197
197
|
## Related
|
|
@@ -55,7 +55,7 @@ const agent = new Agent({
|
|
|
55
55
|
|
|
56
56
|
### Account key
|
|
57
57
|
|
|
58
|
-
Use an account name and account key when you
|
|
58
|
+
Use an account name and account key when you don't want to pass a full connection string:
|
|
59
59
|
|
|
60
60
|
```typescript
|
|
61
61
|
import { AzureBlobFilesystem } from '@mastra/azure/blob'
|
|
@@ -209,7 +209,7 @@ const config = filesystem.getMountConfig()
|
|
|
209
209
|
// { type: 'azure-blob', container: 'my-container', ... }
|
|
210
210
|
```
|
|
211
211
|
|
|
212
|
-
> **Note:** Azure Blob sandbox mounting depends on sandbox support for `azure-blob` mount configs. Use `filesystem` for direct workspace file operations when your sandbox provider
|
|
212
|
+
> **Note:** Azure Blob sandbox mounting depends on sandbox support for `azure-blob` mount configs. Use `filesystem` for direct workspace file operations when your sandbox provider doesn't support Azure Blob mounts.
|
|
213
213
|
|
|
214
214
|
## Related
|
|
215
215
|
|
|
@@ -170,10 +170,10 @@ const url = await filesystem.files.url('reports/q3.pdf')
|
|
|
170
170
|
`FilesSDKFilesystem` treats the configured backend as an object store, even when the underlying adapter is hierarchical (such as `fs`). This keeps behavior consistent across adapters:
|
|
171
171
|
|
|
172
172
|
- **`mkdir`** is a no-op. Directories exist implicitly when keys with that prefix exist.
|
|
173
|
-
- **`exists`** returns `true` only when an exact key is present as a file, or when the path is a prefix that contains at least one child key. Empty leftover directories on hierarchical adapters
|
|
174
|
-
- **`deleteFile`** throws `FileNotFoundError` when the key
|
|
173
|
+
- **`exists`** returns `true` only when an exact key is present as a file, or when the path is a prefix that contains at least one child key. Empty leftover directories on hierarchical adapters don't count.
|
|
174
|
+
- **`deleteFile`** throws `FileNotFoundError` when the key doesn't exist, unless `{ force: true }` is passed.
|
|
175
175
|
- **`deleteFile`** on a directory delegates to `rmdir({ recursive: true })`, matching the [`S3Filesystem`](https://mastra.ai/reference/workspace/s3-filesystem) and [`GCSFilesystem`](https://mastra.ai/reference/workspace/gcs-filesystem) behavior.
|
|
176
|
-
- **`moveFile`** is implemented as `copyFile` followed by `deleteFile`.
|
|
176
|
+
- **`moveFile`** is implemented as `copyFile` followed by `deleteFile`. it's **not atomic** — if the source delete fails after a successful copy, the destination remains and the source isn't removed.
|
|
177
177
|
- **`appendFile`** is a read-modify-write operation. Concurrent appends to the same key may overwrite each other; this is inherent to object storage and not specific to FilesSDK.
|
|
178
178
|
- **`readdir({ recursive: true })`** emits intermediate directory entries (for example, `a/b` is emitted alongside `a/b/c.txt`).
|
|
179
179
|
|
|
@@ -64,7 +64,7 @@ Supply one of the following authentication options:
|
|
|
64
64
|
|
|
65
65
|
#### Service account
|
|
66
66
|
|
|
67
|
-
Service account auth is the recommended option for backend agents.
|
|
67
|
+
Service account auth is the recommended option for backend agents. No user consent flow and no token refresh handling is required. You only need **two values** from the service account JSON key file: `client_email` and `private_key`.
|
|
68
68
|
|
|
69
69
|
##### Set up the service account
|
|
70
70
|
|
|
@@ -76,19 +76,19 @@ Service account auth is the recommended option for backend agents. There is no u
|
|
|
76
76
|
|
|
77
77
|
##### Share the Drive folder with the service account
|
|
78
78
|
|
|
79
|
-
The service account is its own Google identity. It
|
|
79
|
+
The service account is its own Google identity. It can't see anything in Drive until you share with it explicitly.
|
|
80
80
|
|
|
81
81
|
1. Open the target folder in [Google Drive](https://drive.google.com/).
|
|
82
82
|
2. Select **Share**.
|
|
83
83
|
3. Paste the service account's `client_email` address.
|
|
84
84
|
4. Set the role to **Editor** (for read and write) or **Viewer** (for read-only access). Select **Send**.
|
|
85
|
-
5. Copy the folder ID from the URL.
|
|
85
|
+
5. Copy the folder ID from the URL. it's the segment after `/folders/` in `https://drive.google.com/drive/folders/<folderId>`.
|
|
86
86
|
|
|
87
|
-
> **Warning:** Service accounts
|
|
87
|
+
> **Warning:** Service accounts can't create files in standard "My Drive" folders. A service account has no personal Drive storage quota, so any file it creates needs to be owned by a quota-bearing entity. If you only share a personal Drive folder, read operations work but writes fail with a quota error.
|
|
88
88
|
>
|
|
89
89
|
> For write access, place the folder inside a **shared drive** (formerly Team Drive) and add the service account as a member of that shared drive. Shared drives provide the storage quota that service-account-created files need.
|
|
90
90
|
>
|
|
91
|
-
> Read-only workloads against a personal Drive folder
|
|
91
|
+
> Read-only workloads against a personal Drive folder don't have this restriction.
|
|
92
92
|
|
|
93
93
|
##### Configure the filesystem
|
|
94
94
|
|
|
@@ -113,13 +113,13 @@ const filesystem = new GoogleDriveFilesystem({
|
|
|
113
113
|
})
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
You
|
|
116
|
+
You **don't** need to copy the entire JSON file or pass other fields like `project_id`, `client_id`, `private_key_id`, or `token_uri`. They're not used. Only `clientEmail` and `privateKey` are required. `privateKeyId`, `scopes`, and `subject` are optional. `scopes` defaults to `['https://www.googleapis.com/auth/drive']`, which is the scope required for the service account to see folders shared with it. The narrower `drive.file` scope only grants access to files the application created itself, so a folder shared with the service account would return `404 Not Found`.
|
|
117
117
|
|
|
118
118
|
`GoogleDriveFilesystem` automatically normalizes the `privateKey` string before signing. It strips surrounding quotes (including escaped quotes from JSON-wrapped values), converts literal `\n` sequences to real newlines, normalizes `\r\n` line endings, and removes a trailing comma. The key works regardless of how your `.env` loader handles the value.
|
|
119
119
|
|
|
120
120
|
##### Troubleshoot
|
|
121
121
|
|
|
122
|
-
- **`404 File not found: <folderId>`**: The service account
|
|
122
|
+
- **`404 File not found: <folderId>`**: The service account doesn't have access to the folder. Confirm the folder is shared with the exact `client_email` address and that the folder ID matches the URL.
|
|
123
123
|
- **`storageQuotaExceeded` on write**: The folder is in a personal "My Drive". Move the folder to a shared drive and add the service account as a member.
|
|
124
124
|
- **`error:1E08010C:DECODER routines::unsupported`**: The `privateKey` value is malformed. Confirm the value contains the full PEM block and that newlines are preserved (literal `\n` is fine).
|
|
125
125
|
|
|
@@ -155,7 +155,7 @@ console.log(result.exitCode)
|
|
|
155
155
|
await handle.kill()
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
> **Note:** `sendStdin()`
|
|
158
|
+
> **Note:** `sendStdin()` isn't supported — the Modal JS SDK doesn't expose stdin on `Sandbox.exec()`.
|
|
159
159
|
|
|
160
160
|
See [`SandboxProcessManager` reference](https://mastra.ai/reference/workspace/process-manager) for the full API.
|
|
161
161
|
|