@mastra/mcp-docs-server 1.3.9-alpha.9 → 1.3.9

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 (153) hide show
  1. package/.docs/docs/agents/guardrails.md +3 -0
  2. package/.docs/docs/agents/overview.md +1 -0
  3. package/.docs/docs/agents/processors.md +9 -4
  4. package/.docs/docs/auth/composite-auth.md +4 -2
  5. package/.docs/docs/auth/custom-auth-provider.md +1 -1
  6. package/.docs/docs/auth/overview.md +3 -1
  7. package/.docs/docs/connections/sdk-agents.md +18 -7
  8. package/.docs/docs/evals/experiments.md +27 -2
  9. package/.docs/docs/guides/mcp-authentication-authorization.md +2 -2
  10. package/.docs/docs/guides/mcp-events.md +306 -0
  11. package/.docs/docs/harness/agent-controller.md +11 -14
  12. package/.docs/docs/harness/background-tasks.md +11 -0
  13. package/.docs/docs/harness/durable-agents.md +10 -4
  14. package/.docs/docs/harness/schedules.md +8 -6
  15. package/.docs/docs/index.md +1 -0
  16. package/.docs/docs/mastra-platform/connect/end-user-connections.md +116 -0
  17. package/.docs/docs/mastra-platform/environments.md +1 -1
  18. package/.docs/docs/mastra-platform/server.md +1 -1
  19. package/.docs/docs/mastra-platform/studio.md +1 -1
  20. package/.docs/docs/memory/memory-processors.md +14 -8
  21. package/.docs/docs/memory/semantic-recall.md +20 -0
  22. package/.docs/docs/memory/working-memory.md +1 -1
  23. package/.docs/docs/sandbox/filesystem.md +25 -11
  24. package/.docs/docs/server/overview.md +27 -0
  25. package/.docs/docs/studio/auth.md +2 -2
  26. package/.docs/docs/studio/observability.md +5 -1
  27. package/.docs/docs/workflows/control-flow.md +14 -14
  28. package/.docs/docs/workflows/error-handling.md +1 -1
  29. package/.docs/integrations/deploy/aws-bedrock-agentcore.md +1 -0
  30. package/.docs/integrations/sandboxes/e2b.md +2 -0
  31. package/.docs/models/embeddings.md +2 -1
  32. package/.docs/models/environment-variables.md +1 -1
  33. package/.docs/models/gateways/merge-gateway.md +7 -1
  34. package/.docs/models/gateways/vercel.md +6 -2
  35. package/.docs/models/index.md +2 -2
  36. package/.docs/models/providers/aixy.md +3 -1
  37. package/.docs/models/providers/alibaba-cn.md +7 -55
  38. package/.docs/models/providers/alibaba-coding-plan-cn.md +8 -12
  39. package/.docs/models/providers/alibaba-coding-plan.md +8 -12
  40. package/.docs/models/providers/alibaba-token-plan-cn.md +0 -2
  41. package/.docs/models/providers/alibaba-token-plan.md +29 -30
  42. package/.docs/models/providers/alibaba.md +32 -61
  43. package/.docs/models/providers/ambient.md +0 -8
  44. package/.docs/models/providers/amd.md +13 -9
  45. package/.docs/models/providers/anthropic.md +4 -2
  46. package/.docs/models/providers/arcee.md +6 -4
  47. package/.docs/models/providers/baseten.md +0 -10
  48. package/.docs/models/providers/cloudflare-workers-ai.md +1 -1
  49. package/.docs/models/providers/crossmodel.md +70 -72
  50. package/.docs/models/providers/databricks.md +5 -10
  51. package/.docs/models/providers/digitalocean.md +2 -14
  52. package/.docs/models/providers/edenai.md +18 -4
  53. package/.docs/models/providers/empiriolabs.md +1 -7
  54. package/.docs/models/providers/fireworks-ai.md +22 -26
  55. package/.docs/models/providers/google.md +4 -1
  56. package/.docs/models/providers/groq.md +2 -7
  57. package/.docs/models/providers/huggingface.md +2 -5
  58. package/.docs/models/providers/inception.md +3 -2
  59. package/.docs/models/providers/iteracompute.md +2 -2
  60. package/.docs/models/providers/jalapeno.md +1 -1
  61. package/.docs/models/providers/kenari.md +1 -1
  62. package/.docs/models/providers/kilo.md +15 -30
  63. package/.docs/models/providers/liquid.md +77 -0
  64. package/.docs/models/providers/llmgateway-providers.md +3 -12
  65. package/.docs/models/providers/llmgateway.md +5 -15
  66. package/.docs/models/providers/longcat.md +6 -5
  67. package/.docs/models/providers/melious.md +16 -15
  68. package/.docs/models/providers/minimax-cn-coding-plan.md +4 -11
  69. package/.docs/models/providers/minimax-cn.md +4 -10
  70. package/.docs/models/providers/minimax-coding-plan.md +4 -11
  71. package/.docs/models/providers/minimax.md +4 -10
  72. package/.docs/models/providers/mistral.md +4 -4
  73. package/.docs/models/providers/modal.md +11 -7
  74. package/.docs/models/providers/moonshotai-cn.md +2 -2
  75. package/.docs/models/providers/nano-gpt.md +17 -26
  76. package/.docs/models/providers/nearai.md +1 -1
  77. package/.docs/models/providers/ofox.md +148 -156
  78. package/.docs/models/providers/ollama-cloud.md +6 -11
  79. package/.docs/models/providers/openai.md +4 -2
  80. package/.docs/models/providers/opencode.md +2 -1
  81. package/.docs/models/providers/perplexity-agent.md +53 -29
  82. package/.docs/models/providers/perplexity.md +2 -8
  83. package/.docs/models/providers/pioneer.md +8 -113
  84. package/.docs/models/providers/requesty.md +0 -4
  85. package/.docs/models/providers/runinfra.md +2 -1
  86. package/.docs/models/providers/scaleway.md +1 -3
  87. package/.docs/models/providers/snowflake-cortex.md +22 -22
  88. package/.docs/models/providers/stepfun-ai.md +1 -3
  89. package/.docs/models/providers/stepfun.md +4 -6
  90. package/.docs/models/providers/synthetic.md +2 -1
  91. package/.docs/models/providers/thinkingmachines.md +45 -9
  92. package/.docs/models/providers/togetherai.md +17 -23
  93. package/.docs/models/providers/wandb.md +1 -1
  94. package/.docs/models/providers/xai.md +3 -2
  95. package/.docs/models/providers/xiaomi-token-plan-ams.md +0 -1
  96. package/.docs/models/providers/xiaomi-token-plan-cn.md +0 -1
  97. package/.docs/models/providers/xiaomi-token-plan-sgp.md +0 -1
  98. package/.docs/models/providers/zai-coding-plan.md +0 -4
  99. package/.docs/models/providers/zhipuai-coding-plan.md +0 -1
  100. package/.docs/models/providers/zhipuai.md +12 -12
  101. package/.docs/models/providers.md +1 -1
  102. package/.docs/reference/agent-controller/agent-controller-class.md +17 -22
  103. package/.docs/reference/agent-controller/session.md +3 -3
  104. package/.docs/reference/agents/channels.md +7 -1
  105. package/.docs/reference/agents/durable-agent.md +12 -8
  106. package/.docs/reference/agents/getSkill.md +1 -1
  107. package/.docs/reference/agents/listSkills.md +1 -4
  108. package/.docs/reference/browser/mastra-browser.md +1 -1
  109. package/.docs/reference/client-js/agent-controller.md +13 -3
  110. package/.docs/reference/client-js/agents.md +20 -0
  111. package/.docs/reference/client-js/mastra-client.md +1 -1
  112. package/.docs/reference/client-js/observability.md +3 -3
  113. package/.docs/reference/configuration.md +30 -0
  114. package/.docs/reference/connect/credential.md +1 -1
  115. package/.docs/reference/connect/tools.md +3 -1
  116. package/.docs/reference/connect/user-connect-routes.md +68 -0
  117. package/.docs/reference/core/mastra-class.md +2 -2
  118. package/.docs/reference/core/mastra-model-gateway.md +33 -4
  119. package/.docs/reference/datasets/delete.md +6 -0
  120. package/.docs/reference/editor/mastra-editor.md +9 -7
  121. package/.docs/reference/editor/tool-provider.md +2 -2
  122. package/.docs/reference/evals/create-classifier-scorer.md +6 -2
  123. package/.docs/reference/file-based-agents/instructions.md +1 -1
  124. package/.docs/reference/file-based-agents/processors.md +2 -0
  125. package/.docs/reference/file-based-agents/schedules.md +1 -1
  126. package/.docs/reference/file-based-agents/skills.md +1 -1
  127. package/.docs/reference/file-based-agents/subagents.md +1 -1
  128. package/.docs/reference/index.md +1 -0
  129. package/.docs/reference/manual-install.md +1 -0
  130. package/.docs/reference/memory/cloneThread.md +1 -1
  131. package/.docs/reference/memory/copyThread.md +1 -1
  132. package/.docs/reference/memory/deleteMessages.md +4 -1
  133. package/.docs/reference/memory/memory-class.md +2 -0
  134. package/.docs/reference/memory/serialized-memory-config.md +1 -1
  135. package/.docs/reference/observability/tracing/advanced-queries.md +40 -31
  136. package/.docs/reference/processors/processor-interface.md +10 -2
  137. package/.docs/reference/server/routes.md +159 -0
  138. package/.docs/reference/signals/signal-provider.md +2 -0
  139. package/.docs/reference/signals/task-signal-provider.md +1 -1
  140. package/.docs/reference/streaming/agents/stream.md +1 -1
  141. package/.docs/reference/tools/mcp-client.md +236 -0
  142. package/.docs/reference/tools/mcp-server.md +170 -0
  143. package/.docs/reference/workflows/workflow-methods/branch.md +1 -1
  144. package/.docs/reference/workspace/filesystem.md +17 -17
  145. package/.docs/reference/workspace/local-filesystem.md +51 -26
  146. package/.docs/reference/workspace/platform-sandbox.md +2 -0
  147. package/.docs/reference/workspace/sandbox.md +16 -0
  148. package/.docs/reference/workspace/workspace-class.md +13 -12
  149. package/dist/index.js +1 -2
  150. package/dist/{src-Baf8l9Sp.js → src-DnH_jHt9.js} +2 -3
  151. package/dist/{src-Baf8l9Sp.js.map → src-DnH_jHt9.js.map} +1 -1
  152. package/dist/stdio.js +1 -1
  153. package/package.json +6 -6
