@mastra/mcp 2.9.0-alpha.3 → 2.9.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ name: mastra-mcp
3
3
  description: Documentation for @mastra/mcp. Use when working with @mastra/mcp APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mcp"
6
- version: "2.9.0-alpha.3"
6
+ version: "2.9.0-alpha.5"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -19,6 +19,7 @@ Read the individual reference documents for detailed explanations and code examp
19
19
  - [Fine-Grained Authorization (FGA)](references/docs-auth-fga.md) - Configure Mastra Fine-Grained Authorization for resource-level permissions that map routes to actions and scope stored resources for enterprise users.
20
20
  - [MCP](references/docs-connections-mcp.md) - Connect Mastra agents to remote MCP servers, expose Mastra tools through MCPServer, manage approvals, subscribe to MCP events, and build interactive MCP Apps for Studio.
21
21
  - [MCP authentication and authorization](references/docs-guides-mcp-authentication-authorization.md) - Choose credentials for MCP connections, protect a Mastra MCP server, and separate delegated access from tool and data permissions.
22
+ - [Built-in MCP server](references/docs-server-mcp.md) - Let MCP clients such as Claude Code, Cursor, and the MCP Inspector call your agents, workflows, and tools through the built-in /api/mcp endpoint, with the same auth, RBAC, and FGA as the HTTP API.
22
23
 
23
24
  ### Reference
24
25
 
