@mastra/mcp-docs-server 1.1.42-alpha.2 → 1.1.42-alpha.5
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/memory.md +1 -1
- package/.docs/docs/agents/adding-voice.md +31 -0
- package/.docs/docs/agents/agent-approval.md +14 -0
- package/.docs/docs/agents/channels.md +2 -0
- package/.docs/docs/agents/code-mode.md +163 -0
- package/.docs/docs/agents/signals.md +132 -71
- package/.docs/docs/getting-started/manual-install.md +1 -1
- package/.docs/docs/memory/observational-memory.md +19 -0
- package/.docs/docs/memory/semantic-recall.md +1 -1
- package/.docs/docs/observability/metrics/overview.md +1 -0
- package/.docs/docs/observability/metrics/querying.md +292 -0
- package/.docs/docs/server/auth/fga.md +2 -0
- package/.docs/docs/voice/overview.md +62 -0
- package/.docs/docs/voice/speech-to-speech.md +52 -1
- package/.docs/docs/workspace/sandbox.md +4 -2
- package/.docs/guides/deployment/inngest.md +69 -0
- package/.docs/guides/guide/firecrawl.md +5 -5
- package/.docs/models/embeddings.md +2 -2
- package/.docs/reference/agents/agent.md +46 -17
- package/.docs/reference/agents/channels.md +1 -1
- package/.docs/reference/evals/create-scorer.md +2 -0
- package/.docs/reference/index.md +3 -0
- package/.docs/reference/memory/observational-memory.md +2 -0
- package/.docs/reference/observability/metrics/automatic-metrics.md +7 -1
- package/.docs/reference/processors/tool-search-processor.md +31 -0
- package/.docs/reference/server/routes.md +81 -9
- package/.docs/reference/templates/overview.md +2 -2
- package/.docs/reference/tools/mcp-client.md +51 -0
- package/.docs/reference/vectors/pg.md +2 -0
- package/.docs/reference/voice/inworld-realtime.md +353 -0
- package/.docs/reference/voice/inworld.md +2 -0
- package/.docs/reference/workspace/agentcore-runtime-sandbox.md +202 -0
- package/.docs/reference/workspace/blaxel-sandbox.md +3 -0
- package/.docs/reference/workspace/docker-sandbox.md +3 -1
- package/.docs/reference/workspace/vercel-microvm-sandbox.md +199 -0
- package/.docs/reference/workspace/vercel.md +2 -0
- package/CHANGELOG.md +15 -0
- package/package.json +7 -5
|
@@ -96,9 +96,9 @@ export const agent = new Agent({
|
|
|
96
96
|
|
|
97
97
|
## Thread signals
|
|
98
98
|
|
|
99
|
-
Use Agent signals to send real-time context into a memory thread.
|
|
99
|
+
Use Agent signals to send real-time input and context into a memory thread. Message APIs are for user-authored input. `sendSignal()` is the lower-level API for system-generated context.
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
When the target thread is running, `sendMessage()` delivers the message into the active agent loop. When the thread is idle, Mastra starts a stream with the message as the first input by default.
|
|
102
102
|
|
|
103
103
|
```typescript
|
|
104
104
|
const subscription = await agent.subscribeToThread({
|
|
@@ -112,26 +112,22 @@ void (async () => {
|
|
|
112
112
|
}
|
|
113
113
|
})()
|
|
114
114
|
|
|
115
|
-
agent.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
streamOptions: {
|
|
122
|
-
maxSteps: 3,
|
|
123
|
-
},
|
|
115
|
+
agent.sendMessage('Use the latest customer note too.', {
|
|
116
|
+
resourceId: 'user-123',
|
|
117
|
+
threadId: 'thread-abc',
|
|
118
|
+
ifIdle: {
|
|
119
|
+
streamOptions: {
|
|
120
|
+
maxSteps: 3,
|
|
124
121
|
},
|
|
125
122
|
},
|
|
126
|
-
)
|
|
123
|
+
})
|
|
127
124
|
```
|
|
128
125
|
|
|
129
|
-
Use `attributes` to identify different users in a shared thread. The
|
|
126
|
+
Use `attributes` to identify different users in a shared thread. The attributes are rendered as XML so the model can distinguish who said what:
|
|
130
127
|
|
|
131
128
|
```typescript
|
|
132
|
-
agent.
|
|
129
|
+
agent.sendMessage(
|
|
133
130
|
{
|
|
134
|
-
type: 'user',
|
|
135
131
|
contents: 'Can we simplify the API surface?',
|
|
136
132
|
attributes: { name: 'Devin', from: 'slack' },
|
|
137
133
|
},
|
|
@@ -147,11 +143,44 @@ The model receives this as:
|
|
|
147
143
|
|
|
148
144
|
The UI sees just the message contents but can also read `attributes` and `metadata` off the signal message for custom rendering (e.g. showing user names, avatars, or platform badges).
|
|
149
145
|
|
|
146
|
+
### `sendMessage(message, options)`
|
|
147
|
+
|
|
148
|
+
Sends a user message to an active run or memory thread. Use this when the active agent should receive the message immediately.
|
|
149
|
+
|
|
150
|
+
**message** (`string | Array<TextPart | FilePart> | { contents: string | Array<TextPart | FilePart>; attributes?: Record<string, JSONValue>; metadata?: Record<string, unknown>; providerOptions?: ProviderMetadata }`): User-authored input. Bare strings and parts without attributes are sent to the model as normal user input. When \`attributes\` are present, Mastra renders the message as a \`\<user>\` XML element with the attributes included.
|
|
151
|
+
|
|
152
|
+
**options.runId** (`string`): Run ID to target directly. Use this when you already know the active run ID.
|
|
153
|
+
|
|
154
|
+
**options.resourceId** (`string`): Resource ID for the memory thread. Required with \`threadId\` for thread-targeted messages.
|
|
155
|
+
|
|
156
|
+
**options.threadId** (`string`): Thread ID to target. Required with \`resourceId\` for thread-targeted messages.
|
|
157
|
+
|
|
158
|
+
**options.ifActive.behavior** (`'deliver' | 'persist' | 'discard'`): Controls what happens when the target thread is active. Defaults to \`deliver\`.
|
|
159
|
+
|
|
160
|
+
**options.ifIdle.behavior** (`'wake' | 'persist' | 'discard'`): Controls what happens when the target thread is idle. Defaults to \`wake\`.
|
|
161
|
+
|
|
162
|
+
**options.ifIdle.streamOptions** (`AgentExecutionOptions`): Options for the stream that starts when \`ifIdle.behavior\` is \`wake\`. Mastra uses the top-level \`resourceId\` and \`threadId\` for memory context.
|
|
163
|
+
|
|
164
|
+
Returns `{ accepted: true, runId: string, signal: CreatedAgentSignal, persisted?: Promise<void> }`. `persisted` is only present for `persist` behavior and resolves when Mastra finishes writing the message to memory.
|
|
165
|
+
|
|
166
|
+
### `queueMessage(message, options)`
|
|
167
|
+
|
|
168
|
+
Queues a user message for the next turn on a thread. If the thread is active, Mastra waits for the active run to finish, then starts a new run with the queued message. If the thread is idle, Mastra starts a run immediately.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
agent.queueMessage('Also check whether the tests need updates.', {
|
|
172
|
+
resourceId: 'user-123',
|
|
173
|
+
threadId: 'thread-abc',
|
|
174
|
+
})
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`queueMessage()` accepts the same `message` and `options` shape as `sendMessage()` and returns `{ accepted: true, runId: string, signal: CreatedAgentSignal, persisted?: Promise<void> }`.
|
|
178
|
+
|
|
150
179
|
### `sendSignal(signal, options)`
|
|
151
180
|
|
|
152
181
|
Sends a signal to an active run or memory thread.
|
|
153
182
|
|
|
154
|
-
**signal** (`{ type: 'user-message' | 'system-reminder'
|
|
183
|
+
**signal** (`{ type: 'user' | 'state' | 'reactive' | 'notification' | 'user-message' | 'system-reminder'; tagName?: string; contents: string | Array<TextPart | FilePart>; attributes?: Record<string, JSONValue>; metadata?: Record<string, unknown>; providerOptions?: ProviderMetadata }`): Signal context to send to the thread. \`type\` is the semantic signal category. \`tagName\` controls the XML tag the model sees. For example, \`{ type: 'notification', tagName: 'github-review' }\` renders as \`\<github-review>...\</github-review>\`. Legacy \`user-message\` and \`system-reminder\` payloads are still accepted and normalized. Unknown \`type\` values are rejected; use \`tagName\` for custom XML tags.
|
|
155
184
|
|
|
156
185
|
**options.runId** (`string`): Run ID to target directly. Use this when you already know the active run ID.
|
|
157
186
|
|
|
@@ -169,7 +198,7 @@ Returns `{ accepted: true, runId: string, signal: CreatedAgentSignal, persisted?
|
|
|
169
198
|
|
|
170
199
|
### `subscribeToThread(options)`
|
|
171
200
|
|
|
172
|
-
Subscribes to raw stream chunks for a memory thread. Use this before calling `sendSignal()` when you need to render stream output, observe signal echoes, or abort the active run.
|
|
201
|
+
Subscribes to raw stream chunks for a memory thread. Use this before calling `sendMessage()`, `queueMessage()`, or `sendSignal()` when you need to render stream output, observe signal echoes, or abort the active run.
|
|
173
202
|
|
|
174
203
|
**options.resourceId** (`string`): Resource ID for the memory thread.
|
|
175
204
|
|
|
@@ -41,7 +41,7 @@ export const supportAgent = new Agent({
|
|
|
41
41
|
|
|
42
42
|
**userName** (`string`): Bot display name shown in platform messages. Defaults to the agent's \`name\`, or \`'Mastra'\` if no name is set. (Default: `` agent's `name` ``)
|
|
43
43
|
|
|
44
|
-
**threadContext** (`{ maxMessages?: number }`):
|
|
44
|
+
**threadContext** (`{ maxMessages?: number; addSystemMessage?: boolean }`): How the agent picks up context about the current thread. \`maxMessages\` controls how many recent platform messages are fetched on first mention (set to \`0\` to disable; only applies to non-DM threads). \`addSystemMessage: false\` skips the built-in system message that tells the agent which channel/platform a request came from. (Default: `{ maxMessages: 10, addSystemMessage: true }`)
|
|
45
45
|
|
|
46
46
|
**chatOptions** (`Omit<ChatConfig, 'adapters' | 'state' | 'userName'>`): Additional options passed directly to the \[Chat SDK]\(https\://chat-sdk.dev/docs/usage). Use for advanced configuration such as \`dedupeTtlMs\`, \`fallbackStreamingPlaceholderText\`, \`lockScope\`, and \`messageHistory\`.
|
|
47
47
|
|
|
@@ -49,6 +49,8 @@ const scorer = createScorer({
|
|
|
49
49
|
|
|
50
50
|
**judge.instructions** (`string`): System prompt/instructions for the LLM.
|
|
51
51
|
|
|
52
|
+
**judge.jsonPromptInjection** (`boolean`): When true, inject the JSON schema into the prompt instead of using the provider's native \`response\_format\` API. Set this for models that don't support native structured output (e.g. some Groq Llama models) to avoid a wasted 400 call.
|
|
53
|
+
|
|
52
54
|
**type** (`string`): Type specification for input/output. Use 'agent' for automatic agent types. For custom types, use the generic approach instead.
|
|
53
55
|
|
|
54
56
|
**prepareRun** (`(run: ScorerRun) => ScorerRun | Promise<ScorerRun>`): Transform the scorer run data before the pipeline executes. Use this to filter messages, limit context size, or drop fields the scorer doesn't need. The \[\`filterRun()\`]\(/reference/evals/filter-run) utility creates this function from declarative options. Can be async.
|
package/.docs/reference/index.md
CHANGED
|
@@ -274,6 +274,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
274
274
|
- [Google](https://mastra.ai/reference/voice/google)
|
|
275
275
|
- [Google Gemini Live](https://mastra.ai/reference/voice/google-gemini-live)
|
|
276
276
|
- [Inworld](https://mastra.ai/reference/voice/inworld)
|
|
277
|
+
- [Inworld Realtime](https://mastra.ai/reference/voice/inworld-realtime)
|
|
277
278
|
- [Mastra Voice](https://mastra.ai/reference/voice/mastra-voice)
|
|
278
279
|
- [Murf](https://mastra.ai/reference/voice/murf)
|
|
279
280
|
- [OpenAI](https://mastra.ai/reference/voice/openai)
|
|
@@ -315,6 +316,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
315
316
|
- [.start()](https://mastra.ai/reference/workflows/run-methods/start)
|
|
316
317
|
- [.startAsync()](https://mastra.ai/reference/workflows/run-methods/startAsync)
|
|
317
318
|
- [.timeTravel()](https://mastra.ai/reference/workflows/run-methods/timeTravel)
|
|
319
|
+
- [AgentCoreRuntimeSandbox](https://mastra.ai/reference/workspace/agentcore-runtime-sandbox)
|
|
318
320
|
- [AgentFSFilesystem](https://mastra.ai/reference/workspace/agentfs-filesystem)
|
|
319
321
|
- [AzureBlobFilesystem](https://mastra.ai/reference/workspace/azure-blob-filesystem)
|
|
320
322
|
- [BlaxelSandbox](https://mastra.ai/reference/workspace/blaxel-sandbox)
|
|
@@ -329,6 +331,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
329
331
|
- [ModalSandbox](https://mastra.ai/reference/workspace/modal-sandbox)
|
|
330
332
|
- [S3Filesystem](https://mastra.ai/reference/workspace/s3-filesystem)
|
|
331
333
|
- [SandboxProcessManager](https://mastra.ai/reference/workspace/process-manager)
|
|
334
|
+
- [VercelMicroVMSandbox](https://mastra.ai/reference/workspace/vercel-microvm-sandbox)
|
|
332
335
|
- [VercelSandbox](https://mastra.ai/reference/workspace/vercel)
|
|
333
336
|
- [Workspace Class](https://mastra.ai/reference/workspace/workspace-class)
|
|
334
337
|
- [WorkspaceFilesystem](https://mastra.ai/reference/workspace/filesystem)
|
|
@@ -68,6 +68,8 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
68
68
|
|
|
69
69
|
**observation.bufferTokens** (`number | false`): Token interval for async background observation buffering. Can be an absolute token count (e.g. \`5000\`) or a fraction of \`messageTokens\` (e.g. \`0.25\` = buffer every 25% of threshold). When set, observations run in the background at this interval, storing results in a buffer. When the main \`messageTokens\` threshold is reached, buffered observations activate instantly without a blocking LLM call. Must resolve to less than \`messageTokens\`. Set to \`false\` to explicitly disable all async buffering (both observation and reflection).
|
|
70
70
|
|
|
71
|
+
**observation.bufferOnIdle** (`boolean`): Run background observation buffering when an agent turn ends and the agent becomes idle. This is separate from \`bufferTokens\`, which controls step-time async buffering. Set this to \`true\` to buffer short idle turns without waiting for the next turn or the \`messageTokens\` threshold.
|
|
72
|
+
|
|
71
73
|
**observation.bufferActivation** (`number`): Controls how much of the message window to retain after activation. Accepts a ratio (0-1) or an absolute token count (≥ 1000). For example, \`0.8\` means: activate enough buffers to remove 80% of \`messageTokens\` and leave 20% as active message history. An absolute token count like \`4000\` targets a goal of keeping \~4k message tokens remaining after activation. Higher values remove more message history per activation when using a ratio. Higher values keep more message history when using a token count.
|
|
72
74
|
|
|
73
75
|
**observation.activateAfterIdle** (`number | string | false | "auto"`): Time before buffered observations are forced to activate after inactivity. Accepts milliseconds, a duration string, \`"auto"\` for a provider-aware prompt cache TTL, or \`false\`. If unset, the top-level \`activateAfterIdle\` value is used for observations. Set \`false\` to disable the top-level idle setting for observations.
|
|
@@ -127,4 +127,10 @@ When you spot a spike in latency or token usage on the Metrics dashboard, correl
|
|
|
127
127
|
### Token metrics are missing
|
|
128
128
|
|
|
129
129
|
- **Span is a model generation**: Token metrics are only emitted from `MODEL_GENERATION` spans.
|
|
130
|
-
- **Provider reports usage**: The model provider must include `usage` data in its response. If usage is absent, no token metrics are emitted.
|
|
130
|
+
- **Provider reports usage**: The model provider must include `usage` data in its response. If usage is absent, no token metrics are emitted.
|
|
131
|
+
|
|
132
|
+
## Related
|
|
133
|
+
|
|
134
|
+
- [Metrics overview](https://mastra.ai/docs/observability/metrics/overview)
|
|
135
|
+
- [Querying metrics](https://mastra.ai/docs/observability/metrics/querying)
|
|
136
|
+
- [Studio observability](https://mastra.ai/docs/studio/observability)
|
|
@@ -35,6 +35,8 @@ const toolSearch = new ToolSearchProcessor({
|
|
|
35
35
|
|
|
36
36
|
**options.ttl** (`number`): Time-to-live for thread state in milliseconds. After this duration of inactivity, thread state will be cleaned up. Set to 0 to disable cleanup.
|
|
37
37
|
|
|
38
|
+
**options.filter** (`(args: ToolSearchFilterArgs) => boolean | Promise<boolean>`): Optional request-aware hook for hiding tools from search results, blocking tool loading, or hiding already-loaded tools for the current request.
|
|
39
|
+
|
|
38
40
|
## Returns
|
|
39
41
|
|
|
40
42
|
**id** (`string`): Processor identifier set to 'tool-search'
|
|
@@ -43,6 +45,35 @@ const toolSearch = new ToolSearchProcessor({
|
|
|
43
45
|
|
|
44
46
|
**processInputStep** (`(args: ProcessInputStepArgs) => Promise<ProcessInputStepResult>`): Processes each step to inject search/load meta-tools and any previously loaded tools into the agent's tool set.
|
|
45
47
|
|
|
48
|
+
## Request-aware filtering
|
|
49
|
+
|
|
50
|
+
Use `filter` to apply request-specific policy to dynamic tools. The hook receives the resolved tool ID as `toolName`, the tool, request context, and phase. `toolName` is the ID returned by `search_tools`, which may differ from the key used in the `tools` object.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { ToolSearchProcessor } from '@mastra/core/processors'
|
|
54
|
+
|
|
55
|
+
const toolSearch = new ToolSearchProcessor({
|
|
56
|
+
tools: allTools,
|
|
57
|
+
filter: ({ toolName, requestContext, phase }) => {
|
|
58
|
+
const plan = requestContext?.get('plan')
|
|
59
|
+
|
|
60
|
+
if (phase === 'search') {
|
|
61
|
+
return true
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return plan === 'pro' || !toolName.startsWith('premium_')
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The `phase` value describes where the filter is being applied:
|
|
70
|
+
|
|
71
|
+
- `search`: Filters results returned by `search_tools`.
|
|
72
|
+
- `load`: Blocks `load_tool` from loading disallowed tools.
|
|
73
|
+
- `active`: Hides already-loaded tools from the current request if they are no longer allowed.
|
|
74
|
+
|
|
75
|
+
If the hook throws or rejects, `ToolSearchProcessor` treats the tool as disallowed for that request. The hook may run for every matching search candidate, so keep async policy checks cheap or cached. The meta-tools `search_tools` and `load_tool` are always available. Tools passed directly through the agent or `processInputStep` remain available unless you filter them outside `ToolSearchProcessor`.
|
|
76
|
+
|
|
46
77
|
## Extended usage example
|
|
47
78
|
|
|
48
79
|
```typescript
|
|
@@ -4,15 +4,19 @@ Server adapters register these routes when you call `server.init()`. All routes
|
|
|
4
4
|
|
|
5
5
|
## Agents
|
|
6
6
|
|
|
7
|
-
| Method | Path | Description
|
|
8
|
-
| ------ | -------------------------------------------- |
|
|
9
|
-
| `GET` | `/api/agents` | List all agents
|
|
10
|
-
| `GET` | `/api/agents/:agentId` | Get agent by ID (supports version query params)
|
|
11
|
-
| `POST` | `/api/agents/:agentId/generate` | Generate agent response
|
|
12
|
-
| `POST` | `/api/agents/:agentId/stream` | Stream agent response
|
|
13
|
-
| `POST` | `/api/agents/:agentId/
|
|
14
|
-
| `
|
|
15
|
-
| `POST` | `/api/agents/:agentId/
|
|
7
|
+
| Method | Path | Description |
|
|
8
|
+
| ------ | -------------------------------------------- | ----------------------------------------------------- |
|
|
9
|
+
| `GET` | `/api/agents` | List all agents |
|
|
10
|
+
| `GET` | `/api/agents/:agentId` | Get agent by ID (supports version query params) |
|
|
11
|
+
| `POST` | `/api/agents/:agentId/generate` | Generate agent response |
|
|
12
|
+
| `POST` | `/api/agents/:agentId/stream` | Stream agent response |
|
|
13
|
+
| `POST` | `/api/agents/:agentId/send-message` | Send a user message to an active or idle thread |
|
|
14
|
+
| `POST` | `/api/agents/:agentId/queue-message` | Queue a user message for the next thread turn |
|
|
15
|
+
| `POST` | `/api/agents/:agentId/signals` | Send a lower-level signal to an active or idle thread |
|
|
16
|
+
| `POST` | `/api/agents/:agentId/subscribe-thread` | Subscribe to a thread stream |
|
|
17
|
+
| `POST` | `/api/agents/:agentId/resume-stream` | Resume a suspended agent stream with custom data |
|
|
18
|
+
| `GET` | `/api/agents/:agentId/tools` | List agent tools |
|
|
19
|
+
| `POST` | `/api/agents/:agentId/tools/:toolId/execute` | Execute agent tool |
|
|
16
20
|
|
|
17
21
|
### Get agent query parameters
|
|
18
22
|
|
|
@@ -68,6 +72,74 @@ GET /api/agents/my-agent?versionId=abc123
|
|
|
68
72
|
}
|
|
69
73
|
```
|
|
70
74
|
|
|
75
|
+
### Agent message routes
|
|
76
|
+
|
|
77
|
+
Use `POST /api/agents/:agentId/send-message` to send a user message to the active agent loop or wake an idle thread. Use `POST /api/agents/:agentId/queue-message` when the active run should finish before Mastra starts a follow-up run.
|
|
78
|
+
|
|
79
|
+
Both routes accept the same request body:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
{
|
|
83
|
+
message: string | Array<TextPart | FilePart> | {
|
|
84
|
+
contents: string | Array<TextPart | FilePart>;
|
|
85
|
+
attributes?: Record<string, JSONValue>;
|
|
86
|
+
metadata?: Record<string, unknown>;
|
|
87
|
+
providerOptions?: ProviderMetadata;
|
|
88
|
+
};
|
|
89
|
+
runId?: string;
|
|
90
|
+
resourceId?: string;
|
|
91
|
+
threadId?: string;
|
|
92
|
+
ifActive?: {
|
|
93
|
+
behavior?: 'deliver' | 'persist' | 'discard';
|
|
94
|
+
attributes?: Record<string, string | number | boolean>;
|
|
95
|
+
};
|
|
96
|
+
ifIdle?: {
|
|
97
|
+
behavior?: 'wake' | 'persist' | 'discard';
|
|
98
|
+
streamOptions?: Omit<AgentExecutionOptions, 'messages'>;
|
|
99
|
+
attributes?: Record<string, string | number | boolean>;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
When `runId` is omitted, `resourceId` and `threadId` are required. `ifIdle` only applies to thread-targeted requests, not run-targeted requests.
|
|
105
|
+
|
|
106
|
+
#### Send a message
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
curl -X POST http://localhost:4111/api/agents/supportAgent/send-message \
|
|
110
|
+
-H 'Content-Type: application/json' \
|
|
111
|
+
-d '{
|
|
112
|
+
"message": {
|
|
113
|
+
"contents": "Show the shorter version.",
|
|
114
|
+
"attributes": { "sentFrom": "web" }
|
|
115
|
+
},
|
|
116
|
+
"resourceId": "user_123",
|
|
117
|
+
"threadId": "thread_456"
|
|
118
|
+
}'
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### Queue a message
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
curl -X POST http://localhost:4111/api/agents/supportAgent/queue-message \
|
|
125
|
+
-H 'Content-Type: application/json' \
|
|
126
|
+
-d '{
|
|
127
|
+
"message": "Also check whether the tests need updates.",
|
|
128
|
+
"resourceId": "user_123",
|
|
129
|
+
"threadId": "thread_456"
|
|
130
|
+
}'
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Both routes return:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
{
|
|
137
|
+
accepted: true;
|
|
138
|
+
runId: string;
|
|
139
|
+
signal?: CreatedAgentSignal;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
71
143
|
## Workflows
|
|
72
144
|
|
|
73
145
|
| Method | Path | Description |
|
|
@@ -175,7 +175,7 @@ Include a `.env.example` file with all required environment variables:
|
|
|
175
175
|
# LLM provider API keys (choose one or more)
|
|
176
176
|
OPENAI_API_KEY=your_openai_api_key_here
|
|
177
177
|
ANTHROPIC_API_KEY=your_anthropic_api_key_here
|
|
178
|
-
|
|
178
|
+
GOOGLE_API_KEY=your_google_api_key_here
|
|
179
179
|
|
|
180
180
|
# Other service API keys as needed
|
|
181
181
|
OTHER_SERVICE_API_KEY=your_api_key_here
|
|
@@ -233,7 +233,7 @@ Detailed explanation of the template's functionality and use case.
|
|
|
233
233
|
|
|
234
234
|
- `OPENAI_API_KEY`: Your OpenAI API key. Get one at [OpenAI Platform](https://platform.openai.com/api-keys)
|
|
235
235
|
- `ANTHROPIC_API_KEY`: Your Anthropic API key. Get one at [Anthropic Console](https://console.anthropic.com/settings/keys)
|
|
236
|
-
- `
|
|
236
|
+
- `GOOGLE_API_KEY`: Your Google AI API key. Get one at [Google AI Studio](https://makersuite.google.com/app/apikey)
|
|
237
237
|
- `OTHER_API_KEY`: Description of what this key is for
|
|
238
238
|
|
|
239
239
|
## Usage
|
|
@@ -53,6 +53,10 @@ Each server in the `servers` map is configured using the `MastraMCPServerDefinit
|
|
|
53
53
|
|
|
54
54
|
**enableServerLogs** (`boolean`): Whether to enable logging for this server. (Default: `true`)
|
|
55
55
|
|
|
56
|
+
**forwardInstructions** (`boolean`): Whether to append instructions advertised by this MCP server to an agent's system prompt when the agent uses this server's tools. Disabled by default; enable it only for servers you trust, since the instructions are injected into the agent's system prompt. (Default: `false`)
|
|
57
|
+
|
|
58
|
+
**instructionsMaxLength** (`number`): Maximum number of server instruction characters to append to an agent's system prompt. (Default: `512`)
|
|
59
|
+
|
|
56
60
|
**requireToolApproval** (`boolean | (params: RequireToolApprovalContext) => boolean | Promise<boolean>`): Require human approval before executing tools from this server. When set to \`true\`, all tools require approval. When set to a function, the function is called with the tool name, arguments, request context, and any tool annotations advertised by the server to dynamically decide whether approval is needed.
|
|
57
61
|
|
|
58
62
|
## Tool approval
|
|
@@ -123,6 +127,36 @@ Per the MCP specification, **clients MUST consider tool annotations to be untrus
|
|
|
123
127
|
|
|
124
128
|
The same annotations are also exposed on the tools returned by `listTools()` and `listToolsets()` under `tool.mcp.annotations`, so you can inspect them when wiring tools into an agent.
|
|
125
129
|
|
|
130
|
+
## Server instructions
|
|
131
|
+
|
|
132
|
+
When an MCP server advertises instructions during initialization, `MCPClient` stores them for that server. Forwarding those instructions into an agent's system prompt is **opt-in**: set `forwardInstructions: true` on a server to have agents that use its tools (via `listTools()` or `listToolsets()`) receive its instructions automatically.
|
|
133
|
+
|
|
134
|
+
The guidance is grouped by server name and truncated to `instructionsMaxLength` characters per server.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
const mcp = new MCPClient({
|
|
138
|
+
servers: {
|
|
139
|
+
db: {
|
|
140
|
+
url: new URL('http://localhost:3000/mcp'),
|
|
141
|
+
forwardInstructions: true,
|
|
142
|
+
instructionsMaxLength: 512,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
const agent = new Agent({
|
|
148
|
+
id: 'db-agent',
|
|
149
|
+
name: 'DB Agent',
|
|
150
|
+
instructions: 'Help with database changes.',
|
|
151
|
+
model,
|
|
152
|
+
tools: await mcp.listTools(),
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
When `forwardInstructions` is omitted (the default), instructions are still cached and can be inspected via [`getServerInstructions()`](#getserverinstructions), but are not added to any agent's system prompt.
|
|
157
|
+
|
|
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
|
+
|
|
126
160
|
## Methods
|
|
127
161
|
|
|
128
162
|
### `listTools()`
|
|
@@ -143,6 +177,23 @@ const res = await agent.stream(prompt, {
|
|
|
143
177
|
})
|
|
144
178
|
```
|
|
145
179
|
|
|
180
|
+
### `getServerInstructions()`
|
|
181
|
+
|
|
182
|
+
Returns the instructions currently known for each configured MCP server. Servers that have not connected yet, or do not advertise instructions, return `undefined`.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
getServerInstructions(): Record<string, string | undefined>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Example:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
await mcp.listTools()
|
|
192
|
+
|
|
193
|
+
const instructionsByServer = mcp.getServerInstructions()
|
|
194
|
+
console.log(instructionsByServer.db)
|
|
195
|
+
```
|
|
196
|
+
|
|
146
197
|
### `disconnect()`
|
|
147
198
|
|
|
148
199
|
Disconnects from all MCP servers and cleans up resources.
|
|
@@ -26,6 +26,8 @@ The PgVector class provides vector search using [PostgreSQL](https://www.postgre
|
|
|
26
26
|
|
|
27
27
|
**pgPoolOptions** (`PoolConfig`): Additional pg pool configuration options
|
|
28
28
|
|
|
29
|
+
**disableInit** (`boolean`): When true, automatic DDL (schema, extension, table, and index creation) inside \`createIndex\` is skipped. Useful for CI/CD pipelines where schema and indexes are managed separately and the runtime database role lacks DDL privileges. Can also be enabled with the \`MASTRA\_DISABLE\_STORAGE\_INIT\` environment variable. (Default: `false`)
|
|
30
|
+
|
|
29
31
|
## Constructor examples
|
|
30
32
|
|
|
31
33
|
### Connection String
|