@@ -1414,6 +1414,176 @@ const server = new MCPServer({
1414
1414
 
1415
1415
  Link a tool to its app resource by setting `mcp._meta.ui.resourceUri` in `createTool()` to the matching `ui://` URI. The server normalizes this metadata for older hosts when listing tools, and returns the same link on successful tool call results. Visit [MCP Apps](https://mastra.ai/docs/connections/mcp) for the full app bridge API and usage patterns.
1416
1416
 
1417
+ ## Events (experimental)
1418
+
1419
+ > **Warning:** Events implement [SEP-3415](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/3415), a draft MCP extension. The wire format and this API may change in any release.
1420
+
1421
+ For an end-to-end walkthrough, see the [MCP events guide](https://mastra.ai/docs/guides/mcp-events).
1422
+
1423
+ The `events` option lets clients subscribe to things that happen on your server, such as a ticket being created or a build finishing. The server advertises the `io.modelcontextprotocol/events` extension and answers `events/list`, `events/poll` and `events/stream` over both stdio and Streamable HTTP. With [`eventsOptions.webhook`](#webhook-delivery) set, it also answers `events/subscribe` and `events/unsubscribe` and POSTs occurrences to client webhook URLs.
1424
+
1425
+ Declare each event type with `defineEvent()` and publish occurrences with `server.events.emit()`:
1426
+
1427
+ ```typescript
1428
+ import { MCPServer, defineEvent } from '@mastra/mcp'
1429
+ import { z } from 'zod'
1430
+
1431
+ const server = new MCPServer({
1432
+ id: 'tickets',
1433
+ name: 'Tickets',
1434
+ version: '1.0.0',
1435
+ tools: {},
1436
+ events: {
1437
+ 'ticket.created': defineEvent({
1438
+ description: 'A ticket was created',
1439
+ inputSchema: z.object({ project: z.string().optional() }),
1440
+ payloadSchema: z.object({ id: z.string(), project: z.string() }),
1441
+ match: (args, data) => !args.project || data.project === args.project,
1442
+ }),
1443
+ },
1444
+ })
1445
+
1446
+ await server.events.emit('ticket.created', { id: 't-1', project: 'web' })
1447
+ ```
1448
+
1449
+ A client that subscribed with `{ project: 'web' }` receives this occurrence. A client that subscribed with `{ project: 'api' }` doesn't.
1450
+
1451
+ `match` filters on the arguments the client chooses, so it doesn't control who can subscribe. To restrict callers, add `authorize`. It receives the validated arguments and the caller's `requestContext`, which includes `user` when you set `mapAuthInfoToUser`:
1452
+
1453
+ ```typescript
1454
+ const ticketCreated = defineEvent({
1455
+ inputSchema: z.object({ project: z.string() }),
1456
+ payloadSchema: z.object({ id: z.string(), project: z.string() }),
1457
+ match: (args, data) => data.project === args.project,
1458
+ authorize: ({ arguments: args, requestContext }) => {
1459
+ const user = requestContext.get('user') as { projects: string[] } | undefined
1460
+ return user?.projects.includes(args.project) ?? false
1461
+ },
1462
+ })
1463
+ ```
1464
+
1465
+ `authorize` runs on every `events/poll`, every `events/stream` open, and every webhook `events/subscribe`, including refreshes. An open stream isn't checked again until it reconnects, and a webhook subscription until its next refresh. A caller who loses access keeps receiving occurrences until then. FGA isn't applied to events; use `authorize` to restrict them.
1466
+
1467
+ ### `defineEvent()` options
1468
+
1469
+ **description** (`string`): Description returned by events/list.
1470
+
1471
+ **inputSchema** (`StandardSchemaWithJSON`): Schema for the subscription arguments. Advertised as JSON Schema. Arguments that fail validation are rejected with error -32602, and match and poll receive the parsed value.
1472
+
1473
+ **payloadSchema** (`StandardSchemaWithJSON`): Schema for the event data. Advertised as JSON Schema and enforced by server.events.emit().
1474
+
1475
+ **match** (`(args, data) => boolean`): Decides whether an emitted event reaches a subscription with these arguments. Applies to push streams and to polls served from the buffer. Defaults to delivering every event.
1476
+
1477
+ **authorize** (`(context) => boolean | Promise<boolean>`): Decides whether the caller may receive this type with these arguments. Receives arguments, requestContext and delivery ('poll', 'push' or 'webhook'). Runs on every events/poll, before a poll source is called, on every events/stream open, and on every webhook events/subscribe, including refreshes. Returning false rejects the request with -32024. A refresh that is denied also removes the webhook subscription. If it throws, the client gets a generic -32603 error and the details are logged on the server. Defaults to allowing every caller.
1478
+
1479
+ **poll** (`(context) => Promise<MCPServerEventPollResult>`): Pull source for events/poll. Receives arguments, cursor (null means start from now), maxEvents, maxAgeMs, requestContext and signal. Returns { events, cursor, hasMore?, nextPollMs?, truncated? }. Each event needs data and a stable eventId (clients dedupe by it, so return the same id whenever the same occurrence is polled); a missing timestamp defaults to now. If poll or match throws, the client gets a generic -32603 error and the details are logged on the server.
1480
+
1481
+ **delivery** (`Array<'poll' | 'push' | 'webhook'>`): Restricts the advertised delivery modes to this list. It only narrows the modes from the table below, and a definition left with no mode throws when the server is constructed.
1482
+
1483
+ **bufferSize** (`number`): Number of emitted events kept in memory for replay and buffered polls. (Default: `1000`)
1484
+
1485
+ **pollIntervalMs** (`number`): nextPollMs suggested to clients that poll the buffer.
1486
+
1487
+ ### Delivery modes
1488
+
1489
+ How a type is served depends on where its events come from:
1490
+
1491
+ | Definition | Advertised `delivery` | Source |
1492
+ | ---------- | ------------------------------------------------------------------------ | -------------------------------------------------------- |
1493
+ | No `poll` | `['push', 'poll']`, plus `'webhook'` when `eventsOptions.webhook` is set | `server.events.emit()`. Polls read the in-memory buffer. |
1494
+ | `poll` | `['poll']` | Your `poll` function, called for each `events/poll`. |
1495
+
1496
+ A type with a `poll` source can't also be pushed: `delivery` can't add `'push'` to it, and `server.events.emit()` throws for it. The advertised modes never change after the server starts, because clients only learn them from `events/list`. To push events, define a type without `poll` and emit to it.
1497
+
1498
+ A request for a mode the type doesn't advertise fails with `-32026`. An unknown event name fails with `-32023`.
1499
+
1500
+ ### Push streams
1501
+
1502
+ Each `events/stream` request is one subscription. The server sends `notifications/events/active` first, then one `notifications/events/event` per matching occurrence. Every notification carries the request id as `_meta["io.modelcontextprotocol/subscriptionId"]`. When the request includes a `cursor`, buffered events after it are replayed before live ones. If that cursor is older than the buffer, `active` reports `truncated: true`.
1503
+
1504
+ When no other message has been sent for `heartbeatIntervalMs`, the stream sends `notifications/events/heartbeat` with the current cursor. Cancelling the request, or calling `server.close()`, ends the stream and releases its listener and timer.
1505
+
1506
+ ### `eventsOptions`
1507
+
1508
+ **heartbeatIntervalMs** (`number`): Longest gap between messages on a push stream. (Default: `30000`)
1509
+
1510
+ **listPageSize** (`number`): Number of event types per events/list page. (Default: `100`)
1511
+
1512
+ **maxStreams** (`number`): Most push streams open at once across all clients. Further events/stream requests are rejected with -32025 until one closes. A Mastra client retries the rejection when reconnecting an established subscription; a new subscribe() call rejects with it. (Default: `1024`)
1513
+
1514
+ **webhook** (`MCPServerWebhookOptions`): Enables webhook delivery for event types without a poll source. Without it, the server doesn't advertise webhook or answer events/subscribe.
1515
+
1516
+ ### Webhook delivery
1517
+
1518
+ With `eventsOptions.webhook` set, a client can register a callback URL with `events/subscribe`, and the server POSTs each matching occurrence to it, signed with the client's secret using [Standard Webhooks](https://www.standardwebhooks.com/) HMAC-SHA256.
1519
+
1520
+ ```typescript
1521
+ const server = new MCPServer({
1522
+ id: 'tickets',
1523
+ name: 'Tickets',
1524
+ version: '1.0.0',
1525
+ tools: {},
1526
+ events: {
1527
+ 'ticket.created': defineEvent({ payloadSchema: z.object({ id: z.string() }) }),
1528
+ },
1529
+ eventsOptions: {
1530
+ webhook: { ttl: { defaultMs: 30 * 60_000 } },
1531
+ },
1532
+ })
1533
+ ```
1534
+
1535
+ The server enforces these rules:
1536
+
1537
+ - **Authentication:** Webhook subscriptions need an authenticated caller. Without `authInfo` on the request, `events/subscribe` fails with `-32024`. A subscription is identified by the caller, the URL, the event name, and the arguments, so repeating `events/subscribe` refreshes the same subscription and returns the same `id`.
1538
+ - **Authorization:** `authorize` runs on each subscribe and each refresh. When it denies a refresh, the subscription is removed and no further occurrences are POSTed. A Mastra client can't tell this `-32024` from the one for an unauthenticated caller, so in its default delivery mode it reports `MCP_EVENTS_WEBHOOK_UNAVAILABLE`, tries push, and then rejects with the same `-32024`.
1539
+ - **Callback URLs:** The URL must use `https`. Every address it resolves to must be publicly routable: loopback, private, link-local, and other special-purpose ranges are rejected with `-32602` and `data.reason`. The check runs again before every delivery, and the request connects to the address that passed, to prevent DNS rebinding. Redirects are never followed.
1540
+ - **Verification:** Before the first delivery to a URL, the server POSTs a signed verification challenge, and the endpoint must echo it. A failed or unreachable endpoint fails `events/subscribe` with `-32027` and a `data.reason` such as `challenge_failed` or `timeout`. The result is cached per caller and URL. URLs accepted by `allowedUrls` skip this step.
1541
+ - **Lifetime:** Each subscription expires at the returned `refreshBefore` time unless the client refreshes it. A requested `ttlMs` is clamped to the `ttl` bounds.
1542
+ - **Retries:** Each occurrence is retried with exponential backoff until it's acknowledged with a `2xx`, `retry.maxAttempts` is reached, or `retry.maxWindowMs` has passed. A `410` or `413` response stops retries for that occurrence. The `cursor` in each body only advances past occurrences that are acknowledged or given up on.
1543
+ - **Suspension:** When most deliveries to a subscription fail over `suspend.windowMs`, the server pauses it and reports `active: false` in `deliveryStatus` on the next refresh. The refresh resumes delivery.
1544
+ - **Errors:** Clients only see a failure category such as `timeout` or `http_5xx`, never the endpoint's response body or headers.
1545
+
1546
+ **ttl** (`{ defaultMs?: number; minMs?: number; maxMs?: number }`): Subscription lifetime granted when the client omits ttlMs, and the bounds a requested ttlMs is clamped to. Defaults to 30 minutes, 60 seconds, and 24 hours.
1547
+
1548
+ **allowNoExpiry** (`boolean`): Grants ttlMs: null requests a subscription that never expires. Otherwise they get ttl.maxMs. Only enable it with a durable store, because clients with no-expiry subscriptions don't need to refresh after a server restart. (Default: `false`)
1549
+
1550
+ **store** (`WebhookSubscriptionStore`): Stores subscription records (identity, secret, expiry) with async get, set, delete, and list methods. The default keeps them in memory, so subscriptions are lost on restart until clients refresh. (Default: `InMemoryWebhookSubscriptionStore`)
1551
+
1552
+ **url** (`{ allowPrivate?: boolean; allowInsecure?: boolean; lookup?: WebhookLookup }`): Callback URL policy. allowPrivate accepts non-public addresses and allowInsecure accepts http. Use them for local development only. lookup replaces DNS resolution.
1553
+
1554
+ **allowedUrls** (`(url: URL) => boolean`): Returns true for URLs you trust, which then skip the verification challenge.
1555
+
1556
+ **verificationTtlMs** (`number`): How long a successful verification is remembered for a caller and URL. (Default: `86400000`)
1557
+
1558
+ **timeoutMs** (`number`): Timeout for each delivery attempt. (Default: `5000`)
1559
+
1560
+ **retry** (`{ maxAttempts?: number; initialDelayMs?: number; maxDelayMs?: number; maxWindowMs?: number }`): Retry policy for each occurrence. Defaults to 5 attempts, a 1 second initial delay, a 5 minute maximum delay, and a 15 minute window. Time spent suspended doesn't count against the window.
1561
+
1562
+ **suspend** (`{ windowMs?: number; minAttempts?: number; failureRate?: number }`): Suspends a subscription when at least failureRate of at least minAttempts attempts fail within windowMs. Defaults to 0.95, 100, and 60 minutes.
1563
+
1564
+ **maxPending** (`number`): Undelivered occurrences kept per subscription. On overflow the oldest are dropped and the client receives a gap body, so it reports truncated: true. (Default: `1000`)
1565
+
1566
+ **maxSubscriptions** (`number`): Most webhook subscriptions this process keeps across all callers. New subscriptions past the limit are rejected with -32025, and a Mastra client falls back to push or poll unless it forced webhook delivery. Refreshing an existing subscription still works. (Default: `1000`)
1567
+
1568
+ **maxSubscriptionsPerPrincipal** (`number`): Most webhook subscriptions one authenticated caller can hold. (Default: `100`)
1569
+
1570
+ **secretGraceMs** (`number`): After a client rotates its secret, deliveries are signed with both secrets for this long. (Default: `300000`)
1571
+
1572
+ **transport** (`WebhookTransport`): Replaces the HTTP client that sends deliveries, for example in tests.
1573
+
1574
+ ### `server.events.emit(name, data, options?)`
1575
+
1576
+ Records an occurrence, delivers it to matching push streams and webhook subscriptions, and returns it with its `eventId`, `timestamp` and `cursor`. `options.eventId` and `options.timestamp` override the defaults (a random UUID and the current time). It throws when `name` isn't configured, when `data` fails `payloadSchema`, or when the type has a `poll` source.
1577
+
1578
+ `server.events.list()` returns the descriptors `events/list` serves.
1579
+
1580
+ ### Limits
1581
+
1582
+ - Emitted events stay in the process that emitted them. Push streams, webhook subscriptions, and buffered polls only see events emitted by the same `MCPServer` instance, so a serverless or multi-instance deployment needs a `poll` source backed by shared storage.
1583
+ - The buffer is in memory. A restarted server treats earlier cursors as a gap and reports `truncated: true`.
1584
+ - Webhook delivery state (pending retries, suspension, verification results) is in memory and rebuilt when clients refresh.
1585
+ - Changes to the list of event types aren't announced yet. The server doesn't advertise `listChanged` or send `notifications/events/list_changed`, because the MCP TypeScript SDK 2.2.0 doesn't carry the `eventsListChanged` filter on `subscriptions/listen`. Clients should re-run `events/list` to see changed event types.
1586
+
1417
1587
  ## Related information
1418
1588
 
1419
1589
  - For connecting to MCP servers in Mastra, see the [MCPClient documentation](https://mastra.ai/reference/tools/mcp-client).
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Workflow\.branch()
6
6
 
7
- The `.branch()` method creates conditional branches between workflow steps, allowing for different paths to be taken based on the result of a previous step.
7
+ The `.branch()` method creates conditional branches between workflow steps, allowing for different paths to be taken based on the result of a previous step. Every branch whose condition evaluates to `true` runs; conditions are evaluated independently, so overlapping conditions run multiple branches. Use mutually exclusive conditions when only one branch should run.
8
8
 
9
9
  ## Usage example
10
10
 
@@ -15,8 +15,8 @@ The `WorkspaceFilesystem` interface defines how workspaces interact with file st
15
15
  Read file contents.
16
16
 
17
17
  ```typescript
18
- const content = await filesystem.readFile('/docs/guide.md', { encoding: 'utf-8' })
19
- const buffer = await filesystem.readFile('/image.png') // Buffer
18
+ const content = await filesystem.readFile('docs/guide.md', { encoding: 'utf-8' })
19
+ const buffer = await filesystem.readFile('image.png') // Buffer
20
20
  ```
21
21
 
22
22
  **Parameters:**
@@ -34,8 +34,8 @@ const buffer = await filesystem.readFile('/image.png') // Buffer
34
34
  Write file contents.
35
35
 
36
36
  ```typescript
37
- await filesystem.writeFile('/docs/new.md', '# New Document')
38
- await filesystem.writeFile('/nested/path/file.md', content, { recursive: true })
37
+ await filesystem.writeFile('docs/new.md', '# New Document')
38
+ await filesystem.writeFile('nested/path/file.md', content, { recursive: true })
39
39
  ```
40
40
 
41
41
  **Parameters:**
@@ -57,8 +57,8 @@ await filesystem.writeFile('/nested/path/file.md', content, { recursive: true })
57
57
  Delete a file.
58
58
 
59
59
  ```typescript
60
- await filesystem.deleteFile('/docs/old.md')
61
- await filesystem.deleteFile('/docs/maybe.md', { force: true }) // Don't throw if missing
60
+ await filesystem.deleteFile('docs/old.md')
61
+ await filesystem.deleteFile('docs/maybe.md', { force: true }) // Don't throw if missing
62
62
  ```
63
63
 
64
64
  **Parameters:**
@@ -74,7 +74,7 @@ await filesystem.deleteFile('/docs/maybe.md', { force: true }) // Don't throw if
74
74
  Append content to a file, creating it if it doesn't already exist. Parent directories are created automatically.
75
75
 
76
76
  ```typescript
77
- await filesystem.appendFile('/logs/app.log', 'New log entry\n')
77
+ await filesystem.appendFile('logs/app.log', 'New log entry\n')
78
78
  ```
79
79
 
80
80
  **Parameters:**
@@ -88,7 +88,7 @@ await filesystem.appendFile('/logs/app.log', 'New log entry\n')
88
88
  Copy a file to a new location.
89
89
 
90
90
  ```typescript
91
- await filesystem.copyFile('/docs/template.md', '/docs/new-doc.md')
91
+ await filesystem.copyFile('docs/template.md', 'docs/new-doc.md')
92
92
  ```
93
93
 
94
94
  **Parameters:**
@@ -106,7 +106,7 @@ await filesystem.copyFile('/docs/template.md', '/docs/new-doc.md')
106
106
  Move or rename a file.
107
107
 
108
108
  ```typescript
109
- await filesystem.moveFile('/docs/draft.md', '/docs/final.md')
109
+ await filesystem.moveFile('docs/draft.md', 'docs/final.md')
110
110
  ```
111
111
 
112
112
  **Parameters:**
@@ -124,7 +124,7 @@ await filesystem.moveFile('/docs/draft.md', '/docs/final.md')
124
124
  List directory contents.
125
125
 
126
126
  ```typescript
127
- const entries = await filesystem.readdir('/docs')
127
+ const entries = await filesystem.readdir('docs')
128
128
  // [{ name: 'guide.md', type: 'file' }, { name: 'api', type: 'directory' }]
129
129
  ```
130
130
 
@@ -145,8 +145,8 @@ interface FileEntry {
145
145
  Create a directory.
146
146
 
147
147
  ```typescript
148
- await filesystem.mkdir('/docs/api')
149
- await filesystem.mkdir('/deeply/nested/path', { recursive: true })
148
+ await filesystem.mkdir('docs/api')
149
+ await filesystem.mkdir('deeply/nested/path', { recursive: true })
150
150
  ```
151
151
 
152
152
  **Parameters:**
@@ -162,8 +162,8 @@ await filesystem.mkdir('/deeply/nested/path', { recursive: true })
162
162
  Remove a directory.
163
163
 
164
164
  ```typescript
165
- await filesystem.rmdir('/docs/old')
166
- await filesystem.rmdir('/docs/nested', { recursive: true })
165
+ await filesystem.rmdir('docs/old')
166
+ await filesystem.rmdir('docs/nested', { recursive: true })
167
167
  ```
168
168
 
169
169
  **Parameters:**
@@ -181,7 +181,7 @@ await filesystem.rmdir('/docs/nested', { recursive: true })
181
181
  Check if a path exists.
182
182
 
183
183
  ```typescript
184
- const exists = await filesystem.exists('/docs/guide.md')
184
+ const exists = await filesystem.exists('docs/guide.md')
185
185
  ```
186
186
 
187
187
  **Returns:** `Promise<boolean>`
@@ -191,8 +191,8 @@ const exists = await filesystem.exists('/docs/guide.md')
191
191
  Get file or directory metadata.
192
192
 
193
193
  ```typescript
194
- const stat = await filesystem.stat('/docs/guide.md')
195
- // { name: 'guide.md', path: '/docs/guide.md', type: 'file', size: 1234, createdAt: Date, modifiedAt: Date }
194
+ const stat = await filesystem.stat('docs/guide.md')
195
+ // { name: 'guide.md', path: 'docs/guide.md', type: 'file', size: 1234, createdAt: Date, modifiedAt: Date }
196
196
  ```
197
197
 
198
198
  **Returns:** `Promise<FileStat>`
@@ -110,8 +110,8 @@ filesystem.setAllowedPaths([])
110
110
  Read file contents.
111
111
 
112
112
  ```typescript
113
- const content = await filesystem.readFile('/docs/guide.md', { encoding: 'utf-8' })
114
- const buffer = await filesystem.readFile('/image.png')
113
+ const content = await filesystem.readFile('docs/guide.md', { encoding: 'utf-8' })
114
+ const buffer = await filesystem.readFile('image.png')
115
115
  ```
116
116
 
117
117
  **Parameters:**
@@ -127,8 +127,8 @@ const buffer = await filesystem.readFile('/image.png')
127
127
  Write content to a file.
128
128
 
129
129
  ```typescript
130
- await filesystem.writeFile('/docs/new.md', '# New Document')
131
- await filesystem.writeFile('/nested/path/file.md', content, { recursive: true })
130
+ await filesystem.writeFile('docs/new.md', '# New Document')
131
+ await filesystem.writeFile('nested/path/file.md', content, { recursive: true })
132
132
  ```
133
133
 
134
134
  **Parameters:**
@@ -150,7 +150,7 @@ await filesystem.writeFile('/nested/path/file.md', content, { recursive: true })
150
150
  Append content to an existing file.
151
151
 
152
152
  ```typescript
153
- await filesystem.appendFile('/logs/app.log', 'New log entry\n')
153
+ await filesystem.appendFile('logs/app.log', 'New log entry\n')
154
154
  ```
155
155
 
156
156
  **Parameters:**
@@ -164,8 +164,8 @@ await filesystem.appendFile('/logs/app.log', 'New log entry\n')
164
164
  Delete a file.
165
165
 
166
166
  ```typescript
167
- await filesystem.deleteFile('/docs/old.md')
168
- await filesystem.deleteFile('/docs/maybe.md', { force: true }) // Don't throw if missing
167
+ await filesystem.deleteFile('docs/old.md')
168
+ await filesystem.deleteFile('docs/maybe.md', { force: true }) // Don't throw if missing
169
169
  ```
170
170
 
171
171
  **Parameters:**
@@ -181,8 +181,8 @@ await filesystem.deleteFile('/docs/maybe.md', { force: true }) // Don't throw if
181
181
  Copy a file to a new location.
182
182
 
183
183
  ```typescript
184
- await filesystem.copyFile('/docs/template.md', '/docs/new-doc.md')
185
- await filesystem.copyFile('/src/config.json', '/backup/config.json', { overwrite: false })
184
+ await filesystem.copyFile('docs/template.md', 'docs/new-doc.md')
185
+ await filesystem.copyFile('src/config.json', 'backup/config.json', { overwrite: false })
186
186
  ```
187
187
 
188
188
  **Parameters:**
@@ -200,8 +200,8 @@ await filesystem.copyFile('/src/config.json', '/backup/config.json', { overwrite
200
200
  Move or rename a file.
201
201
 
202
202
  ```typescript
203
- await filesystem.moveFile('/docs/draft.md', '/docs/final.md')
204
- await filesystem.moveFile('/temp/upload.txt', '/files/document.txt')
203
+ await filesystem.moveFile('docs/draft.md', 'docs/final.md')
204
+ await filesystem.moveFile('temp/upload.txt', 'files/document.txt')
205
205
  ```
206
206
 
207
207
  **Parameters:**
@@ -219,8 +219,8 @@ await filesystem.moveFile('/temp/upload.txt', '/files/document.txt')
219
219
  Create a directory.
220
220
 
221
221
  ```typescript
222
- await filesystem.mkdir('/docs/api')
223
- await filesystem.mkdir('/deeply/nested/path', { recursive: true })
222
+ await filesystem.mkdir('docs/api')
223
+ await filesystem.mkdir('deeply/nested/path', { recursive: true })
224
224
  ```
225
225
 
226
226
  **Parameters:**
@@ -236,8 +236,8 @@ await filesystem.mkdir('/deeply/nested/path', { recursive: true })
236
236
  Remove a directory.
237
237
 
238
238
  ```typescript
239
- await filesystem.rmdir('/docs/old')
240
- await filesystem.rmdir('/docs/nested', { recursive: true })
239
+ await filesystem.rmdir('docs/old')
240
+ await filesystem.rmdir('docs/nested', { recursive: true })
241
241
  ```
242
242
 
243
243
  **Parameters:**
@@ -255,8 +255,11 @@ await filesystem.rmdir('/docs/nested', { recursive: true })
255
255
  List directory contents.
256
256
 
257
257
  ```typescript
258
- const entries = await filesystem.readdir('/docs')
258
+ const entries = await filesystem.readdir('docs')
259
259
  // [{ name: 'guide.md', type: 'file' }, { name: 'api', type: 'directory' }]
260
+
261
+ // List the basePath root
262
+ const rootEntries = await filesystem.readdir('.')
260
263
  ```
261
264
 
262
265
  ### `exists(path)`
@@ -264,7 +267,7 @@ const entries = await filesystem.readdir('/docs')
264
267
  Check if a path exists.
265
268
 
266
269
  ```typescript
267
- const exists = await filesystem.exists('/docs/guide.md')
270
+ const exists = await filesystem.exists('docs/guide.md')
268
271
  ```
269
272
 
270
273
  ### `stat(path)`
@@ -272,8 +275,8 @@ const exists = await filesystem.exists('/docs/guide.md')
272
275
  Get file or directory metadata.
273
276
 
274
277
  ```typescript
275
- const stat = await filesystem.stat('/docs/guide.md')
276
- // { type: 'file', size: 1234, modifiedAt: Date, createdAt: Date, path: '/docs/guide.md' }
278
+ const stat = await filesystem.stat('docs/guide.md')
279
+ // { type: 'file', size: 1234, modifiedAt: Date, createdAt: Date, path: 'docs/guide.md' }
277
280
  ```
278
281
 
279
282
  ### `getInfo()`
@@ -291,7 +294,7 @@ Returns a description of how paths work in this filesystem. When assigned to an
291
294
 
292
295
  ```typescript
293
296
  const instructions = filesystem.getInstructions()
294
- // 'Local filesystem at "/workspace". Files at workspace path "/foo" are stored at "/workspace/foo" on disk.'
297
+ // 'Local filesystem at "/workspace". Relative paths resolve from this directory. File access is restricted to this directory.'
295
298
  ```
296
299
 
297
300
  Pass `requestContext` to enable per-request customization when the `instructions` constructor option is a function:
@@ -312,22 +315,44 @@ To override the default output, pass an `instructions` option to the constructor
312
315
 
313
316
  ### How `basePath` works
314
317
 
315
- The `basePath` option sets the root directory for all file operations. File paths passed to methods like `readFile()` are resolved relative to this base:
318
+ The `basePath` option sets the root directory for all file operations. Paths passed to methods like `readFile()` are resolved as follows:
316
319
 
317
- - Leading slashes are stripped: `/docs/guide.md` → `docs/guide.md`
318
- - The path is normalized and joined with basePath
319
- - Result: `./workspace` + `docs/guide.md` → `./workspace/docs/guide.md`
320
+ - Relative paths are resolved against `basePath`: `docs/guide.md` → `<basePath>/docs/guide.md`
321
+ - Use `.` to refer to the root of `basePath`, for example `readdir('.')`
322
+ - Absolute paths are treated as host paths, not as paths inside `basePath`. With the default `contained: true`, any absolute path that falls outside `basePath` and the configured `allowedPaths` is rejected with a `PermissionError`
323
+ - `~` expands to the user's home directory, so it's also a host path and is subject to the same containment rules
320
324
 
321
325
  ```typescript
322
326
  const filesystem = new LocalFilesystem({
323
327
  basePath: './workspace',
324
328
  })
325
329
 
326
- // These all resolve to ./workspace/docs/guide.md
327
- await filesystem.readFile('/docs/guide.md')
330
+ // Resolves to ./workspace/docs/guide.md
328
331
  await filesystem.readFile('docs/guide.md')
332
+ await filesystem.readFile('./docs/guide.md')
333
+
334
+ // Root of basePath
335
+ await filesystem.readdir('.')
336
+
337
+ // Throws a PermissionError with the default contained: true
338
+ await filesystem.readFile('/docs/guide.md')
329
339
  ```
330
340
 
341
+ To read host absolute paths outside `basePath`, add them to `allowedPaths` or set `contained: false`. Prefer `allowedPaths` when only a few external directories are needed.
342
+
343
+ ```typescript
344
+ const filesystem = new LocalFilesystem({
345
+ basePath: './workspace',
346
+ allowedPaths: ['/home/user/shared-docs'],
347
+ })
348
+
349
+ await filesystem.readFile('/home/user/shared-docs/guide.md')
350
+ ```
351
+
352
+ ### Mounted filesystems
353
+
354
+ When a `LocalFilesystem` is mounted in a workspace through `CompositeFilesystem`, workspace-facing paths include the mount prefix. For example, with a mount at `/workspace`, the workspace path `/workspace/report.md` is passed to the underlying filesystem as `report.md`, relative to its `basePath`. See [Filesystem mounts](https://mastra.ai/docs/sandbox/filesystem) for mount configuration.
355
+
331
356
  ### Relative paths and execution context
332
357
 
333
358
  When you use a relative path for `basePath`, it resolves from `process.cwd()`. In Mastra projects, the cwd changes based on how you run your code:
@@ -360,6 +360,8 @@ console.log(result.exitCode)
360
360
 
361
361
  **processes** (`PlatformProcessManager`): Background process manager. See SandboxProcessManager reference.
362
362
 
363
+ **filesystem** (`PlatformSandboxFilesystem | undefined`): The sandbox's disk through E2B's files API, sent straight to the VM with the same lease executeCommand() uses. undefined when the sandbox isn't E2B-backed; use executeCommand() then. Paths are absolute and not confined to a root. Copies, appends, and no-overwrite writes run as one command in the VM. See Native filesystem.
364
+
363
365
  **templatePending** (`{ templateId: string; retryAfterMs: number } | undefined`): Set when the running sandbox booted from a fallback template (same-lineage stale or provider base) while the exact template continues to build in the background. Undefined when the sandbox booted from the exact template. Observability only — PlatformSandbox does not re-execute template operations; reconcile filesystem state in your own runtime setup.
364
366
 
365
367
  ## Methods
@@ -14,6 +14,8 @@ The `WorkspaceSandbox` interface defines how workspaces execute commands and man
14
14
 
15
15
  **computer** (`SandboxComputer`): Computer-use (desktop) capability. If not implemented, computer tools won't be available. See Computer capability.
16
16
 
17
+ **filesystem** (`WorkspaceFilesystem`): Direct access to the sandbox's disk through the provider's file API, one request per operation instead of a shell command. See Native filesystem.
18
+
17
19
  ## Methods
18
20
 
19
21
  ### `start()`
@@ -216,6 +218,20 @@ const instructions = sandbox.getInstructions?.()
216
218
 
217
219
  **Returns:** `string`
218
220
 
221
+ ## Native filesystem
222
+
223
+ Sandboxes whose provider has a file API expose it on the optional `filesystem` property. Reads, writes, and listings take one request each, where the same work through `executeCommand()` takes a command per step. Paths are absolute inside the sandbox.
224
+
225
+ The provider owns containment: `filesystem` doesn't confine paths or symlinks to a workspace root. Fall back to `executeCommand()` when the property is absent:
226
+
227
+ ```typescript
228
+ const pkg = sandbox.filesystem
229
+ ? await sandbox.filesystem.readFile('/workspace/app/package.json', { encoding: 'utf-8' })
230
+ : (await sandbox.executeCommand?.('cat', ['/workspace/app/package.json']))?.stdout
231
+ ```
232
+
233
+ `E2BSandbox` and `PlatformSandbox` implement `filesystem`. A `Workspace` doesn't use it automatically; pass it as the workspace `filesystem` or call it directly.
234
+
219
235
  ## Computer capability
220
236
 
221
237
  Sandboxes with a controllable desktop environment implement the optional `SandboxComputer` interface on the `computer` property. When present on a statically configured sandbox, the workspace tools factory registers the `mastra_workspace_computer_*` tools automatically. See [Computer-use tools](https://mastra.ai/docs/sandbox/computer).
@@ -471,18 +471,19 @@ A workspace provides tools to agents based on what's configured.
471
471
 
472
472
  Added when a filesystem is configured:
473
473
 
474
- | Tool | Description |
475
- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
476
- | `mastra_workspace_read_file` | Read file contents. Text files return as text (with optional line range). Images and PDFs return as native media parts the model can view directly. Other binaries return metadata only unless an explicit `encoding` is passed. |
477
- | `mastra_workspace_write_file` | Create or overwrite a file with new content. Creates parent directories automatically. |
478
- | `mastra_workspace_edit_file` | Edit an existing file by finding and replacing text. Useful for targeted changes without rewriting the entire file. |
479
- | `mastra_workspace_list_files` | List directory contents as a tree structure. Supports recursive listing with depth limits, glob patterns, and `.gitignore` filtering (enabled by default: every `.gitignore` applies relative to its own directory, and `node_modules` is skipped unless the listed path is inside it). |
480
- | `mastra_workspace_delete` | Delete a file or directory. Supports recursive deletion for directories. |
481
- | `mastra_workspace_file_stat` | Get metadata about a file or directory including size, type, and modification time. |
482
- | `mastra_workspace_mkdir` | Create a directory. Creates parent directories automatically if they don't exist. |
483
- | `mastra_workspace_grep` | Search file contents using regex patterns. Supports glob filtering, context lines, and case-insensitive search. Applies `.gitignore` files the same way as `list_files` and skips `node_modules` unless the search path is inside it. |
484
-
485
- With a static filesystem, write tools (`write_file`, `edit_file`, `delete`, `mkdir`) are excluded when the filesystem is in read-only mode. With a [runtime-defined filesystem](https://mastra.ai/docs/sandbox/filesystem), write tools are always included and read-only is enforced at runtime.
474
+ | Tool | Description |
475
+ | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
476
+ | `mastra_workspace_read_file` | Read file contents. Text files return as text (with optional line range). Images and PDFs return as native media parts the model can view directly. Other binaries return metadata only unless an explicit `encoding` is passed. |
477
+ | `mastra_workspace_write_file` | Create or overwrite a file with new content. Creates parent directories automatically. |
478
+ | `mastra_workspace_edit_file` | Edit an existing file by finding and replacing text. Useful for targeted changes without rewriting the entire file. |
479
+ | `mastra_workspace_list_files` | List directory contents as a tree structure. Supports recursive listing with depth limits, glob patterns, and `.gitignore` filtering (enabled by default: every `.gitignore` applies relative to its own directory, and `node_modules` is skipped unless the listed path is inside it). |
480
+ | `mastra_workspace_delete` | Delete a file or directory. Supports recursive deletion for directories. |
481
+ | `mastra_workspace_file_stat` | Get metadata about a file or directory including size, type, and modification time. |
482
+ | `mastra_workspace_mkdir` | Create a directory. Creates parent directories automatically if they don't exist. |
483
+ | `mastra_workspace_grep` | Search file contents using regex patterns. Supports glob filtering, context lines, and case-insensitive search. Applies `.gitignore` files the same way as `list_files` and skips `node_modules` unless the search path is inside it. |
484
+ | `mastra_workspace_apply_patch` | Create, update, move, and delete several files in one call using a patch. Opt-in: only added when `tools[WORKSPACE_TOOLS.FILESYSTEM.APPLY_PATCH].enabled` is set. The top-level `tools.enabled` doesn't enable it. The tool checks every hunk before it writes anything. If a hunk doesn't match, every file stays as it was. |
485
+
486
+ With a static filesystem, write tools (`write_file`, `edit_file`, `delete`, `mkdir`, `apply_patch`) are excluded when the filesystem is in read-only mode. With a [runtime-defined filesystem](https://mastra.ai/docs/sandbox/filesystem), write tools are always included and read-only is enforced at runtime.
486
487
 
487
488
  The `read_file` tool accepts `mediaTypes` and `maxMediaBytes` options to control which mime types are surfaced to the model as native media parts and how large those files can be:
488
489
 
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- import { n as runServer, t as createDocsServer } from "./src-Baf8l9Sp.js";
2
- export { createDocsServer, runServer };
1
+ export { t as createDocsServer, n as runServer } from "./src-DnH_jHt9.js";
@@ -3,8 +3,7 @@ import { MCPServer } from "@mastra/mcp";
3
3
  import { MCPServer as MCPServer$1 } from "@mastra/mcp-legacy";
4
4
  import * as fs$1 from "fs";
5
5
  import { existsSync, mkdirSync } from "fs";
6
- import * as os$1 from "os";
7
- import os from "os";
6
+ import os, * as os$1 from "os";
8
7
  import * as path$1 from "path";
9
8
  import path, { dirname } from "path";
10
9
  import { z } from "zod";
@@ -1856,4 +1855,4 @@ async function runServer() {
1856
1855
  //#endregion
1857
1856
  export { writeErrorLog as i, runServer as n, setLogLevel as r, createDocsServer as t };
1858
1857
 
1859
- //# sourceMappingURL=src-Baf8l9Sp.js.map
1858
+ //# sourceMappingURL=src-DnH_jHt9.js.map