@@ -1,71 +1,71 @@
1
1
  {
2
- "version": "2.9.0-alpha.3",
2
+ "version": "2.9.0-alpha.5",
3
3
  "package": "@mastra/mcp",
4
4
  "exports": {
5
5
  "InMemoryMCPEventCursorStore": {
6
6
  "types": "dist/integrations/events-cursor-store.d.ts",
7
7
  "implementation": "dist/index.js",
8
- "line": 25452
8
+ "line": 25752
9
9
  },
10
10
  "InMemoryMCPTaskStore": {
11
11
  "types": "dist/server/tasks/in-memory-store.d.ts",
12
12
  "implementation": "dist/index.js",
13
- "line": 22227
13
+ "line": 22527
14
14
  },
15
15
  "InMemoryOAuthStorage": {
16
16
  "types": "dist/client/oauth-provider.d.ts",
17
17
  "implementation": "dist/index.js",
18
- "line": 17800
18
+ "line": 18100
19
19
  },
20
20
  "InMemoryWebhookSubscriptionStore": {
21
21
  "types": "dist/server/events/webhook-store.d.ts",
22
22
  "implementation": "dist/index.js",
23
- "line": 20597
23
+ "line": 20897
24
24
  },
25
25
  "InternalMastraMCPClient": {
26
26
  "types": "dist/client/client.d.ts",
27
27
  "implementation": "dist/index.js",
28
- "line": 16070
28
+ "line": 16370
29
29
  },
30
30
  "MCPClient": {
31
31
  "types": "dist/client/configuration.d.ts",
32
32
  "implementation": "dist/index.js",
33
- "line": 18293
33
+ "line": 18593
34
34
  },
35
35
  "MCPClientServerProxy": {
36
36
  "types": "dist/client/server-proxy.d.ts",
37
37
  "implementation": "dist/index.js",
38
- "line": 18141
38
+ "line": 18441
39
39
  },
40
40
  "MCPEventsSignalProvider": {
41
41
  "types": "dist/integrations/events-signals.d.ts",
42
42
  "implementation": "dist/index.js",
43
- "line": 25637
43
+ "line": 25937
44
44
  },
45
45
  "MCPOAuthClientProvider": {
46
46
  "types": "dist/client/oauth-provider.d.ts",
47
47
  "implementation": "dist/index.js",
48
- "line": 17852
48
+ "line": 18152
49
49
  },
50
50
  "MCPServer": {
51
51
  "types": "dist/server/server.d.ts",
52
52
  "implementation": "dist/index.js",
53
- "line": 23242
53
+ "line": 23542
54
54
  },
55
55
  "MCPTaskLimitError": {
56
56
  "types": "dist/server/tasks/store.d.ts",
57
57
  "implementation": "dist/index.js",
58
- "line": 21409
58
+ "line": 21709
59
59
  },
60
60
  "MCP_CALL_TOOL_CONTENT": {
61
61
  "types": "dist/client/client.d.ts",
62
62
  "implementation": "dist/index.js",
63
- "line": 15914
63
+ "line": 16214
64
64
  },
65
65
  "MCP_CALL_TOOL_META": {
66
66
  "types": "dist/client/client.d.ts",
67
67
  "implementation": "dist/index.js",
68
- "line": 15916
68
+ "line": 16216
69
69
  },
70
70
  "MCP_CLIENT_PROTOCOL_VERSION": {
71
71
  "types": "dist/client/types.d.ts",
@@ -75,122 +75,122 @@
75
75
  "MCP_DISCOVERY_TIMEOUT_CODE": {
76
76
  "types": "dist/client/configuration.d.ts",
77
77
  "implementation": "dist/index.js",
78
- "line": 18262
78
+ "line": 18562
79
79
  },
80
80
  "MCP_PROTOCOL_VERSION": {
81
81
  "types": "dist/server/types.d.ts",
82
82
  "implementation": "dist/index.js",
83
- "line": 25179
83
+ "line": 25479
84
84
  },
85
85
  "ServerEventActions": {
86
86
  "types": "dist/server/events/actions.d.ts",
87
87
  "implementation": "dist/index.js",
88
- "line": 19698
88
+ "line": 19998
89
89
  },
90
90
  "ServerPromptActions": {
91
91
  "types": "dist/server/actions.d.ts",
92
92
  "implementation": "dist/index.js",
93
- "line": 19678
93
+ "line": 19978
94
94
  },
95
95
  "ServerResourceActions": {
96
96
  "types": "dist/server/actions.d.ts",
97
97
  "implementation": "dist/index.js",
98
- "line": 19664
98
+ "line": 19964
99
99
  },
100
100
  "ServerToolActions": {
101
101
  "types": "dist/server/actions.d.ts",
102
102
  "implementation": "dist/index.js",
103
- "line": 19646
103
+ "line": 19946
104
104
  },
105
105
  "createIntrospectionValidator": {
106
106
  "types": "dist/server/oauth-middleware.d.ts",
107
107
  "implementation": "dist/index.js",
108
- "line": 25371
108
+ "line": 25671
109
109
  },
110
110
  "createOAuthCallbackServer": {
111
111
  "types": "dist/client/oauth-callback-server.d.ts",
112
112
  "implementation": "dist/index.js",
113
- "line": 17682
113
+ "line": 17982
114
114
  },
115
115
  "createOAuthMiddleware": {
116
116
  "types": "dist/server/oauth-middleware.d.ts",
117
117
  "implementation": "dist/index.js",
118
- "line": 25224
118
+ "line": 25524
119
119
  },
120
120
  "createSimpleTokenProvider": {
121
121
  "types": "dist/client/oauth-provider.d.ts",
122
122
  "implementation": "dist/index.js",
123
- "line": 18115
123
+ "line": 18415
124
124
  },
125
125
  "createStaticTokenValidator": {
126
126
  "types": "dist/server/oauth-middleware.d.ts",
127
127
  "implementation": "dist/index.js",
128
- "line": 25340
128
+ "line": 25640
129
129
  },
130
130
  "defineEvent": {
131
131
  "types": "dist/server/events/define-event.d.ts",
132
132
  "implementation": "dist/index.js",
133
- "line": 25442
133
+ "line": 25742
134
134
  },
135
135
  "extractBearerToken": {
136
136
  "types": "dist/shared/oauth-types.d.ts",
137
137
  "implementation": "dist/index.js",
138
- "line": 13220
138
+ "line": 13520
139
139
  },
140
140
  "generateProtectedResourceMetadata": {
141
141
  "types": "dist/shared/oauth-types.d.ts",
142
142
  "implementation": "dist/index.js",
143
- "line": 13204
143
+ "line": 13504
144
144
  },
145
145
  "generateWWWAuthenticateHeader": {
146
146
  "types": "dist/shared/oauth-types.d.ts",
147
147
  "implementation": "dist/index.js",
148
- "line": 13189
148
+ "line": 13489
149
149
  },
150
150
  "getCallbackUrlCandidates": {
151
151
  "types": "dist/client/oauth-callback-server.d.ts",
152
152
  "implementation": "dist/index.js",
153
- "line": 17615
153
+ "line": 17915
154
154
  },
155
155
  "getMcpCallToolContent": {
156
156
  "types": "dist/client/client.d.ts",
157
157
  "implementation": "dist/index.js",
158
- "line": 15936
158
+ "line": 16236
159
159
  },
160
160
  "getMcpCallToolMeta": {
161
161
  "types": "dist/client/client.d.ts",
162
162
  "implementation": "dist/index.js",
163
- "line": 15945
163
+ "line": 16245
164
164
  },
165
165
  "isMCPTaskStoreAdmin": {
166
166
  "types": "dist/server/tasks/store.d.ts",
167
167
  "implementation": "dist/index.js",
168
- "line": 21460
168
+ "line": 21760
169
169
  },
170
170
  "isWorkflowTaskContext": {
171
171
  "types": "dist/server/tasks/workflow-runs.d.ts",
172
172
  "implementation": "dist/index.js",
173
- "line": 23000
173
+ "line": 23300
174
174
  },
175
175
  "principalKeyOf": {
176
176
  "types": "dist/server/tasks/store.d.ts",
177
177
  "implementation": "dist/index.js",
178
- "line": 21401
178
+ "line": 21701
179
179
  },
180
180
  "taskKeyOf": {
181
181
  "types": "dist/shared/tasks/task-id.d.ts",
182
182
  "implementation": "dist/index.js",
183
- "line": 13384
183
+ "line": 13684
184
184
  },
185
185
  "traceContextFromMeta": {
186
186
  "types": "dist/shared/trace-context.d.ts",
187
187
  "implementation": "dist/index.js",
188
- "line": 13406
188
+ "line": 13706
189
189
  },
190
190
  "traceContextToMeta": {
191
191
  "types": "dist/shared/trace-context.d.ts",
192
192
  "implementation": "dist/index.js",
193
- "line": 13418
193
+ "line": 13718
194
194
  }
195
195
  },
196
196
  "modules": {}
@@ -200,6 +200,8 @@ export async function handleRequest(prompt: string, apiKey: string) {
200
200
 
201
201
  Visit [`listTools()`](https://mastra.ai/reference/tools/mcp-client) and [`listToolsets()`](https://mastra.ai/reference/tools/mcp-client) for their full APIs.
202
202
 
203
+ This example finishes within one request. When agent work must continue after the request ends or survive a process restart, use [durable agents](https://mastra.ai/docs/harness/durable-agents) or [background tasks](https://mastra.ai/docs/harness/background-tasks) instead of building your own task tracking. Call-time `toolsets` can't move to another process, so with a durable agent, load per-request MCP tools in the agent's `tools` function from [request context](https://mastra.ai/docs/server/request-context).
204
+
203
205
  ### Tool approval
204
206
 
205
207
  Set `requireToolApproval` on a server to require approval for all its tools:
@@ -287,6 +289,8 @@ A tool that needs something from the user before it can finish calls `context.su
287
289
 
288
290
  Visit the [`MCPServer` reference](https://mastra.ai/reference/tools/mcp-server) for prompts, resources, transports, and other server options.
289
291
 
292
+ To expose every agent, workflow, and tool on your Mastra app without defining a server, use the [built-in MCP server](https://mastra.ai/docs/server/mcp) at `/api/mcp`.
293
+
290
294
  ### Publish a stdio server package
291
295
 
292
296
  Package a server that uses the standard input/output (stdio) transport when you want clients to run it locally through a command such as `npx`. Create a separate executable entry point that starts the server:
@@ -444,71 +448,6 @@ export const mastra = new Mastra({
444
448
 
445
449
  Tools loaded through `listTools()` include a `serverId` in `_meta.ui`, allowing Studio to resolve each app resource without scanning every server. Visit [`toMCPServerProxies()`](https://mastra.ai/reference/tools/mcp-client) for proxy configuration details.
446
450
 
447
- ### Use prebuilt Mastra apps
448
-
449
- The `@mastra/mcp-apps-components` package includes prebuilt MCP Apps. Each one is a self-contained HTML page that you register as an app resource, next to the tools it talks to.
450
-
451
- **npm**:
452
-
453
- ```bash
454
- npm install @mastra/mcp-apps-components
455
- ```
456
-
457
- **pnpm**:
458
-
459
- ```bash
460
- pnpm add @mastra/mcp-apps-components
461
- ```
462
-
463
- **Yarn**:
464
-
465
- ```bash
466
- yarn add @mastra/mcp-apps-components
467
- ```
468
-
469
- **Bun**:
470
-
471
- ```bash
472
- bun add @mastra/mcp-apps-components
473
- ```
474
-
475
- `greetingApp` greets someone by name. The host sends it the arguments of the tool that opened it, and the app reads `name`. It then calls the `getGreeting` tool on the same server for its data and shows the `greeting` from the result. Mark `getGreeting` as app-only with `visibility: ['app']`, so the model doesn't see it:
476
-
477
- ```typescript
478
- import { createTool } from '@mastra/core/tools'
479
- import { MCPServer } from '@mastra/mcp'
480
- import { greetingApp } from '@mastra/mcp-apps-components'
481
- import { z } from 'zod'
482
-
483
- const uri = 'ui://mastra/greeting'
484
-
485
- export const greetingServer = new MCPServer({
486
- id: 'greeting-server',
487
- name: 'Greeting Server',
488
- version: '1.0.0',
489
- appResources: { [uri]: greetingApp },
490
- tools: {
491
- showGreeting: createTool({
492
- id: 'showGreeting',
493
- description: 'Shows a greeting card for someone',
494
- inputSchema: z.object({ name: z.string() }),
495
- mcp: { _meta: { ui: { resourceUri: uri } } },
496
- execute: async ({ name }) => ({ name }),
497
- }),
498
- getGreeting: createTool({
499
- id: 'getGreeting',
500
- description: 'Returns the greeting for a name',
501
- inputSchema: z.object({ name: z.string() }),
502
- outputSchema: z.object({ greeting: z.string() }),
503
- mcp: { _meta: { ui: { resourceUri: uri, visibility: ['app'] } } },
504
- execute: async ({ name }) => ({ greeting: `Hello, ${name}!` }),
505
- }),
506
- },
507
- })
508
- ```
509
-
510
- `getGreeting` runs on your server, so it can call any API with your server's credentials. The app's iframe has no network access of its own.
511
-
512
451
  ### Sandbox security
513
452
 
514
453
  Mastra Studio uses [`@mcp-ui/client`](https://www.npmjs.com/package/@mcp-ui/client) to load app HTML through a sandbox proxy and communicate over JSON-RPC with `postMessage`.