@mastra/mcp 1.0.0-beta.3 → 1.0.0-beta.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.
- package/CHANGELOG.md +124 -0
- package/README.md +61 -4
- package/dist/client/{elicitationActions.d.ts → actions/elicitation.d.ts} +2 -2
- package/dist/client/actions/elicitation.d.ts.map +1 -0
- package/dist/client/actions/progress.d.ts +23 -0
- package/dist/client/actions/progress.d.ts.map +1 -0
- package/dist/client/{promptActions.d.ts → actions/prompt.d.ts} +2 -2
- package/dist/client/actions/prompt.d.ts.map +1 -0
- package/dist/client/{resourceActions.d.ts → actions/resource.d.ts} +2 -2
- package/dist/client/actions/resource.d.ts.map +1 -0
- package/dist/client/client.d.ts +76 -138
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +23 -1
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/types.d.ts +237 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/index.cjs +316 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +298 -69
- package/dist/index.js.map +1 -1
- package/dist/server/server.d.ts +19 -3
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/types.d.ts +11 -4
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/client/elicitationActions.d.ts.map +0 -1
- package/dist/client/promptActions.d.ts.map +0 -1
- package/dist/client/resourceActions.d.ts.map +0 -1
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export type { LoggingLevel, LogMessage, LogHandler, MastraMCPServerDefinition, ElicitationHandler } from './
|
|
1
|
+
export type { LoggingLevel, LogMessage, LogHandler, MastraMCPServerDefinition, ElicitationHandler, ProgressHandler, InternalMastraMCPClientOptions, } from './types.js';
|
|
2
|
+
export * from './client.js';
|
|
2
3
|
export * from './configuration.js';
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EACf,8BAA8B,GACjC,MAAM,SAAS,CAAC;AACjB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,237 @@
|
|
|
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 { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
5
|
+
import type { ClientCapabilities, ElicitRequest, ElicitResult, LoggingLevel, ProgressNotification } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
export type { LoggingLevel } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Log message structure for MCP client logging.
|
|
9
|
+
*/
|
|
10
|
+
export interface LogMessage {
|
|
11
|
+
/** Logging level (debug, info, warning, error, etc.) */
|
|
12
|
+
level: LoggingLevel;
|
|
13
|
+
/** Log message content */
|
|
14
|
+
message: string;
|
|
15
|
+
/** Timestamp when the log was created */
|
|
16
|
+
timestamp: Date;
|
|
17
|
+
/** Name of the MCP server that generated the log */
|
|
18
|
+
serverName: string;
|
|
19
|
+
/** Optional additional details */
|
|
20
|
+
details?: Record<string, any>;
|
|
21
|
+
requestContext?: RequestContext | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Handler function for processing log messages from MCP servers.
|
|
25
|
+
*/
|
|
26
|
+
export type LogHandler = (logMessage: LogMessage) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Handler function for processing elicitation requests from MCP servers.
|
|
29
|
+
*
|
|
30
|
+
* @param request - The elicitation request parameters including message and schema
|
|
31
|
+
* @returns Promise resolving to the user's response (accept/decline/cancel with optional content)
|
|
32
|
+
*/
|
|
33
|
+
export type ElicitationHandler = (request: ElicitRequest['params']) => Promise<ElicitResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Handler function for processing progress notifications from MCP servers.
|
|
36
|
+
*
|
|
37
|
+
* @param params - The progress notification parameters including message and status
|
|
38
|
+
*/
|
|
39
|
+
export type ProgressHandler = (params: ProgressNotification['params']) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Represents a filesystem root that the client exposes to MCP servers.
|
|
42
|
+
*
|
|
43
|
+
* Per MCP spec (https://modelcontextprotocol.io/specification/2025-11-25/client/roots):
|
|
44
|
+
* Roots define the boundaries of where servers can operate within the filesystem,
|
|
45
|
+
* allowing them to understand which directories and files they have access to.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const root: Root = {
|
|
50
|
+
* uri: 'file:///home/user/projects/myproject',
|
|
51
|
+
* name: 'My Project'
|
|
52
|
+
* };
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export interface Root {
|
|
56
|
+
/** Unique identifier for the root. Must be a file:// URI. */
|
|
57
|
+
uri: string;
|
|
58
|
+
/** Optional human-readable name for display purposes. */
|
|
59
|
+
name?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Base options common to all MCP server definitions.
|
|
63
|
+
*/
|
|
64
|
+
export type BaseServerOptions = {
|
|
65
|
+
/** Optional handler for server log messages */
|
|
66
|
+
logger?: LogHandler;
|
|
67
|
+
/** Optional timeout in milliseconds for server operations */
|
|
68
|
+
timeout?: number;
|
|
69
|
+
/** Optional client capabilities to advertise to the server */
|
|
70
|
+
capabilities?: ClientCapabilities;
|
|
71
|
+
/** Whether to enable server log forwarding (default: true) */
|
|
72
|
+
enableServerLogs?: boolean;
|
|
73
|
+
/** Whether to enable progress tracking (default: false) */
|
|
74
|
+
enableProgressTracking?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* List of filesystem roots to expose to the MCP server.
|
|
77
|
+
*
|
|
78
|
+
* Per MCP spec (https://modelcontextprotocol.io/specification/2025-11-25/client/roots):
|
|
79
|
+
* Roots define the boundaries of where servers can operate within the filesystem.
|
|
80
|
+
*
|
|
81
|
+
* When configured, the client will:
|
|
82
|
+
* 1. Automatically advertise the `roots` capability to the server
|
|
83
|
+
* 2. Respond to `roots/list` requests with these roots
|
|
84
|
+
* 3. Send `notifications/roots/list_changed` when roots are updated via `setRoots()`
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* {
|
|
89
|
+
* command: 'npx',
|
|
90
|
+
* args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'],
|
|
91
|
+
* roots: [
|
|
92
|
+
* { uri: 'file:///tmp', name: 'Temp Directory' }
|
|
93
|
+
* ]
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
roots?: Root[];
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Configuration for MCP servers using stdio (subprocess) transport.
|
|
101
|
+
*
|
|
102
|
+
* Used when the MCP server is spawned as a subprocess that communicates via stdin/stdout.
|
|
103
|
+
*/
|
|
104
|
+
export type StdioServerDefinition = BaseServerOptions & {
|
|
105
|
+
/** Command to execute (e.g., 'node', 'python', 'npx') */
|
|
106
|
+
command: string;
|
|
107
|
+
/** Optional arguments to pass to the command */
|
|
108
|
+
args?: string[];
|
|
109
|
+
/** Optional environment variables for the subprocess */
|
|
110
|
+
env?: Record<string, string>;
|
|
111
|
+
url?: never;
|
|
112
|
+
requestInit?: never;
|
|
113
|
+
eventSourceInit?: never;
|
|
114
|
+
authProvider?: never;
|
|
115
|
+
reconnectionOptions?: never;
|
|
116
|
+
sessionId?: never;
|
|
117
|
+
connectTimeout?: never;
|
|
118
|
+
fetch?: never;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Configuration for MCP servers using HTTP-based transport (Streamable HTTP or SSE fallback).
|
|
122
|
+
*
|
|
123
|
+
* Used when connecting to remote MCP servers over HTTP. The client will attempt Streamable HTTP
|
|
124
|
+
* transport first and fall back to SSE if that fails.
|
|
125
|
+
*
|
|
126
|
+
* When `fetch` is provided, all other HTTP-related options (`requestInit`, `eventSourceInit`, `authProvider`)
|
|
127
|
+
* become optional, as the custom fetch function can handle authentication and request customization.
|
|
128
|
+
*/
|
|
129
|
+
export type HttpServerDefinition = BaseServerOptions & {
|
|
130
|
+
/** URL of the MCP server endpoint */
|
|
131
|
+
url: URL;
|
|
132
|
+
command?: never;
|
|
133
|
+
args?: never;
|
|
134
|
+
env?: never;
|
|
135
|
+
/**
|
|
136
|
+
* Custom fetch implementation used for all network requests.
|
|
137
|
+
*
|
|
138
|
+
* When provided, this function will be used for all HTTP requests, allowing you to:
|
|
139
|
+
* - Add dynamic authentication headers (e.g., refreshing bearer tokens)
|
|
140
|
+
* - Customize request behavior per-request
|
|
141
|
+
* - Intercept and modify requests/responses
|
|
142
|
+
*
|
|
143
|
+
* When `fetch` is provided, `requestInit`, `eventSourceInit`, and `authProvider` become optional,
|
|
144
|
+
* as you can handle these concerns within your custom fetch function.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* {
|
|
149
|
+
* url: new URL('https://api.example.com/mcp'),
|
|
150
|
+
* fetch: async (url, init) => {
|
|
151
|
+
* const token = await getAuthToken(); // Your token refresh logic
|
|
152
|
+
* return fetch(url, {
|
|
153
|
+
* ...init,
|
|
154
|
+
* headers: {
|
|
155
|
+
* ...init?.headers,
|
|
156
|
+
* Authorization: `Bearer ${token}`,
|
|
157
|
+
* },
|
|
158
|
+
* });
|
|
159
|
+
* },
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
fetch?: FetchLike;
|
|
164
|
+
/** Optional request configuration for HTTP requests (optional when `fetch` is provided) */
|
|
165
|
+
requestInit?: StreamableHTTPClientTransportOptions['requestInit'];
|
|
166
|
+
/** Optional configuration for SSE fallback (required when using custom headers with SSE, optional when `fetch` is provided) */
|
|
167
|
+
eventSourceInit?: SSEClientTransportOptions['eventSourceInit'];
|
|
168
|
+
/** Optional authentication provider for HTTP requests (optional when `fetch` is provided) */
|
|
169
|
+
authProvider?: StreamableHTTPClientTransportOptions['authProvider'];
|
|
170
|
+
/** Optional reconnection configuration for Streamable HTTP */
|
|
171
|
+
reconnectionOptions?: StreamableHTTPClientTransportOptions['reconnectionOptions'];
|
|
172
|
+
/** Optional session ID for Streamable HTTP */
|
|
173
|
+
sessionId?: StreamableHTTPClientTransportOptions['sessionId'];
|
|
174
|
+
/** Optional timeout in milliseconds for the connection phase (default: 3000ms).
|
|
175
|
+
* This timeout allows the system to switch MCP streaming protocols during the setup phase.
|
|
176
|
+
* The default is set to 3s because the long default timeout would be extremely slow for SSE backwards compat (60s).
|
|
177
|
+
*/
|
|
178
|
+
connectTimeout?: number;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Configuration for connecting to an MCP server.
|
|
182
|
+
*
|
|
183
|
+
* Either stdio-based (subprocess) or HTTP-based (remote server). The transport type is
|
|
184
|
+
* automatically detected based on whether `command` or `url` is provided.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* // Stdio server
|
|
189
|
+
* const stdioServer: MastraMCPServerDefinition = {
|
|
190
|
+
* command: 'npx',
|
|
191
|
+
* args: ['tsx', 'server.ts'],
|
|
192
|
+
* env: { API_KEY: 'secret' }
|
|
193
|
+
* };
|
|
194
|
+
*
|
|
195
|
+
* // HTTP server with static headers
|
|
196
|
+
* const httpServer: MastraMCPServerDefinition = {
|
|
197
|
+
* url: new URL('http://localhost:8080/mcp'),
|
|
198
|
+
* requestInit: {
|
|
199
|
+
* headers: { Authorization: 'Bearer token' }
|
|
200
|
+
* }
|
|
201
|
+
* };
|
|
202
|
+
*
|
|
203
|
+
* // HTTP server with custom fetch for dynamic auth
|
|
204
|
+
* const httpServerWithFetch: MastraMCPServerDefinition = {
|
|
205
|
+
* url: new URL('http://localhost:8080/mcp'),
|
|
206
|
+
* fetch: async (url, init) => {
|
|
207
|
+
* const token = await getAuthToken(); // Refresh token on each request
|
|
208
|
+
* return fetch(url, {
|
|
209
|
+
* ...init,
|
|
210
|
+
* headers: {
|
|
211
|
+
* ...init?.headers,
|
|
212
|
+
* Authorization: `Bearer ${token}`,
|
|
213
|
+
* },
|
|
214
|
+
* });
|
|
215
|
+
* },
|
|
216
|
+
* };
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
export type MastraMCPServerDefinition = StdioServerDefinition | HttpServerDefinition;
|
|
220
|
+
/**
|
|
221
|
+
* Options for creating an internal MCP client instance.
|
|
222
|
+
*
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
225
|
+
export type InternalMastraMCPClientOptions = {
|
|
226
|
+
/** Name identifier for this client */
|
|
227
|
+
name: string;
|
|
228
|
+
/** Server connection configuration */
|
|
229
|
+
server: MastraMCPServerDefinition;
|
|
230
|
+
/** Optional client capabilities to advertise to the server */
|
|
231
|
+
capabilities?: ClientCapabilities;
|
|
232
|
+
/** Optional client version */
|
|
233
|
+
version?: string;
|
|
234
|
+
/** Optional timeout in milliseconds */
|
|
235
|
+
timeout?: number;
|
|
236
|
+
};
|
|
237
|
+
//# 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,EAA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