@mastra/mcp 1.18.1-alpha.2 → 2.0.0-alpha.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.
- package/dist/client/actions/resource.d.ts +9 -59
- package/dist/client/actions/resource.d.ts.map +1 -1
- package/dist/client/client.d.ts +71 -124
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +30 -120
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/error-utils.d.ts +9 -0
- package/dist/client/error-utils.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/oauth-callback-server.d.ts +8 -4
- package/dist/client/oauth-callback-server.d.ts.map +1 -1
- package/dist/client/oauth-provider.d.ts +91 -45
- package/dist/client/oauth-provider.d.ts.map +1 -1
- package/dist/client/server-proxy.d.ts +26 -46
- package/dist/client/server-proxy.d.ts.map +1 -1
- package/dist/client/types.d.ts +106 -143
- package/dist/client/types.d.ts.map +1 -1
- package/dist/conformance/fixture.d.ts +3 -0
- package/dist/conformance/fixture.d.ts.map +1 -0
- package/dist/conformance/run.d.ts +2 -0
- package/dist/conformance/run.d.ts.map +1 -0
- package/dist/conformance/stdio-server.d.ts +2 -0
- package/dist/conformance/stdio-server.d.ts.map +1 -0
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-migrations-mcp-v2.md +268 -0
- package/dist/docs/references/reference-tools-mcp-client.md +36 -14
- package/dist/docs/references/reference-tools-mcp-server.md +24 -83
- package/dist/index.cjs +1532 -3284
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1535 -3288
- package/dist/index.js.map +1 -1
- package/dist/server/actions.d.ts +34 -0
- package/dist/server/actions.d.ts.map +1 -0
- package/dist/server/oauth-middleware.d.ts +1 -1
- package/dist/server/request.d.ts +54 -0
- package/dist/server/request.d.ts.map +1 -0
- package/dist/server/server.d.ts +112 -808
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/types.d.ts +82 -138
- package/dist/server/types.d.ts.map +1 -1
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/oauth-types.d.ts +3 -3
- package/dist/shared/oauth-types.d.ts.map +1 -1
- package/dist/shared/trace-context.d.ts +20 -0
- package/dist/shared/trace-context.d.ts.map +1 -0
- package/package.json +12 -17
- package/dist/_types/hono/dist/types/client/client.d.ts +0 -4
- package/dist/_types/hono/dist/types/client/fetch-result-please.d.ts +0 -35
- package/dist/_types/hono/dist/types/client/index.d.ts +0 -7
- package/dist/_types/hono/dist/types/client/types.d.ts +0 -229
- package/dist/_types/hono/dist/types/client/utils.d.ts +0 -18
- package/dist/_types/hono/dist/types/context.d.ts +0 -455
- package/dist/_types/hono/dist/types/helper/streaming/index.d.ts +0 -8
- package/dist/_types/hono/dist/types/helper/streaming/sse.d.ts +0 -13
- package/dist/_types/hono/dist/types/helper/streaming/stream.d.ts +0 -3
- package/dist/_types/hono/dist/types/helper/streaming/text.d.ts +0 -3
- package/dist/_types/hono/dist/types/hono-base.d.ts +0 -220
- package/dist/_types/hono/dist/types/hono.d.ts +0 -19
- package/dist/_types/hono/dist/types/index.d.ts +0 -37
- package/dist/_types/hono/dist/types/request/constants.d.ts +0 -1
- package/dist/_types/hono/dist/types/request.d.ts +0 -324
- package/dist/_types/hono/dist/types/router.d.ts +0 -97
- package/dist/_types/hono/dist/types/types.d.ts +0 -573
- package/dist/_types/hono/dist/types/utils/body.d.ts +0 -79
- package/dist/_types/hono/dist/types/utils/headers.d.ts +0 -8
- package/dist/_types/hono/dist/types/utils/http-status.d.ts +0 -32
- package/dist/_types/hono/dist/types/utils/mime.d.ts +0 -70
- package/dist/_types/hono/dist/types/utils/stream.d.ts +0 -31
- package/dist/_types/hono/dist/types/utils/types.d.ts +0 -74
- package/dist/_types/hono/package.json +0 -1
- package/dist/_types/hono-mcp-server-sse-transport/build/index.d.ts +0 -1
- package/dist/_types/hono-mcp-server-sse-transport/build/sse.d.ts +0 -25
- package/dist/_types/hono-mcp-server-sse-transport/package.json +0 -1
- package/dist/client/actions/elicitation.d.ts +0 -63
- package/dist/client/actions/elicitation.d.ts.map +0 -1
- package/dist/server/__tests__/mock-extra.d.ts +0 -15
- package/dist/server/__tests__/mock-extra.d.ts.map +0 -1
- package/dist/server/mrtrElicitation.d.ts +0 -39
- package/dist/server/mrtrElicitation.d.ts.map +0 -1
- package/dist/server/notificationBroadcast.d.ts +0 -24
- package/dist/server/notificationBroadcast.d.ts.map +0 -1
- package/dist/server/promptActions.d.ts +0 -49
- package/dist/server/promptActions.d.ts.map +0 -1
- package/dist/server/resourceActions.d.ts +0 -72
- package/dist/server/resourceActions.d.ts.map +0 -1
- package/dist/server/toolActions.d.ts +0 -84
- package/dist/server/toolActions.d.ts.map +0 -1
|
@@ -2,7 +2,7 @@ import type { Stream } from 'node:stream';
|
|
|
2
2
|
import { MastraBase } from '@mastra/core/base';
|
|
3
3
|
import type { MCPServerBase } from '@mastra/core/mcp';
|
|
4
4
|
import type { Tool } from '@mastra/core/tools';
|
|
5
|
-
import type {
|
|
5
|
+
import type { ProgressNotification, Prompt, Resource, ResourceTemplateType } from '@modelcontextprotocol/client';
|
|
6
6
|
import type { MastraMCPServerDefinition, MCPServerAuthState } from './client.js';
|
|
7
7
|
import type { MCPDiscoveryErrorDetails } from './error-utils.js';
|
|
8
8
|
import type { SerializableMCPToolCatalog, SerializableMCPToolDefinition } from './types.js';
|
|
@@ -81,7 +81,7 @@ export declare class MCPClient extends MastraBase {
|
|
|
81
81
|
* const mcp = new MCPClient({
|
|
82
82
|
* servers: {
|
|
83
83
|
* weatherServer: {
|
|
84
|
-
* url: new URL('http://localhost:8080/
|
|
84
|
+
* url: new URL('http://localhost:8080/mcp'),
|
|
85
85
|
* requestInit: {
|
|
86
86
|
* headers: { Authorization: 'Bearer token' }
|
|
87
87
|
* }
|
|
@@ -114,48 +114,6 @@ export declare class MCPClient extends MastraBase {
|
|
|
114
114
|
get progress(): {
|
|
115
115
|
onUpdate: (serverName: string, handler: (params: ProgressNotification['params']) => void) => Promise<void>;
|
|
116
116
|
};
|
|
117
|
-
/**
|
|
118
|
-
* Provides access to elicitation-related operations for interactive user input collection.
|
|
119
|
-
*
|
|
120
|
-
* Elicitation allows MCP servers to request structured information from users during tool execution.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```typescript
|
|
124
|
-
* // Set up handler for elicitation requests from a server
|
|
125
|
-
* await mcp.elicitation.onRequest('serverName', async (request) => {
|
|
126
|
-
* console.log(`Server requests: ${request.message}`);
|
|
127
|
-
* console.log('Schema:', request.requestedSchema);
|
|
128
|
-
*
|
|
129
|
-
* // Collect user input and return response
|
|
130
|
-
* return {
|
|
131
|
-
* action: 'accept',
|
|
132
|
-
* content: { name: 'John Doe', email: 'john@example.com' }
|
|
133
|
-
* };
|
|
134
|
-
* });
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
get elicitation(): {
|
|
138
|
-
/**
|
|
139
|
-
* Sets up a handler function for elicitation requests from a specific server.
|
|
140
|
-
*
|
|
141
|
-
* The handler receives requests for user input and must return a response with
|
|
142
|
-
* action ('accept', 'decline', or 'cancel') and optional content.
|
|
143
|
-
*
|
|
144
|
-
* @param serverName - Name of the server to handle elicitation requests for
|
|
145
|
-
* @param handler - Function to handle elicitation requests
|
|
146
|
-
* @throws {MastraError} If setting up the handler fails
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
* await mcp.elicitation.onRequest('weatherServer', async (request) => {
|
|
151
|
-
* // Prompt user for input
|
|
152
|
-
* const userInput = await promptUser(request.requestedSchema);
|
|
153
|
-
* return { action: 'accept', content: userInput };
|
|
154
|
-
* });
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
onRequest: (serverName: string, handler: (request: ElicitRequest['params']) => Promise<ElicitResult>) => Promise<void>;
|
|
158
|
-
};
|
|
159
117
|
/**
|
|
160
118
|
* Provides access to resource-related operations across all configured servers.
|
|
161
119
|
*
|
|
@@ -172,11 +130,11 @@ export declare class MCPClient extends MastraBase {
|
|
|
172
130
|
* // Read a specific resource
|
|
173
131
|
* const content = await mcp.resources.read('weatherServer', 'file://data.json');
|
|
174
132
|
*
|
|
175
|
-
* //
|
|
176
|
-
* await mcp.resources.subscribe('weatherServer', 'file://data.json');
|
|
133
|
+
* // Receive resource updates
|
|
177
134
|
* await mcp.resources.onUpdated('weatherServer', async (params) => {
|
|
178
135
|
* console.log(`Resource updated: ${params.uri}`);
|
|
179
136
|
* });
|
|
137
|
+
* await mcp.resources.subscribe('weatherServer', 'file://data.json');
|
|
180
138
|
* ```
|
|
181
139
|
*/
|
|
182
140
|
get resources(): {
|
|
@@ -279,69 +237,31 @@ export declare class MCPClient extends MastraBase {
|
|
|
279
237
|
})[];
|
|
280
238
|
}>;
|
|
281
239
|
/**
|
|
282
|
-
* Subscribes to
|
|
240
|
+
* Subscribes to update notifications for a resource on a server. Subscriptions ride
|
|
241
|
+
* the client's single `subscriptions/listen` stream and are restored after reconnects.
|
|
283
242
|
*
|
|
284
243
|
* @param serverName - Name of the server
|
|
285
|
-
* @param uri - URI of the resource to
|
|
286
|
-
* @
|
|
287
|
-
* @throws {MastraError} If subscription fails
|
|
244
|
+
* @param uri - URI of the resource to watch
|
|
245
|
+
* @throws {MastraError} If the server declines the subscription
|
|
288
246
|
*
|
|
289
247
|
* @example
|
|
290
248
|
* ```typescript
|
|
291
|
-
* await mcp.resources.
|
|
249
|
+
* await mcp.resources.onUpdated('weatherServer', ({ uri }) => console.log(`updated ${uri}`));
|
|
250
|
+
* await mcp.resources.subscribe('weatherServer', 'file://data.json');
|
|
292
251
|
* ```
|
|
293
252
|
*/
|
|
294
|
-
subscribe: (serverName: string, uri: string) => Promise<
|
|
295
|
-
_meta?: {
|
|
296
|
-
[x: string]: unknown;
|
|
297
|
-
"io.modelcontextprotocol/serverInfo"?: {
|
|
298
|
-
version: string;
|
|
299
|
-
websiteUrl?: string | undefined;
|
|
300
|
-
description?: string | undefined;
|
|
301
|
-
icons?: {
|
|
302
|
-
src: string;
|
|
303
|
-
mimeType?: string | undefined;
|
|
304
|
-
sizes?: string[] | undefined;
|
|
305
|
-
theme?: "dark" | "light" | undefined;
|
|
306
|
-
}[] | undefined;
|
|
307
|
-
name: string;
|
|
308
|
-
title?: string | undefined;
|
|
309
|
-
} | undefined;
|
|
310
|
-
} | undefined;
|
|
311
|
-
}>;
|
|
253
|
+
subscribe: (serverName: string, uri: string) => Promise<void>;
|
|
312
254
|
/**
|
|
313
|
-
*
|
|
255
|
+
* Stops update notifications for a resource previously passed to `subscribe`.
|
|
314
256
|
*
|
|
315
257
|
* @param serverName - Name of the server
|
|
316
|
-
* @param uri - URI of the resource
|
|
317
|
-
* @
|
|
318
|
-
* @throws {MastraError} If unsubscription fails
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* ```typescript
|
|
322
|
-
* await mcp.resources.unsubscribe('weatherServer', 'file://config.json');
|
|
323
|
-
* ```
|
|
258
|
+
* @param uri - URI of the resource
|
|
259
|
+
* @throws {MastraError} If the stream cannot be updated
|
|
324
260
|
*/
|
|
325
|
-
unsubscribe: (serverName: string, uri: string) => Promise<
|
|
326
|
-
_meta?: {
|
|
327
|
-
[x: string]: unknown;
|
|
328
|
-
"io.modelcontextprotocol/serverInfo"?: {
|
|
329
|
-
version: string;
|
|
330
|
-
websiteUrl?: string | undefined;
|
|
331
|
-
description?: string | undefined;
|
|
332
|
-
icons?: {
|
|
333
|
-
src: string;
|
|
334
|
-
mimeType?: string | undefined;
|
|
335
|
-
sizes?: string[] | undefined;
|
|
336
|
-
theme?: "dark" | "light" | undefined;
|
|
337
|
-
}[] | undefined;
|
|
338
|
-
name: string;
|
|
339
|
-
title?: string | undefined;
|
|
340
|
-
} | undefined;
|
|
341
|
-
} | undefined;
|
|
342
|
-
}>;
|
|
261
|
+
unsubscribe: (serverName: string, uri: string) => Promise<void>;
|
|
343
262
|
/**
|
|
344
263
|
* Sets a notification handler for when subscribed resources are updated on a server.
|
|
264
|
+
* Updates arrive for resources passed to `subscribe`.
|
|
345
265
|
*
|
|
346
266
|
* @param serverName - Name of the server to monitor
|
|
347
267
|
* @param handler - Callback function receiving the updated resource URI
|
|
@@ -647,8 +567,9 @@ export declare class MCPClient extends MastraBase {
|
|
|
647
567
|
*
|
|
648
568
|
* 1. Starts a loopback callback server on the redirect URL's port (falling
|
|
649
569
|
* back to the next sequential ports when it is in use)
|
|
650
|
-
* 2. Attempts a connection so the SDK runs
|
|
651
|
-
*
|
|
570
|
+
* 2. Attempts a connection so the SDK runs authorization server discovery
|
|
571
|
+
* (identifying the client by its pre-registered id or its client metadata
|
|
572
|
+
* URL) and delivers the authorization URL through the provider's
|
|
652
573
|
* `onRedirectToAuthorization` callback — the host directs the user there
|
|
653
574
|
* 3. Waits for the browser to deliver the authorization code, validates the
|
|
654
575
|
* OAuth state, exchanges the code for tokens, and reconnects
|
|
@@ -701,12 +622,17 @@ export declare class MCPClient extends MastraBase {
|
|
|
701
622
|
*/
|
|
702
623
|
cancelAuthentication(serverName: string): Promise<boolean>;
|
|
703
624
|
/**
|
|
704
|
-
* Returns instructions advertised by connected MCP servers during
|
|
625
|
+
* Returns instructions advertised by connected MCP servers during discovery.
|
|
705
626
|
*
|
|
706
627
|
* Servers that have not connected yet, or did not advertise instructions,
|
|
707
628
|
* return `undefined`.
|
|
708
629
|
*/
|
|
709
630
|
getServerInstructions(): Record<string, string | undefined>;
|
|
631
|
+
/**
|
|
632
|
+
* The protocol revision negotiated with each configured server, keyed by
|
|
633
|
+
* server name. Servers that have not connected yet return `undefined`.
|
|
634
|
+
*/
|
|
635
|
+
getServerProtocolVersions(): Record<string, string | undefined>;
|
|
710
636
|
/**
|
|
711
637
|
* Retrieves all tools from all configured servers with namespaced names.
|
|
712
638
|
*
|
|
@@ -894,12 +820,12 @@ export declare class MCPClient extends MastraBase {
|
|
|
894
820
|
*/
|
|
895
821
|
private discoverAcrossServers;
|
|
896
822
|
/**
|
|
897
|
-
* Creates MCPServerBase
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
823
|
+
* Creates `MCPServerBase` proxy objects for each server connection in this
|
|
824
|
+
* MCPClient. The returned record can be spread directly into Mastra's
|
|
825
|
+
* `mcpServers` config so that external (non-Mastra) servers appear in Studio
|
|
826
|
+
* alongside local MCPServer instances.
|
|
901
827
|
*
|
|
902
|
-
* @returns Record mapping server names to
|
|
828
|
+
* @returns Record mapping server names to proxy instances
|
|
903
829
|
*
|
|
904
830
|
* @example
|
|
905
831
|
* ```typescript
|
|
@@ -917,22 +843,6 @@ export declare class MCPClient extends MastraBase {
|
|
|
917
843
|
* ```
|
|
918
844
|
*/
|
|
919
845
|
toMCPServerProxies(): Record<string, MCPServerBase>;
|
|
920
|
-
/**
|
|
921
|
-
* Gets current session IDs for all connected MCP clients using Streamable HTTP transport.
|
|
922
|
-
*
|
|
923
|
-
* Returns an object mapping server names to their session IDs. Only includes servers
|
|
924
|
-
* that are currently connected via Streamable HTTP transport.
|
|
925
|
-
*
|
|
926
|
-
* @returns Object mapping server names to session IDs
|
|
927
|
-
*
|
|
928
|
-
* @example
|
|
929
|
-
* ```typescript
|
|
930
|
-
* const sessions = mcp.sessionIds;
|
|
931
|
-
* console.log(sessions);
|
|
932
|
-
* // { weatherServer: 'abc-123', stockServer: 'def-456' }
|
|
933
|
-
* ```
|
|
934
|
-
*/
|
|
935
|
-
get sessionIds(): Record<string, string>;
|
|
936
846
|
/**
|
|
937
847
|
* Gets the stderr stream of a connected stdio server.
|
|
938
848
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/client/configuration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB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AAM,EAAE,MAAM,CAAC,CAAC;KACpC,CAAC,CA+BD;IAED;;;;;;;;;;;;;;OAcG;IACU,kBAAkB,CAAC,EAC9B,UAAU,EACV,UAAU,GACX,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,6BAA6B,CAAC;KAC3C,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAMpC;IAED;;;;;;;;;;;;;;;OAeG;IACU,oBAAoB,CAAC,EAChC,WAAW,EAAE,OAAO,GACrB,EAAE;QACD,WAAW,EAAE,0BAA0B,CAAC;KACzC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAkBpD;YAEa,uBAAuB;YAcvB,+BAA+B;YAiB/B,qBAAqB;YAcrB,wBAAwB;IA8BtC;;;;;;;;;;;OAWG;YACW,qBAAqB;IAsEnC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAQzD;IAED;;;;;;;;OAQG;IACI,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIxD;IAED,OAAO,CAAC,eAAe;YAQT,iBAAiB;YAgCjB,kBAAkB;IAchC,OAAO,CAAC,kBAAkB;YAyBZ,2BAA2B;YAI3B,kBAAkB;YAIlB,iBAAiB;CAuBhC"}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a failed MCP call is worth one transport reconnect and retry.
|
|
3
|
+
*
|
|
4
|
+
* Qualifying failures are a detached SDK client, an HTTP 400/401/403/404 from
|
|
5
|
+
* the endpoint (a gateway or auth layer answering while the backend behind it
|
|
6
|
+
* is unhealthy or the credentials went stale), or a dropped/refused connection.
|
|
7
|
+
* The caller reconnects and retries once. Tool execution errors and JSON-RPC
|
|
8
|
+
* protocol errors are never reconnectable.
|
|
9
|
+
*/
|
|
1
10
|
export declare function isReconnectableMCPError(error: unknown): boolean;
|
|
2
11
|
/** Structured transport metadata for a failed aggregate MCP discovery. */
|
|
3
12
|
export interface MCPDiscoveryErrorDetails {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/client/error-utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/client/error-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAmB/D;AAED,0EAA0E;AAC1E,MAAM,WAAW,wBAAwB;IACvC,8FAA8F;IAC9F,OAAO,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qGAAqG;IACrG,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAoCD;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,wBAAwB,CAmDpF"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type { LoggingLevel, LogMessage, LogHandler, MastraMCPServerDefinition,
|
|
1
|
+
export type { LoggingLevel, LogMessage, LogHandler, MastraMCPServerDefinition, MCPClientCapabilities, MCPClientProtocolVersion, MCPInputRequest, MCPInputRequestHandler, ProgressHandler, InternalMastraMCPClientOptions, RequireToolApproval, RequireToolApprovalFn, RequireToolApprovalContext, ToolAnnotations, SerializableMCPToolDefinition, SerializableMCPToolCatalog, } from './types.js';
|
|
2
|
+
export { MCP_CLIENT_PROTOCOL_VERSION } from './types.js';
|
|
2
3
|
export * from './client.js';
|
|
3
4
|
export * from './configuration.js';
|
|
4
5
|
export type { MCPDiscoveryErrorDetails } from './error-utils.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ,UAAU,EACV,UAAU,EACV,yBAAyB,EACzB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ,UAAU,EACV,UAAU,EACV,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,EACxB,eAAe,EACf,sBAAsB,EACtB,eAAe,EACf,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,EAC1B,eAAe,EACf,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AACtD,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC9D,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* with MCPOAuthClientProvider to complete the authorization-code flow for
|
|
7
7
|
* OAuth-protected MCP servers.
|
|
8
8
|
*
|
|
9
|
-
* @see https://modelcontextprotocol.io/specification/
|
|
9
|
+
* @see https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
12
|
* Options for creating an OAuth callback server.
|
|
@@ -44,6 +44,10 @@ export interface OAuthCallbackResult {
|
|
|
44
44
|
* The state parameter echoed back by the authorization server.
|
|
45
45
|
*/
|
|
46
46
|
state: string;
|
|
47
|
+
/**
|
|
48
|
+
* RFC 9207 authorization-server issuer returned with the callback, when present.
|
|
49
|
+
*/
|
|
50
|
+
iss?: string;
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* A running loopback OAuth callback server.
|
|
@@ -81,9 +85,9 @@ export interface OAuthCallbackServer {
|
|
|
81
85
|
* its preferred port, followed by the sequential fallback-port variants that
|
|
82
86
|
* createOAuthCallbackServer will try when the preferred port is in use.
|
|
83
87
|
*
|
|
84
|
-
* This is the single source of the candidate list:
|
|
85
|
-
* redirect_uris
|
|
86
|
-
* callback URL always matches a
|
|
88
|
+
* This is the single source of the candidate list: include all of these as
|
|
89
|
+
* redirect_uris in the pre-registered client or the hosted Client ID Metadata
|
|
90
|
+
* Document so a fallback-bound callback URL always matches a listed URI.
|
|
87
91
|
*/
|
|
88
92
|
export declare function getCallbackUrlCandidates(redirectUrl: string | URL): URL[];
|
|
89
93
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-callback-server.d.ts","sourceRoot":"","sources":["../../src/client/oauth-callback-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAkCH;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;;;;;OASG;IACH,WAAW,EAAE,MAAM,GAAG,GAAG,CAAC;IAE1B;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"oauth-callback-server.d.ts","sourceRoot":"","sources":["../../src/client/oauth-callback-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAkCH;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;;;;;OASG;IACH,WAAW,EAAE,MAAM,GAAG,GAAG,CAAC;IAE1B;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;OAOG;IACH,WAAW,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAE5E;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,GAAG,GAAG,GAAG,EAAE,CAezE;AAmCD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA8IjH"}
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
* Provides a ready-to-use OAuthClientProvider implementation that can be used
|
|
5
5
|
* with Mastra's MCPClient for connecting to OAuth-protected MCP servers.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Client identity is configured, never registered at runtime: the provider is
|
|
8
|
+
* given either pre-registered client information or a Client ID Metadata
|
|
9
|
+
* Document URL (SEP-991), and it never performs dynamic client registration.
|
|
8
10
|
*/
|
|
9
|
-
import type { OAuthClientProvider, OAuthClientMetadata, OAuthClientInformation,
|
|
11
|
+
import type { OAuthClientProvider, OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationContext, OAuthDiscoveryState, StoredOAuthTokens } from '../shared/oauth-types.js';
|
|
10
12
|
/**
|
|
11
13
|
* Storage interface for persisting OAuth data.
|
|
12
14
|
*
|
|
13
|
-
* Implement this interface to persist OAuth data across
|
|
15
|
+
* Implement this interface to persist OAuth data across processes.
|
|
14
16
|
* For simple in-memory usage, use InMemoryOAuthStorage.
|
|
15
17
|
*/
|
|
16
18
|
export interface OAuthStorage {
|
|
@@ -42,7 +44,19 @@ export declare class InMemoryOAuthStorage implements OAuthStorage {
|
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Options for creating a MCPOAuthClientProvider.
|
|
47
|
+
*
|
|
48
|
+
* Exactly one client identity source is required: `clientInformation` for a
|
|
49
|
+
* client pre-registered with the authorization server, or `clientMetadataUrl`
|
|
50
|
+
* for a Client ID Metadata Document the authorization server fetches.
|
|
45
51
|
*/
|
|
52
|
+
export interface MCPClientMetadata extends OAuthClientMetadata {
|
|
53
|
+
/**
|
|
54
|
+
* The `client_id` published in a Client ID Metadata Document. When present it
|
|
55
|
+
* must equal `clientMetadataUrl`; the provider never sends it to the
|
|
56
|
+
* authorization server itself.
|
|
57
|
+
*/
|
|
58
|
+
client_id?: string;
|
|
59
|
+
}
|
|
46
60
|
export interface MCPOAuthClientProviderOptions {
|
|
47
61
|
/**
|
|
48
62
|
* The redirect URL for the OAuth callback.
|
|
@@ -53,19 +67,32 @@ export interface MCPOAuthClientProviderOptions {
|
|
|
53
67
|
*/
|
|
54
68
|
redirectUrl: string | URL;
|
|
55
69
|
/**
|
|
56
|
-
* OAuth client metadata
|
|
57
|
-
*
|
|
58
|
-
*
|
|
70
|
+
* OAuth client metadata (name, redirect URIs, grant types, scope).
|
|
71
|
+
*
|
|
72
|
+
* Used for scope selection and as the description of this client; it is
|
|
73
|
+
* never posted to a registration endpoint. With `clientMetadataUrl` it must
|
|
74
|
+
* mirror the hosted document: `client_name` and at least one redirect URI.
|
|
59
75
|
*/
|
|
60
|
-
clientMetadata:
|
|
76
|
+
clientMetadata: MCPClientMetadata;
|
|
61
77
|
/**
|
|
62
|
-
*
|
|
63
|
-
* If provided, skips dynamic client registration.
|
|
78
|
+
* Client information for a client pre-registered with the authorization server.
|
|
64
79
|
*/
|
|
65
80
|
clientInformation?: OAuthClientInformation;
|
|
66
81
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
82
|
+
* HTTPS URL of this client's Client ID Metadata Document (SEP-991).
|
|
83
|
+
*
|
|
84
|
+
* The URL is used as the `client_id`; the authorization server fetches the
|
|
85
|
+
* document to learn the client's metadata. Must be an HTTPS URL with a
|
|
86
|
+
* non-root pathname.
|
|
87
|
+
*/
|
|
88
|
+
clientMetadataUrl?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Storage for persisting OAuth data (tokens, discovery state and the PKCE
|
|
91
|
+
* verifier). Defaults to InMemoryOAuthStorage if not provided.
|
|
92
|
+
*
|
|
93
|
+
* Tokens are keyed by the authorization server's validated `issuer`, and
|
|
94
|
+
* mutation ordering is coordinated only within one provider instance, so
|
|
95
|
+
* give each provider its own storage namespace.
|
|
69
96
|
*/
|
|
70
97
|
storage?: OAuthStorage;
|
|
71
98
|
/**
|
|
@@ -86,19 +113,19 @@ export interface MCPOAuthClientProviderOptions {
|
|
|
86
113
|
/**
|
|
87
114
|
* Mastra's OAuth Client Provider implementation.
|
|
88
115
|
*
|
|
89
|
-
* This provider handles the OAuth 2.1 flow for connecting to
|
|
90
|
-
* MCP servers, including:
|
|
91
|
-
* -
|
|
116
|
+
* This provider handles the OAuth 2.1 authorization-code flow for connecting to
|
|
117
|
+
* OAuth-protected MCP servers, including:
|
|
118
|
+
* - Pre-registered or URL-based (Client ID Metadata Document) client identity
|
|
92
119
|
* - PKCE (Proof Key for Code Exchange)
|
|
93
120
|
* - Token storage and refresh
|
|
94
121
|
*
|
|
95
122
|
* @example
|
|
96
123
|
* ```typescript
|
|
97
|
-
* import { MCPClient, MCPOAuthClientProvider
|
|
124
|
+
* import { MCPClient, MCPOAuthClientProvider } from '@mastra/mcp';
|
|
98
125
|
*
|
|
99
|
-
* // Create the OAuth provider
|
|
100
126
|
* const oauthProvider = new MCPOAuthClientProvider({
|
|
101
127
|
* redirectUrl: 'http://localhost:3000/oauth/callback',
|
|
128
|
+
* clientMetadataUrl: 'https://my-app.example.com/oauth/client-metadata.json',
|
|
102
129
|
* clientMetadata: {
|
|
103
130
|
* redirect_uris: ['http://localhost:3000/oauth/callback'],
|
|
104
131
|
* client_name: 'My MCP Client',
|
|
@@ -106,33 +133,31 @@ export interface MCPOAuthClientProviderOptions {
|
|
|
106
133
|
* response_types: ['code'],
|
|
107
134
|
* },
|
|
108
135
|
* onRedirectToAuthorization: (url) => {
|
|
109
|
-
* // Open URL in browser for CLI, or redirect response for web
|
|
110
136
|
* console.log(`Please visit: ${url}`);
|
|
111
137
|
* },
|
|
112
138
|
* });
|
|
113
139
|
*
|
|
114
|
-
* // Create the MCP client with OAuth
|
|
115
140
|
* const client = new MCPClient({
|
|
116
141
|
* servers: {
|
|
117
142
|
* 'protected-server': {
|
|
118
|
-
* url: 'https://mcp.example.com/mcp',
|
|
143
|
+
* url: new URL('https://mcp.example.com/mcp'),
|
|
119
144
|
* authProvider: oauthProvider,
|
|
120
145
|
* },
|
|
121
146
|
* },
|
|
122
147
|
* });
|
|
123
|
-
*
|
|
124
|
-
* await client.connect();
|
|
125
148
|
* ```
|
|
126
149
|
*/
|
|
127
150
|
export declare class MCPOAuthClientProvider implements OAuthClientProvider {
|
|
128
151
|
private _redirectUrl;
|
|
129
|
-
private _clientMetadata;
|
|
152
|
+
private readonly _clientMetadata;
|
|
153
|
+
private readonly _clientMetadataUrl?;
|
|
154
|
+
private readonly _clientInfo?;
|
|
130
155
|
private readonly storage;
|
|
131
156
|
private readonly onRedirect?;
|
|
132
157
|
private readonly generateState;
|
|
133
|
-
private _clientInfo?;
|
|
134
158
|
private _sessionState?;
|
|
135
159
|
private _sessionRedirectUrl?;
|
|
160
|
+
private credentialMutation;
|
|
136
161
|
constructor(options: MCPOAuthClientProviderOptions);
|
|
137
162
|
/**
|
|
138
163
|
* The URL to redirect the user agent to after authorization.
|
|
@@ -142,6 +167,10 @@ export declare class MCPOAuthClientProvider implements OAuthClientProvider {
|
|
|
142
167
|
* Metadata about this OAuth client.
|
|
143
168
|
*/
|
|
144
169
|
get clientMetadata(): OAuthClientMetadata;
|
|
170
|
+
/**
|
|
171
|
+
* URL of this client's Client ID Metadata Document, when identity is URL-based.
|
|
172
|
+
*/
|
|
173
|
+
get clientMetadataUrl(): string | undefined;
|
|
145
174
|
/**
|
|
146
175
|
* Returns a OAuth2 state parameter.
|
|
147
176
|
*
|
|
@@ -172,30 +201,50 @@ export declare class MCPOAuthClientProvider implements OAuthClientProvider {
|
|
|
172
201
|
*
|
|
173
202
|
* Loopback callback servers may bind a fallback port when the preferred one
|
|
174
203
|
* is in use. Call this before triggering authorization so the authorization
|
|
175
|
-
* request's redirect_uri matches the listening server
|
|
176
|
-
*
|
|
177
|
-
*
|
|
204
|
+
* request's redirect_uri matches the listening server. The bound URL must be
|
|
205
|
+
* one of the redirect URIs the client is registered with (or lists in its
|
|
206
|
+
* metadata document).
|
|
178
207
|
*
|
|
179
208
|
* @param redirectUrl - The callback URL that is actually bound
|
|
180
|
-
* @param registeredRedirectUris - The redirect URIs to register during dynamic client registration
|
|
181
209
|
*/
|
|
182
|
-
applyResolvedRedirectUrl(redirectUrl: string | URL
|
|
210
|
+
applyResolvedRedirectUrl(redirectUrl: string | URL): void;
|
|
183
211
|
/**
|
|
184
|
-
*
|
|
212
|
+
* The client's identity: pre-registered information, or the metadata
|
|
213
|
+
* document URL used as `client_id`.
|
|
185
214
|
*/
|
|
186
|
-
clientInformation():
|
|
215
|
+
clientInformation(): OAuthClientInformation;
|
|
216
|
+
private tokensKey;
|
|
187
217
|
/**
|
|
188
|
-
*
|
|
218
|
+
* Serializes storage mutations so concurrent writes and invalidations settle
|
|
219
|
+
* in call order: a write started before `invalidateCredentials` cannot land
|
|
220
|
+
* after it completes.
|
|
189
221
|
*/
|
|
190
|
-
|
|
222
|
+
private enqueueCredentialMutation;
|
|
223
|
+
private readStored;
|
|
224
|
+
private readIssuerIndex;
|
|
225
|
+
private rememberIssuer;
|
|
191
226
|
/**
|
|
192
227
|
* Loads existing OAuth tokens.
|
|
228
|
+
*
|
|
229
|
+
* With an issuer context, only tokens minted by that authorization server are
|
|
230
|
+
* returned; without one, the most recently saved token set is returned for
|
|
231
|
+
* the transport's bearer-token read.
|
|
232
|
+
*/
|
|
233
|
+
tokens(ctx?: OAuthClientInformationContext): Promise<StoredOAuthTokens | undefined>;
|
|
234
|
+
/**
|
|
235
|
+
* Stores new OAuth tokens after successful authorization, bound to the
|
|
236
|
+
* authorization server's issuer when known.
|
|
237
|
+
*/
|
|
238
|
+
saveTokens(tokens: StoredOAuthTokens, ctx?: OAuthClientInformationContext): Promise<void>;
|
|
239
|
+
/**
|
|
240
|
+
* Persists authorization-server discovery state so the callback leg can
|
|
241
|
+
* verify the code is exchanged with the server that issued the redirect.
|
|
193
242
|
*/
|
|
194
|
-
|
|
243
|
+
saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
|
|
195
244
|
/**
|
|
196
|
-
*
|
|
245
|
+
* Loads persisted authorization-server discovery state.
|
|
197
246
|
*/
|
|
198
|
-
|
|
247
|
+
discoveryState(): Promise<OAuthDiscoveryState | undefined>;
|
|
199
248
|
/**
|
|
200
249
|
* Invoked to redirect the user agent to the authorization URL.
|
|
201
250
|
*/
|
|
@@ -209,16 +258,17 @@ export declare class MCPOAuthClientProvider implements OAuthClientProvider {
|
|
|
209
258
|
*/
|
|
210
259
|
codeVerifier(): Promise<string>;
|
|
211
260
|
/**
|
|
212
|
-
* Invalidate credentials when server indicates they're no longer valid.
|
|
261
|
+
* Invalidate stored credentials when the server indicates they're no longer valid.
|
|
262
|
+
* Client identity is configuration, so the `client` scope has nothing to discard.
|
|
213
263
|
*/
|
|
214
|
-
invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier'): Promise<void>;
|
|
264
|
+
invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier' | 'discovery'): Promise<void>;
|
|
215
265
|
/**
|
|
216
266
|
* Clear all stored OAuth data.
|
|
217
267
|
* Useful for logging out or resetting state.
|
|
218
268
|
*/
|
|
219
269
|
clear(): Promise<void>;
|
|
220
270
|
/**
|
|
221
|
-
* Check if the provider has
|
|
271
|
+
* Check if the provider has tokens with an access token.
|
|
222
272
|
*/
|
|
223
273
|
hasValidTokens(): Promise<boolean>;
|
|
224
274
|
}
|
|
@@ -240,19 +290,15 @@ export declare class MCPOAuthClientProvider implements OAuthClientProvider {
|
|
|
240
290
|
* redirect_uris: ['http://localhost:3000/callback'],
|
|
241
291
|
* client_name: 'Test Client',
|
|
242
292
|
* },
|
|
243
|
-
* }
|
|
244
|
-
*
|
|
245
|
-
* const client = new MCPClient({
|
|
246
|
-
* servers: {
|
|
247
|
-
* test: { url: 'https://mcp.example.com', authProvider: provider }
|
|
248
|
-
* },
|
|
293
|
+
* clientInformation: { client_id: 'test-client' },
|
|
249
294
|
* });
|
|
250
295
|
* ```
|
|
251
296
|
*/
|
|
252
297
|
export declare function createSimpleTokenProvider(accessToken: string, options: {
|
|
253
298
|
redirectUrl: string | URL;
|
|
254
299
|
clientMetadata: OAuthClientMetadata;
|
|
255
|
-
|
|
300
|
+
/** Client identity used if the token must be refreshed. */
|
|
301
|
+
clientInformation: OAuthClientInformation;
|
|
256
302
|
tokenType?: string;
|
|
257
303
|
refreshToken?: string;
|
|
258
304
|
expiresIn?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-provider.d.ts","sourceRoot":"","sources":["../../src/client/oauth-provider.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"oauth-provider.d.ts","sourceRoot":"","sources":["../../src/client/oauth-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,6BAA6B,EAC7B,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,0BAA0B,CA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