@mastra/mcp 1.0.0-beta.2 → 1.0.0-beta.4

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.
@@ -0,0 +1,188 @@
1
+ import type { RequestContext } from '@mastra/core/di';
2
+ import type { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
3
+ import type { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
4
+ import type { ClientCapabilities, ElicitRequest, ElicitResult, LoggingLevel, ProgressNotification } from '@modelcontextprotocol/sdk/types.js';
5
+ export type { LoggingLevel } from '@modelcontextprotocol/sdk/types.js';
6
+ /**
7
+ * Log message structure for MCP client logging.
8
+ */
9
+ export interface LogMessage {
10
+ /** Logging level (debug, info, warning, error, etc.) */
11
+ level: LoggingLevel;
12
+ /** Log message content */
13
+ message: string;
14
+ /** Timestamp when the log was created */
15
+ timestamp: Date;
16
+ /** Name of the MCP server that generated the log */
17
+ serverName: string;
18
+ /** Optional additional details */
19
+ details?: Record<string, any>;
20
+ requestContext?: RequestContext | null;
21
+ }
22
+ /**
23
+ * Handler function for processing log messages from MCP servers.
24
+ */
25
+ export type LogHandler = (logMessage: LogMessage) => void;
26
+ /**
27
+ * Handler function for processing elicitation requests from MCP servers.
28
+ *
29
+ * @param request - The elicitation request parameters including message and schema
30
+ * @returns Promise resolving to the user's response (accept/decline/cancel with optional content)
31
+ */
32
+ export type ElicitationHandler = (request: ElicitRequest['params']) => Promise<ElicitResult>;
33
+ /**
34
+ * Handler function for processing progress notifications from MCP servers.
35
+ *
36
+ * @param params - The progress notification parameters including message and status
37
+ */
38
+ export type ProgressHandler = (params: ProgressNotification['params']) => void;
39
+ /**
40
+ * Represents a filesystem root that the client exposes to MCP servers.
41
+ *
42
+ * Per MCP spec (https://modelcontextprotocol.io/specification/2025-11-25/client/roots):
43
+ * Roots define the boundaries of where servers can operate within the filesystem,
44
+ * allowing them to understand which directories and files they have access to.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const root: Root = {
49
+ * uri: 'file:///home/user/projects/myproject',
50
+ * name: 'My Project'
51
+ * };
52
+ * ```
53
+ */
54
+ export interface Root {
55
+ /** Unique identifier for the root. Must be a file:// URI. */
56
+ uri: string;
57
+ /** Optional human-readable name for display purposes. */
58
+ name?: string;
59
+ }
60
+ /**
61
+ * Base options common to all MCP server definitions.
62
+ */
63
+ export type BaseServerOptions = {
64
+ /** Optional handler for server log messages */
65
+ logger?: LogHandler;
66
+ /** Optional timeout in milliseconds for server operations */
67
+ timeout?: number;
68
+ /** Optional client capabilities to advertise to the server */
69
+ capabilities?: ClientCapabilities;
70
+ /** Whether to enable server log forwarding (default: true) */
71
+ enableServerLogs?: boolean;
72
+ /** Whether to enable progress tracking (default: false) */
73
+ enableProgressTracking?: boolean;
74
+ /**
75
+ * List of filesystem roots to expose to the MCP server.
76
+ *
77
+ * Per MCP spec (https://modelcontextprotocol.io/specification/2025-11-25/client/roots):
78
+ * Roots define the boundaries of where servers can operate within the filesystem.
79
+ *
80
+ * When configured, the client will:
81
+ * 1. Automatically advertise the `roots` capability to the server
82
+ * 2. Respond to `roots/list` requests with these roots
83
+ * 3. Send `notifications/roots/list_changed` when roots are updated via `setRoots()`
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * {
88
+ * command: 'npx',
89
+ * args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'],
90
+ * roots: [
91
+ * { uri: 'file:///tmp', name: 'Temp Directory' }
92
+ * ]
93
+ * }
94
+ * ```
95
+ */
96
+ roots?: Root[];
97
+ };
98
+ /**
99
+ * Configuration for MCP servers using stdio (subprocess) transport.
100
+ *
101
+ * Used when the MCP server is spawned as a subprocess that communicates via stdin/stdout.
102
+ */
103
+ export type StdioServerDefinition = BaseServerOptions & {
104
+ /** Command to execute (e.g., 'node', 'python', 'npx') */
105
+ command: string;
106
+ /** Optional arguments to pass to the command */
107
+ args?: string[];
108
+ /** Optional environment variables for the subprocess */
109
+ env?: Record<string, string>;
110
+ url?: never;
111
+ requestInit?: never;
112
+ eventSourceInit?: never;
113
+ authProvider?: never;
114
+ reconnectionOptions?: never;
115
+ sessionId?: never;
116
+ connectTimeout?: never;
117
+ };
118
+ /**
119
+ * Configuration for MCP servers using HTTP-based transport (Streamable HTTP or SSE fallback).
120
+ *
121
+ * Used when connecting to remote MCP servers over HTTP. The client will attempt Streamable HTTP
122
+ * transport first and fall back to SSE if that fails.
123
+ */
124
+ export type HttpServerDefinition = BaseServerOptions & {
125
+ /** URL of the MCP server endpoint */
126
+ url: URL;
127
+ command?: never;
128
+ args?: never;
129
+ env?: never;
130
+ /** Optional request configuration for HTTP requests */
131
+ requestInit?: StreamableHTTPClientTransportOptions['requestInit'];
132
+ /** Optional configuration for SSE fallback (required when using custom headers with SSE) */
133
+ eventSourceInit?: SSEClientTransportOptions['eventSourceInit'];
134
+ /** Optional authentication provider for HTTP requests */
135
+ authProvider?: StreamableHTTPClientTransportOptions['authProvider'];
136
+ /** Optional reconnection configuration for Streamable HTTP */
137
+ reconnectionOptions?: StreamableHTTPClientTransportOptions['reconnectionOptions'];
138
+ /** Optional session ID for Streamable HTTP */
139
+ sessionId?: StreamableHTTPClientTransportOptions['sessionId'];
140
+ /** Optional timeout in milliseconds for the connection phase (default: 3000ms).
141
+ * This timeout allows the system to switch MCP streaming protocols during the setup phase.
142
+ * The default is set to 3s because the long default timeout would be extremely slow for SSE backwards compat (60s).
143
+ */
144
+ connectTimeout?: number;
145
+ };
146
+ /**
147
+ * Configuration for connecting to an MCP server.
148
+ *
149
+ * Either stdio-based (subprocess) or HTTP-based (remote server). The transport type is
150
+ * automatically detected based on whether `command` or `url` is provided.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // Stdio server
155
+ * const stdioServer: MastraMCPServerDefinition = {
156
+ * command: 'npx',
157
+ * args: ['tsx', 'server.ts'],
158
+ * env: { API_KEY: 'secret' }
159
+ * };
160
+ *
161
+ * // HTTP server
162
+ * const httpServer: MastraMCPServerDefinition = {
163
+ * url: new URL('http://localhost:8080/mcp'),
164
+ * requestInit: {
165
+ * headers: { Authorization: 'Bearer token' }
166
+ * }
167
+ * };
168
+ * ```
169
+ */
170
+ export type MastraMCPServerDefinition = StdioServerDefinition | HttpServerDefinition;
171
+ /**
172
+ * Options for creating an internal MCP client instance.
173
+ *
174
+ * @internal
175
+ */
176
+ export type InternalMastraMCPClientOptions = {
177
+ /** Name identifier for this client */
178
+ name: string;
179
+ /** Server connection configuration */
180
+ server: MastraMCPServerDefinition;
181
+ /** Optional client capabilities to advertise to the server */
182
+ capabilities?: ClientCapabilities;
183
+ /** Optional client version */
184
+ version?: string;
185
+ /** Optional timeout in milliseconds */
186
+ timeout?: number;
187
+ };
188
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACzF,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,oDAAoD,CAAC;AAC/G,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACrB,MAAM,oCAAoC,CAAC;AAG5C,YAAY,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,KAAK,EAAE,YAAY,CAAC;IACpB,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,SAAS,EAAE,IAAI,CAAC;IAChB,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,CAAC,EAAE,cAAc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