@mastra/mcp 1.0.0-beta.4 → 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 +41 -0
- package/README.md +61 -4
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/types.d.ts +53 -4
- package/dist/client/types.d.ts.map +1 -1
- package/dist/index.cjs +22 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -9
- package/dist/index.js.map +1 -1
- package/dist/server/server.d.ts +1 -0
- 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/index.js
CHANGED
|
@@ -384,6 +384,7 @@ var ResourceClientActions = class {
|
|
|
384
384
|
|
|
385
385
|
// src/client/client.ts
|
|
386
386
|
var DEFAULT_SERVER_CONNECT_TIMEOUT_MSEC = 3e3;
|
|
387
|
+
var SSE_FALLBACK_STATUS_CODES = [400, 404, 405];
|
|
387
388
|
function convertLogLevelToLoggerMethod(level) {
|
|
388
389
|
switch (level) {
|
|
389
390
|
case "debug":
|
|
@@ -576,7 +577,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
576
577
|
}
|
|
577
578
|
}
|
|
578
579
|
async connectHttp(url) {
|
|
579
|
-
const { requestInit, eventSourceInit, authProvider, connectTimeout } = this.serverConfig;
|
|
580
|
+
const { requestInit, eventSourceInit, authProvider, connectTimeout, fetch } = this.serverConfig;
|
|
580
581
|
this.log("debug", `Attempting to connect to URL: ${url}`);
|
|
581
582
|
let shouldTrySSE = url.pathname.endsWith(`/sse`);
|
|
582
583
|
if (!shouldTrySSE) {
|
|
@@ -585,7 +586,8 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
585
586
|
const streamableTransport = new StreamableHTTPClientTransport(url, {
|
|
586
587
|
requestInit,
|
|
587
588
|
reconnectionOptions: this.serverConfig.reconnectionOptions,
|
|
588
|
-
authProvider
|
|
589
|
+
authProvider,
|
|
590
|
+
fetch
|
|
589
591
|
});
|
|
590
592
|
await this.client.connect(streamableTransport, {
|
|
591
593
|
timeout: connectTimeout ?? DEFAULT_SERVER_CONNECT_TIMEOUT_MSEC
|
|
@@ -594,13 +596,23 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
594
596
|
this.log("debug", "Successfully connected using Streamable HTTP transport.");
|
|
595
597
|
} catch (error) {
|
|
596
598
|
this.log("debug", `Streamable HTTP transport failed: ${error}`);
|
|
599
|
+
const status = error?.code;
|
|
600
|
+
if (status !== void 0 && !SSE_FALLBACK_STATUS_CODES.includes(status)) {
|
|
601
|
+
throw error;
|
|
602
|
+
}
|
|
597
603
|
shouldTrySSE = true;
|
|
598
604
|
}
|
|
599
605
|
}
|
|
600
606
|
if (shouldTrySSE) {
|
|
601
607
|
this.log("debug", "Falling back to deprecated HTTP+SSE transport...");
|
|
602
608
|
try {
|
|
603
|
-
const
|
|
609
|
+
const sseEventSourceInit = fetch ? { ...eventSourceInit, fetch } : eventSourceInit;
|
|
610
|
+
const sseTransport = new SSEClientTransport(url, {
|
|
611
|
+
requestInit,
|
|
612
|
+
eventSourceInit: sseEventSourceInit,
|
|
613
|
+
authProvider,
|
|
614
|
+
fetch
|
|
615
|
+
});
|
|
604
616
|
await this.client.connect(sseTransport, { timeout: this.serverConfig.timeout ?? this.timeout });
|
|
605
617
|
this.transport = sseTransport;
|
|
606
618
|
this.log("debug", "Successfully connected using deprecated HTTP+SSE transport.");
|
|
@@ -2383,8 +2395,8 @@ var MCPServer = class extends MCPServerBase {
|
|
|
2383
2395
|
}
|
|
2384
2396
|
});
|
|
2385
2397
|
this.elicitation = {
|
|
2386
|
-
sendRequest: async (request) => {
|
|
2387
|
-
return this.handleElicitationRequest(request);
|
|
2398
|
+
sendRequest: async (request, options) => {
|
|
2399
|
+
return this.handleElicitationRequest(request, void 0, options);
|
|
2388
2400
|
}
|
|
2389
2401
|
};
|
|
2390
2402
|
}
|
|
@@ -2394,12 +2406,13 @@ var MCPServer = class extends MCPServerBase {
|
|
|
2394
2406
|
*
|
|
2395
2407
|
* @param request - The elicitation request containing message and schema
|
|
2396
2408
|
* @param serverInstance - Optional server instance to use; defaults to main server for backward compatibility
|
|
2409
|
+
* @param options - Optional request options (timeout, signal, etc.)
|
|
2397
2410
|
* @returns Promise that resolves to the client's response
|
|
2398
2411
|
*/
|
|
2399
|
-
async handleElicitationRequest(request, serverInstance) {
|
|
2412
|
+
async handleElicitationRequest(request, serverInstance, options) {
|
|
2400
2413
|
this.logger.debug(`Sending elicitation request: ${request.message}`);
|
|
2401
2414
|
const server = serverInstance || this.server;
|
|
2402
|
-
const response = await server.elicitInput(request);
|
|
2415
|
+
const response = await server.elicitInput(request, options);
|
|
2403
2416
|
this.logger.debug(`Received elicitation response: ${JSON.stringify(response)}`);
|
|
2404
2417
|
return response;
|
|
2405
2418
|
}
|
|
@@ -2523,8 +2536,8 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
|
|
|
2523
2536
|
};
|
|
2524
2537
|
}
|
|
2525
2538
|
const sessionElicitation = {
|
|
2526
|
-
sendRequest: async (request2) => {
|
|
2527
|
-
return this.handleElicitationRequest(request2, serverInstance);
|
|
2539
|
+
sendRequest: async (request2, options) => {
|
|
2540
|
+
return this.handleElicitationRequest(request2, serverInstance, options);
|
|
2528
2541
|
}
|
|
2529
2542
|
};
|
|
2530
2543
|
const mcpOptions = {
|