@mastra/mcp-docs-server 1.2.15-alpha.3 → 1.2.15-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/docs/agents/a2a.md +39 -0
- package/.docs/docs/agents/skills.md +15 -1
- package/.docs/docs/evals/overview.md +16 -4
- package/.docs/docs/index.md +1 -1
- package/.docs/docs/observability/feedback.md +16 -0
- package/.docs/guides/getting-started/quickstart.md +1 -1
- package/.docs/models/gateways/neon.md +4 -1
- package/.docs/models/gateways/netlify.md +1 -2
- package/.docs/models/gateways/openrouter.md +1 -1
- package/.docs/models/gateways/vercel.md +8 -2
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/cortecs.md +2 -1
- package/.docs/models/providers/deepinfra.md +2 -2
- package/.docs/models/providers/digitalocean.md +3 -2
- package/.docs/models/providers/empiriolabs.md +6 -4
- package/.docs/models/providers/hyper.md +4 -5
- package/.docs/models/providers/kilo.md +3 -3
- package/.docs/models/providers/llmgateway.md +2 -2
- package/.docs/models/providers/nano-gpt.md +3 -2
- package/.docs/models/providers/neuralwatt.md +2 -1
- package/.docs/models/providers/ofox.md +74 -16
- package/.docs/models/providers/opencode-go.md +1 -1
- package/.docs/models/providers/opencode.md +2 -2
- package/.docs/models/providers/vivgrid.md +4 -2
- package/.docs/models/providers/wandb.md +1 -1
- package/.docs/reference/agents/channels.md +20 -1
- package/.docs/reference/client-js/workflows.md +13 -0
- package/.docs/reference/file-based-agents/config.md +22 -21
- package/.docs/reference/file-based-agents/instructions.md +42 -17
- package/.docs/reference/index.md +1 -0
- package/.docs/reference/observability/metrics/automatic-metrics.md +10 -8
- package/.docs/reference/server/routes.md +25 -11
- package/.docs/reference/storage/composite.md +58 -0
- package/.docs/reference/tools/bedrock-kb-tool.md +117 -0
- package/.docs/reference/voice/google.md +19 -3
- package/.docs/reference/workflows/step.md +40 -0
- package/CHANGELOG.md +15 -0
- package/package.json +5 -5
|
@@ -36,7 +36,7 @@ for await (const chunk of stream) {
|
|
|
36
36
|
|
|
37
37
|
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|
|
38
38
|
| ------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- |
|
|
39
|
-
| `opencode-go/deepseek-v4-flash` | 1.0M | | | | | | $0.
|
|
39
|
+
| `opencode-go/deepseek-v4-flash` | 1.0M | | | | | | $0.07 | $0.14 |
|
|
40
40
|
| `opencode-go/deepseek-v4-pro` | 1.0M | | | | | | $0.43 | $0.87 |
|
|
41
41
|
| `opencode-go/glm-5.1` | 203K | | | | | | $1 | $4 |
|
|
42
42
|
| `opencode-go/glm-5.2` | 1.0M | | | | | | $1 | $4 |
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# OpenCode Zen
|
|
4
4
|
|
|
5
|
-
Access
|
|
5
|
+
Access 87 OpenCode Zen models through Mastra's model router. Authentication is handled automatically using the `OPENCODE_API_KEY` environment variable.
|
|
6
6
|
|
|
7
7
|
Learn more in the [OpenCode Zen documentation](https://opencode.ai/docs/zen).
|
|
8
8
|
|
|
@@ -86,7 +86,7 @@ for await (const chunk of stream) {
|
|
|
86
86
|
| `opencode/kimi-k2.7-code` | 262K | | | | | | $0.95 | $4 |
|
|
87
87
|
| `opencode/kimi-k3` | 1.0M | | | | | | $3 | $15 |
|
|
88
88
|
| `opencode/laguna-s-2.1-free` | 256K | | | | | | — | — |
|
|
89
|
-
| `opencode/ling-3.0-
|
|
89
|
+
| `opencode/ling-3.0-tiny-free` | 262K | | | | | | — | — |
|
|
90
90
|
| `opencode/longcat-2.0-free` | 1.0M | | | | | | — | — |
|
|
91
91
|
| `opencode/mimo-v2.5-free` | 200K | | | | | | — | — |
|
|
92
92
|
| `opencode/minimax-m2.5` | 205K | | | | | | $0.30 | $1 |
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Vivgrid
|
|
4
4
|
|
|
5
|
-
Access
|
|
5
|
+
Access 19 Vivgrid models through Mastra's model router. Authentication is handled automatically using the `VIVGRID_API_KEY` environment variable.
|
|
6
6
|
|
|
7
7
|
Learn more in the [Vivgrid documentation](https://docs.vivgrid.com/models).
|
|
8
8
|
|
|
@@ -37,6 +37,7 @@ for await (const chunk of stream) {
|
|
|
37
37
|
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|
|
38
38
|
| --------------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- |
|
|
39
39
|
| `vivgrid/deepseek-v3.2` | 128K | | | | | | $0.28 | $0.42 |
|
|
40
|
+
| `vivgrid/deepseek-v4-flash` | 1.0M | | | | | | $0.15 | $0.30 |
|
|
40
41
|
| `vivgrid/deepseek-v4-pro` | 1.0M | | | | | | $0.43 | $0.87 |
|
|
41
42
|
| `vivgrid/gemini-3.1-flash-lite-preview` | 1.0M | | | | | | $0.25 | $2 |
|
|
42
43
|
| `vivgrid/gemini-3.1-pro-preview` | 1.0M | | | | | | $2 | $12 |
|
|
@@ -53,6 +54,7 @@ for await (const chunk of stream) {
|
|
|
53
54
|
| `vivgrid/gpt-5.6-luna` | 1.1M | | | | | | $1 | $6 |
|
|
54
55
|
| `vivgrid/gpt-5.6-sol` | 1.1M | | | | | | $5 | $30 |
|
|
55
56
|
| `vivgrid/gpt-5.6-terra` | 1.1M | | | | | | $3 | $15 |
|
|
57
|
+
| `vivgrid/kimi-k3` | 1.0M | | | | | | $3 | $15 |
|
|
56
58
|
|
|
57
59
|
## Advanced configuration
|
|
58
60
|
|
|
@@ -82,7 +84,7 @@ const agent = new Agent({
|
|
|
82
84
|
model: ({ requestContext }) => {
|
|
83
85
|
const useAdvanced = requestContext.task === "complex";
|
|
84
86
|
return useAdvanced
|
|
85
|
-
? "vivgrid/
|
|
87
|
+
? "vivgrid/kimi-k3"
|
|
86
88
|
: "vivgrid/deepseek-v3.2";
|
|
87
89
|
}
|
|
88
90
|
});
|
|
@@ -39,7 +39,7 @@ for await (const chunk of stream) {
|
|
|
39
39
|
| `wandb/deepseek-ai/DeepSeek-V3.1` | 161K | | | | | | $0.55 | $2 |
|
|
40
40
|
| `wandb/deepseek-ai/DeepSeek-V4-Flash` | 1.0M | | | | | | $0.14 | $0.28 |
|
|
41
41
|
| `wandb/deepseek-ai/DeepSeek-V4-Flash-0731` | 262K | | | | | | $0.13 | $0.28 |
|
|
42
|
-
| `wandb/deepseek-ai/DeepSeek-V4-Pro` | 1.0M | | | | | | $
|
|
42
|
+
| `wandb/deepseek-ai/DeepSeek-V4-Pro` | 1.0M | | | | | | $1 | $3 |
|
|
43
43
|
| `wandb/google/gemma-4-31B-it` | 262K | | | | | | $0.10 | $0.34 |
|
|
44
44
|
| `wandb/ibm-granite/granite-4.1-8b` | 131K | | | | | | $0.05 | $0.10 |
|
|
45
45
|
| `wandb/JetBrains/Mellum2-12B-A2.5B-Instruct` | 131K | | | | | | $0.05 | $0.10 |
|
|
@@ -102,7 +102,7 @@ const agent = new Agent({
|
|
|
102
102
|
|
|
103
103
|
**streaming** (`boolean | { updateIntervalMs?: number }`): Stream agent text deltas to the channel as the agent generates them instead of buffering and posting once per step. Requires the underlying adapter to support post-and-edit streaming. Slack defaults to true; other adapters default to false. (Default: `false (true for Slack)`)
|
|
104
104
|
|
|
105
|
-
**toolDisplay** (`'cards' | 'text' | 'timeline' | 'grouped' | 'hidden' | ToolDisplayFn`): How tool calls are rendered in the channel. "cards" posts per-tool running/result cards as rich Block Kit. "text" posts the same lifecycle as plain text (no Block Kit). "timeline" and "grouped" stream tool state as inline task\_update chunks (requires streaming: true; Slack only today — other adapters may render a placeholder). "hidden" executes tools silently. Pass a function to render tool events yourself; return { kind: "post", message } for a discrete post/edit, { kind: "stream", chunk } to push into the
|
|
105
|
+
**toolDisplay** (`'cards' | 'text' | 'timeline' | 'grouped' | 'hidden' | ToolDisplayFn`): How tool calls are rendered in the channel. "cards" posts per-tool running/result cards as rich Block Kit. "text" posts the same lifecycle as plain text (no Block Kit). "timeline" and "grouped" stream tool state as inline task\_update chunks (requires streaming: true; Slack only today — other adapters may render a placeholder). "hidden" executes tools silently. Pass a function to render tool events yourself; return { kind: "post", message } for a discrete post/edit, { kind: "stream", chunk } to push into the streaming widget, or undefined to skip rendering that event. Add openIfEmpty: false to a stream result when its chunk should only apply to an active streaming session. Approve/deny prompts always render as a separate card regardless of mode. (Default: `'cards' ('grouped' for Slack)`)
|
|
106
106
|
|
|
107
107
|
**typingStatus** (`boolean | ((chunk: AgentChunkType, ctx: TypingStatusContext) => string | false | null | undefined | void)`): Control the platform typing indicator. true uses built-in defaults (is typing… on text, is calling {tool}… on tool-call, is waiting for approval… on tool-call-approval). false suppresses typing entirely — useful when a live streaming widget (e.g. toolDisplay: "grouped" in Slack) already conveys progress. Pass a function to set custom status copy per chunk; return a string to set the status, or false/null/undefined to leave it unchanged. Compose with defaultTypingStatus (exported from @mastra/core/channels) to fall back to defaults for chunks you don't handle. (Default: `true`)
|
|
108
108
|
|
|
@@ -116,6 +116,25 @@ const agent = new Agent({
|
|
|
116
116
|
|
|
117
117
|
Pass a function to `toolDisplay` for fully custom rendering. The function receives a `ToolDisplayEvent` (`running` / `result` / `error` / `approval`) and a `ToolDisplayContext` (`{ mode, platform }`); return `{ kind: 'post', message }` for a discrete post/edit, `{ kind: 'stream', chunk }` to push into the active streaming widget, or `undefined` to skip rendering that event.
|
|
118
118
|
|
|
119
|
+
By default, a stream result opens a streaming session when none is active. Set `openIfEmpty: false` when the chunk only applies to an existing session. Mastra skips the chunk when no session is active. Static channels ignore this option and keep their existing plain-text fallback behavior.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
toolDisplay: event => {
|
|
123
|
+
if (event.kind !== 'running') return undefined
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
kind: 'stream',
|
|
127
|
+
chunk: {
|
|
128
|
+
type: 'task_update',
|
|
129
|
+
id: event.toolCallId,
|
|
130
|
+
title: event.displayName,
|
|
131
|
+
status: 'in_progress',
|
|
132
|
+
},
|
|
133
|
+
openIfEmpty: false,
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
119
138
|
Approve/deny prompts (`requireApproval`) always render as a separate card regardless of mode, because inline task entries can't carry interactive buttons.
|
|
120
139
|
|
|
121
140
|
```typescript
|
|
@@ -12,6 +12,19 @@ Retrieve a list of all available workflows:
|
|
|
12
12
|
const workflows = await mastraClient.listWorkflows()
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## Getting workflow run counts
|
|
16
|
+
|
|
17
|
+
Retrieve per-workflow counts of `running` and [`suspended`](https://mastra.ai/docs/workflows/suspend-and-resume) runs in a single request. The counts are computed on the server and keyed by the workflow's registry key — the key used when registering the workflow in the Mastra config, which can differ from the workflow's own `id`:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
const runCounts = await mastraClient.listWorkflowRunCounts()
|
|
21
|
+
// { "cityWorkflow": { running: 2, suspended: 1 }, ... }
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Returns: `Record<string, { running: number; suspended: number }>`
|
|
25
|
+
|
|
26
|
+
The server may cache the counts for a few seconds between requests. Servers that predate this endpoint respond with `404 Not Found` — handle the error when the client can talk to older deployments.
|
|
27
|
+
|
|
15
28
|
## Working with a specific workflow
|
|
16
29
|
|
|
17
30
|
Get an instance of a specific workflow by its ID:
|
|
@@ -69,32 +69,33 @@ Please note:
|
|
|
69
69
|
|
|
70
70
|
Keep `config.ts` focused on runtime options. Use sibling files for concerns that benefit from their own location.
|
|
71
71
|
|
|
72
|
-
| Setting | File or folder
|
|
73
|
-
| ------------ |
|
|
74
|
-
| Instructions | [`instructions.md`](https://mastra.ai/reference/file-based-agents/instructions) | Keeps the always-on prompt readable as markdown
|
|
75
|
-
| Tools | [`tools/`](https://mastra.ai/reference/file-based-agents/tools)
|
|
76
|
-
| Skills | [`skills/`](https://mastra.ai/reference/file-based-agents/skills)
|
|
77
|
-
| Memory | [`memory.ts`](https://mastra.ai/reference/file-based-agents/memory)
|
|
78
|
-
| Workspace | [`workspace.ts`](https://mastra.ai/reference/file-based-agents/workspace)
|
|
79
|
-
| Processors | [`processors/`](https://mastra.ai/reference/file-based-agents/processors)
|
|
80
|
-
| Subagents | [`subagents/`](https://mastra.ai/reference/file-based-agents/subagents)
|
|
72
|
+
| Setting | File or folder | Why it lives there |
|
|
73
|
+
| ------------ | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
74
|
+
| Instructions | [`instructions.md` or `instructions.ts`](https://mastra.ai/reference/file-based-agents/instructions) | Keeps the always-on prompt readable as markdown, or computed in TypeScript |
|
|
75
|
+
| Tools | [`tools/`](https://mastra.ai/reference/file-based-agents/tools) | Gives each callable action its own typed module |
|
|
76
|
+
| Skills | [`skills/`](https://mastra.ai/reference/file-based-agents/skills) | Keeps load-on-demand procedures separate from always-on instructions |
|
|
77
|
+
| Memory | [`memory.ts`](https://mastra.ai/reference/file-based-agents/memory) | Configures persistent memory without crowding runtime options |
|
|
78
|
+
| Workspace | [`workspace.ts`](https://mastra.ai/reference/file-based-agents/workspace) | Configures files and sandbox behavior separately from model settings |
|
|
79
|
+
| Processors | [`processors/`](https://mastra.ai/reference/file-based-agents/processors) | Separates input and output processing pipelines |
|
|
80
|
+
| Subagents | [`subagents/`](https://mastra.ai/reference/file-based-agents/subagents) | Gives each specialist child agent its own directory |
|
|
81
81
|
|
|
82
82
|
## Precedence
|
|
83
83
|
|
|
84
84
|
`config.ts` merges with the agent's other files according to these rules:
|
|
85
85
|
|
|
86
|
-
| Domain | Source A
|
|
87
|
-
| ------------ |
|
|
88
|
-
| Instructions | Dynamic `config.instructions`
|
|
89
|
-
| Instructions | Static `config.instructions`
|
|
90
|
-
|
|
|
91
|
-
| Tools |
|
|
92
|
-
|
|
|
93
|
-
| Skills |
|
|
94
|
-
|
|
|
95
|
-
|
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
| Domain | Source A | Source B | Winner |
|
|
87
|
+
| ------------ | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
|
|
88
|
+
| Instructions | Dynamic `config.instructions` | [`instructions.ts` or `instructions.md`](https://mastra.ai/reference/file-based-agents/instructions) | Dynamic `config.instructions` |
|
|
89
|
+
| Instructions | Static `config.instructions` | [`instructions.ts` or `instructions.md`](https://mastra.ai/reference/file-based-agents/instructions) | The instructions file |
|
|
90
|
+
| Instructions | [`instructions.ts`](https://mastra.ai/reference/file-based-agents/instructions) | [`instructions.md`](https://mastra.ai/reference/file-based-agents/instructions) | `instructions.ts` |
|
|
91
|
+
| Tools | `config.tools` | [`tools/`](https://mastra.ai/reference/file-based-agents/tools) | Both merge; `config.tools` wins on key collisions |
|
|
92
|
+
| Tools | Function `config.tools` | [`tools/`](https://mastra.ai/reference/file-based-agents/tools) | Function `config.tools`; discovered tools are ignored |
|
|
93
|
+
| Skills | `config.skills` | [`skills/`](https://mastra.ai/reference/file-based-agents/skills) | Both merge; `config.skills` wins on name collisions |
|
|
94
|
+
| Skills | Function `config.skills` | [`skills/`](https://mastra.ai/reference/file-based-agents/skills) | Function `config.skills`; discovered skills are ignored |
|
|
95
|
+
| Memory | `config.memory` | [`memory.ts`](https://mastra.ai/reference/file-based-agents/memory) | `config.memory` |
|
|
96
|
+
| Workspace | `config.workspace` | [`workspace.ts`](https://mastra.ai/reference/file-based-agents/workspace) | `config.workspace` |
|
|
97
|
+
|
|
98
|
+
Missing `instructions.md`, `instructions.ts`, and `config.instructions` fails the build. Missing both `config.memory` and `memory.ts` leaves the agent without memory.
|
|
98
99
|
|
|
99
100
|
## Discovery lifecycle
|
|
100
101
|
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
# Instructions
|
|
4
4
|
|
|
5
|
-
An agent's
|
|
5
|
+
An agent's instructions hold its always-on system prompt: the model reads it on every turn. Use them to define the agent's identity, tone, role, and standing rules.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Write them in one of two files at the agent root. Use `instructions.md` when the prompt is fixed text. Use `instructions.ts` when the prompt needs code, for example when it's built from shared constants or resolved per request.
|
|
8
|
+
|
|
9
|
+
Instructions are always in context, so keep them for stable behavior that applies to every request. Move anything conditional, large, or action-oriented into [`tools/`](https://mastra.ai/reference/file-based-agents/tools) or [`skills/`](https://mastra.ai/reference/file-based-agents/skills), which the model uses only when relevant.
|
|
8
10
|
|
|
9
11
|
## Quickstart
|
|
10
12
|
|
|
@@ -25,30 +27,53 @@ Effective instructions cover the parts of an agent's behavior that don't change
|
|
|
25
27
|
|
|
26
28
|
Move conditional, large, or action-oriented guidance into [`tools/`](https://mastra.ai/reference/file-based-agents/tools) or [`skills/`](https://mastra.ai/reference/file-based-agents/skills), which the model uses only when relevant.
|
|
27
29
|
|
|
28
|
-
##
|
|
30
|
+
## Instructions in TypeScript
|
|
31
|
+
|
|
32
|
+
Use `instructions.ts` when markdown can't express the prompt. The file default-exports a string, a system message, or a function returning one, and `agentInstructions()` types the export without changing it.
|
|
33
|
+
|
|
34
|
+
Export a string when the prompt is assembled in code, for example from constants shared with the rest of your app:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { agentInstructions } from '@mastra/core/agent'
|
|
38
|
+
import { SUPPORTED_UNITS } from '../../constants'
|
|
39
|
+
|
|
40
|
+
export default agentInstructions(`
|
|
41
|
+
You are a helpful weather assistant.
|
|
42
|
+
Report conditions using one of these units: ${SUPPORTED_UNITS.join(', ')}.
|
|
43
|
+
`)
|
|
44
|
+
```
|
|
29
45
|
|
|
30
|
-
|
|
46
|
+
Export a function when the prompt depends on the request. Mastra calls it on every turn and passes the request context:
|
|
31
47
|
|
|
32
48
|
```typescript
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
export default
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const tier = runtimeContext.get('tier') ?? 'standard'
|
|
39
|
-
return `You are a support agent. Treat this as a ${tier}-tier customer.`
|
|
40
|
-
},
|
|
49
|
+
import { agentInstructions } from '@mastra/core/agent'
|
|
50
|
+
|
|
51
|
+
export default agentInstructions(({ requestContext }) => {
|
|
52
|
+
const tier = requestContext.get('tier') ?? 'standard'
|
|
53
|
+
return `You are a support agent. Treat this as a ${tier}-tier customer.`
|
|
41
54
|
})
|
|
42
55
|
```
|
|
43
56
|
|
|
57
|
+
The function can be `async` and receives `mastra` alongside `requestContext`, so it can read from storage or another registered primitive before returning the prompt.
|
|
58
|
+
|
|
59
|
+
Both files can also live in a [subagent](https://mastra.ai/reference/file-based-agents/subagents) directory, which follows the same rules.
|
|
60
|
+
|
|
44
61
|
## Build-time behavior
|
|
45
62
|
|
|
46
|
-
|
|
63
|
+
`instructions.md` and `instructions.ts` reach the deployed agent differently:
|
|
64
|
+
|
|
65
|
+
- `instructions.md`: Mastra reads the file and inlines its contents into the generated code at build time.
|
|
66
|
+
- `instructions.ts`: The generated code imports the module, so it's bundled like any other TypeScript file and can import from the rest of your project.
|
|
67
|
+
|
|
68
|
+
Under `mastra dev`, editing either file triggers a rebuild. In a deployed app neither file is read from disk at runtime, so changes take effect after the next build.
|
|
47
69
|
|
|
48
70
|
## Precedence with config
|
|
49
71
|
|
|
50
|
-
Instructions can come from `instructions.md
|
|
72
|
+
Instructions can come from `instructions.ts`, `instructions.md`, or the `instructions` field in [`config.ts`](https://mastra.ai/reference/file-based-agents/config):
|
|
73
|
+
|
|
74
|
+
- A runtime-defined (function) `instructions` in `config.ts` wins over both files.
|
|
75
|
+
- Otherwise `instructions.ts` wins over `instructions.md`.
|
|
76
|
+
- `instructions.md` wins over a static `instructions` string in `config.ts`.
|
|
77
|
+
- If none is present, the build fails and names the agent directory.
|
|
51
78
|
|
|
52
|
-
|
|
53
|
-
- Otherwise `instructions.md` wins over a static `instructions` string.
|
|
54
|
-
- If neither is present, the build fails and names the agent directory.
|
|
79
|
+
Defining instructions in more than one place logs a warning that names both sources and which one wins. Keep one source per agent.
|
package/.docs/reference/index.md
CHANGED
|
@@ -302,6 +302,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
302
302
|
- [Overview](https://mastra.ai/reference/templates/overview)
|
|
303
303
|
- [askUserTool](https://mastra.ai/reference/tools/ask-user-tool)
|
|
304
304
|
- [Bright Data Tools](https://mastra.ai/reference/tools/brightdata)
|
|
305
|
+
- [createBedrockKBTool()](https://mastra.ai/reference/tools/bedrock-kb-tool)
|
|
305
306
|
- [createCodeMode()](https://mastra.ai/reference/tools/create-code-mode)
|
|
306
307
|
- [createDocumentChunkerTool()](https://mastra.ai/reference/tools/document-chunker-tool)
|
|
307
308
|
- [createGraphRAGTool()](https://mastra.ai/reference/tools/graph-rag-tool)
|
|
@@ -64,17 +64,19 @@ The detailed breakdown metrics (everything except `total_input` and `total_outpu
|
|
|
64
64
|
|
|
65
65
|
### When cost context is attached
|
|
66
66
|
|
|
67
|
-
Cost context is attached to token metrics when the embedded pricing registry has a matching entry for the provider and model. Mastra
|
|
67
|
+
Cost context is attached to token metrics when the provider reports a valid cost for every completed model step or when the embedded pricing registry has a matching entry for the provider and model. Mastra sums the per-step provider costs into one query total. If any completed step lacks a valid reported cost, Mastra uses the pricing registry instead of reporting a partial total. If neither source is available, token metrics are still emitted without cost fields.
|
|
68
|
+
|
|
69
|
+
A caller-supplied `costContext` takes precedence over provider-reported costs and pricing registry estimates. Provider-reported totals use `costMetadata.source: 'provider_reported'`, `costMetadata.scope: 'query_total'`, and `costMetadata.reportedStepCount` to identify the source, scope, and number of completed steps included in the total.
|
|
68
70
|
|
|
69
71
|
### What cost fields may be included
|
|
70
72
|
|
|
71
|
-
| Field | Description
|
|
72
|
-
| --------------- |
|
|
73
|
-
| `provider` | Provider name (e.g. `openai`, `anthropic`)
|
|
74
|
-
| `model` | Model identifier (e.g. `gpt-4o`, `claude-sonnet-4-20250514`)
|
|
75
|
-
| `estimatedCost` | Estimated cost
|
|
76
|
-
| `costUnit` | Currency unit (e.g. `USD`)
|
|
77
|
-
| `costMetadata` | Additional pricing context
|
|
73
|
+
| Field | Description |
|
|
74
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
75
|
+
| `provider` | Provider name (e.g. `openai`, `anthropic`) |
|
|
76
|
+
| `model` | Model identifier (e.g. `gpt-4o`, `claude-sonnet-4-20250514`) |
|
|
77
|
+
| `estimatedCost` | Estimated cost from token count and pricing tier, or a total reported by the provider |
|
|
78
|
+
| `costUnit` | Currency unit (e.g. `USD`) |
|
|
79
|
+
| `costMetadata` | Additional pricing context, including tier information, error details, and provider-reported cost source and scope |
|
|
78
80
|
|
|
79
81
|
## Correlation with traces
|
|
80
82
|
|
|
@@ -171,17 +171,31 @@ The route returns:
|
|
|
171
171
|
|
|
172
172
|
## Workflows
|
|
173
173
|
|
|
174
|
-
| Method | Path | Description
|
|
175
|
-
| ------ | ----------------------------------------- |
|
|
176
|
-
| `GET` | `/api/workflows` | List all workflows
|
|
177
|
-
| `GET` | `/api/workflows
|
|
178
|
-
| `
|
|
179
|
-
| `POST` | `/api/workflows/:workflowId/
|
|
180
|
-
| `POST` | `/api/workflows/:workflowId/
|
|
181
|
-
| `POST` | `/api/workflows/:workflowId/
|
|
182
|
-
| `POST` | `/api/workflows/:workflowId/resume
|
|
183
|
-
| `
|
|
184
|
-
| `GET` | `/api/workflows/:workflowId/runs
|
|
174
|
+
| Method | Path | Description |
|
|
175
|
+
| ------ | ----------------------------------------- | ----------------------------------------------------- |
|
|
176
|
+
| `GET` | `/api/workflows` | List all workflows |
|
|
177
|
+
| `GET` | `/api/workflows/run-counts` | Get per-workflow counts of running and suspended runs |
|
|
178
|
+
| `GET` | `/api/workflows/:workflowId` | Get workflow by ID |
|
|
179
|
+
| `POST` | `/api/workflows/:workflowId/create-run` | Create a new workflow run |
|
|
180
|
+
| `POST` | `/api/workflows/:workflowId/start-async` | Start workflow and await result |
|
|
181
|
+
| `POST` | `/api/workflows/:workflowId/stream` | Stream workflow execution |
|
|
182
|
+
| `POST` | `/api/workflows/:workflowId/resume` | Resume suspended workflow |
|
|
183
|
+
| `POST` | `/api/workflows/:workflowId/resume-async` | Resume asynchronously |
|
|
184
|
+
| `GET` | `/api/workflows/:workflowId/runs` | List workflow runs |
|
|
185
|
+
| `GET` | `/api/workflows/:workflowId/runs/:runId` | Get specific run |
|
|
186
|
+
|
|
187
|
+
### Run counts response
|
|
188
|
+
|
|
189
|
+
The `/api/workflows/run-counts` endpoint returns counts of `running` and [`suspended`](https://mastra.ai/docs/workflows/suspend-and-resume) runs for every registered workflow. The record is keyed by the workflow's registry key from the Mastra config, and the server may cache the response for a few seconds:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
{
|
|
193
|
+
[workflowRegistryKey: string]: {
|
|
194
|
+
running: number;
|
|
195
|
+
suspended: number;
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
```
|
|
185
199
|
|
|
186
200
|
### Stored workflows
|
|
187
201
|
|
|
@@ -251,6 +251,64 @@ const memoryStore = await storage.getStore('memory')
|
|
|
251
251
|
const thread = await memoryStore?.getThreadById({ threadId: '...' })
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
+
## Closing connections
|
|
255
|
+
|
|
256
|
+
`close()` releases the connections of the stores a composite was built from: the `default` and `editor` stores, plus any domain that owns its own client. Each store is closed once, even when it backs several domains. When passed to the Mastra class, `close()` is called by `shutdown()`:
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
260
|
+
import { PostgresStore } from '@mastra/pg'
|
|
261
|
+
import { Mastra } from '@mastra/core'
|
|
262
|
+
|
|
263
|
+
const pgStore = new PostgresStore({
|
|
264
|
+
id: 'pg-storage',
|
|
265
|
+
connectionString: process.env.DATABASE_URL,
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
export const mastra = new Mastra({
|
|
269
|
+
storage: new MastraCompositeStore({ id: 'composite', default: pgStore }),
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
process.on('SIGTERM', async () => {
|
|
273
|
+
// Releases the Postgres pool, so the process can exit
|
|
274
|
+
await mastra.shutdown()
|
|
275
|
+
})
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
A store you construct only to supply a domain isn't reachable through the composite. Keep a reference to it and close it yourself:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { MastraCompositeStore } from '@mastra/core/storage'
|
|
282
|
+
import { ClickhouseStore } from '@mastra/clickhouse'
|
|
283
|
+
import { PostgresStore } from '@mastra/pg'
|
|
284
|
+
import { Mastra } from '@mastra/core'
|
|
285
|
+
|
|
286
|
+
const pgStore = new PostgresStore({
|
|
287
|
+
id: 'pg-storage',
|
|
288
|
+
connectionString: process.env.DATABASE_URL,
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
const clickhouseStore = new ClickhouseStore({
|
|
292
|
+
id: 'clickhouse-storage',
|
|
293
|
+
url: process.env.CLICKHOUSE_URL,
|
|
294
|
+
username: process.env.CLICKHOUSE_USERNAME,
|
|
295
|
+
password: process.env.CLICKHOUSE_PASSWORD,
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
export const mastra = new Mastra({
|
|
299
|
+
storage: new MastraCompositeStore({
|
|
300
|
+
id: 'composite',
|
|
301
|
+
default: pgStore,
|
|
302
|
+
domains: { observability: clickhouseStore.stores?.observability },
|
|
303
|
+
}),
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
process.on('SIGTERM', async () => {
|
|
307
|
+
await mastra.shutdown()
|
|
308
|
+
await clickhouseStore.close()
|
|
309
|
+
})
|
|
310
|
+
```
|
|
311
|
+
|
|
254
312
|
## Use cases
|
|
255
313
|
|
|
256
314
|
### Separate databases for different workloads
|
|
@@ -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+)
|
|
@@ -109,7 +109,17 @@ Converts speech to text using Google Cloud Speech-to-Text service. Supports both
|
|
|
109
109
|
|
|
110
110
|
Pass `v2: true` to use the Cloud Speech-to-Text v2 API, which supports additional audio formats like AAC-in-MP4 (iOS Safari).
|
|
111
111
|
|
|
112
|
+
The v2 `recognize` call is IAM-authorized and does not accept API-key-only authentication. Configure service account credentials on the `listeningModel` (or set `GOOGLE_APPLICATION_CREDENTIALS`) and set `GOOGLE_CLOUD_PROJECT` so the recognizer path can be resolved, even when `vertexAI` is not enabled.
|
|
113
|
+
|
|
112
114
|
```typescript
|
|
115
|
+
import { GoogleVoice } from '@mastra/voice-google'
|
|
116
|
+
|
|
117
|
+
// v2 listen() requires service account credentials, not just GOOGLE_API_KEY.
|
|
118
|
+
// Set GOOGLE_CLOUD_PROJECT so the recognizer path can be resolved.
|
|
119
|
+
const voice = new GoogleVoice({
|
|
120
|
+
listeningModel: { keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS },
|
|
121
|
+
})
|
|
122
|
+
|
|
113
123
|
const transcript = await voice.listen(iosSafariAacStream, {
|
|
114
124
|
v2: true,
|
|
115
125
|
config: {
|
|
@@ -118,6 +128,8 @@ const transcript = await voice.listen(iosSafariAacStream, {
|
|
|
118
128
|
})
|
|
119
129
|
```
|
|
120
130
|
|
|
131
|
+
> **Note:** `listen({ v2: true })` fails with `PERMISSION_DENIED` on `speech.recognizers.recognize` when only `GOOGLE_API_KEY` is set. An API-key request carries no OAuth identity, so granting `roles/speech.client` to a user account does not help — the role must be granted to the service account presented in the request. This applies regardless of the `vertexAI` setting; `speak()` and v1 `listen()` still work with an API key alone.
|
|
132
|
+
|
|
121
133
|
**audioStream** (`NodeJS.ReadableStream`): Audio stream to transcribe
|
|
122
134
|
|
|
123
135
|
**options** (`GoogleListenOptionsV2`): v2 recognition options
|
|
@@ -162,7 +174,7 @@ The Google Voice provider supports two authentication methods:
|
|
|
162
174
|
|
|
163
175
|
### Standard Mode (API Key)
|
|
164
176
|
|
|
165
|
-
Uses a Google Cloud API key for authentication.
|
|
177
|
+
Uses a Google Cloud API key for authentication. Covers `speak()` and v1 `listen()`. It does not cover `listen({ v2: true })`, which is IAM-authorized and requires service account credentials (see [v2](#v2)).
|
|
166
178
|
|
|
167
179
|
```typescript
|
|
168
180
|
// Using environment variable (GOOGLE_API_KEY)
|
|
@@ -238,6 +250,8 @@ For Speech-to-Text:
|
|
|
238
250
|
|
|
239
251
|
- `roles/speech.client` - Speech-to-Text Client
|
|
240
252
|
|
|
253
|
+
Grant `roles/speech.client` to the service account whose credentials the request presents (via `keyFilename`, `credentials`, or `GOOGLE_APPLICATION_CREDENTIALS`). This role is required for `listen({ v2: true })` specifically, not only for Vertex AI mode. Granting it to a user account has no effect on API-key-only requests, which carry no identity to authorize.
|
|
254
|
+
|
|
241
255
|
#### OAuth Scopes
|
|
242
256
|
|
|
243
257
|
For synchronous Text-to-Speech synthesis:
|
|
@@ -269,6 +283,8 @@ For long-audio Text-to-Speech operations:
|
|
|
269
283
|
|
|
270
284
|
6. The `listen()` method supports various recognition configurations through the Google Cloud Speech-to-Text API.
|
|
271
285
|
|
|
272
|
-
7.
|
|
286
|
+
7. `listen({ v2: true })` requires service account credentials and `GOOGLE_CLOUD_PROJECT`; it fails with `PERMISSION_DENIED` when only `GOOGLE_API_KEY` is set. `speak()` and v1 `listen()` work with an API key alone.
|
|
287
|
+
|
|
288
|
+
8. Available voices can be filtered by language code using the `getSpeakers()` method.
|
|
273
289
|
|
|
274
|
-
|
|
290
|
+
9. Vertex AI mode provides enterprise features including IAM control, audit logs, and project-level billing.
|