@mastra/mcp-docs-server 1.1.42 → 1.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/.docs/docs/agents/acp.md +21 -158
  2. package/.docs/docs/agents/processors.md +143 -0
  3. package/.docs/docs/agents/signals.md +229 -9
  4. package/.docs/docs/build-with-ai/skills.md +3 -3
  5. package/.docs/docs/editor/overview.md +11 -10
  6. package/.docs/docs/getting-started/build-with-ai.md +37 -0
  7. package/.docs/docs/mastra-platform/observability.md +4 -4
  8. package/.docs/docs/memory/multi-user-threads.md +1 -1
  9. package/.docs/docs/memory/working-memory.md +27 -0
  10. package/.docs/docs/observability/metrics/querying.md +1 -1
  11. package/.docs/docs/server/pubsub.md +124 -0
  12. package/.docs/docs/studio/auth.md +20 -0
  13. package/.docs/reference/acp/acp-agent.md +228 -0
  14. package/.docs/reference/acp/create-acp-tool.md +131 -0
  15. package/.docs/reference/agents/agent.md +51 -1
  16. package/.docs/reference/agents/durable-agent.md +239 -0
  17. package/.docs/reference/cli/mastra.md +5 -5
  18. package/.docs/reference/client-js/agents.md +41 -7
  19. package/.docs/reference/index.md +9 -0
  20. package/.docs/reference/processors/response-cache.md +2 -2
  21. package/.docs/reference/pubsub/base.md +168 -0
  22. package/.docs/reference/pubsub/caching-pubsub.md +102 -0
  23. package/.docs/reference/pubsub/event-emitter.md +72 -0
  24. package/.docs/reference/pubsub/google-cloud-pubsub.md +94 -0
  25. package/.docs/reference/pubsub/redis-streams.md +108 -0
  26. package/.docs/reference/pubsub/unix-socket-pubsub.md +52 -0
  27. package/.docs/reference/storage/libsql.md +6 -0
  28. package/.docs/reference/storage/mongodb.md +3 -0
  29. package/.docs/reference/storage/postgresql.md +3 -0
  30. package/CHANGELOG.md +16 -0
  31. package/package.json +6 -6
  32. package/.docs/docs/agents/response-caching.md +0 -150
@@ -1,8 +1,8 @@
1
- # ACP (Agent Client Protocol)
1
+ # Agent Client Protocol
2
2
 
