@mastra/mcp 2.5.0 → 2.6.0-alpha.0

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 (40) hide show
  1. package/dist/cli/generate-K-rW1Wck.js +219 -0
  2. package/dist/cli/generate-K-rW1Wck.js.map +1 -0
  3. package/dist/cli/generate.d.ts +18 -0
  4. package/dist/cli/generate.d.ts.map +1 -0
  5. package/dist/cli/index.d.ts +3 -0
  6. package/dist/cli/index.d.ts.map +1 -0
  7. package/dist/cli/index.js +33 -0
  8. package/dist/cli/index.js.map +1 -0
  9. package/dist/cli/json-schema-dialect-B5B7l9Po.js +133 -0
  10. package/dist/cli/json-schema-dialect-B5B7l9Po.js.map +1 -0
  11. package/dist/cli/typegen-CLDjVF16.js +364 -0
  12. package/dist/cli/typegen-CLDjVF16.js.map +1 -0
  13. package/dist/cli/typegen.d.ts +14 -0
  14. package/dist/cli/typegen.d.ts.map +1 -0
  15. package/dist/client/client.d.ts +2 -1
  16. package/dist/client/client.d.ts.map +1 -1
  17. package/dist/client/configuration.d.ts +30 -10
  18. package/dist/client/configuration.d.ts.map +1 -1
  19. package/dist/client/index.d.ts +1 -1
  20. package/dist/client/index.d.ts.map +1 -1
  21. package/dist/client/types.d.ts +38 -1
  22. package/dist/client/types.d.ts.map +1 -1
  23. package/dist/docs/SKILL.md +2 -3
  24. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  25. package/dist/docs/references/docs-connections-mcp.md +159 -50
  26. package/dist/docs/references/docs-connections-overview.md +1 -1
  27. package/dist/docs/references/docs-guides-mcp-authentication-authorization.md +2 -2
  28. package/dist/docs/references/reference-migrations-mcp-v2.md +1 -1
  29. package/dist/docs/references/reference-tools-mcp-client.md +202 -11
  30. package/dist/docs/references/reference-tools-mcp-server.md +5 -3
  31. package/dist/index.cjs +116 -121
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.js +116 -121
  34. package/dist/index.js.map +1 -1
  35. package/dist/server/server.d.ts +13 -1
  36. package/dist/server/server.d.ts.map +1 -1
  37. package/dist/shared/json-schema-dialect.d.ts +34 -0
  38. package/dist/shared/json-schema-dialect.d.ts.map +1 -1
  39. package/package.json +18 -13
  40. package/dist/docs/references/docs-guides-mcp-events.md +0 -306
@@ -17,7 +17,9 @@ constructor({
17
17
  id?: string;
18
18
  servers: Record<string, MastraMCPServerDefinition>;
19
19
  timeout?: number;
20
+ typegen?: { outFile: string };
20
21
  clientInfo?: { name?: string; version?: string };
22
+ registerProcessHooks?: boolean;
21
23
  }: MCPClientOptions)
