@mastra/mcp-docs-server 1.3.11-alpha.2 → 1.3.11-alpha.3
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/human-in-the-loop.md +25 -0
- package/.docs/docs/auth/fga.md +1 -1
- package/.docs/docs/harness/background-tasks.md +85 -1
- package/.docs/docs/license.md +20 -0
- package/.docs/docs/mastra-platform/observability.md +32 -5
- package/.docs/docs/memory/semantic-recall.md +20 -20
- package/.docs/docs/studio/auth.md +2 -4
- package/.docs/docs/studio/observability.md +1 -1
- package/.docs/integrations/agentic-ui/ai-sdk-ui.md +2 -0
- package/.docs/integrations/auth/google.md +2 -0
- package/.docs/integrations/auth/okta.md +2 -0
- package/.docs/integrations/auth/workos.md +2 -0
- package/.docs/integrations/databases/convex.md +1 -1
- package/.docs/integrations/databases/duckdb.md +2 -2
- package/.docs/integrations/databases/libsql.md +1 -1
- package/.docs/integrations/databases/mongodb.md +1 -1
- package/.docs/integrations/databases/neon.md +1 -1
- package/.docs/integrations/databases/oracledb.md +1 -1
- package/.docs/integrations/deploy/kubernetes-helm.md +1 -1
- package/.docs/integrations/observability/braintrust.md +6 -0
- package/.docs/integrations/sandboxes/daytona.md +1 -1
- package/.docs/{reference → integrations}/vectors/astra.md +4 -0
- package/.docs/{reference → integrations}/vectors/chroma.md +13 -9
- package/.docs/{reference → integrations}/vectors/convex.md +12 -0
- package/.docs/{reference → integrations}/vectors/elasticsearch.md +5 -1
- package/.docs/{reference → integrations}/vectors/lance.md +1 -1
- package/.docs/{reference → integrations}/vectors/libsql.md +16 -0
- package/.docs/{reference → integrations}/vectors/mongodb.md +2 -0
- package/.docs/{reference → integrations}/vectors/pg.md +12 -0
- package/.docs/{reference → integrations}/vectors/qdrant.md +2 -0
- package/.docs/{reference → integrations}/vectors/s3vectors.md +10 -0
- package/.docs/{reference → integrations}/vectors/turbopuffer.md +2 -0
- package/.docs/{reference → integrations}/vectors/upstash.md +12 -0
- package/.docs/integrations.md +24 -1
- package/.docs/models/embeddings.md +1 -1
- package/.docs/models/environment-variables.md +1 -0
- package/.docs/models/gateways/merge-gateway.md +2 -1
- package/.docs/models/gateways/vercel.md +1 -1
- package/.docs/models/index.md +2 -1
- package/.docs/models/providers/aiand.md +15 -13
- package/.docs/models/providers/anthropic.md +1 -1
- package/.docs/models/providers/edenai.md +10 -9
- package/.docs/models/providers/empiriolabs.md +5 -5
- package/.docs/models/providers/hopper.md +82 -0
- package/.docs/models/providers/inceptron.md +5 -5
- package/.docs/models/providers/kilo.md +12 -11
- package/.docs/models/providers/llmgateway-providers.md +4 -4
- package/.docs/models/providers/llmgateway.md +9 -6
- package/.docs/models/providers/mistral.md +3 -2
- package/.docs/models/providers/nano-gpt.md +8 -8
- package/.docs/models/providers/nearai.md +63 -60
- package/.docs/models/providers/openai.md +1 -1
- package/.docs/models/providers.md +1 -0
- package/.docs/reference/agent-controller/agent-controller-class.md +10 -0
- package/.docs/reference/agents/channels.md +4 -0
- package/.docs/reference/auth/fga.md +2 -0
- package/.docs/reference/auth/google.md +1 -1
- package/.docs/reference/auth/neon.md +2 -0
- package/.docs/reference/auth/okta.md +1 -1
- package/.docs/reference/cli/create-mastra.md +35 -3
- package/.docs/reference/cli/mastra.md +3 -3
- package/.docs/reference/client-js/observability.md +6 -23
- package/.docs/reference/configuration.md +5 -3
- package/.docs/reference/connect/providers.md +99 -1
- package/.docs/reference/core/mastra-class.md +2 -0
- package/.docs/reference/index.md +1 -21
- package/.docs/reference/observability/tracing/advanced-queries.md +226 -86
- package/.docs/reference/observability/tracing/exporters/braintrust.md +11 -1
- package/.docs/reference/observability/tracing/spans.md +3 -3
- package/.docs/reference/processors/processor-interface.md +1 -1
- package/.docs/reference/pubsub/redis-streams.md +45 -2
- package/.docs/reference/pubsub/valkey-streams.md +5 -1
- package/.docs/reference/rag/metadata-filters.md +11 -11
- package/.docs/reference/rag/vector-databases.md +3 -3
- package/.docs/reference/server/routes.md +18 -14
- package/.docs/reference/tools/mcp-client.md +48 -0
- package/.docs/reference/tools/mcp-server.md +216 -1
- package/.docs/reference/tools/submit-plan-tool.md +1 -1
- package/.docs/reference/workspace/filesystem.md +10 -0
- package/.docs/reference/workspace/local-sandbox.md +6 -0
- package/package.json +5 -5
- /package/.docs/{reference → integrations}/vectors/azure-ai-search.md +0 -0
- /package/.docs/{reference → integrations}/vectors/couchbase.md +0 -0
- /package/.docs/{reference → integrations}/vectors/duckdb.md +0 -0
- /package/.docs/{reference → integrations}/vectors/opensearch.md +0 -0
- /package/.docs/{reference → integrations}/vectors/oracledb.md +0 -0
- /package/.docs/{reference → integrations}/vectors/pinecone.md +0 -0
- /package/.docs/{reference → integrations}/vectors/vectorize.md +0 -0
- /package/.docs/{reference → integrations}/vectors/weaviate.md +0 -0
|
@@ -101,7 +101,7 @@ const pubsub = new RedisStreamsPubSub({
|
|
|
101
101
|
|
|
102
102
|
**maxStreamLength** (`number`): Approximate maximum number of entries kept per stream. Set to 0 to disable trimming. (Default: `10000`)
|
|
103
103
|
|
|
104
|
-
**streamIdleTtlMs** (`number`): Idle expiry in milliseconds: a sliding TTL refreshed on every write to a stream (publish, subscribe creating its consumer group, nack retry). Each write resets it, so an actively-written stream never expires mid-flight; a stream left idle for the full duration is deleted by Redis automatically, together with its entries and consumer groups. Only writes refresh the TTL — a consumer slowly draining a backlog does not — so keep it well above the longest expected gap between writes on a live topic, and above the longest a grouped worker may be offline while still expecting to replay its backlog on restart. For topics with a clear end of life (workflow and agent runs), clearTopic deletes the stream eagerly and the TTL only covers streams that never reach that call, such as a crashed run. For open-ended topics that are never cleared (for example, per-conversation streams), the TTL is the only mechanism that reclaims their memory
|
|
104
|
+
**streamIdleTtlMs** (`number`): Idle expiry in milliseconds: a sliding TTL refreshed on every write to a stream (publish, subscribe creating its consumer group, nack retry). Each write resets it, so an actively-written stream never expires mid-flight; a stream left idle for the full duration is deleted by Redis automatically, together with its entries and consumer groups. Only writes refresh the TTL — a consumer slowly draining a backlog does not — so keep it well above the longest expected gap between writes on a live topic, and above the longest a grouped worker may be offline while still expecting to replay its backlog on restart. For topics with a clear end of life (workflow and agent runs), clearTopic deletes the stream eagerly and the TTL only covers streams that never reach that call, such as a crashed run. For open-ended topics that are never cleared (for example, per-conversation streams), the TTL is the only mechanism that reclaims their memory. Set to 0 to disable expiry; streams that never reach clearTopic then stay in Redis forever. Must be a non-negative integer. (Default: `604800000 (7 days)`)
|
|
105
105
|
|
|
106
106
|
**reclaimIntervalMs** (`number`): How often, in milliseconds, a subscription reclaims events that an earlier consumer read but never acknowledged. Set to 0 to disable. (Default: `30000`)
|
|
107
107
|
|
|
@@ -153,7 +153,7 @@ Deletes a topic's stream and every consumer group on it, freeing the memory a fi
|
|
|
153
153
|
|
|
154
154
|
Automatic cleanup requires `@mastra/core` and `@mastra/redis-streams` versions that both support `clearTopic`: the runtime routes the call through its caching layer, so upgrade the two packages together to get end-of-run stream deletion.
|
|
155
155
|
|
|
156
|
-
Not every topic reaches a `clearTopic` call. Topics without a defined end of life (per-conversation streams, application feeds) are never cleared, and a stream that misses its cleanup (for example, a crashed run) is never retried.
|
|
156
|
+
Not every topic reaches a `clearTopic` call. Topics without a defined end of life (per-conversation streams, application feeds) are never cleared, and a stream that misses its cleanup (for example, a crashed run) is never retried. The `streamIdleTtlMs` sliding TTL (7 days by default) reclaims those streams once they go idle. Deleting a thread with `Memory.deleteThread()` also clears that thread's stream.
|
|
157
157
|
|
|
158
158
|
```typescript
|
|
159
159
|
await pubsub.clearTopic('workflow.events.run-123')
|
|
@@ -175,6 +175,49 @@ Closes the Redis connections and stops all subscriptions. Call this during grace
|
|
|
175
175
|
await pubsub.close()
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
+
## Redis configuration
|
|
179
|
+
|
|
180
|
+
Set `maxmemory-policy` to `noeviction` on the Redis instance. Consumer groups, unacknowledged entries, and [lease keys](#distributed-leasing) are live state, not cache. Under any evicting policy, Redis deletes them when it reaches `maxmemory`: lease keys and streams with a TTL are eviction candidates under `volatile-*` policies, and every key is a candidate under `allkeys-*` policies. Lost leases let two processes run the same thread, and evicted streams silently drop events.
|
|
181
|
+
|
|
182
|
+
With `noeviction`, Redis rejects writes instead of deleting data when memory runs out, so size `maxmemory` for your traffic and rely on `streamIdleTtlMs` to reclaim idle streams. Managed services often default to an evicting policy (Amazon ElastiCache defaults to `volatile-lru`), so check the setting explicitly.
|
|
183
|
+
|
|
184
|
+
When `maxmemory` is set and the policy isn't `noeviction`, `RedisStreamsPubSub` logs a warning once after it first connects. It reads the policy with `INFO memory`, because many managed services block `CONFIG GET`.
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
redis-server --maxmemory-policy noeviction
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Reclaim streams created without a TTL
|
|
191
|
+
|
|
192
|
+
Streams written while `streamIdleTtlMs` was `0`, including by versions before the 7-day default, have no TTL. They stay in Redis until a new write gives them one. To reclaim them:
|
|
193
|
+
|
|
194
|
+
1. Switch the instance to `noeviction` first. Under a `volatile-*` policy, adding a TTL makes a live stream an eviction candidate.
|
|
195
|
+
2. Deploy every process that writes to this Redis with a version that defaults the TTL, or with an explicit `streamIdleTtlMs` greater than `0`. A write with expiry turned off doesn't refresh an existing TTL, so a stream that an old writer still uses would expire mid-use.
|
|
196
|
+
3. Give every stream without a TTL the expiry it would have had: 7 days after its last write. Streams idle for longer than that expire immediately, which frees memory right away. `PEXPIRE` runs even on an instance that's rejecting writes because it's out of memory.
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Replace mastra:topic with your keyPrefix, and add your connection flags
|
|
200
|
+
# (-h, -p, -a, --tls) to every redis-cli call. On a cluster, run it against each primary.
|
|
201
|
+
TTL_MS=604800000
|
|
202
|
+
NOW_MS=$(redis-cli time | awk 'NR == 1 { s = $1 } NR == 2 { printf "%.0f", s * 1000 + $1 / 1000 }')
|
|
203
|
+
redis-cli --scan --pattern 'mastra:topic:*' | while read -r key; do
|
|
204
|
+
[ "$(redis-cli type "$key")" = "stream" ] || continue
|
|
205
|
+
[ "$(redis-cli pttl "$key")" = "-1" ] || continue
|
|
206
|
+
last_ms=$(redis-cli --raw xinfo stream "$key" | awk 'prev == "last-generated-id" { split($0, id, "-"); print id[1]; exit } { prev = $0 }')
|
|
207
|
+
[ -n "$last_ms" ] || continue
|
|
208
|
+
if [ "$last_ms" = "0" ]; then
|
|
209
|
+
remaining=$TTL_MS # never written to, only subscribed
|
|
210
|
+
else
|
|
211
|
+
remaining=$(( TTL_MS - (NOW_MS - last_ms) ))
|
|
212
|
+
[ "$remaining" -lt 1 ] && remaining=1
|
|
213
|
+
[ "$remaining" -gt "$TTL_MS" ] && remaining=$TTL_MS
|
|
214
|
+
fi
|
|
215
|
+
redis-cli pexpire "$key" "$remaining" > /dev/null
|
|
216
|
+
done
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The loop only touches streams without a TTL, so it's safe to run repeatedly. After step 2, a stream that's still in use keeps its data, because every write refreshes the TTL.
|
|
220
|
+
|
|
178
221
|
## Redelivery and reclaim
|
|
179
222
|
|
|
180
223
|
When a subscriber calls `nack`, the event is republished with an incremented `deliveryAttempt` and the original is acknowledged. Once an event reaches `maxDeliveryAttempts`, it's dropped instead of redelivered. Separately, each subscription periodically reclaims events that an earlier consumer in the group read but never acknowledged, controlled by `reclaimIntervalMs` and `reclaimIdleMs`.
|
|
@@ -59,7 +59,7 @@ export const mastra = new Mastra({
|
|
|
59
59
|
|
|
60
60
|
**maxStreamLength** (`number`): Approximate maximum entries retained per stream. Set to 0 to disable trimming. (Default: `10000`)
|
|
61
61
|
|
|
62
|
-
**streamIdleTtlMs** (`number`): Sliding idle expiry refreshed on stream
|
|
62
|
+
**streamIdleTtlMs** (`number`): Sliding idle expiry in milliseconds, refreshed on every write to a stream. A stream left idle for the full duration is deleted with its entries and consumer groups. Keep it above the longest time a grouped worker may be offline while still expecting to replay its backlog. Set to 0 to disable expiry; streams that never reach clearTopic then stay in Valkey forever. (Default: `604800000 (7 days)`)
|
|
63
63
|
|
|
64
64
|
**reclaimIntervalMs** (`number`): Interval for reclaiming unacknowledged events. Set to 0 to disable. (Default: `30000`)
|
|
65
65
|
|
|
@@ -81,6 +81,10 @@ When a subscriber calls `nack`, the event is republished with an incremented `de
|
|
|
81
81
|
|
|
82
82
|
A subscription never reclaims an event its own handler is still processing, so a slow handler isn't invoked twice for the same event. If a handler hangs, a different consumer in the group reclaims the event once it has been idle for `reclaimIdleMs`. In a single-consumer group there's no sibling to do that, so set `inFlightTimeoutMs` to have the subscription nack the event itself after that long.
|
|
83
83
|
|
|
84
|
+
## Server configuration
|
|
85
|
+
|
|
86
|
+
Set `maxmemory-policy` to `noeviction`. Consumer groups, unacknowledged entries, and lease keys are live state, and any evicting policy deletes them when the server reaches `maxmemory`, dropping events and leases. When `maxmemory` is set and the policy isn't `noeviction`, `ValkeyStreamsPubSub` logs a warning once after it first connects. To reclaim streams created without a TTL, follow the [Redis Streams runbook](https://mastra.ai/reference/pubsub/redis-streams) with `valkey-cli`.
|
|
87
|
+
|
|
84
88
|
## Cleanup and shutdown
|
|
85
89
|
|
|
86
90
|
`clearTopic(topic)` deletes a topic stream and its consumer groups. `flush()` waits for in-flight publishes, and `close()` stops subscriptions and closes GLIDE connections.
|
|
@@ -225,14 +225,14 @@ await store.createIndex({
|
|
|
225
225
|
|
|
226
226
|
## Related
|
|
227
227
|
|
|
228
|
-
- [Astra](https://mastra.ai/
|
|
229
|
-
- [Chroma](https://mastra.ai/
|
|
230
|
-
- [Cloudflare Vectorize](https://mastra.ai/
|
|
231
|
-
- [libSQL](https://mastra.ai/
|
|
232
|
-
- [MongoDB](https://mastra.ai/
|
|
233
|
-
- [OracleDB](https://mastra.ai/
|
|
234
|
-
- [PgVector](https://mastra.ai/
|
|
235
|
-
- [Pinecone](https://mastra.ai/
|
|
236
|
-
- [Qdrant](https://mastra.ai/
|
|
237
|
-
- [Upstash](https://mastra.ai/
|
|
238
|
-
- [Amazon S3 Vectors](https://mastra.ai/
|
|
228
|
+
- [Astra](https://mastra.ai/integrations/vectors/astra)
|
|
229
|
+
- [Chroma](https://mastra.ai/integrations/vectors/chroma)
|
|
230
|
+
- [Cloudflare Vectorize](https://mastra.ai/integrations/vectors/vectorize)
|
|
231
|
+
- [libSQL](https://mastra.ai/integrations/vectors/libsql)
|
|
232
|
+
- [MongoDB](https://mastra.ai/integrations/vectors/mongodb)
|
|
233
|
+
- [OracleDB](https://mastra.ai/integrations/vectors/oracledb)
|
|
234
|
+
- [PgVector](https://mastra.ai/integrations/vectors/pg)
|
|
235
|
+
- [Pinecone](https://mastra.ai/integrations/vectors/pinecone)
|
|
236
|
+
- [Qdrant](https://mastra.ai/integrations/vectors/qdrant)
|
|
237
|
+
- [Upstash](https://mastra.ai/integrations/vectors/upstash)
|
|
238
|
+
- [Amazon S3 Vectors](https://mastra.ai/integrations/vectors/s3vectors)
|
|
@@ -35,7 +35,7 @@ MongoDB Vector Search is a good solution for teams who want to consolidate vecto
|
|
|
35
35
|
|
|
36
36
|
### Using VoyageAI with MongoDB
|
|
37
37
|
|
|
38
|
-
MongoDB works directly with VoyageAI's embedding models, which are optimized for retrieval tasks. For complete examples and specialized models, see the [VoyageAI embeddings documentation](https://mastra.ai/models/embeddings) and [MongoDB vector reference](https://mastra.ai/
|
|
38
|
+
MongoDB works directly with VoyageAI's embedding models, which are optimized for retrieval tasks. For complete examples and specialized models, see the [VoyageAI embeddings documentation](https://mastra.ai/models/embeddings) and [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb).
|
|
39
39
|
|
|
40
40
|
### Hybrid Search (Vector + Full-Text)
|
|
41
41
|
|
|
@@ -52,7 +52,7 @@ const results = await store.hybridQuery({
|
|
|
52
52
|
})
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
See the [MongoDB vector reference](https://mastra.ai/
|
|
55
|
+
See the [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb) for details on `createSearchIndex()`, `textQuery()`, and `hybridQuery()`.
|
|
56
56
|
|
|
57
57
|
### Automated Embedding
|
|
58
58
|
|
|
@@ -75,7 +75,7 @@ const results = await store.query({
|
|
|
75
75
|
})
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
Automated Embedding is a MongoDB Preview feature and needs a deployment where it's available. See the [MongoDB vector reference](https://mastra.ai/
|
|
78
|
+
Automated Embedding is a MongoDB Preview feature and needs a deployment where it's available. See the [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb) for the supported options and requirements.
|
|
79
79
|
|
|
80
80
|
**PgVector**:
|
|
81
81
|
|
|
@@ -704,20 +704,24 @@ How a supplied `id` is treated depends on the storage adapter. Some adapters ups
|
|
|
704
704
|
|
|
705
705
|
## MCP
|
|
706
706
|
|
|
707
|
-
| Method | Path | Description
|
|
708
|
-
| ------ | ------------------------------------------ |
|
|
709
|
-
| `GET` | `/api/mcp/v0/servers` | List MCP servers
|
|
710
|
-
| `GET` | `/api/mcp/v0/servers/:id` | Get server details
|
|
711
|
-
| `GET` | `/api/mcp/:serverId/tools` | List server tools
|
|
712
|
-
| `GET` | `/api/mcp/:serverId/tools/:toolId` | Get tool details
|
|
713
|
-
| `POST` | `/api/mcp/:serverId/tools/:toolId/execute` | Execute a tool
|
|
714
|
-
| `GET` | `/api/mcp/:serverId/resources` | List server resources
|
|
715
|
-
| `POST` | `/api/mcp/:serverId/resources/read` | Read a resource
|
|
716
|
-
| `
|
|
717
|
-
| `
|
|
718
|
-
| `POST` | `/api/mcp/:serverId/
|
|
719
|
-
|
|
720
|
-
|
|
707
|
+
| Method | Path | Description |
|
|
708
|
+
| ------ | ------------------------------------------ | -------------------------------------------------- |
|
|
709
|
+
| `GET` | `/api/mcp/v0/servers` | List MCP servers |
|
|
710
|
+
| `GET` | `/api/mcp/v0/servers/:id` | Get server details |
|
|
711
|
+
| `GET` | `/api/mcp/:serverId/tools` | List server tools |
|
|
712
|
+
| `GET` | `/api/mcp/:serverId/tools/:toolId` | Get tool details |
|
|
713
|
+
| `POST` | `/api/mcp/:serverId/tools/:toolId/execute` | Execute a tool |
|
|
714
|
+
| `GET` | `/api/mcp/:serverId/resources` | List server resources |
|
|
715
|
+
| `POST` | `/api/mcp/:serverId/resources/read` | Read a resource |
|
|
716
|
+
| `GET` | `/api/mcp/:serverId/tasks` | List a server's recent MCP tasks (experimental) |
|
|
717
|
+
| `POST` | `/api/mcp/:serverId/tasks/find` | Find an MCP task by its task id (experimental) |
|
|
718
|
+
| `POST` | `/api/mcp/:serverId/tasks/:taskKey/cancel` | Cancel an MCP task (experimental) |
|
|
719
|
+
| `POST` | `/api/mcp/:serverId/tasks/:taskKey/input` | Answer an MCP task's input requests (experimental) |
|
|
720
|
+
| `ALL` | `/api/mcp/:serverId/mcp` | MCP HTTP transport |
|
|
721
|
+
| `ALL` | `/api/mcp/:serverId/sse` | Legacy MCP SSE transport |
|
|
722
|
+
| `POST` | `/api/mcp/:serverId/messages` | Legacy MCP SSE messages |
|
|
723
|
+
|
|
724
|
+
All MCP routes declare `requiresAuth: true`. Authentication is enforced only when `server.auth` is configured. With an RBAC provider, listing and finding tasks need `mcp:read`. Cancelling and answering a task need `mcp:write`, since they act on a task another client started. Paths use the default `/api` prefix. The legacy SSE routes return `404` for MCP v2 servers.
|
|
721
725
|
|
|
722
726
|
## Responses API
|
|
723
727
|
|
|
@@ -236,6 +236,8 @@ The client speaks the MCP `2026-07-28` revision. On connect it asks the server w
|
|
|
236
236
|
|
|
237
237
|
**inputRequests** (`MCPInputRequestHandler`): Answers input requests from this server. When a tool, resource or prompt call ends as input_required, the handler is called with each embedded request and the client retries the call with the answers. Without a handler an input_required result surfaces as an error. See Answering input requests below.
|
|
238
238
|
|
|
239
|
+
**tasks** (`boolean | MCPClientTasksOptions`): Experimental. Lets this server answer tool calls with an MCP task, which the client waits for. pollIntervalMs (default 5000) is used when the server suggests no interval. The client waits at least 100 ms and at most 1 hour between polls, whatever the server suggests. Both values must be at most 2147483647 (about 24.8 days), the longest delay a timer allows. maxWaitMs stops waiting and cancels the task after that long; by default only the server TTL applies. See the tasks property below.
|
|
240
|
+
|
|
239
241
|
**authProvider** (`OAuthClientProvider`): For HTTP servers: OAuth authentication provider for automatic token refresh and OAuth flow management. Use MCPOAuthClientProvider for a ready-to-use implementation.
|
|
240
242
|
|
|
241
243
|
**enableServerLogs** (`boolean`): Whether to request per-request server logs. Attaches the io.modelcontextprotocol/logLevel metadata key to every request so the server delivers notifications/message for it, and forwards delivered messages to logger. (Default: `true`)
|
|
@@ -1163,6 +1165,52 @@ for await (const event of subscription) {
|
|
|
1163
1165
|
}
|
|
1164
1166
|
```
|
|
1165
1167
|
|
|
1168
|
+
### `tasks` Property (experimental)
|
|
1169
|
+
|
|
1170
|
+
Some tools take longer than one HTTP request can stay open. A server that implements the [MCP Tasks extension (SEP-2663)](https://modelcontextprotocol.github.io/ext-tasks/specification/2026-07-28/tasks.html) can answer such a call with a task, and the client fetches the result later. Set `tasks` on a server to accept them:
|
|
1171
|
+
|
|
1172
|
+
```typescript
|
|
1173
|
+
const mcpClient = new MCPClient({
|
|
1174
|
+
servers: {
|
|
1175
|
+
reports: {
|
|
1176
|
+
url: new URL('https://reports.example.com/mcp'),
|
|
1177
|
+
tasks: { maxWaitMs: 30 * 60_000 },
|
|
1178
|
+
inputRequests: async ({ params }) => askUser(params),
|
|
1179
|
+
},
|
|
1180
|
+
},
|
|
1181
|
+
})
|
|
1182
|
+
```
|
|
1183
|
+
|
|
1184
|
+
> **Warning:** This API may change in any release.
|
|
1185
|
+
|
|
1186
|
+
With `tasks` set, the client tells the server it accepts tasks. The server decides per call whether to answer directly or with a task. Without `tasks`, the client never receives one and tool calls behave as before.
|
|
1187
|
+
|
|
1188
|
+
When a tool call returns a task, the tool keeps its usual shape:
|
|
1189
|
+
|
|
1190
|
+
- The client polls the task at the interval the server suggests until it finishes, then returns the tool result.
|
|
1191
|
+
- A task that needs input is answered through `inputRequests`, once per request key. The client sends the answers with `tasks/update` and keeps polling the same task. It never sends `tools/call` again. Without a handler the call fails with `MCP_CLIENT_TOOL_TASK_INPUT_UNHANDLED`, and the task stays open on the server until its TTL ends.
|
|
1192
|
+
- Aborting the tool call sends `tasks/cancel`. Reaching `maxWaitMs` sends it too, and fails the call with `MCP_CLIENT_TOOL_TASK_TIMEOUT`. Both end the call right away, even while a poll or your input handler is still running. A late answer from either is dropped.
|
|
1193
|
+
- A disconnect while the client polls ends the call with `MCP_CLIENT_TOOL_TASK_POLL_FAILED` and doesn't reconnect.
|
|
1194
|
+
- If the server can't be reached while the client polls, for example during a restart or deploy, the client reconnects and keeps polling with growing delays of up to 30 seconds. Refused connections and HTTP 502, 503, and 504 from a proxy count as unreachable. After 5 minutes without an answer, or when `maxWaitMs` or the task's TTL ends first, the call fails with `MCP_CLIENT_TOOL_TASK_POLL_FAILED`. The task may still finish on the server. The TTL counts from the task's `createdAt`. If the client can't read that timestamp, it counts from when it started waiting.
|
|
1195
|
+
- The tool call span gets `mcpTaskKey` metadata: a SHA-256 hash of the task id. A Mastra server tags its spans for the task with the same key, so you can match both sides and the task id stays out of both traces.
|
|
1196
|
+
- A tool error inside a finished task is handled like a direct tool error, following `onToolError`. A task the server cancelled fails with `MCP_CLIENT_TOOL_TASK_CANCELLED`, and a task the server marked `failed` fails with `MCP_CLIENT_TOOL_TASK_FAILED`.
|
|
1197
|
+
- A call that returned a task is never retried, because a retry would start a second task.
|
|
1198
|
+
- When the call continues as a task, and whenever the task's status changes, the tool writes an `MCPTaskProgress` entry (`{ type: 'mcp-task', taskId, status, createdAt, serverName }`) to its output stream. Studio's tool-call card uses it to show the task's status, elapsed time and MCP task id while it runs. Tool output isn't saved with the thread. After a reload, the card shows only the result.
|
|
1199
|
+
|
|
1200
|
+
On an agent with [background tasks](https://mastra.ai/docs/harness/background-tasks) enabled, tools from a server with `tasks` set run as deferred background tasks with no retries. The agent keeps working while the remote task runs, and cancelling the background task cancels the remote task. Override this per tool with the agent's `backgroundTasks.tools`.
|
|
1201
|
+
|
|
1202
|
+
#### `tasks.get(serverName: string, taskId: string)`
|
|
1203
|
+
|
|
1204
|
+
Returns the task's current state (`MCPDetailedTask`), including `result` once it's `completed` and `inputRequests` while it's `input_required`. Fails with `MCP_CLIENT_GET_TASK_FAILED`; an unknown task, or one created by another caller, has `error.cause.code` `-32602`.
|
|
1205
|
+
|
|
1206
|
+
#### `tasks.update(serverName: string, taskId: string, inputResponses: MCPTaskInputResponses)`
|
|
1207
|
+
|
|
1208
|
+
Answers the `inputRequests` of an `input_required` task, keyed like the requests. The server ignores keys it didn't ask for or that are already answered. Fails with `MCP_CLIENT_UPDATE_TASK_FAILED`.
|
|
1209
|
+
|
|
1210
|
+
#### `tasks.cancel(serverName: string, taskId: string)`
|
|
1211
|
+
|
|
1212
|
+
Asks the server to stop the task. The server may still finish it. Fails with `MCP_CLIENT_CANCEL_TASK_FAILED`.
|
|
1213
|
+
|
|
1166
1214
|
## Answering input requests
|
|
1167
1215
|
|
|
1168
1216
|
A server tool, resource or prompt that needs something from the user ends its call with an `input_required` result instead of a value. The result carries one or more embedded requests, each with a server-chosen `key` and either a form (`requestedSchema`) or a URL the user must visit. Configure `inputRequests` on the server definition to answer them: the client calls the handler once per embedded request, retries the original call with the answers, and resolves the tool call with the final result. Without a handler an `input_required` result surfaces as an error.
|
|
@@ -725,7 +725,7 @@ If the available prompts change, your server can notify listening clients.
|
|
|
725
725
|
Call this method when the list of available prompts has changed (e.g., a prompt was added or removed). This will send a `notifications/prompts/list_changed` message to listening clients, prompting them to re-fetch the list of prompts.
|
|
726
726
|
|
|
727
727
|
```typescript
|
|
728
|
-
await serverWithPrompts.prompts.notifyListChanged()
|
|
728
|
+
await serverWithPrompts.prompts.notifyListChanged();
|
|
729
729
|
```
|
|
730
730
|
|
|
731
731
|
### Best practices for Prompt Handling
|
|
@@ -1586,6 +1586,221 @@ Records an occurrence, delivers it to matching push streams and webhook subscrip
|
|
|
1586
1586
|
- Webhook delivery state (pending retries, suspension, verification results) is in memory and rebuilt when clients refresh.
|
|
1587
1587
|
- Event-list change announcements require the `eventsListChanged` filter on `subscriptions/listen`, which the MCP TypeScript SDK version used by `@mastra/mcp` doesn't carry. Until that support is available, the server neither advertises `listChanged` nor sends `notifications/events/list_changed`. Clients should re-run `events/list` to see changed event types.
|
|
1588
1588
|
|
|
1589
|
+
## Tasks (experimental)
|
|
1590
|
+
|
|
1591
|
+
> **Warning:** Tasks implement SEP-2663, the `io.modelcontextprotocol/tasks` MCP extension. This API may change in any release.
|
|
1592
|
+
|
|
1593
|
+
The `tasks` option lets a tool, a workflow (`run_*`) or an agent (`ask_*`) answer `tools/call` with a task instead of a result. The client gets a task handle at once and polls `tasks/get` until the task finishes. The result outlives the request and isn't limited by HTTP timeouts. When at least one of them can answer with a task, the server advertises the extension and answers `tasks/get`, `tasks/update` and `tasks/cancel` over both stdio and Streamable HTTP. Without a `tasks` option, it does neither.
|
|
1594
|
+
|
|
1595
|
+
Only clients that declare the extension on a request get a task. Every other client gets a synchronous answer, unless the tool is listed in `required`.
|
|
1596
|
+
|
|
1597
|
+
```typescript
|
|
1598
|
+
import { MCPServer } from '@mastra/mcp'
|
|
1599
|
+
|
|
1600
|
+
const server = new MCPServer({
|
|
1601
|
+
id: 'reports',
|
|
1602
|
+
name: 'Reports',
|
|
1603
|
+
version: '1.0.0',
|
|
1604
|
+
tools: { buildReport, lookupCustomer },
|
|
1605
|
+
tasks: {
|
|
1606
|
+
tools: {
|
|
1607
|
+
buildReport: 'always',
|
|
1608
|
+
lookupCustomer: { mode: 'auto', syncWindowMs: 1000 },
|
|
1609
|
+
},
|
|
1610
|
+
},
|
|
1611
|
+
})
|
|
1612
|
+
```
|
|
1613
|
+
|
|
1614
|
+
### Modes
|
|
1615
|
+
|
|
1616
|
+
| Mode | Client declared the extension | Client didn't |
|
|
1617
|
+
| ---------- | ------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
|
|
1618
|
+
| `'off'` | Synchronous answer. | Synchronous answer. |
|
|
1619
|
+
| `'always'` | Task handle at once. | Synchronous answer, or error `-32021` when the tool is in `required`. |
|
|
1620
|
+
| `'auto'` | Synchronous answer if the tool finishes within `syncWindowMs`. Otherwise a task handle, and the same run continues. | Synchronous answer, or error `-32021` when the tool is in `required`. |
|
|
1621
|
+
|
|
1622
|
+
The server creates the task before it answers, so a `tasks/get` sent right after the handle arrives succeeds.
|
|
1623
|
+
|
|
1624
|
+
### `tasks` options
|
|
1625
|
+
|
|
1626
|
+
**default** (`'off' | 'auto' | 'always'`): Mode for every tool, workflow and agent not listed in tools, workflows or agents, including tools added later with toolActions.add(). It covers run\_\* and ask\_\* tools too, so default: 'always' serves every workflow and agent as a task; list one as 'off' to keep it synchronous. (Default: `'off'`)
|
|
1627
|
+
|
|
1628
|
+
**tools** (`Record<string, 'off' | 'auto' | 'always' | { mode; syncWindowMs?; ttlMs?; recover? }>`): Mode per tool name. syncWindowMs (default 2000) is how long 'auto' waits for a synchronous answer. ttlMs and recover override tasks.ttlMs and tasks.recover for that tool. A name that isn't one of the server's tools throws when the server is created.
|
|
1629
|
+
|
|
1630
|
+
**required** (`string[]`): Tools that only run as tasks, by the name clients call: a tool's key, run\_\<workflow> or ask\_\<agent>. A client that didn't declare the extension gets error -32021 instead of a synchronous answer. Each name must be served as a task.
|
|
1631
|
+
|
|
1632
|
+
**ttlMs** (`number | null`): How long a task is kept after it is created, in milliseconds. A task still running when it expires is aborted and ends failed. With the in-memory store, null keeps tasks until the server closes, and finished results stay in memory until their TTL ends; maxRetainedTasksPerClient and maxRetainedTasks bound how many it holds. A task with a null TTL counts against them until the server closes. In Mastra storage, the server deletes the row of a finished task once its TTL ends, null keeps the row until you delete it, and a task still running after about 24.8 days (the longest timer Node.js supports) ends failed. (Default: `86400000`)
|
|
1633
|
+
|
|
1634
|
+
**recover** (`boolean`): Whether a tool or agent task whose server stopped mid-run runs again from the start on another instance. Only applies to tasks kept in Mastra storage. Workflow tasks ignore it, see Workflow tasks. See Recovery after a crash. (Default: `false`)
|
|
1635
|
+
|
|
1636
|
+
**store** (`MCPTaskStore`): Where tasks are kept. By default, a server registered on a Mastra instance with background tasks keeps them in Mastra storage (see Tasks across instances); any other server keeps them in memory, in this process.
|
|
1637
|
+
|
|
1638
|
+
**maxOpenTasksPerClient** (`number`): Most open tasks (working or input_required) one caller can hold. See open task caps. (Default: `100`)
|
|
1639
|
+
|
|
1640
|
+
**maxOpenTasks** (`number`): Most open tasks across all callers. See open task caps. (Default: `1000`)
|
|
1641
|
+
|
|
1642
|
+
**maxRetainedTasksPerClient** (`number`): Most tasks one caller can have in the store, open or finished, until each is forgotten. Only the in-memory store enforces it. See retained task caps. (Default: `1000`)
|
|
1643
|
+
|
|
1644
|
+
**maxRetainedTasks** (`number`): Most tasks in the store across all callers, open or finished. See retained task caps. (Default: `10000`)
|
|
1645
|
+
|
|
1646
|
+
**authorize** (`(context: { principal: string; task: MCPDetailedTask; requestContext: RequestContext }) => boolean | Promise<boolean>`): Runs on every tasks/get, tasks/update and tasks/cancel, after the caller is matched to the task. Return false to refuse; the caller gets the same error as for an unknown task.
|
|
1647
|
+
|
|
1648
|
+
**workflows** (`Record<string, 'off' | 'auto' | 'always' | { mode; syncWindowMs?; ttlMs? }>`): Mode per workflow key, for its run\_\<key> tool. A key that isn't one of the server's workflows throws when the server is created. See Workflow tasks.
|
|
1649
|
+
|
|
1650
|
+
**agents** (`Record<string, 'off' | 'auto' | 'always' | { mode; syncWindowMs?; ttlMs?; recover? }>`): Mode per agent key, for its ask\_\<key> tool. A key that isn't one of the server's agents throws when the server is created. See Agent tasks.
|
|
1651
|
+
|
|
1652
|
+
### Access to tasks
|
|
1653
|
+
|
|
1654
|
+
A task id is an unguessable bearer token, and each task is bound to the caller that created it. The caller is identified the same way as for [continuation state](#continuation-state): by the OAuth subject, the mapped `user`, or a hash of the bearer token. Another caller asking for the task, and a caller `authorize` refuses, both get error `-32602`, the same answer as for an id that doesn't exist. Clients can't list tasks over MCP.
|
|
1655
|
+
|
|
1656
|
+
### Tasks in Studio
|
|
1657
|
+
|
|
1658
|
+
The Studio page of a server with `tasks` shows which tools run as tasks (`always` or `auto`, plus `required` and `recover`), and lists the server's tasks across all callers, newest first: their status, the client that sent them, open input requests, and when they expire. You can filter the list by status, tool or client, load older tasks, or paste the MCP task id a client shows to open that task. Opening a task shows its result or error. From there you can cancel it, or answer an elicitation it's waiting on. Cancelling and answering run the same code as `tasks/cancel` and `tasks/update`, but skip `authorize`.
|
|
1659
|
+
|
|
1660
|
+
- Studio identifies a task by a hash of its id, and the caller by a hash of its identity. Neither can be used over MCP, and the raw values are never sent to Studio. A task id you paste is sent in the request body and hashed on the server.
|
|
1661
|
+
- The client is shown as its client id with the token's subject or user id. A caller identified only by its token is shown with a short prefix of the token's hash instead. The label is never a credential.
|
|
1662
|
+
- With an RBAC provider, the list and task lookup need `mcp:read`. Cancelling and answering need `mcp:write`, which the default `admin` role has and `member` and `viewer` don't. Without it, Studio shows the task without those actions.
|
|
1663
|
+
- Only Studio sessions without a resource scope get the list. MCP callers and Mastra resources are separate identities, so a session scoped to a resource gets no tasks and can't cancel or answer one.
|
|
1664
|
+
- The built-in task stores support the list. A custom `store` must also implement `MCPTaskStoreAdmin` (`list`, `updateByKey`, `cancelByKey`); otherwise Studio says the store can't be listed.
|
|
1665
|
+
|
|
1666
|
+
### Open task caps
|
|
1667
|
+
|
|
1668
|
+
A task counts as open while it's `working` or `input_required`. It stops counting when it completes, fails, is cancelled or expires. When a call would go over `maxOpenTasksPerClient` or `maxOpenTasks`, the server creates no task:
|
|
1669
|
+
|
|
1670
|
+
- An `'always'` tool doesn't run. The call answers with `isError: true` and a message such as `Too many open tasks for this client (limit 100). Wait for one to finish or cancel one.`
|
|
1671
|
+
- An `'auto'` tool that's still running when its sync window ends keeps running under the request and answers synchronously, the same way it would without tasks. Cancelling the request still aborts it.
|
|
1672
|
+
- `run_<workflow>` and `ask_<agent>` tasks count against the same caps, and against the [retained task caps](#retained-task-caps). An `'always'` workflow starts no run, and an `'always'` agent doesn't run. An `'auto'` workflow run that suspends can only be answered through a task, so at the cap the server cancels it and answers with `isError: true`.
|
|
1673
|
+
|
|
1674
|
+
Both values must be positive integers. The server passes them to `store.create()` as `limits`, and the store enforces them by throwing `MCPTaskLimitError`. A custom store that ignores `limits` doesn't cap open tasks.
|
|
1675
|
+
|
|
1676
|
+
### Retained task caps
|
|
1677
|
+
|
|
1678
|
+
The in-memory store keeps a finished task's result in memory so the client can still read it, until the task's `ttlMs` ends plus one more minute. Finishing a task frees its open slot but not its memory, so a client that runs many short tasks in a row could otherwise grow memory without bound. `maxRetainedTasksPerClient` and `maxRetainedTasks` cap every task the store still holds, open or finished.
|
|
1679
|
+
|
|
1680
|
+
- A call that would go over a retained cap gets the same answer as at an open cap. An `'always'` tool answers with `isError: true` and a message such as `Too many recent tasks for this client (limit 1000). Try again once older tasks expire.` An `'auto'` tool answers synchronously.
|
|
1681
|
+
- Tasks already created keep their full `ttlMs`. The store never drops a result early to make room. A slot frees when the store forgets a task.
|
|
1682
|
+
- Every open task is also retained. When you set only one of a pair, the other follows it: lowering `maxRetainedTasksPerClient` below 100 lowers the default `maxOpenTasksPerClient` to match, and raising `maxOpenTasks` above 10000 raises the default `maxRetainedTasks`. Setting both with the retained cap below the open cap throws when the server is created.
|
|
1683
|
+
|
|
1684
|
+
Only the in-memory store enforces retained caps. Tasks kept in Mastra storage (see [Tasks across instances](#tasks-across-instances)) keep finished results in the database, so retained caps don't apply to them. Open task caps still do. A custom store that keeps finished results elsewhere can ignore them too.
|
|
1685
|
+
|
|
1686
|
+
### Asking for input inside a task
|
|
1687
|
+
|
|
1688
|
+
A tool that calls `suspend()` inside a task moves it to `input_required`. Its input request is the same form a synchronous call would get, built from the tool's `resumeSchema`. When the client answers with `tasks/update`, the server runs `execute` again with `resumeData`, as for a synchronous call. Keep the work before `suspend()` safe to repeat.
|
|
1689
|
+
|
|
1690
|
+
A declined or cancelled input request completes the task with `isError: true`. Answers to keys the task didn't ask for are ignored.
|
|
1691
|
+
|
|
1692
|
+
### What a task run receives
|
|
1693
|
+
|
|
1694
|
+
Task runs are rebuilt from what the task stored when it was created. This keeps a task store free to run them again after a restart. Every run of a task gets the stored request context and no `context.mcp`. The one exception is the first run of an `'auto'` tool, which started under the request before the sync window elapsed.
|
|
1695
|
+
|
|
1696
|
+
- The bearer token is removed from `authInfo` before the request context is stored. Everything else is stored unchanged, including `authInfo.extra` and the `user` returned by `mapAuthInfoToUser`. Don't put credentials there that the task store shouldn't keep.
|
|
1697
|
+
- Values are stored as JSON. A run reads back plain objects, so a `user` class instance arrives as a plain object with the same fields.
|
|
1698
|
+
- A key that can't be stored as JSON is left out, and the server logs a warning when it creates the task. If that key is `user`, authorization checks on later runs fail.
|
|
1699
|
+
- Read cancellation from `context.abortSignal`, because `context.mcp` isn't available.
|
|
1700
|
+
- Each run is authorized again against the stored request context, as each round of a synchronous call is.
|
|
1701
|
+
|
|
1702
|
+
### Cancellation and errors
|
|
1703
|
+
|
|
1704
|
+
- `tasks/cancel` aborts the tool's `abortSignal` and the task ends `cancelled`. Stopping is up to the tool. A result it returns afterwards is discarded.
|
|
1705
|
+
- A tool that throws completes the task with `isError: true` and the serialized error, as a synchronous call answers.
|
|
1706
|
+
- A task ends `failed` only when the server can't run it, for example when its TTL expires.
|
|
1707
|
+
|
|
1708
|
+
### Workflow tasks
|
|
1709
|
+
|
|
1710
|
+
A `run_<key>` task follows one workflow run. The run starts once, under the `tools/call` that creates the task, with a run id of its own. The task id is never the run id.
|
|
1711
|
+
|
|
1712
|
+
```typescript
|
|
1713
|
+
const server = new MCPServer({
|
|
1714
|
+
id: 'reports',
|
|
1715
|
+
name: 'Reports',
|
|
1716
|
+
version: '1.0.0',
|
|
1717
|
+
workflows: { nightly },
|
|
1718
|
+
tasks: {
|
|
1719
|
+
workflows: { nightly: { mode: 'auto', syncWindowMs: 1000 } },
|
|
1720
|
+
},
|
|
1721
|
+
})
|
|
1722
|
+
```
|
|
1723
|
+
|
|
1724
|
+
- A run that ends `success` or `bailed` completes the task with the same text a synchronous call answers: `status`, `input`, `steps` and `result`.
|
|
1725
|
+
- A run that ends `failed`, `tripwire` or `canceled` completes the task with `isError: true` and the error message. In `'auto'` mode, a run that fails within `syncWindowMs` answers the same way, without a task. Only a client without the Tasks extension, or a workflow whose mode is `'off'`, gets the plain `run_` answer, where a failed run comes back without `isError`.
|
|
1726
|
+
- In `'auto'` mode, a run that suspends within `syncWindowMs` continues as a task, so it can ask for input.
|
|
1727
|
+
- Invalid arguments answer with `isError: true` before any run or task exists.
|
|
1728
|
+
- A step that suspends moves the task to `input_required`, with a form built from the step's `resumeSchema` and its suspend payload as the message. The server asks for one suspended step at a time. `tasks/update` resumes the run with the answer as `resumeData`. Resuming needs Mastra storage.
|
|
1729
|
+
- A run is resumed at most once per suspension. If it was already resumed, for example from Studio or by another instance, the answer is dropped and the task follows the run: when the run suspends again, even on the same step in a loop, the task asks again with a new input request. A resume from outside the task that reaches the run at the same moment as the task's own can still let a stale answer resume the next suspension of that same step.
|
|
1730
|
+
- A step whose `resumeSchema` can't be shown as a form, such as one with nested objects, leaves the task `working`. Resume the run another way, for example from Studio, and the task follows it. Until then the task reads the run's state every second and, on Mastra background tasks, holds a background task slot, as it does while it follows a run another instance executes.
|
|
1731
|
+
- Declining the input request, `tasks/cancel`, and TTL expiry cancel the run, including a run waiting for input, from any instance. A run executing on the instance that handles the cancel stops there. A run executing on another instance stops when that instance next renews its lease on the task, within about one lease.
|
|
1732
|
+
- A server that shuts down, or loses a task to another worker, stops following the run but leaves it running. Another instance picks the task up and follows the run to its end.
|
|
1733
|
+
- With a `store` passed in `tasks`, the server cancels the run only when the client declines. Have the store's cancel and expiry check the task's context with `isWorkflowTaskContext()` and call `mastra.getWorkflow(context.workflowKey).createRun({ runId: context.runId })`, then `run.cancel()` on it. In the process executing the run, that handle is the executing run, so `cancel()` stops it there.
|
|
1734
|
+
|
|
1735
|
+
When the server running a workflow task stops, Mastra's [workflow recovery](https://mastra.ai/reference/core/mastra-class) continues the run on the next instance that starts, and the task follows it there. This requires `recovery.workflows` to be `'auto'`, the default. With `'off'`, the task stays `working` until its TTL expires. The step that was running when the server stopped runs again, so keep steps safe to repeat. A task whose run was never saved, or whose follower stops a second time, ends `failed`.
|
|
1736
|
+
|
|
1737
|
+
### Agent tasks
|
|
1738
|
+
|
|
1739
|
+
An `ask_<key>` task runs the agent's `generate()` as the task's work, like a tool task: `tasks/cancel` aborts the agent's `abortSignal`, an error completes the task with `isError: true`, and `recover` applies.
|
|
1740
|
+
|
|
1741
|
+
An agent that pauses for tool approval or other input completes the task with `isError: true`. Tasks can't answer an agent's approval requests yet.
|
|
1742
|
+
|
|
1743
|
+
### Tasks across instances
|
|
1744
|
+
|
|
1745
|
+
Register the server on a Mastra instance with [background tasks](https://mastra.ai/docs/harness/background-tasks) enabled and its tasks are kept in Mastra storage. Any instance sharing that storage can answer `tasks/get`, `tasks/update` and `tasks/cancel` for a task, and run it.
|
|
1746
|
+
|
|
1747
|
+
```typescript
|
|
1748
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
1749
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
1750
|
+
|
|
1751
|
+
export const mastra = new Mastra({
|
|
1752
|
+
// A local file is only shared by instances on the same host. Use a database every instance can reach.
|
|
1753
|
+
storage: new LibSQLStore({ id: 'mastra', url: 'file:./mastra.db' }),
|
|
1754
|
+
backgroundTasks: {
|
|
1755
|
+
enabled: true,
|
|
1756
|
+
// MCP tasks share the per-agent limit (5) unless their owner gets its own
|
|
1757
|
+
perOwnerConcurrency: { 'mcp-server:reports': 50 },
|
|
1758
|
+
},
|
|
1759
|
+
mcpServers: { reports: server },
|
|
1760
|
+
})
|
|
1761
|
+
```
|
|
1762
|
+
|
|
1763
|
+
- This needs a storage adapter that keeps a TTL per task. On an older adapter the server falls back to memory and logs a warning when it's registered. A `store` passed in `tasks` always wins.
|
|
1764
|
+
- A server that served tasks before it was registered kept those in memory. After registration it still serves them from memory on that instance, and keeps new tasks in Mastra storage.
|
|
1765
|
+
- Register the same server, with the same id and tools, on every instance. An instance without it can't run that server's tasks, and fails them instead. Set the id with `id`, or register the server under a key in `mcpServers`: a generated id changes on every start, and the server logs a warning.
|
|
1766
|
+
- Each task counts against `perOwnerConcurrency` for `mcp-server:<server id>` (or `perAgentConcurrency` when unset) and against `globalConcurrency`. Keep `backpressure` at its default, `'queue'`. With other values a full queue fails the call.
|
|
1767
|
+
- An answer sent with `tasks/update` is stored before it's acknowledged. The task resumes even if the instance that took the answer stops before running it.
|
|
1768
|
+
- The server deletes a finished task's row about a minute after its `ttlMs` ends, without `backgroundTasks.cleanup`. It only deletes its own rows. A task with `ttlMs: null` keeps its row until you delete it.
|
|
1769
|
+
- Expired tasks are failed, and answered tasks still waiting are resumed, by a periodic sweep on each instance. The sweep starts when the server is registered. An instance sweeps even before any client sends it a task request. Each sweep handles at most 100 expired tasks and checks 100 other open tasks, moving on to the next 100 on the following sweep. It restarts a task left waiting by a stopped instance only when a slot is free. The rest wait for a later sweep.
|
|
1770
|
+
- `maxOpenTasksPerClient` and `maxOpenTasks` count open tasks in storage across every instance, so they hold for the whole deployment. Each call counts before it adds its task, so calls arriving at the same moment on different instances can go over a cap by up to the number of those calls.
|
|
1771
|
+
- `tasks/cancel` can reach any instance. If the task's first attempt is still waiting for a slot on the instance that started it, that instance stops it on its next sweep, up to one lease (`leaseDurationMs`) later.
|
|
1772
|
+
|
|
1773
|
+
Tasks are rows in the background tasks storage, owned by agent id `mcp-server:<server id>` with resource id `mcp-server:<server id>:<caller>`:
|
|
1774
|
+
|
|
1775
|
+
- They don't belong to any agent, thread or memory, so they never appear in an agent's conversation.
|
|
1776
|
+
- The `/background-tasks` routes don't return them to a caller scoped to a resource. Callers without a resource scope can list them, as can the global `onTaskComplete` and `onTaskFailed` hooks. Check `task.agentId.startsWith('mcp-server:')` in hooks that only expect agent tasks.
|
|
1777
|
+
- A row is looked up by hashes of the task id and of the caller's principal, and stores neither value nor the bearer token. It does store the request context without the bearer token, and a readable `metadata.clientLabel` that keeps the client id with the subject or user id (next bullet). `authInfo.extra` and `user` are stored unchanged, so they're visible to anyone who can read the row.
|
|
1778
|
+
- To show which client sent a task, `metadata.clientLabel` holds the OAuth client id with the token's subject (`<client id>:sub:<subject>`), or with the id of the user `mapAuthInfoToUser` returned (`<client id>:user:<user id>`). Without either, it holds the client id and the first 8 characters of the token's hash (`<client id>:token:<hash prefix>`). The label is for debugging only: the server matches callers on the hashed principal, never on the label.
|
|
1779
|
+
|
|
1780
|
+
### Recovery after a crash
|
|
1781
|
+
|
|
1782
|
+
When the instance running a task stops, another instance notices it at its next sweep: after the task's lease lapses if the instance crashed, or right away if the instance shut down and handed the lease back. Every instance with the server registered on a Mastra instance with background tasks sweeps, whether or not it has served a task request. An instance that keeps tasks in memory, or without the server registered, doesn't. What happens next depends on `recover`:
|
|
1783
|
+
|
|
1784
|
+
- `recover: false` (default): the task ends `failed` with `task lost: the server restarted while it was running`. `execute` never runs twice.
|
|
1785
|
+
- `recover: true`: another instance runs `execute` again from the start, once. Only turn it on for tools that are safe to repeat.
|
|
1786
|
+
|
|
1787
|
+
With `recover: true` the same single retry also covers an attempt that fails for a reason other than the tool, such as a storage write failing while the task records that it needs input. An error from the tool itself isn't retried: it ends the task with an `isError` result.
|
|
1788
|
+
|
|
1789
|
+
`recover` doesn't affect a task waiting for input: answering it resumes it on any instance either way.
|
|
1790
|
+
|
|
1791
|
+
### Tracing
|
|
1792
|
+
|
|
1793
|
+
Each task is one trace. The `tools/call` that creates the task is its root span, and it ends without an error once the task starts. Every run of the tool is a `task attempt <tool> #<n>` span under it, including resumed and recovered runs on other instances, and the tool's own spans sit inside its attempt. `tasks/update` and `tasks/cancel` requests join the same trace. `tasks/get` polls aren't traced.
|
|
1794
|
+
|
|
1795
|
+
The same holds for `run_<workflow>` and `ask_<agent>` tasks. A workflow task's run sits under its first attempt, or under the root in `'auto'` mode, and each run resumed after `tasks/update` sits under the attempt that resumed it, on whichever instance that is. An agent task's `agent run` sits under its attempt. A run that Mastra's workflow recovery restarts after a crash starts a trace of its own, by design. Durable workflows and agents cover tracing across a crash. The task's attempt that follows the restarted run stays in the task's trace.
|
|
1796
|
+
|
|
1797
|
+
Task details are in span metadata: `mcpTaskKey` (a SHA-256 hash of the task id), `attempt`, `resumed`, `recovered` and `mcpTaskStatus`. Spans never record the task id itself. The server writes out the root span as soon as the task starts. A trace without its root drops out of trace lists, and this keeps it listed even if that instance stops before its next export. Attempts are numbered across instances, so a run recovered after a crash shows as `#2` even when the crashed attempt's span was lost with its instance.
|
|
1798
|
+
|
|
1799
|
+
### Limits
|
|
1800
|
+
|
|
1801
|
+
- Without Mastra background tasks, tasks are kept in memory. They're lost when the process restarts, and a multi-instance deployment needs every `tasks/*` request for a task to reach the instance that created it. Streamable HTTP requests carry the task id in the `Mcp-Name` header, so a load balancer can route on it.
|
|
1802
|
+
- Progress and log notifications sent after the task handle is answered are dropped.
|
|
1803
|
+
|
|
1589
1804
|
## Related information
|
|
1590
1805
|
|
|
1591
1806
|
- For connecting to MCP servers in Mastra, see the [MCPClient documentation](https://mastra.ai/reference/tools/mcp-client).
|
|
@@ -94,4 +94,4 @@ Pass an object to `agent.resumeStream()`:
|
|
|
94
94
|
- **Rejected with feedback:** The tool returns the feedback and asks the model to revise the plan and submit again.
|
|
95
95
|
- **Rejected without feedback:** The tool tells the model to wait for the user's next message before revising.
|
|
96
96
|
|
|
97
|
-
When used inside an [AgentController](https://mastra.ai/docs/harness/agent-controller), plan approval switches from the current mode to the mode configured by `transitionsTo`. When no `transitionsTo` is configured, the controller switches to its resolved default mode. See [Modes](https://mastra.ai/docs/harness/agent-controller) for details.
|
|
97
|
+
When used inside an [AgentController](https://mastra.ai/docs/harness/agent-controller), plan approval switches from the current mode to the mode configured by `transitionsTo`. When no `transitionsTo` is configured, the controller switches to its [resolved default mode](https://mastra.ai/reference/agent-controller/agent-controller-class). See [Modes](https://mastra.ai/docs/harness/agent-controller) for details.
|
|
@@ -209,6 +209,16 @@ interface FileStat {
|
|
|
209
209
|
}
|
|
210
210
|
```
|
|
211
211
|
|
|
212
|
+
The built-in `read_file` tool uses `mimeType` to choose how to return a file. Files whose type matches the tool's `mediaTypes` option come back as native media parts, up to `maxMediaBytes`. Larger files return metadata only unless the caller passes an `encoding`. By default the media types are PNG, JPEG, WebP, and PDF. Files that `mediaTypes` doesn't match and that have no `mimeType`, a text-like type, or `application/octet-stream` come back as text. See [agent tools](https://mastra.ai/reference/workspace/workspace-class) for the `mediaTypes` and `maxMediaBytes` options. A custom filesystem that never sets `mimeType` returns images and PDFs as text.
|
|
213
|
+
|
|
214
|
+
Set `mimeType` for files only, and leave it unset for directories. `getMimeType()` from `@mastra/core/workspace` is the extension lookup that `LocalFilesystem` uses. It returns `application/octet-stream` for unknown extensions.
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import { getMimeType } from '@mastra/core/workspace'
|
|
218
|
+
|
|
219
|
+
const mimeType = type === 'file' ? getMimeType(path) : undefined
|
|
220
|
+
```
|
|
221
|
+
|
|
212
222
|
## Optional methods
|
|
213
223
|
|
|
214
224
|
### `init()`
|
|
@@ -118,6 +118,12 @@ const sandbox = new LocalSandbox({
|
|
|
118
118
|
|
|
119
119
|
Set `WORKSPACE_PATH` in your environment to an absolute path like `/home/user/my-project/workspace`. It ensures commands run from a consistent directory regardless of how you run your code.
|
|
120
120
|
|
|
121
|
+
## Windows shell
|
|
122
|
+
|
|
123
|
+
`executeCommand(command, args)` quotes `args` for a POSIX shell. On native Windows without isolation, `LocalSandbox` runs these commands through Git Bash instead of `cmd.exe`. It uses the shell in `MASTRA_WINDOWS_SHELL` if set, then the `bin\bash.exe` next to `git.exe` on the command's `PATH`, then `%ProgramFiles%\Git\bin\bash.exe`. If no shell is found, commands fall back to `cmd.exe`, which can't parse POSIX-quoted arguments. Commands passed as a single string without `args` always run through `cmd.exe`, as do argv calls to `cmd`, `powershell`, and `pwsh`. Under Git Bash, `LocalSandbox` sets `MSYS_NO_PATHCONV=1` and `MSYS2_ARG_CONV_EXCL=*` so switches like `/F` and Windows paths reach native tools unchanged.
|
|
124
|
+
|
|
125
|
+
Install [Git for Windows](https://git-scm.com/download/win) to get Git Bash. Deep repository paths can exceed the Windows path limit, so also run `git config --global core.longpaths true`. To keep running argv commands through `cmd.exe`, for example to call `cmd.exe` builtins like `dir`, set `MASTRA_WINDOWS_SHELL` to the full path of `cmd.exe`.
|
|
126
|
+
|
|
121
127
|
## Background processes
|
|
122
128
|
|
|
123
129
|
`LocalSandbox` includes a built-in process manager for spawning and managing background processes. Processes run as child processes on the local machine using `child_process.spawn`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "1.3.11-alpha.
|
|
3
|
+
"version": "1.3.11-alpha.3",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@mastra/mcp-legacy": "npm:@mastra/mcp@^1.18.0",
|
|
27
27
|
"local-pkg": "^1.2.1",
|
|
28
28
|
"zod": "^4.6.7",
|
|
29
|
-
"@mastra/core": "1.81.0-alpha.
|
|
30
|
-
"@mastra/mcp": "^2.
|
|
29
|
+
"@mastra/core": "1.81.0-alpha.2",
|
|
30
|
+
"@mastra/mcp": "^2.7.0-alpha.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@hono/node-server": "^2.1.3",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"tsx": "^4.23.15",
|
|
43
43
|
"typescript": "^7.0.2",
|
|
44
44
|
"vitest": "4.1.12",
|
|
45
|
-
"@internal/lint": "0.0.146",
|
|
46
45
|
"@internal/types-builder": "0.0.121",
|
|
47
|
-
"@
|
|
46
|
+
"@internal/lint": "0.0.146",
|
|
47
|
+
"@mastra/core": "1.81.0-alpha.2"
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://mastra.ai",
|
|
50
50
|
"repository": {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|