3
3
  Mastra supports the [Agent Client Protocol (ACP)](https://agentclientprotocol.com/overview/introduction) for running ACP-compatible coding agents from a Mastra agent. Use `@mastra/acp` to wrap a coding agent process as a Mastra tool or as a subagent.
4
4
 
5
- ACP is useful for coding agents such as Claude Code, Amp, Codex, or any other executable that implements the Agent Client Protocol over standard input and output.
5
+ ACP is useful for coding agents such as Claude Code, Amp, Codex, or any other executable that implements ACP over standard input and output.
6
6
 
7
7
  ## When to use ACP
8
8
 
@@ -23,14 +23,14 @@ The flow is:
23
23
  3. The client sends ACP `initialize` and `session/new` requests.
24
24
  4. Mastra sends the user task to the ACP agent with `session/prompt`.
25
25
  5. The ACP agent streams session updates and message chunks back to Mastra.
26
- 6. Mastra returns the buffered output, emits streaming chunks, or suspends for permission input.
27
- 7. The ACP process stays alive by default, or stops after the prompt when `persistSession` is `false`.
26
+ 6. Mastra returns the buffered output, emits streaming chunks, or handles permission input.
27
+ 7. The ACP connection stops the process after the prompt when `persistSession` is `false`; `AcpAgent` can keep a reusable process alive across calls by default.
28
28
 
29
29
  During execution, the ACP client also handles permission requests and file operations. File reads and writes go through Mastra's `Workspace`, so the ACP agent operates inside the workspace you provide.
30
30
 
31
31
  ## Getting started
32
32
 
33
- Install `@mastra/acp` in a project that already uses `@mastra/core`:
33
+ Install `@mastra/acp` in a project that already uses `@mastra/core`. The package requires `@mastra/core` version `1.34.0` or later.
34
34
 
35
35
  **npm**:
36
36
 
@@ -58,14 +58,12 @@ bun add @mastra/acp
58
58
 
59
59
  `@mastra/acp` exports two APIs:
60
60
 
61
- - `createACPTool`: Create a Mastra tool that sends a `task` string to an ACP agent and returns an `output` string.
62
- - `AcpAgent`: Wrap an ACP agent as a Mastra subagent with `generate()` and `stream()` support.
63
-
64
- The package requires `@mastra/core` version `1.34.0` or later.
61
+ - [`createACPTool()`](https://mastra.ai/reference/acp/create-acp-tool): Create a Mastra tool that sends a `task` string to an ACP agent and returns an `output` string.
62
+ - [`AcpAgent`](https://mastra.ai/reference/acp/acp-agent): Wrap an ACP agent as a Mastra subagent with `generate()` and `stream()` support.
65
63
 
66
64
  ## Use ACP as a subagent
67
65
 
68
- Use `AcpAgent` when a parent Mastra agent should delegate directly to an ACP-compatible coding agent as a subagent. Create the ACP agent, then register it in the parent agent's `agents` map.
66
+ Use `AcpAgent` when a parent Mastra agent should delegate directly to an ACP-compatible coding agent as a subagent.
69
67
 
70
68
  ```typescript
71
69
  import { AcpAgent } from '@mastra/acp'
@@ -91,11 +89,11 @@ export const codeSupervisor = new Agent({
91
89
  })
92
90
  ```
93
91
 
94
- `AcpAgent.generate()` buffers the ACP response and returns it as text. `AcpAgent.stream()` emits Mastra `text-delta` chunks as ACP `agent_message_chunk` updates arrive.
92
+ See the [AcpAgent reference](https://mastra.ai/reference/acp/acp-agent) for all options, methods, and configuration.
95
93
 
96
94
  ## Use ACP as a tool
97
95
 
98
- Use `createACPTool` when the parent Mastra agent should decide when to call the ACP agent as a tool. The following example creates a code editing tool and registers it on a parent agent:
96
+ Use `createACPTool()` when the parent Mastra agent should decide when to call the ACP agent as a tool.
99
97
 
100
98
  ```typescript
101
99
  import { createACPTool } from '@mastra/acp'
@@ -120,171 +118,36 @@ export const codeSupervisor = new Agent({
120
118
  })
121
119
  ```
122
120
 
123
- Use the `command` and `args` required by the ACP-compatible agent you run. The tool input schema has a single `task` string, and the output schema returns the final ACP response as `output`.
124
-
125
- If the ACP agent requests permission, the tool can suspend and resume through Mastra's tool suspension flow. Use `onPermissionRequest` when you need custom permission behavior.
126
-
127
- ## Options reference
128
-
129
- `createACPTool` and `AcpAgent` accept the same ACP connection options. `AcpAgent` also accepts `name` to set the display name used during agent delegation.
130
-
131
- | Option | Type | Description |
132
- | --------------------- | -------------------------------- | --------------------------------------------------------------------------------------- |
133
- | `id` | `string` | Unique tool or subagent identifier. |
134
- | `description` | `string` | Description shown to the model when it can call the tool or delegate to the subagent. |
135
- | `command` | `string` | ACP agent executable to spawn. |
136
- | `args` | `string[]` | Arguments passed to the ACP agent executable. |
137
- | `env` | `Record<string, string>` | Environment variables to merge with the current process environment. |
138
- | `cwd` | `string` | Working directory for the ACP process, ACP session, and default workspace. |
139
- | `session` | `Partial<NewSessionRequest>` | ACP session creation options. Defaults to `cwd` or `process.cwd()` and no MCP servers. |
140
- | `initialize` | `Partial<InitializeRequest>` | ACP initialization options. Defaults to Mastra client information and protocol version. |
141
- | `authMethodId` | `string` | ACP authentication method ID to invoke after initialization. |
142
- | `persistSession` | `boolean` | Keep the ACP process alive after execution. Defaults to `true`. |
143
- | `onPermissionRequest` | `(request) => Promise<Response>` | Callback for ACP permission requests. Defaults to selecting the first option. |
144
- | `workspace` | `Workspace` | Workspace used for ACP file reads and writes. |
145
- | `model` | `string` | Model ID to select after session creation via the ACP `session/set_model` method. |
121
+ See the [createACPTool() reference](https://mastra.ai/reference/acp/create-acp-tool) for all options and configuration.
146
122
 
147
123
  ## Model selection
148
124
 
149
- ACP agents may expose selectable models. Instead of setting an environment variable like `ANTHROPIC_MODEL`, you can pass a `model` ID directly in the configuration.
150
-
151
- ### Discover available models
152
-
153
- Call `getAvailableModels()` to see which models the ACP agent supports. This starts the agent process and returns the model list from the session:
154
-
155
- ```typescript
156
- import { AcpAgent } from '@mastra/acp'
157
-
158
- const codeAgent = new AcpAgent({
159
- id: 'code-agent',
160
- description: 'An ACP-compatible coding agent',
161
- command: 'claude',
162
- args: ['--acp'],
163
- })
164
-
165
- const models = await codeAgent.getAvailableModels()
166
- // [{ modelId: 'claude-sonnet-4-20250514', name: 'Claude Sonnet' }, ...]
167
- ```
168
-
169
- ### Set the model
125
+ ACP agents may expose selectable models. Pass `model` in the ACP configuration to select a model after session creation, or use `AcpAgent.getAvailableModels()` and `AcpAgent.setModel()` to manage models at runtime.
170
126
 
171
- Pass the `model` option to select a model at connection time:
172
-
173
- ```typescript
174
- import { AcpAgent } from '@mastra/acp'
175
-
176
- export const codeAgent = new AcpAgent({
177
- id: 'code-agent',
178
- description: 'An ACP-compatible coding agent',
179
- command: 'claude',
180
- args: ['--acp'],
181
- model: 'claude-sonnet-4-6',
182
- })
183
- ```
184
-
185
- You can also change the model at runtime with `setModel()`:
186
-
187
- ```typescript
188
- await codeAgent.setModel('claude-sonnet-4-6')
189
- ```
190
-
191
- If the ACP agent advertises available models and your model ID doesn't match any of them, Mastra throws an error listing the valid options:
192
-
193
- ```text
194
- Model "bad-model-id" is not available. Available models: claude-sonnet-4-20250514, claude-haiku-4-20250514
195
- ```
196
-
197
- If the agent doesn't advertise a model list, the value is passed through without validation.
127
+ See the [AcpAgent model management methods](https://mastra.ai/reference/acp/acp-agent) for examples.
198
128
 
199
129
  ## Session lifecycle
200
130
 
201
- `createACPTool` and `AcpAgent` start the configured command on first use and create an ACP session. By default, `persistSession` is `true`, so the child process stays alive across calls.
202
-
203
- Use the default persistent session when:
204
-
205
- - The ACP agent benefits from keeping conversation or repository context.
206
- - Startup is expensive and repeated calls should reuse the same process.
207
- - A parent agent may delegate several related tasks to the same coding agent.
131
+ `AcpAgent` starts the configured command on first use and creates an ACP session. By default, `persistSession` is `true`, so the child process stays alive across calls. Set `persistSession: false` when each prompt should run in an isolated process.
208
132
 
209
- Set `persistSession: false` when each prompt should run in an isolated process:
210
-
211
- ```typescript
212
- import { AcpAgent } from '@mastra/acp'
213
-
214
- export const codeAgent = new AcpAgent({
215
- id: 'code-agent',
216
- description: 'Run one isolated ACP coding task',
217
- command: 'acp-agent',
218
- args: ['--stdio'],
219
- cwd: process.cwd(),
220
- persistSession: false,
221
- })
222
- ```
223
-
224
- With `persistSession: false`, `@mastra/acp` stops the ACP process after each prompt completes.
133
+ See the [AcpAgent session lifecycle](https://mastra.ai/reference/acp/acp-agent) section for details.
225
134
 
226
135
  ## Permission handling
227
136
 
228
- ACP agents may ask the client to choose a permission option before they continue. By default, `@mastra/acp` selects the first option returned by the ACP agent.
229
-
230
- Pass `onPermissionRequest` to inspect the request and return the selected option yourself:
231
-
232
- ```typescript
233
- import { createACPTool } from '@mastra/acp'
234
-
235
- export const codeAgentTool = createACPTool({
236
- id: 'code-agent',
237
- description: 'Use an ACP-compatible coding agent',
238
- command: 'acp-agent',
239
- args: ['--stdio'],
240
- async onPermissionRequest(request) {
241
- const allowOption = request.options.find(option => option.name === 'Allow')
242
-
243
- if (!allowOption) {
244
- return { outcome: { outcome: 'cancelled' } }
245
- }
246
-
247
- return {
248
- outcome: {
249
- outcome: 'selected',
250
- optionId: allowOption.optionId,
251
- },
252
- }
253
- },
254
- })
255
- ```
137
+ ACP agents may ask the client to choose a permission option before they continue. By default, `@mastra/acp` selects the first option returned by the ACP agent. Pass `onPermissionRequest` when you need custom permission behavior.
256
138
 
257
- Use this callback to enforce local policy, inspect the permission title, or route the decision to your own approval flow.
139
+ See the [createACPTool() permission handling](https://mastra.ai/reference/acp/create-acp-tool) section for a complete example.
258
140
 
259
141
  ## Workspace integration
260
142
 
261
- ACP file operations go through Mastra's workspace abstraction. If you don't pass `workspace`, `@mastra/acp` creates a `Workspace` backed by `LocalFilesystem` and uses `cwd` as the filesystem root.
262
-
263
- Pass a custom `Workspace` when the ACP agent should read and write through a specific filesystem implementation:
264
-
265
- ```typescript
266
- import { AcpAgent } from '@mastra/acp'
267
- import { LocalFilesystem, Workspace } from '@mastra/core/workspace'
268
-
269
- const workspace = new Workspace({
270
- filesystem: new LocalFilesystem({
271
- root: process.cwd(),
272
- }),
273
- })
274
-
275
- export const codeAgent = new AcpAgent({
276
- id: 'code-agent',
277
- description: 'Run coding tasks in a controlled workspace',
278
- command: 'acp-agent',
279
- args: ['--stdio'],
280
- workspace,
281
- })
282
- ```
143
+ ACP file operations go through Mastra's workspace abstraction. `AcpAgent` can use a `workspace` option, and `createACPTool()` uses the current Mastra workspace from the tool execution context when one is available. Without a workspace, `@mastra/acp` falls back to a `Workspace` backed by `LocalFilesystem` at `cwd` or `process.cwd()`.
283
144
 
284
- Use `cwd` and `workspace` together when the ACP process should start in one directory but file operations should use an explicitly configured workspace root.
145
+ See the [AcpAgent workspace integration](https://mastra.ai/reference/acp/acp-agent) section for custom workspace examples.
285
146
 
286
147
  ## Related
287
148
 
149
+ - [AcpAgent reference](https://mastra.ai/reference/acp/acp-agent)
150
+ - [createACPTool() reference](https://mastra.ai/reference/acp/create-acp-tool)
288
151
  - [Agent reference](https://mastra.ai/reference/agents/agent)
289
152
  - [Subagents](https://mastra.ai/docs/agents/supervisor-agents)
290
153
  - [Agent Client Protocol introduction](https://agentclientprotocol.com/overview/introduction)
@@ -425,6 +425,149 @@ Add `ProviderHistoryCompat` explicitly when you need provider history compatibil
425
425
 
426
426
  See the [`ProviderHistoryCompat` reference](https://mastra.ai/reference/processors/provider-history-compat) for setup, built-in rules, and custom rule options.
427
427
 
428
+ ## Response caching
429
+
430
+ > **Alpha:** This feature is in alpha. Breaking changes may occur without a major version bump until the API is stable.
431
+
432
+ Response caching skips the LLM call and replays a previously cached response when an agent receives an identical request. Use it to reduce latency and avoid paying for repeated calls.
433
+
434
+ Caching is implemented as the [`ResponseCache`](https://mastra.ai/reference/processors/response-cache) input processor. Mastra doesn't provide an agent-level option. To enable caching, register the processor explicitly. This keeps the API surface small while Mastra collects feedback; per-call overrides flow through `RequestContext`.
435
+
436
+ ### When to use response caching
437
+
438
+ Reach for it when the same request shape repeats across users or sessions, for example prompt templates, suggested-prompt buttons, agentic search re-asks, or guardrail LLMs that classify the same input over and over. Skip it when calls trigger external side effects through tools, since cache hits replay tool calls without re-executing them.
439
+
440
+ ### Quickstart
441
+
442
+ Add a `ResponseCache` to the agent's `inputProcessors` and pass any `MastraServerCache` as the backend. For development, `InMemoryServerCache` works out of the box:
443
+
444
+ ```typescript
445
+ import { Agent } from '@mastra/core/agent'
446
+ import { InMemoryServerCache } from '@mastra/core/cache'
447
+ import { ResponseCache } from '@mastra/core/processors'
448
+
449
+ const cache = new InMemoryServerCache()
450
+
451
+ export const searchAgent = new Agent({
452
+ name: 'Search Agent',
453
+ instructions: 'You answer questions concisely.',
454
+ model: 'openai/gpt-5',
455
+ inputProcessors: [new ResponseCache({ cache, ttl: 600 })], // 10 minutes
456
+ })
457
+ ```
458
+
459
+ The first call runs the LLM normally and writes the response to the cache. Subsequent calls with an identical resolved prompt return the cached response without invoking the LLM.
460
+
461
+ ### Per-call overrides via RequestContext
462
+
463
+ Per-call config flows through `RequestContext`. Use `ResponseCache.context()` to build a fresh context, or `ResponseCache.applyContext()` to merge into one you already have:
464
+
465
+ ```typescript
466
+ import { ResponseCache } from '@mastra/core/processors'
467
+ import { RequestContext } from '@mastra/core/request-context'
468
+
469
+ // Fresh context with the override
470
+ await agent.stream('hello', {
471
+ requestContext: ResponseCache.context({ key: 'custom-key', bust: true }),
472
+ })
473
+
474
+ // Or merge into an existing context
475
+ const ctx = new RequestContext()
476
+ ctx.set('caller-meta', { userId: 'u-123' })
477
+ ResponseCache.applyContext(ctx, { bust: true })
478
+ await agent.stream('hello', { requestContext: ctx })
479
+ ```
480
+
481
+ Three fields are overridable per call:
482
+
483
+ - `key`: String or function. Overrides the auto-derived cache key for this request only.
484
+ - `scope`: String or `null`. Overrides the tenant/user scope for this request only. `null` opts out of scoping.
485
+ - `bust`: Boolean. Skips the cache read but still writes on completion (useful for "force refresh" buttons).
486
+
487
+ `cache`, `ttl`, and `agentId` stay on the constructor. They're instance-level concerns and not safe to vary per call.
488
+
489
+ ### Tenant scoping
490
+
491
+ By default, `ResponseCache` looks up `MASTRA_RESOURCE_ID_KEY` on the request context and uses it as the cache scope. This means an agent that already populates the resource id (e.g. via memory) gets per-user isolation automatically. Two users never see each other's cached responses.
492
+
493
+ Override explicitly when you need a different scope:
494
+
495
+ ```typescript
496
+ new Agent({
497
+ // ...
498
+ inputProcessors: [
499
+ new ResponseCache({
500
+ cache,
501
+ scope: 'org-123', // explicit tenant scope
502
+ }),
503
+ ],
504
+ })
505
+ ```
506
+
507
+ Pass `scope: null` to deliberately share entries across all callers. Only use this for known-public, non-personalized content.
508
+
509
+ ### Custom cache backend
510
+
511
+ `ResponseCache` accepts any `MastraServerCache`. For production, use `RedisCache` from `@mastra/redis`:
512
+
513
+ ```typescript
514
+ import { Agent } from '@mastra/core/agent'
515
+ import { ResponseCache } from '@mastra/core/processors'
516
+ import { RedisCache } from '@mastra/redis'
517
+
518
+ const cache = new RedisCache({ url: process.env.REDIS_URL })
519
+
520
+ export const agent = new Agent({
521
+ name: 'Cached Agent',
522
+ instructions: '...',
523
+ model: 'openai/gpt-5',
524
+ inputProcessors: [new ResponseCache({ cache })],
525
+ })
526
+ ```
527
+
528
+ For a custom backend, extend `MastraServerCache` and implement its abstract methods (the processor only calls `get` and `set`).
529
+
530
+ ### How caching is implemented
531
+
532
+ `ResponseCache` hooks into `processLLMRequest` (cache lookup, short-circuits on hit) and `processLLMResponse` (cache write on completion). Both run inside the agentic loop _after_ memory has loaded and earlier input processors have transformed the prompt.
533
+
534
+ This means the cache key is derived from the resolved `LanguageModelV2Prompt` Mastra is about to send to the model. The key is created _after_ memory has loaded and earlier input processors have run, and each step in an agentic tool loop is independently cached.
535
+
536
+ ### What's in the cache key
537
+
538
+ When you don't supply `key`, the processor derives one deterministically from the inputs that change the LLM's response at this step: `agentId`, `stepNumber` (so each step in a tool loop has its own cache entry), `scope`, model identity (`provider`, `modelId`, spec version), and the resolved `prompt` (post-memory + post-processors). Any change to these inputs automatically invalidates the cache.
539
+
540
+ #### Customize the cache key
541
+
542
+ Pass `key` as a function on the constructor or per-call to derive your own cache key from any subset of those inputs. The function receives the same inputs the deterministic hash would have consumed and returns a string (or a `Promise<string>`):
543
+
544
+ ```typescript
545
+ import { ResponseCache, buildResponseCacheKey } from '@mastra/core/processors'
546
+
547
+ await agent.stream(input, {
548
+ requestContext: ResponseCache.context({
549
+ // Cache only on the model id and the resolved prompt tail — ignore
550
+ // step number, scope, etc.
551
+ key: ({ model, prompt }) => `qa:${model.modelId}:${JSON.stringify(prompt).slice(-200)}`,
552
+ }),
553
+ })
554
+
555
+ // Or reuse the deterministic helper while overriding individual fields:
556
+ await agent.stream(input, {
557
+ requestContext: ResponseCache.context({
558
+ key: inputs => buildResponseCacheKey({ ...inputs, scope: 'global' }),
559
+ }),
560
+ })
561
+ ```
562
+
563
+ If the function throws, the processor falls back to the default key derivation so the call still benefits from caching.
564
+
565
+ ### How cache hits work
566
+
567
+ When the processor finds a cache hit, it short-circuits the LLM call by returning the cached chunks from `processLLMRequest`. The agentic loop synthesizes a stream from those chunks instead of calling the model. `agent.generate()` collects them into a `FullOutput`; `agent.stream()` returns a `MastraModelOutput` whose chunks come from the cached buffer, so consumers iterating `fullStream` or awaiting `text`, `usage`, and `finishReason` see the cached values.
568
+
569
+ Cache writes happen after the response completes. Failed runs (errors, tripwire activations) aren't cached, so the next call retries cleanly.
570
+
428
571
  ## Advanced patterns
429
572
 
430
573
  ### Ensure a final response with `maxSteps`