22
24
  ```
23
25
 
@@ -29,10 +31,174 @@ constructor({
29
31
 
30
32
  **timeout** (`number`): Global timeout value in milliseconds for all servers unless overridden in individual server configs. (Default: `60000`)
31
33
 
34
+ **typegen** (`{ outFile: string }`): Enables optional CLI generation for this client. outFile must be a nonempty path, resolved from the command working directory. Construction stores readonly metadata and does not generate files.
35
+
32
36
  **clientInfo** (`{ name?: string; version?: string }`): Client name and version every server receives on connect and with each request, so servers can attribute traffic to your application. Defaults to the server key as name and '1.0.0' as version. Individual server configs can override either field with their own clientInfo. Doesn't change tool name prefixes, which always use the server key.
33
37
 
38
+ **registerProcessHooks** (`boolean`): Install process exit and signal hooks that disconnect servers and end the process. Set to false when your application handles shutdown, and call disconnect() from that handler. See Handle shutdown yourself. (Default: `true`)
39
+
34
40
  **webhook** (`MCPClientWebhookOptions`): Experimental. Enables webhook delivery for MCP events. Servers POST occurrences to webhook.url, which must route to events.handleWebhook().
35
41
 
42
+ ### Typed client contracts
43
+
44
+ Pass an explicit server-map type to `MCPClient<TServers>` to check configured server names, discovered tool names, and direct-call arguments. `MCPClientOptions<TServers>` accepts the same map. All declared servers are required. Use `Pick<TServers, 'weather'>` to configure a subset. Without a type argument, discovery keeps its existing broad types.
45
+
46
+ The map describes each server's `tools`, with `input` and `output` types for each tool. This example assumes a running weather server at `WEATHER_MCP_URL`:
47
+
48
+ ```typescript
49
+ import { MCPClient } from '@mastra/mcp'
50
+
51
+ interface MCPServers {
52
+ weather: {
53
+ tools: {
54
+ get_weather: {
55
+ input: { location: string }
56
+ output: { temperature: number; conditions: string }
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ const mcp = new MCPClient<MCPServers>({
63
+ servers: { weather: { url: new URL(process.env.WEATHER_MCP_URL!) } },
64
+ })
65
+
66
+ try {
67
+ const tools = await mcp.listTools()
68
+ const weather = tools.weather_get_weather
69
+ if (weather?.execute) {
70
+ const result = await weather.execute({ location: 'Paris' })
71
+ if (result && 'temperature' in result && typeof result.temperature === 'number') {
72
+ console.log(result.temperature)
73
+ }
74
+ }
75
+ } finally {
76
+ await mcp.disconnect()
77
+ }
78
+ ```
79
+
80
+ `listTools()` and `listToolsWithErrors().tools` expose exact `server_tool` keys. `listToolsets()` and `listToolsetsWithErrors().toolsets` expose server keys containing raw tool names. Both forms are partial: a server or tool can be absent. Check availability before calling a tool. Error maps, error details, and optional discovery durations keep their existing types.
81
+
82
+ Execution can return the structured output, a protocol result envelope, a validation error, or `undefined`. Check the shape and property types before reading success fields. Protocol envelopes can have additional properties. Set `output: unknown` for tools without an output schema.
83
+
84
+ These contracts describe a schema snapshot. Live servers can differ from that snapshot. Update them when server schemas change, using equivalent permissions. Extra live tools remain available at runtime but aren't included in the snapshot's known keys. Runtime discovery, validation, and execution are unchanged.
85
+
86
+ ### Generate client types
87
+
88
+ Generate concrete TypeScript interfaces from live tool input and output schemas with the command included in `@mastra/mcp`. Export your existing client and set `typegen.outFile`:
89
+
90
+ ```typescript
91
+ import { MCPClient } from '@mastra/mcp'
92
+ import type { MCPServers } from './mcp-types.generated'
93
+
94
+ export const mcp = new MCPClient<MCPServers>({
95
+ id: 'weather-client',
96
+ servers: { weather: { url: new URL(process.env.WEATHER_MCP_URL!) } },
97
+ typegen: { outFile: 'src/mcp/mcp-types.generated.ts' },
98
+ })
99
+ ```
100
+
101
+ Set the environment variables and authentication credentials your module needs, then run this command from your project root:
102
+
103
+ **npm**:
104
+
105
+ ```bash
106
+ npx @mastra/mcp generate ./src/mcp/client.ts
107
+ ```
108
+
109
+ **pnpm**:
110
+
111
+ ```bash
112
+ pnpm dlx @mastra/mcp generate ./src/mcp/client.ts
113
+ ```
114
+
115
+ **Yarn**:
116
+
117
+ ```bash
118
+ yarn dlx @mastra/mcp generate ./src/mcp/client.ts
119
+ ```
120
+
121
+ **Bun**:
122
+
123
+ ```bash
124
+ bun x @mastra/mcp generate ./src/mcp/client.ts
125
+ ```
126
+
127
+ The generated type-only import can be missing on the first run. The loader handles TypeScript and transitive imports without typechecking. Run your typecheck after generation.
128
+
129
+ Use the generated names and check runtime availability and result shape. This example assumes the server publishes `get_weather` with a required string `location` and a numeric `temperature` output:
130
+
131
+ ```typescript
132
+ import { mcp } from './client'
133
+
134
+ try {
135
+ const tools = await mcp.listTools()
136
+ const weather = tools.weather_get_weather
137
+ if (weather?.execute) {
138
+ const result = await weather.execute({ location: 'Paris' })
139
+ if (result && 'temperature' in result && typeof result.temperature === 'number') {
140
+ console.log(result.temperature)
141
+ }
142
+ }
143
+ } finally {
144
+ await mcp.disconnect()
145
+ }
146
+ ```
147
+
148
+ The command accepts one or more file paths. Both input files and `outFile` paths are relative to the command's working directory. It selects direct named and default exports of typegen-enabled clients. It doesn't scan your source tree, invoke factories, or inspect nested exported objects. Repeated files, symlink aliases, and exports of the same client are processed once. A file without an eligible client fails.
149
+
150
+ For independent clients with identical server configurations, use distinct IDs and output paths:
151
+
152
+ ```typescript
153
+ import { MCPClient } from '@mastra/mcp'
154
+
155
+ const servers = { weather: { url: new URL(process.env.WEATHER_MCP_URL!) } }
156
+ export const first = new MCPClient({
157
+ id: 'first',
158
+ servers,
159
+ typegen: { outFile: 'first.generated.ts' },
160
+ })
161
+ export const second = new MCPClient({
162
+ id: 'second',
163
+ servers,
164
+ typegen: { outFile: 'second.generated.ts' },
165
+ })
166
+ ```
167
+
168
+ **npm**:
169
+
170
+ ```bash
171
+ npx @mastra/mcp generate ./src/mcp/clients.ts
172
+ ```
173
+
174
+ **pnpm**:
175
+
176
+ ```bash
177
+ pnpm dlx @mastra/mcp generate ./src/mcp/clients.ts
178
+ ```
179
+
180
+ **Yarn**:
181
+
182
+ ```bash
183
+ yarn dlx @mastra/mcp generate ./src/mcp/clients.ts
184
+ ```
185
+
186
+ **Bun**:
187
+
188
+ ```bash
189
+ bun x @mastra/mcp generate ./src/mcp/clients.ts
190
+ ```
191
+
192
+ The existing instance cache still applies. Constructing a client with the same explicit ID, server configuration, and `typegen.outFile` returns the existing object. A different server configuration or `outFile` replaces the cached instance instead, so a later constructor never silently keeps an output file it wasn't given.
193
+
194
+ Generation lists tool definitions without calling tools. It fails on discovery errors, missing authentication, timeouts, output collisions, outputs that overwrite supplied input files, and schemas that can't be represented at all, such as reference cycles, excessive depth, or unresolved local references. Each failure names the client file, server, or tool it concerns. It prepares all sources before replacing files and disconnects selected clients on success or failure. Discovery and preflight failures preserve existing outputs. Each replacement is atomic, but multiple replacements aren't one transaction. A filesystem failure during replacement can leave earlier files updated.
195
+
196
+ Tools without output schemas use `unknown`. Constraints such as string formats, length limits, and numeric bounds retain their base TypeScript types and remain runtime validation rules. Unsupported schema portions, including conditional schemas and `prefixItems` tuples, widen to `unknown` with a warning. A keyword whose value is outside its allowed shape widens that schema to `unknown` with a warning too, so one unusable tool doesn't stop generation for other servers. Warnings name the server, tool, and schema position they concern. External schema references aren't fetched. Unresolved local references and reference cycles fail generation. Schemas nested deeper than 128 levels fail generation too, matching the protocol depth limit. A schema that exceeds the protocol node budget of 10,000 widens to `unknown` with a warning, as does any schema or catalogue that exceeds the larger budgets generation applies to raw JSON values. Generation measures those budgets before it copies or converts a schema, so a server that advertises large schemas can't stall the command.
197
+
198
+ > **Module execution and credentials:** The command executes the supplied modules and their imports. Use trusted modules without application startup side effects. Provide credentials before invoking the command. It doesn't load dotenv files or launch interactive authentication. Existing client timeout and discovery settings apply.
199
+ >
200
+ > Generator diagnostics omit raw schemas, transport errors, and credentials. Logs emitted by your imported application, custom log handlers, or server subprocesses remain outside that guarantee.
201
+
36
202
  ### `MastraMCPServerDefinition`
37
203
 
38
204
  Each server in the `servers` map is configured using the `MastraMCPServerDefinition` type. The transport type is detected based on the provided parameters:
@@ -765,9 +931,9 @@ Notes:
765
931
 
766
932
  ### `events` Property (experimental)
767
933
 
768
- The `events` property lists and subscribes to server events from servers that implement the [MCP Events extension (SEP-3415)](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/3415). Use it to react to things that happen on the server, such as a push to a repository, without polling a tool.
934
+ The `events` property lists and subscribes to server events from servers that implement the [MCP Events extension (SEP-3415)](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/3415). Use it to react to things that happen on the server, such as a push to a repository, without polling a tool. Delivery is at least once. After a reconnect or a resume, the server can resend an occurrence, and the client drops repeats by `eventId` within `dedupWindow` of recent ids.
769
935
 
770
- For an end-to-end walkthrough, see the [MCP events guide](https://mastra.ai/docs/guides/mcp-events).
936
+ For an end-to-end walkthrough, see [MCP events](https://mastra.ai/docs/connections/mcp).
771
937
 
772
938
  > **Warning:** SEP-3415 is a draft. This API may change in any release.
773
939
 
@@ -802,7 +968,7 @@ The client doesn't receive notifications when the server's event list changes ye
802
968
 
803
969
  #### `events.subscribe(serverName, eventName, args?, options?)`
804
970
 
805
- Starts a subscription and resolves once the server confirms it. Errors such as an unknown event, invalid arguments, or a forbidden subscription reject the returned promise.
971
+ Starts a subscription and resolves once the server confirms it. Errors such as an unknown event, invalid arguments, or a forbidden subscription reject the returned promise. A new subscription starts at the point the server accepts it, so occurrences from before that point are not delivered unless `options.cursor` resumes from an earlier position. Under webhook delivery the promise can resolve after that point: the client answers `503` for a delivery it can't route yet, and the server retries it.
806
972
 
807
973
  ```typescript
808
974
  async subscribe(
@@ -860,7 +1026,7 @@ It verifies the Standard Webhooks signature on the raw body before parsing it, a
860
1026
 
861
1027
  - `200` after the occurrence is handed to its subscription, or with the echoed challenge for a verification request.
862
1028
  - `401` when the signature is invalid or the timestamp is more than 5 minutes old.
863
- - `503` when the subscription id isn't known yet, so the server retries. This covers deliveries that arrive before the subscribe response.
1029
+ - `503` when the subscription id isn't known yet. The server retries in that case, covering deliveries that arrive before the subscribe response.
864
1030
  - `400` for a signed but malformed body, and `405` for methods other than `POST`.
865
1031
  - `413` for a body over 1 MiB. The body is read only up to that limit, before any other check.
866
1032
  - `404` when the client has no `webhook` settings.
@@ -906,11 +1072,11 @@ export const mastra = new Mastra({
906
1072
 
907
1073
  **refreshMarginMs** (`number`): How long before the server-granted refreshBefore time to refresh the subscription. Defaults to the smaller of 60 seconds and 20% of the grant.
908
1074
 
909
- The client refreshes each subscription before it expires by repeating `events/subscribe` with the latest cursor. When the server reports failing delivery in `deliveryStatus`, for example because your endpoint timed out, `onError` receives `MCP_EVENTS_WEBHOOK_DELIVERY_FAILING` with `lastError` in its details. The next refresh resumes a suspended subscription. `cancel()` sends `events/unsubscribe`.
1075
+ The client refreshes each subscription before it expires by repeating `events/subscribe` with the latest cursor. When the server reports failing delivery in `deliveryStatus`, for example because your endpoint timed out, `onError` receives `MCP_EVENTS_WEBHOOK_DELIVERY_FAILING` with `lastError` in its details. The `cursor` in each webhook delivery only covers occurrences your endpoint has acknowledged, so resuming from a saved cursor can deliver the last handled occurrence again. The next refresh resumes a suspended subscription. `cancel()` sends `events/unsubscribe`.
910
1076
 
911
1077
  Webhook state lives in this process: run the receiving route in the same process as the `MCPClient` that subscribed.
912
1078
 
913
- Webhook delivery needs an authenticated HTTP connection to the server, because the server ties each webhook subscription to the caller. Over stdio, or over HTTP without authentication, the server rejects `events/subscribe`; it also rejects new subscriptions once its webhook subscription cap is reached (`-32025`). A subscription that didn't force a mode then falls back to `push` or `poll`, and the first `onError` handler receives `MCP_EVENTS_WEBHOOK_UNAVAILABLE` with the rejection `code` and the `fallback` mode in its details. Forcing `delivery: 'webhook'` rejects instead.
1079
+ Webhook delivery needs an authenticated HTTP connection to the server, because the server ties each webhook subscription to the caller. Over stdio, or over HTTP without authentication, the server rejects `events/subscribe`. It also rejects new subscriptions once its webhook subscription cap is reached (`-32025`). A subscription that didn't force a mode then falls back to `push` or `poll`, and the first `onError` handler receives `MCP_EVENTS_WEBHOOK_UNAVAILABLE` with the rejection `code` and the `fallback` mode in its details. Forcing `delivery: 'webhook'` rejects instead.
914
1080
 
915
1081
  Subscriptions on one server with the same event name and arguments share a single server-side webhook subscription. Each one gets every occurrence through its own iterator, and the client sends `events/unsubscribe` only when the last of them is cancelled.
916
1082
 
@@ -937,7 +1103,7 @@ export const repoAgent = new Agent({
937
1103
  id: 'repo-agent',
938
1104
  name: 'Repo Agent',
939
1105
  instructions: 'Triage repository activity.',
940
- model: 'openai/gpt-5.6-sol',
1106
+ model: 'openai/gpt-6.1-sol',
941
1107
  signals: [repoEvents],
942
1108
  })
943
1109
 
@@ -947,7 +1113,7 @@ await repoEvents.subscribeThread(
947
1113
  )
948
1114
  ```
949
1115
 
950
- Threads that subscribe to the same server, event and arguments share one MCP subscription. Argument key order doesn't matter. Each occurrence becomes a notification with `kind: 'mcp-event'` and `attributes: { server, event }`. The raw occurrence is in `payload`. The notification `summary`, which is the only part the model reads, labels the event as untrusted and wraps its data, together with the server-advertised event name, in an `<untrusted-mcp-event-data>` block that the content can't close. When the server reports a gap, `attributes.truncated` is `true` and the summary says that events may have been skipped.
1116
+ Threads that subscribe to the same server, event and arguments share one MCP subscription regardless of argument key order. Each occurrence becomes a notification with `kind: 'mcp-event'` and `attributes: { server, event }`. The raw occurrence is in `payload`. The notification `summary`, which is the only part the model reads, labels the event as untrusted and wraps its data, together with the server-advertised event name, in an `<untrusted-mcp-event-data>` block that the content can't close. When the server reports a gap, `attributes.truncated` is `true` and the summary says that events may have been skipped.
951
1117
 
952
1118
  If the subscription ends, for example because the server terminates it, each subscribed thread receives a `high` priority notification with `kind: 'mcp-event-subscription-ended'` and the threads are unsubscribed.
953
1119
 
@@ -1234,7 +1400,7 @@ const client = new MCPClient({
1234
1400
 
1235
1401
  ### Custom Token Storage
1236
1402
 
1237
- For persistent token storage across sessions, implement the `OAuthStorage` interface. The provider stores tokens (both the latest set and one entry per authorization-server issuer), discovery state, and the PKCE verifier under string keys, so the backend only needs a key-value contract:
1403
+ For persistent token storage across sessions, implement the `OAuthStorage` interface. The provider stores tokens (both the latest set and one entry per authorization-server issuer), discovery state, and the PKCE verifier under string keys. The backend only needs a key-value contract:
1238
1404
 
1239
1405
  ```typescript
1240
1406
  import { MCPOAuthClientProvider, OAuthStorage } from '@mastra/mcp'
@@ -1310,7 +1476,7 @@ const agent = new Agent({
1310
1476
  id: 'multi-tool-agent',
1311
1477
  name: 'Multi-tool Agent',
1312
1478
  instructions: 'You have access to multiple tool servers.',
1313
- model: 'openai/gpt-5.6-sol',
1479
+ model: 'openai/gpt-6.1-sol',
1314
1480
  tools: await mcp.listTools(),
1315
1481
  })
1316
1482
 
@@ -1361,7 +1527,7 @@ const agent = new Agent({
1361
1527
  id: 'multi-tool-agent',
1362
1528
  name: 'Multi-tool Agent',
1363
1529
  instructions: 'You help users check stocks and weather.',
1364
- model: 'openai/gpt-5.6-sol',
1530
+ model: 'openai/gpt-6.1-sol',
1365
1531
  })
1366
1532
 
1367
1533
  // Later, configure MCP with user-specific settings
@@ -1436,6 +1602,31 @@ MCPClient handles server connections gracefully:
1436
1602
  2. Graceful server shutdown to prevent error messages during development
1437
1603
  3. Proper cleanup of resources when disconnecting
1438
1604
 
1605
+ ### Handle shutdown yourself
1606
+
1607
+ By default, a connected client installs hooks for `SIGINT`, `SIGTERM`, `SIGHUP`, and `beforeExit` that disconnect its servers and end the process. These hooks can interrupt your application's awaited cleanup, such as draining HTTP requests.
1608
+
1609
+ Set `registerProcessHooks: false` to let your application own shutdown. Call `disconnect()` after requests that use the client have finished:
1610
+
1611
+ ```typescript
1612
+ import { MCPClient } from '@mastra/mcp'
1613
+
1614
+ const mcp = new MCPClient({
1615
+ servers: { weather: { url: new URL('https://example.com/mcp') } },
1616
+ registerProcessHooks: false,
1617
+ })
1618
+
1619
+ process.once('SIGTERM', async () => {
1620
+ // Finish your application's cleanup before disconnecting the client.
1621
+ await mcp.disconnect()
1622
+ process.exit(0)
1623
+ })
1624
+ ```
1625
+
1626
+ Set the option on every `MCPClient` in the process before connecting. Once any client registers the default hooks, the global `SIGINT` and `SIGTERM` listeners remain until the process exits, even after `disconnect()`.
1627
+
1628
+ With hooks disabled, your application is responsible for closing MCP connections. In a Mastra server, coordinate `disconnect()` with your server's shutdown lifecycle so in-flight requests can finish using the client.
1629
+
1439
1630
  ## Using custom fetch for runtime-defined authentication
1440
1631
 
1441
1632
  For HTTP servers, you can provide a custom `fetch` function to handle runtime-defined authentication or request interception. It can also handle other custom behavior. This is particularly useful when you need to refresh tokens on each request or forward user credentials from the incoming request to the MCP server.
@@ -28,7 +28,7 @@ const myAgent = new Agent({
28
28
  name: 'MyExampleAgent',
29
29
  description: 'A generalist to help with basic questions.',
30
30
  instructions: 'You are a helpful assistant.',
31
- model: 'openai/gpt-5.6-sol',
31
+ model: 'openai/gpt-6.1-sol',
32
32
  })
33
33
 
34
34
  const weatherTool = createTool({
@@ -93,6 +93,8 @@ The constructor accepts an `MCPServerConfig` object with the following propertie
93
93
 
94
94
  **cacheHints** (`MCPServerCacheHints`): Cache hints (ttlMs / cacheScope) advertised on cacheable results, keyed by operation: 'tools/list', 'prompts/list', 'resources/list', 'resources/templates/list', 'resources/read' and 'server/discover'.
95
95
 
96
+ **legacy** (`'reject' | 'stateless'`): How HTTP requests from 2025-era clients (those that open with initialize, such as VS Code and Cursor) are served. 'reject' (default) answers them with an unsupported-protocol-version error. 'stateless' answers each request without a session: listing and calling tools, reading resources and getting prompts work, GET and DELETE session requests get 405, and features that need 2026-07-28 (suspend/resume, subscriptions/listen, events) aren't available to these clients.
97
+
96
98
  **jsonSchemaValidator** (`jsonSchemaValidator`): Custom JSON Schema validator used for tool input, output and continuation answers, for runtimes where the SDK default is unavailable.
97
99
 
98
100
  **repository** (`Repository`): Optional repository information for the server's source code.
@@ -1418,7 +1420,7 @@ Link a tool to its app resource by setting `mcp._meta.ui.resourceUri` in `create
1418
1420
 
1419
1421
  > **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
1422
 
1421
- For an end-to-end walkthrough, see the [MCP events guide](https://mastra.ai/docs/guides/mcp-events).
1423
+ For an end-to-end walkthrough, see [MCP events](https://mastra.ai/docs/connections/mcp).
1422
1424
 
1423
1425
  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
1426
 
@@ -1476,7 +1478,7 @@ const ticketCreated = defineEvent({
1476
1478
 
1477
1479
  **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
1480
 
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.
1481
+ **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); when cursor is null, resolve the starting position once, and return the id of the last occurrence, or that starting position when the result is empty; 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
1482
 
1481
1483
  **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
1484