@mastra/mcp 1.15.1 → 1.16.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.
- package/CHANGELOG.md +59 -0
- package/dist/client/actions/elicitation.d.ts +1 -1
- package/dist/client/actions/elicitation.d.ts.map +1 -1
- package/dist/client/actions/progress.d.ts +1 -1
- package/dist/client/actions/progress.d.ts.map +1 -1
- package/dist/client/actions/prompt.d.ts +1 -1
- package/dist/client/actions/prompt.d.ts.map +1 -1
- package/dist/client/actions/resource.d.ts +38 -11
- package/dist/client/actions/resource.d.ts.map +1 -1
- package/dist/client/client.d.ts +3 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +50 -14
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/types.d.ts +65 -10
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/url-policy.d.ts +67 -0
- package/dist/client/url-policy.d.ts.map +1 -0
- package/dist/docs/SKILL.md +3 -3
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-connections-overview.md +94 -0
- package/dist/docs/references/docs-mcp-overview.md +229 -278
- package/dist/docs/references/reference-tools-mcp-client.md +54 -0
- package/dist/docs/references/reference-tools-mcp-server.md +1 -1
- package/dist/index.cjs +2435 -275
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2403 -243
- package/dist/index.js.map +1 -1
- package/dist/server/__tests__/mock-extra.d.ts +15 -0
- package/dist/server/__tests__/mock-extra.d.ts.map +1 -0
- package/dist/server/notificationBroadcast.d.ts +1 -1
- package/dist/server/notificationBroadcast.d.ts.map +1 -1
- package/dist/server/promptActions.d.ts +1 -1
- package/dist/server/promptActions.d.ts.map +1 -1
- package/dist/server/resourceActions.d.ts +1 -1
- package/dist/server/resourceActions.d.ts.map +1 -1
- package/dist/server/server.d.ts +10 -12
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/toolActions.d.ts +1 -1
- package/dist/server/toolActions.d.ts.map +1 -1
- package/dist/server/types.d.ts +7 -7
- package/dist/server/types.d.ts.map +1 -1
- package/dist/shared/oauth-types.d.ts +8 -6
- package/dist/shared/oauth-types.d.ts.map +1 -1
- package/package.json +18 -14
- package/dist/docs/references/docs-mcp-mcp-apps.md +0 -306
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MCPRequestHandlerExtra } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Builds a ServerContext-shaped `extra` for invoking SDK request handlers
|
|
4
|
+
* directly in tests. The MCP 2.0 SDK wraps tools/call, prompts/get and
|
|
5
|
+
* resources/read handlers with a seam that reads `ctx.mcpReq` (e.g.
|
|
6
|
+
* `requestState()`), so handler mocks must carry a real `mcpReq` envelope.
|
|
7
|
+
* The flattened fields mirror what `toMCPRequestHandlerExtra` derives so
|
|
8
|
+
* test assertions can keep referencing the mock object directly.
|
|
9
|
+
*/
|
|
10
|
+
export declare const makeMockExtra: ({ sessionId, authInfo, requestId, }?: {
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
authInfo?: Record<string, unknown>;
|
|
13
|
+
requestId?: string;
|
|
14
|
+
}) => MCPRequestHandlerExtra;
|
|
15
|
+
//# sourceMappingURL=mock-extra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-extra.d.ts","sourceRoot":"","sources":["../../../src/server/__tests__/mock-extra.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAI,sCAI3B;IACD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACf,KAAG,sBAmBR,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IMastraLogger } from '@mastra/core/logger';
|
|
2
|
-
import type { Server } from '@modelcontextprotocol/
|
|
2
|
+
import type { Server } from '@modelcontextprotocol/server';
|
|
3
3
|
/**
|
|
4
4
|
* Sends a notification to every active server instance (the main stdio/SSE
|
|
5
5
|
* instance plus each streamable HTTP session instance).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notificationBroadcast.d.ts","sourceRoot":"","sources":["../../src/server/notificationBroadcast.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"notificationBroadcast.d.ts","sourceRoot":"","sources":["../../src/server/notificationBroadcast.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAE3D;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,OAAO,EACP,IAAI,EACJ,MAAM,EACN,OAAO,EACP,SAAS,EACT,YAAY,GACb,EAAE;IACD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;CAChD,GAAG,OAAO,CAAC,IAAI,CAAC,CAgChB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IMastraLogger } from '@mastra/core/logger';
|
|
2
|
-
import type { Server } from '@modelcontextprotocol/
|
|
2
|
+
import type { Server } from '@modelcontextprotocol/server';
|
|
3
3
|
interface ServerPromptActionsDependencies {
|
|
4
4
|
getLogger: () => IMastraLogger;
|
|
5
5
|
getSdkServers: () => Server[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promptActions.d.ts","sourceRoot":"","sources":["../../src/server/promptActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"promptActions.d.ts","sourceRoot":"","sources":["../../src/server/promptActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAG3D,UAAU,+BAA+B;IACvC,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAC/C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAa;IAEjD;;OAEG;gBACS,YAAY,EAAE,+BAA+B;IAMzD;;;;;;;;;;;;;OAaG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAWhD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IMastraLogger } from '@mastra/core/logger';
|
|
2
|
-
import type { Server } from '@modelcontextprotocol/
|
|
2
|
+
import type { Server } from '@modelcontextprotocol/server';
|
|
3
3
|
interface ServerResourceActionsDependencies {
|
|
4
4
|
getSubscribedServers: (uri: string) => Server[];
|
|
5
5
|
getLogger: () => IMastraLogger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceActions.d.ts","sourceRoot":"","sources":["../../src/server/resourceActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"resourceActions.d.ts","sourceRoot":"","sources":["../../src/server/resourceActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAG3D,UAAU,iCAAiC;IACzC,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IAChD,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA4B;IACjE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAE/C;;OAEG;gBACS,YAAY,EAAE,iCAAiC;IAM3D;;;;;;;;;;;;;;;;OAgBG;IACU,aAAa,CAAC,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBnE;;;;;;;;;;;;;;OAcG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAUhD"}
|
package/dist/server/server.d.ts
CHANGED
|
@@ -5,12 +5,11 @@ import type { MCPServerConfig, ServerInfo, ServerDetailInfo, MCPServerHonoSSEOpt
|
|
|
5
5
|
import { RequestContext } from '@mastra/core/request-context';
|
|
6
6
|
import type { InternalCoreTool, MCPToolType } from '@mastra/core/tools';
|
|
7
7
|
import type { Workflow } from '@mastra/core/workflows';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import type { jsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/types.js';
|
|
8
|
+
import type { StreamableHTTPServerTransportOptions } from '@modelcontextprotocol/node';
|
|
9
|
+
import { Server } from '@modelcontextprotocol/server';
|
|
10
|
+
import type { Resource, LoggingLevel, jsonSchemaValidator } from '@modelcontextprotocol/server';
|
|
11
|
+
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
12
|
+
import { SSEServerTransport } from '@modelcontextprotocol/server-legacy/sse';
|
|
14
13
|
import type { SSEStreamingApi } from '../_types/hono/dist/types/helper/streaming/index.d.ts';
|
|
15
14
|
import { SSETransport } from '../_types/hono-mcp-server-sse-transport/build/index.d.ts';
|
|
16
15
|
import { ServerPromptActions } from './promptActions.js';
|
|
@@ -147,11 +146,11 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
147
146
|
*/
|
|
148
147
|
getSseHonoTransport(sessionId: string): SSETransport | undefined;
|
|
149
148
|
/**
|
|
150
|
-
* Gets the underlying MCP
|
|
149
|
+
* Gets the underlying MCP Server instance.
|
|
151
150
|
*
|
|
152
151
|
* This provides access to the low-level server instance for advanced use cases.
|
|
153
152
|
*
|
|
154
|
-
* @returns The Server instance from @modelcontextprotocol/
|
|
153
|
+
* @returns The Server instance from @modelcontextprotocol/server
|
|
155
154
|
*/
|
|
156
155
|
getServer(): Server;
|
|
157
156
|
/**
|
|
@@ -231,11 +230,10 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
231
230
|
appResources?: AppResources;
|
|
232
231
|
/**
|
|
233
232
|
* Optional custom JSON Schema validator forwarded to the underlying MCP
|
|
234
|
-
*
|
|
235
|
-
* implementation.
|
|
233
|
+
* server. Use this to opt into a non-default validator implementation.
|
|
236
234
|
*
|
|
237
235
|
* Pass `CfWorkerJsonSchemaValidator` (from
|
|
238
|
-
* `@modelcontextprotocol/
|
|
236
|
+
* `@modelcontextprotocol/server/validators/cf-worker`) when running in
|
|
239
237
|
* Cloudflare Workers / V8 isolates: the default
|
|
240
238
|
* `AjvJsonSchemaValidator` compiles validators with `new Function(...)`,
|
|
241
239
|
* which workerd refuses to evaluate when a registered tool has an
|
|
@@ -244,7 +242,7 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
244
242
|
* @example
|
|
245
243
|
* ```typescript
|
|
246
244
|
* import { MCPServer } from '@mastra/mcp';
|
|
247
|
-
* import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/
|
|
245
|
+
* import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker';
|
|
248
246
|
*
|
|
249
247
|
* const server = new MCPServer({
|
|
250
248
|
* name: 'My Server',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAGV,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAA+B,MAAM,oBAAoB,CAAC;AAErG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC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AAU,CAAC,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,cAAc,CAAA;KAAE,GAC5F,OAAO,CAAC,GAAG,CAAC;IAsGf;;;;;;;OAOG;IACU,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,KAAK,CAAC;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC;IAuBnH;;;;;;OAMG;IACU,aAAa,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;KAAE,CAAC;CASjE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ToolsInput } from '@mastra/core/agent';
|
|
2
2
|
import type { IMastraLogger } from '@mastra/core/logger';
|
|
3
|
-
import type { Server } from '@modelcontextprotocol/
|
|
3
|
+
import type { Server } from '@modelcontextprotocol/server';
|
|
4
4
|
interface ServerToolActionsDependencies {
|
|
5
5
|
getLogger: () => IMastraLogger;
|
|
6
6
|
getSdkServers: () => Server[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolActions.d.ts","sourceRoot":"","sources":["../../src/server/toolActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"toolActions.d.ts","sourceRoot":"","sources":["../../src/server/toolActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAG3D,UAAU,6BAA6B;IACrC,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;CAC9C;AAED;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;IAE9D;;OAEG;gBACS,YAAY,EAAE,6BAA6B;IAOvD;;;;;;;;;;;;;;OAcG;IACU,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlD;;;;;;;;;;;;;;OAcG;IACU,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASrD;;;;;;;;;;;;;OAaG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAUhD"}
|
package/dist/server/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { MCPServerContext } from '@mastra/core/tools';
|
|
1
2
|
import type { McpUiResourceMeta } from '@modelcontextprotocol/ext-apps';
|
|
2
|
-
import type {
|
|
3
|
-
import type { ElicitRequest, ElicitResult, Prompt, PromptMessage, Resource, ResourceTemplate } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import type { RequestOptions, ElicitRequest, ElicitResult, Prompt, PromptMessage, Resource, ResourceTemplateType } from '@modelcontextprotocol/server';
|
|
4
4
|
/**
|
|
5
5
|
* Callback function to retrieve content for a specific resource.
|
|
6
6
|
*
|
|
@@ -36,10 +36,10 @@ export type MCPServerResources = {
|
|
|
36
36
|
/** Optional function to list resource templates */
|
|
37
37
|
resourceTemplates?: ({ extra }: {
|
|
38
38
|
extra: MCPRequestHandlerExtra;
|
|
39
|
-
}) => Promise<
|
|
39
|
+
}) => Promise<ResourceTemplateType[]>;
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
|
-
* Extends the MCP
|
|
42
|
+
* Extends the MCP Prompt type with an optional version field.
|
|
43
43
|
*
|
|
44
44
|
* The MCP protocol does not include `version` on prompts, so this field is
|
|
45
45
|
* only used server-side for internal prompt lookup and is not sent over the wire.
|
|
@@ -103,15 +103,15 @@ export type ElicitationActions = {
|
|
|
103
103
|
/**
|
|
104
104
|
* Extra context passed to MCP request handlers.
|
|
105
105
|
*/
|
|
106
|
-
export type MCPRequestHandlerExtra =
|
|
106
|
+
export type MCPRequestHandlerExtra = MCPServerContext;
|
|
107
107
|
/**
|
|
108
|
-
* Re-exported MCP
|
|
108
|
+
* Re-exported MCP types for resource handling.
|
|
109
109
|
*
|
|
110
110
|
* - `Resource`: Represents a data resource exposed by the server
|
|
111
111
|
* - `ResourceTemplate`: URI template for dynamic resource generation
|
|
112
112
|
* - `RequestOptions`: Options for MCP requests (timeout, signal, etc.)
|
|
113
113
|
*/
|
|
114
|
-
export type { Resource, ResourceTemplate, RequestOptions };
|
|
114
|
+
export type { Resource, ResourceTemplateType as ResourceTemplate, RequestOptions };
|
|
115
115
|
/**
|
|
116
116
|
* Configuration for a single MCP App resource.
|
|
117
117
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACx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5
|
-
*
|
|
4
|
+
* Re-exports and extends the MCP OAuth types for use in Mastra's MCP client and
|
|
5
|
+
* server implementations. The OAuth metadata shapes are identical across the
|
|
6
|
+
* MCP packages, so both sides source them from `@modelcontextprotocol/client`
|
|
7
|
+
* alongside the OAuth flow helpers below.
|
|
6
8
|
*
|
|
7
9
|
* @see https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization
|
|
8
10
|
*/
|
|
9
|
-
import type { OAuthProtectedResourceMetadata as SDKOAuthProtectedResourceMetadata } from '@modelcontextprotocol/
|
|
10
|
-
export type { OAuthMetadata, OAuthTokens, OAuthErrorResponse, OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationFull, OAuthClientRegistrationError, OAuthTokenRevocationRequest, OAuthProtectedResourceMetadata, AuthorizationServerMetadata, } from '@modelcontextprotocol/
|
|
11
|
-
export { auth, discoverOAuthProtectedResourceMetadata, discoverOAuthMetadata, discoverAuthorizationServerMetadata, startAuthorization, exchangeAuthorization, refreshAuthorization, registerClient, extractResourceMetadataUrl, selectResourceURL, parseErrorResponse, UnauthorizedError, buildDiscoveryUrls, } from '@modelcontextprotocol/
|
|
12
|
-
export type { OAuthClientProvider, AuthResult } from '@modelcontextprotocol/
|
|
11
|
+
import type { OAuthProtectedResourceMetadata as SDKOAuthProtectedResourceMetadata } from '@modelcontextprotocol/client';
|
|
12
|
+
export type { OAuthMetadata, OAuthTokens, OAuthErrorResponse, OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationFull, OAuthClientRegistrationError, OAuthTokenRevocationRequest, OAuthProtectedResourceMetadata, AuthorizationServerMetadata, } from '@modelcontextprotocol/client';
|
|
13
|
+
export { auth, discoverOAuthProtectedResourceMetadata, discoverOAuthMetadata, discoverAuthorizationServerMetadata, startAuthorization, exchangeAuthorization, refreshAuthorization, registerClient, extractResourceMetadataUrl, selectResourceURL, parseErrorResponse, UnauthorizedError, buildDiscoveryUrls, } from '@modelcontextprotocol/client';
|
|
14
|
+
export type { OAuthClientProvider, AuthResult } from '@modelcontextprotocol/client';
|
|
13
15
|
/**
|
|
14
16
|
* Configuration for OAuth-protected MCP server.
|
|
15
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-types.d.ts","sourceRoot":"","sources":["../../src/shared/oauth-types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"oauth-types.d.ts","sourceRoot":"","sources":["../../src/shared/oauth-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,8BAA8B,IAAI,iCAAiC,EAAE,MAAM,8BAA8B,CAAC;AAExH,YAAY,EACV,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,EAC3B,8BAA8B,EAC9B,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,IAAI,EACJ,sCAAsC,EACtC,qBAAqB,EACrB,mCAAmC,EACnC,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,0BAA0B,EAC1B,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AAGtC,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAE/B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACrF;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AASD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAkBxF;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,oBAAoB,GAAG,iCAAiC,CAWjH;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAU5F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,20 +27,24 @@
|
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@modelcontextprotocol/ext-apps": "^1.7.1",
|
|
30
|
-
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
31
30
|
"exit-hook": "^5.1.0",
|
|
32
|
-
"fast-deep-equal": "^3.1.3"
|
|
31
|
+
"fast-deep-equal": "^3.1.3",
|
|
32
|
+
"@modelcontextprotocol/server": "2.0.0",
|
|
33
|
+
"@modelcontextprotocol/client": "2.0.0",
|
|
34
|
+
"@modelcontextprotocol/node": "2.0.0",
|
|
35
|
+
"@modelcontextprotocol/server-legacy": "2.0.0",
|
|
36
|
+
"@modelcontextprotocol/core": "2.0.0"
|
|
33
37
|
},
|
|
34
38
|
"peerDependencies": {
|
|
35
39
|
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
|
-
"@hono/node-server": "^
|
|
42
|
+
"@hono/node-server": "^2.0.0",
|
|
39
43
|
"@mendable/firecrawl-js": "^1.29.3",
|
|
40
44
|
"@types/node": "22.20.1",
|
|
41
45
|
"@vitest/coverage-v8": "4.1.10",
|
|
42
46
|
"@vitest/ui": "4.1.10",
|
|
43
|
-
"ai": "^5.0.
|
|
47
|
+
"ai": "^5.0.221",
|
|
44
48
|
"eslint": "^10.7.0",
|
|
45
49
|
"get-port": "^7.1.0",
|
|
46
50
|
"hono": "^4.12.8",
|
|
@@ -51,14 +55,14 @@
|
|
|
51
55
|
"vitest": "4.1.10",
|
|
52
56
|
"zod": "^4.4.3",
|
|
53
57
|
"zod-to-json-schema": "^3.25.1",
|
|
54
|
-
"@internal/ai-sdk-v5": "0.0.
|
|
55
|
-
"@internal/
|
|
56
|
-
"@internal/
|
|
57
|
-
"@internal/
|
|
58
|
-
"@
|
|
59
|
-
"@mastra/
|
|
60
|
-
"@
|
|
61
|
-
"@mastra/
|
|
58
|
+
"@internal/ai-sdk-v5": "0.0.68",
|
|
59
|
+
"@internal/llm-recorder": "0.0.57",
|
|
60
|
+
"@internal/test-utils": "0.0.57",
|
|
61
|
+
"@internal/lint": "0.0.121",
|
|
62
|
+
"@internal/types-builder": "0.0.96",
|
|
63
|
+
"@mastra/schema-compat": "1.3.6-alpha.0",
|
|
64
|
+
"@mastra/core": "1.58.0-alpha.1",
|
|
65
|
+
"@mastra/observability": "1.16.6-alpha.0"
|
|
62
66
|
},
|
|
63
67
|
"homepage": "https://mastra.ai",
|
|
64
68
|
"repository": {
|
|
@@ -75,7 +79,7 @@
|
|
|
75
79
|
"scripts": {
|
|
76
80
|
"build:lib": "tsdown --silent --config tsdown.config.ts",
|
|
77
81
|
"build:watch": "pnpm build:lib --watch",
|
|
78
|
-
"test:client": "vitest run ./src/client/client.test.ts ./src/client/configuration.test.ts ./src/client/oauth.test.ts ./src/client/oauth-callback-server.test.ts ./src/client/oauth-flow.test.ts",
|
|
82
|
+
"test:client": "vitest run ./src/client/client.test.ts ./src/client/configuration.test.ts ./src/client/oauth.test.ts ./src/client/oauth-callback-server.test.ts ./src/client/oauth-flow.test.ts ./src/client/url-policy.test.ts ./src/client/stdio-env.test.ts",
|
|
79
83
|
"test:server": "vitest run ./src/server",
|
|
80
84
|
"test:integration": "cd integration-tests && pnpm test:mcp",
|
|
81
85
|
"test": "pnpm test:server && pnpm test:client && pnpm test:integration",
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
-
|
|
3
|
-
# MCP Apps
|
|
4
|
-
|
|
5
|
-
The [MCP Apps extension](https://github.com/modelcontextprotocol/ext-apps) allows MCP tools to serve interactive HTML UIs via `ui://` resources. When a tool has an associated app resource, Mastra Studio renders it in a sandboxed iframe alongside the tool form or inline in agent chat.
|
|
6
|
-
|
|
7
|
-
## When to use MCP Apps
|
|
8
|
-
|
|
9
|
-
Use MCP Apps when a tool result is better presented as an interactive UI rather than plain text. For example:
|
|
10
|
-
|
|
11
|
-
- A calculator that renders input fields and buttons for computation
|
|
12
|
-
- A color picker that displays swatches and hex values
|
|
13
|
-
- A form builder that captures structured user input
|
|
14
|
-
- A data visualizer that renders charts
|
|
15
|
-
|
|
16
|
-
## Quickstart
|
|
17
|
-
|
|
18
|
-
Define app resources on your `MCPServer` by providing a `ui://` URI mapped to inline HTML or an HTML file path.
|
|
19
|
-
|
|
20
|
-
```typescript
|
|
21
|
-
import { MCPServer } from '@mastra/mcp'
|
|
22
|
-
import { createTool } from '@mastra/core/tools'
|
|
23
|
-
import { z } from 'zod'
|
|
24
|
-
|
|
25
|
-
const calculatorTool = createTool({
|
|
26
|
-
id: 'calculatorWithUI',
|
|
27
|
-
description: 'An interactive calculator',
|
|
28
|
-
inputSchema: z.object({
|
|
29
|
-
num1: z.number(),
|
|
30
|
-
num2: z.number(),
|
|
31
|
-
operation: z.enum(['add', 'subtract']),
|
|
32
|
-
}),
|
|
33
|
-
execute: async ({ num1, num2, operation }) => {
|
|
34
|
-
const result = operation === 'add' ? num1 + num2 : num1 - num2
|
|
35
|
-
return {
|
|
36
|
-
content: [{ type: 'text', text: 'An interactive calculator is displayed.' }],
|
|
37
|
-
structuredContent: { result },
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const server = new MCPServer({
|
|
43
|
-
id: 'my-app-server',
|
|
44
|
-
name: 'My App Server',
|
|
45
|
-
version: '1.0.0',
|
|
46
|
-
tools: { calculatorTool },
|
|
47
|
-
appResources: {
|
|
48
|
-
'ui://calculator/main': {
|
|
49
|
-
name: 'Interactive Calculator',
|
|
50
|
-
html: `<html>
|
|
51
|
-
<body>
|
|
52
|
-
<h2>Calculator</h2>
|
|
53
|
-
<button id="btn">Compute</button>
|
|
54
|
-
<script type="module">
|
|
55
|
-
import { App } from 'https://cdn.jsdelivr.net/npm/@modelcontextprotocol/ext-apps/+esm';
|
|
56
|
-
const app = new App({ name: 'Calculator', version: '1.0.0' });
|
|
57
|
-
app.ontoolinput = (params) => {
|
|
58
|
-
console.log('Tool input:', params.arguments);
|
|
59
|
-
};
|
|
60
|
-
document.getElementById('btn').addEventListener('click', async () => {
|
|
61
|
-
const result = await app.callServerTool({
|
|
62
|
-
name: 'calculatorWithUI',
|
|
63
|
-
arguments: { num1: 10, num2: 5, operation: 'add' }
|
|
64
|
-
});
|
|
65
|
-
document.body.innerHTML += '<p>Result: ' + JSON.stringify(result) + '</p>';
|
|
66
|
-
});
|
|
67
|
-
await app.connect();
|
|
68
|
-
</script>
|
|
69
|
-
</body>
|
|
70
|
-
</html>`,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
})
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Link the tool to its app resource by adding `_meta.ui.resourceUri` to the tool definition:
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
calculatorTool._meta = {
|
|
80
|
-
ui: { resourceUri: 'ui://calculator/main' },
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Visit [MCPServer reference](https://mastra.ai/reference/tools/mcp-server) for the full `appResources` configuration.
|
|
85
|
-
|
|
86
|
-
## Connecting MCP Apps to agents
|
|
87
|
-
|
|
88
|
-
Agents consume tools, they don't need to know about MCP servers. Pass tools to the agent's `tools` config, and register the MCP server at the Mastra level so Studio can resolve app resources.
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
import { Agent } from '@mastra/core/agent'
|
|
92
|
-
import { calculatorTool } from '../mcp/tools'
|
|
93
|
-
|
|
94
|
-
export const myAgent = new Agent({
|
|
95
|
-
id: 'my-agent',
|
|
96
|
-
name: 'My Agent',
|
|
97
|
-
instructions: 'You have access to interactive UI tools.',
|
|
98
|
-
model: 'openai/gpt-5-mini',
|
|
99
|
-
tools: { calculatorTool },
|
|
100
|
-
})
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Register the MCP server at the Mastra level. Studio scans registered MCP servers to map tools to their app resources.
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
import { Mastra } from '@mastra/core/mastra'
|
|
107
|
-
import { myAgent } from './agents'
|
|
108
|
-
import { myAppServer } from './mcp/server'
|
|
109
|
-
|
|
110
|
-
export const mastra = new Mastra({
|
|
111
|
-
agents: { myAgent },
|
|
112
|
-
mcpServers: { myAppServer },
|
|
113
|
-
})
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
For remote MCP servers, use `MCPClient.listTools()` to get tools and `toMCPServerProxies()` to register the server:
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
import { MCPClient } from '@mastra/mcp'
|
|
120
|
-
|
|
121
|
-
const mcpClient = new MCPClient({
|
|
122
|
-
servers: {
|
|
123
|
-
remoteApp: { url: new URL('https://remote-mcp-server.example.com/mcp') },
|
|
124
|
-
},
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
const myAgent = new Agent({
|
|
128
|
-
id: 'my-agent',
|
|
129
|
-
name: 'My Agent',
|
|
130
|
-
model: 'openai/gpt-5-mini',
|
|
131
|
-
tools: await mcpClient.listTools(),
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
export const mastra = new Mastra({
|
|
135
|
-
agents: { myAgent },
|
|
136
|
-
mcpServers: { ...mcpClient.toMCPServerProxies() },
|
|
137
|
-
})
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
When tools come from `MCPClient.listTools()`, each tool's `_meta.ui` is automatically stamped with a `serverId` so Studio can resolve its app resources without scanning all servers.
|
|
141
|
-
|
|
142
|
-
## How MCP Apps work
|
|
143
|
-
|
|
144
|
-
MCP Apps follow a specific communication pattern between the host (Mastra Studio) and the iframe:
|
|
145
|
-
|
|
146
|
-
1. The tool executes and returns a brief summary in `content` (visible to the model) and detailed data in `structuredContent` (visible to the UI only).
|
|
147
|
-
2. The host renders the app HTML in a sandboxed iframe.
|
|
148
|
-
3. The iframe communicates with the host via a JSON-RPC postMessage protocol.
|
|
149
|
-
4. The app can call server tools using `callServerTool()` and inject messages into the chat using `sendMessage()`.
|
|
150
|
-
|
|
151
|
-
```text
|
|
152
|
-
Agent calls tool → Tool returns brief content + structuredContent
|
|
153
|
-
→ Host renders iframe with app HTML
|
|
154
|
-
→ User interacts with UI
|
|
155
|
-
→ UI calls callServerTool() for computation
|
|
156
|
-
→ UI calls sendMessage() to inject result into chat
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
## Tool result format
|
|
160
|
-
|
|
161
|
-
Tools with app resources should return two fields:
|
|
162
|
-
|
|
163
|
-
- `content`: A brief text summary for the model. Keep this short so the agent doesn't parrot the full result.
|
|
164
|
-
- `structuredContent`: The data payload that hydrates the UI. The model doesn't see this field.
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
execute: async ({ num1, num2, operation }) => {
|
|
168
|
-
const result = operation === 'add' ? num1 + num2 : num1 - num2
|
|
169
|
-
return {
|
|
170
|
-
content: [{ type: 'text', text: 'An interactive calculator is displayed.' }],
|
|
171
|
-
structuredContent: { result },
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## App API (guest-side)
|
|
177
|
-
|
|
178
|
-
MCP App HTML uses the standard [`App` class from `@modelcontextprotocol/ext-apps`](https://github.com/modelcontextprotocol/ext-apps) to communicate with the host. Import it via ESM CDN or bundle it.
|
|
179
|
-
|
|
180
|
-
```javascript
|
|
181
|
-
import { App } from 'https://cdn.jsdelivr.net/npm/@modelcontextprotocol/ext-apps/+esm'
|
|
182
|
-
const app = new App({ name: 'MyApp', version: '1.0.0' })
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### `app.callServerTool(params)`
|
|
186
|
-
|
|
187
|
-
Calls an MCP server tool from within the iframe. This is useful for interactive computation without leaving the UI.
|
|
188
|
-
|
|
189
|
-
```javascript
|
|
190
|
-
const result = await app.callServerTool({
|
|
191
|
-
name: 'calculatorWithUI',
|
|
192
|
-
arguments: { num1: 42, num2: 8, operation: 'add' },
|
|
193
|
-
})
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### `app.sendMessage(params)`
|
|
197
|
-
|
|
198
|
-
Injects a user message into the agent chat, triggering a new model turn. Use this for sharing results or requesting follow-up actions.
|
|
199
|
-
|
|
200
|
-
```javascript
|
|
201
|
-
await app.sendMessage({
|
|
202
|
-
role: 'user',
|
|
203
|
-
content: [{ type: 'text', text: 'The result of 42 + 8 is 50' }],
|
|
204
|
-
})
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
### `app.ontoolinput`
|
|
208
|
-
|
|
209
|
-
A callback that fires when the host delivers tool input data to the iframe, allowing pre-population of form fields. The `params.arguments` object contains the tool call arguments.
|
|
210
|
-
|
|
211
|
-
```javascript
|
|
212
|
-
app.ontoolinput = params => {
|
|
213
|
-
document.getElementById('num1').value = params.arguments.num1
|
|
214
|
-
}
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
> **Preventing UI flicker:** If your app has default form values, the user may briefly see them before `ontoolinput` hydrates the correct values. To prevent this, start the body hidden and reveal it after hydration:
|
|
218
|
-
>
|
|
219
|
-
> ```html
|
|
220
|
-
> <style>
|
|
221
|
-
> body {
|
|
222
|
-
> opacity: 0;
|
|
223
|
-
> transition: opacity 0.15s;
|
|
224
|
-
> }
|
|
225
|
-
> body.ready {
|
|
226
|
-
> opacity: 1;
|
|
227
|
-
> }
|
|
228
|
-
> </style>
|
|
229
|
-
> <script type="module">
|
|
230
|
-
> import { App } from 'https://cdn.jsdelivr.net/npm/@modelcontextprotocol/ext-apps/+esm'
|
|
231
|
-
> const app = new App({ name: 'MyApp', version: '1.0.0' })
|
|
232
|
-
>
|
|
233
|
-
> app.ontoolinput = params => {
|
|
234
|
-
> // Hydrate form fields from params.arguments
|
|
235
|
-
> document.body.classList.add('ready')
|
|
236
|
-
> }
|
|
237
|
-
>
|
|
238
|
-
> await app.connect()
|
|
239
|
-
> // Fallback: reveal after connection if no tool input arrives
|
|
240
|
-
> setTimeout(() => document.body.classList.add('ready'), 150)
|
|
241
|
-
> </script>
|
|
242
|
-
> ```
|
|
243
|
-
|
|
244
|
-
### `app.connect()`
|
|
245
|
-
|
|
246
|
-
Establishes the connection to the host. Call this after registering all event handlers.
|
|
247
|
-
|
|
248
|
-
```javascript
|
|
249
|
-
await app.connect()
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
See the [`App` class API reference](https://apps.extensions.modelcontextprotocol.io/api/classes/app.App.html) for the full list of methods, callbacks, and lifecycle hooks.
|
|
253
|
-
|
|
254
|
-
## Using external MCP servers with apps
|
|
255
|
-
|
|
256
|
-
External (non-Mastra) MCP servers that implement the MCP Apps extension work with Mastra via `MCPClient`. Use `listTools()` for agent tools and `toMCPServerProxies()` to register them in Studio.
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
import { Mastra } from '@mastra/core/mastra'
|
|
260
|
-
import { MCPClient } from '@mastra/mcp'
|
|
261
|
-
import { Agent } from '@mastra/core/agent'
|
|
262
|
-
|
|
263
|
-
const mcpClient = new MCPClient({
|
|
264
|
-
servers: {
|
|
265
|
-
'external-server': {
|
|
266
|
-
command: 'node',
|
|
267
|
-
args: ['path/to/external-server.js'],
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
const myAgent = new Agent({
|
|
273
|
-
id: 'my-agent',
|
|
274
|
-
name: 'My Agent',
|
|
275
|
-
model: 'openai/gpt-5-mini',
|
|
276
|
-
tools: await mcpClient.listTools(),
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
export const mastra = new Mastra({
|
|
280
|
-
agents: { myAgent },
|
|
281
|
-
mcpServers: {
|
|
282
|
-
...mcpClient.toMCPServerProxies(),
|
|
283
|
-
},
|
|
284
|
-
})
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
Visit [MCPClient reference](https://mastra.ai/reference/tools/mcp-client) for more details on proxying external servers.
|
|
288
|
-
|
|
289
|
-
## Sandbox security
|
|
290
|
-
|
|
291
|
-
Mastra Studio uses [`@mcp-ui/client`](https://www.npmjs.com/package/@mcp-ui/client) to render MCP App iframes through a sandbox proxy. The proxy loads app HTML via `postMessage` rather than `srcDoc`, providing additional isolation.
|
|
292
|
-
|
|
293
|
-
App iframes are sandboxed with the following permissions:
|
|
294
|
-
|
|
295
|
-
- `allow-scripts`: Enables JavaScript execution
|
|
296
|
-
- `allow-forms`: Allows form submission
|
|
297
|
-
- `allow-popups`: Permits `window.open()` and link targets
|
|
298
|
-
|
|
299
|
-
The iframe doesn't have access to the parent page's DOM, cookies, or storage. All communication happens through the JSON-RPC postMessage protocol managed by `@mcp-ui/client`'s `AppRenderer` on the host side and `@modelcontextprotocol/ext-apps`'s `App` class on the guest side.
|
|
300
|
-
|
|
301
|
-
## Related
|
|
302
|
-
|
|
303
|
-
- [MCP overview](https://mastra.ai/docs/mcp/overview)
|
|
304
|
-
- [MCPServer reference](https://mastra.ai/reference/tools/mcp-server)
|
|
305
|
-
- [MCPClient reference](https://mastra.ai/reference/tools/mcp-client)
|
|
306
|
-
- [MCP Apps extension spec](https://github.com/modelcontextprotocol/ext-apps)
|