@mastra/mcp 1.14.0-alpha.0 → 1.15.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 +86 -0
- package/dist/_types/hono/dist/types/utils/body.d.ts +1 -1
- package/dist/_types/hono/dist/types/utils/types.d.ts +1 -1
- package/dist/client/client.d.ts +41 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +71 -1
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/oauth-callback-server.d.ts +117 -0
- package/dist/client/oauth-callback-server.d.ts.map +1 -0
- package/dist/client/oauth-provider.d.ts +38 -2
- package/dist/client/oauth-provider.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-mcp-overview.md +1 -1
- package/dist/docs/references/reference-tools-mcp-client.md +96 -0
- package/dist/index.cjs +26866 -26353
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26867 -26355
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,91 @@
|
|
|
1
1
|
# @mastra/mcp
|
|
2
2
|
|
|
3
|
+
## 1.15.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Complete the OAuth authorization-code loop in MCPClient for HTTP MCP servers. Connections rejected with an authorization error now surface a `needs-auth` state (readable via `getServerAuthState()`), and the new `authenticate(serverName)` method runs the interactive flow end to end: it captures the authorization code on a local loopback callback server (exported as `createOAuthCallbackServer` for hosts with custom redirect handling), exchanges it for tokens, and reconnects. ([#19466](https://github.com/mastra-ai/mastra/pull/19466))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`8b20926`](https://github.com/mastra-ai/mastra/commit/8b20926cd59e2ba3d66458e062fa0e6e2ada3e68), [`74faf8b`](https://github.com/mastra-ai/mastra/commit/74faf8bd9c1018f2492653c06b1e25fc8300e9e6), [`1fadac4`](https://github.com/mastra-ai/mastra/commit/1fadac44537caeefe81f9f775ae2f2f3d94e9069), [`792ec9a`](https://github.com/mastra-ai/mastra/commit/792ec9a0869bab8274cf5e0ed2840738737a1607), [`712b864`](https://github.com/mastra-ai/mastra/commit/712b864aa1ed12b14c54390ec17b69de163c37f7), [`8f7a5de`](https://github.com/mastra-ai/mastra/commit/8f7a5dedc246cdc938bb65516703cf9b27b03756), [`c0bec73`](https://github.com/mastra-ai/mastra/commit/c0bec732c93d1a22ae5e51ed66cf8cacca8bd6a6)]:
|
|
12
|
+
- @mastra/core@1.52.0-alpha.2
|
|
13
|
+
|
|
14
|
+
## 1.14.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- Add `serverlessStreaming` option to `MCPServer.startHTTP()` for request-scoped progress notifications in serverless mode. ([#17927](https://github.com/mastra-ai/mastra/pull/17927))
|
|
19
|
+
|
|
20
|
+
Serverless mode (`serverless: true`) buffers each request into a single JSON response, which silently drops any `notifications/progress` a tool emits via `extra.sendNotification()`. Setting `options: { serverless: true, serverlessStreaming: true }` now handles the request with request-scoped SSE streaming (`enableJsonResponse: false` on the transient transport), so progress notifications reach the MCP client's `onprogress` handler before the final result. An explicit `enableJsonResponse` is also honored.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
await server.startHTTP({
|
|
24
|
+
url,
|
|
25
|
+
httpPath: '/mcp',
|
|
26
|
+
req,
|
|
27
|
+
res,
|
|
28
|
+
options: { serverless: true, serverlessStreaming: true },
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This is still fully stateless — no `mcp-session-id` is required or persisted — and the default behavior is unchanged (`enableJsonResponse: true`), so existing serverless JSON-response users are unaffected. It enables only notifications scoped to the current request, such as progress; elicitation, resource subscriptions, and out-of-request resource/list-change notifications still require session state.
|
|
33
|
+
|
|
34
|
+
- Fixed MCP server notifications (resource updates, resource/prompt list changes) not reaching clients connected over streamable HTTP. Notifications are now broadcast to every connected session across all transports. ([#19193](https://github.com/mastra-ai/mastra/pull/19193))
|
|
35
|
+
|
|
36
|
+
Fixed resource subscriptions being shared globally across all clients. Subscriptions are now tracked per session, so `resources.notifyUpdated()` only notifies sessions that subscribed to the resource URI, and one client unsubscribing no longer removes another client's subscription. Clients that relied on receiving `notifications/resources/updated` without subscribing must now call `resources/subscribe` first.
|
|
37
|
+
|
|
38
|
+
Added support for the remaining MCP notification features:
|
|
39
|
+
|
|
40
|
+
**Dynamic tools and tools/list_changed**
|
|
41
|
+
|
|
42
|
+
Servers can now add and remove tools at runtime and notify clients via `notifications/tools/list_changed`:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// Server: manage tools at runtime
|
|
46
|
+
await server.toolActions.add({ myNewTool });
|
|
47
|
+
await server.toolActions.remove(['myNewTool']);
|
|
48
|
+
await server.toolActions.notifyListChanged();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
When the server is registered with a Mastra instance, dynamic add/remove also keeps the Mastra instance's tool registry in sync.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
// Client: react to tool list changes
|
|
55
|
+
await mcp.tools.onListChanged('myServer', async () => {
|
|
56
|
+
const tools = await mcp.listTools();
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Server-side log messages**
|
|
61
|
+
|
|
62
|
+
Servers can now emit `notifications/message` log notifications. The minimum level a client sets via `logging/setLevel` is honored per session:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// Broadcast to all connected clients
|
|
66
|
+
await server.sendLoggingMessage({ level: 'info', data: { message: 'Sync completed' } });
|
|
67
|
+
|
|
68
|
+
// From inside a tool, send to the calling client
|
|
69
|
+
await context.mcp.log('debug', 'Fetching weather', { location });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Progress notifications from tools**
|
|
73
|
+
|
|
74
|
+
Tools can now report progress to the calling client:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
await context.mcp.progress({ progress: 1, total: 3, message: 'step 1' });
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- Fixed MCP clients advertising elicitation support before a handler is registered. ([#19192](https://github.com/mastra-ai/mastra/pull/19192))
|
|
83
|
+
|
|
84
|
+
- Fixed `MCPServer` dropping a resource's `_meta` from `resources/read` results. The read handler rebuilt each content item with only `{ uri, mimeType, text | blob }`, so `appResources` (MCP Apps / SEP-1865) metadata attached during `resources/list` as `_meta: { ui: meta }` never reached the client. Hosts read the UI CSP from `contents[]._meta.ui.csp`, so `connectDomains` was silently ignored and widget `fetch`/XHR calls failed with `Failed to fetch`. The resource's `_meta` is now preserved on the read contents. ([#19163](https://github.com/mastra-ai/mastra/pull/19163))
|
|
85
|
+
|
|
86
|
+
- Updated dependencies [[`bd6d240`](https://github.com/mastra-ai/mastra/commit/bd6d2402db93dddaef0721667e7e8a030e7c6e16), [`0111486`](https://github.com/mastra-ai/mastra/commit/01114867612593eef5cfa2fda6a1194dfedda841), [`96a3749`](https://github.com/mastra-ai/mastra/commit/96a37492235f5b8076b3e3177d83ed5a5e44a640), [`fe1bda0`](https://github.com/mastra-ai/mastra/commit/fe1bda06f6af92a694a51712db747cda1e7185f0), [`25e7c12`](https://github.com/mastra-ai/mastra/commit/25e7c126a770069ae7fb7ecf1d2adb40e017b009), [`1ce5121`](https://github.com/mastra-ai/mastra/commit/1ce512155d122bb21f47d98383e82ffbf84b39e8), [`fb8aea3`](https://github.com/mastra-ai/mastra/commit/fb8aea384291e77311be3a64ee1717320d5c3c73), [`4adc391`](https://github.com/mastra-ai/mastra/commit/4adc3911075249c352bb4832d2471922826344de), [`a5c6337`](https://github.com/mastra-ai/mastra/commit/a5c6337d23c7686c81a32ce62f550f610543a240), [`3cfc47a`](https://github.com/mastra-ai/mastra/commit/3cfc47a6b89940aadd0f46fb01ae9624a73a865d), [`2bb7817`](https://github.com/mastra-ai/mastra/commit/2bb78176112fde628483de2830528f7eee911e56), [`51d9870`](https://github.com/mastra-ai/mastra/commit/51d987032c689c2855374d0f244f5d654da809d1), [`5cab274`](https://github.com/mastra-ai/mastra/commit/5cab2744250e22d12fefa7b32637dce224233cee), [`7fa27d3`](https://github.com/mastra-ai/mastra/commit/7fa27d3b6f5ed68cd34e454a4d3ad9c482a0cfbc), [`8b97958`](https://github.com/mastra-ai/mastra/commit/8b979589f9aa59ba67cac565949475f2ffeb4ac3), [`8410541`](https://github.com/mastra-ai/mastra/commit/84105412c60ecd3bb33a9838146f59c4b588228f), [`a58dcbb`](https://github.com/mastra-ai/mastra/commit/a58dcbb546d7e1d65ebdc1f39e55f0908fcd9391), [`aa38805`](https://github.com/mastra-ai/mastra/commit/aa38805b878b827403be785eb90688d7172f5a40), [`153bd3b`](https://github.com/mastra-ai/mastra/commit/153bd3b396bdfed6b74cf43de12db8fd2d83c04a), [`45a8e65`](https://github.com/mastra-ai/mastra/commit/45a8e65e1556d1362cb3f25187023c36de26661d), [`e955965`](https://github.com/mastra-ai/mastra/commit/e955965dce575a903e37cf054d28ea99aa48785e), [`2d22570`](https://github.com/mastra-ai/mastra/commit/2d22570c7dfdd02123d0ecc529efb05ccba2d9fc), [`07bb863`](https://github.com/mastra-ai/mastra/commit/07bb8631919c6f7cf377dccd45b096e0f17fbed0), [`c8ed116`](https://github.com/mastra-ai/mastra/commit/c8ed11699f62bcac70102ab4ec84d80d20541da6), [`01b338c`](https://github.com/mastra-ai/mastra/commit/01b338c56271f0219606710e3e8b26dee27ac6c2), [`a99eae8`](https://github.com/mastra-ai/mastra/commit/a99eae8908e500c1b2d12f9d277be616b98617a5), [`860ef7e`](https://github.com/mastra-ai/mastra/commit/860ef7e77d92b63469cbe5857aa1e626197e43e9), [`17e818c`](https://github.com/mastra-ai/mastra/commit/17e818c51a958ba90641b1a959dc38faf8c034e9), [`edce8d2`](https://github.com/mastra-ai/mastra/commit/edce8d2769f19e27a05737c627af2d765472a4f8), [`8a586ec`](https://github.com/mastra-ai/mastra/commit/8a586eca9a4914f31dff6140d0d45ac375b00669), [`4451dfe`](https://github.com/mastra-ai/mastra/commit/4451dfe857428e7abcc0261a507a2e186dae6d47), [`8b7361d`](https://github.com/mastra-ai/mastra/commit/8b7361d35de68b80d05d30a74e0c69e7218fd612), [`1d39058`](https://github.com/mastra-ai/mastra/commit/1d39058e548efd691799985d5c8af2737f1c3bd2), [`3927473`](https://github.com/mastra-ai/mastra/commit/392747323ddb10c643d12be7b9ae913159dfaeed), [`dce50dc`](https://github.com/mastra-ai/mastra/commit/dce50dc9a1c1fcd0f427bb5f6250ec74910cb04b), [`fd13f8e`](https://github.com/mastra-ai/mastra/commit/fd13f8e21990f9904c3eedba3a626bb4a929cdb8), [`634caff`](https://github.com/mastra-ai/mastra/commit/634caff29a9200ad058b67d53f96d9e5832fb8a2), [`f703f87`](https://github.com/mastra-ai/mastra/commit/f703f878de072d51fda557f9c50867d8252bef05), [`3e26c87`](https://github.com/mastra-ai/mastra/commit/3e26c87de0c5bc2583b795ce6ca5889b6b161acb), [`33f2b88`](https://github.com/mastra-ai/mastra/commit/33f2b88842c09a567f906fac4cb61cd5277ced59), [`177010f`](https://github.com/mastra-ai/mastra/commit/177010ff096d2e4b28d89803be5b1a4cad2a0d6b), [`0ad646f`](https://github.com/mastra-ai/mastra/commit/0ad646f71a530f2454664299e5e01bfd13fa12e5), [`b486abf`](https://github.com/mastra-ai/mastra/commit/b486abfa2a7528c6f527e4015c819ea9fa54aaad), [`54a51e0`](https://github.com/mastra-ai/mastra/commit/54a51e0a484fe1ebad3fb1f7ef5282a075709eb7), [`c43f3a9`](https://github.com/mastra-ai/mastra/commit/c43f3a9d1efde99b38789364ba4d0ba670f430e3), [`a5008f2`](https://github.com/mastra-ai/mastra/commit/a5008f22ae710ad9402ea9f2547d8c02f74d384b), [`e2d5f37`](https://github.com/mastra-ai/mastra/commit/e2d5f373bd289be534d5f8694d34465010533df6), [`4ce0163`](https://github.com/mastra-ai/mastra/commit/4ce0163dc86e675a86809685c8ce6c49f1aeb87e), [`4378341`](https://github.com/mastra-ai/mastra/commit/43783412df5ea3dd35f5b1f6e4851e79c346fc89)]:
|
|
87
|
+
- @mastra/core@1.51.0
|
|
88
|
+
|
|
3
89
|
## 1.14.0-alpha.0
|
|
4
90
|
|
|
5
91
|
### Minor Changes
|
|
@@ -42,7 +42,7 @@ export type JSONParsed<T, TError = bigint | ReadonlyArray<bigint>> = T extends {
|
|
|
42
42
|
toJSON(): unknown;
|
|
43
43
|
} ? {} : JSONParsed<J, TError> : T extends JSONPrimitive ? T : T extends InvalidJSONValue ? never : T extends ReadonlyArray<unknown> ? {
|
|
44
44
|
[K in keyof T]: JSONParsed<InvalidToNull<T[K]>, TError>;
|
|
45
|
-
} : T extends Set<unknown> | Map<unknown, unknown> | Record<string, never> ? {} : T extends object ? T[keyof T] extends TError ? never : {
|
|
45
|
+
} extends infer A ? A extends ReadonlyArray<unknown> ? A : JSONParsed<InvalidToNull<T[number]>, TError>[] : never : T extends Set<unknown> | Map<unknown, unknown> | Record<string, never> ? {} : T extends object ? T[keyof T] extends TError ? never : {
|
|
46
46
|
[K in keyof OmitSymbolKeys<T> as IsInvalid<T[K]> extends true ? never : K]: boolean extends IsInvalid<T[K]> ? JSONParsed<T[K], TError> | undefined : JSONParsed<T[K], TError>;
|
|
47
47
|
} : T extends unknown ? T extends TError ? never : JSONValue : never;
|
|
48
48
|
/**
|
package/dist/client/client.d.ts
CHANGED
|
@@ -8,6 +8,16 @@ import { PromptClientActions } from './actions/prompt.js';
|
|
|
8
8
|
import { ResourceClientActions } from './actions/resource.js';
|
|
9
9
|
import type { ElicitationHandler, ProgressHandler, InternalMastraMCPClientOptions, Root } from './types.js';
|
|
10
10
|
export type { LoggingLevel, LogMessage, LogHandler, ElicitationHandler, ProgressHandler, MastraFetchLike, MastraMCPServerDefinition, InternalMastraMCPClientOptions, Root, RequireToolApproval, RequireToolApprovalFn, RequireToolApprovalContext, } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* OAuth authorization state of an MCP server connection.
|
|
13
|
+
*
|
|
14
|
+
* - `needs-auth`: the server rejected the connection with a 401 and interactive
|
|
15
|
+
* authorization is required (see MCPClient.authenticate)
|
|
16
|
+
* - `authorized`: the server accepted the configured authProvider's credentials
|
|
17
|
+
*
|
|
18
|
+
* Servers without an authProvider never carry an auth state.
|
|
19
|
+
*/
|
|
20
|
+
export type MCPServerAuthState = 'needs-auth' | 'authorized';
|
|
11
21
|
/**
|
|
12
22
|
* Internal MCP client implementation for connecting to a single MCP server.
|
|
13
23
|
*
|
|
@@ -25,6 +35,8 @@ export declare class InternalMastraMCPClient extends MastraBase {
|
|
|
25
35
|
private enableProgressTracking?;
|
|
26
36
|
private serverConfig;
|
|
27
37
|
private transport?;
|
|
38
|
+
private pendingAuthTransport?;
|
|
39
|
+
private _authState?;
|
|
28
40
|
private operationContextStore;
|
|
29
41
|
private exitHookUnsubscribe?;
|
|
30
42
|
private sigTermHandler?;
|
|
@@ -94,6 +106,35 @@ export declare class InternalMastraMCPClient extends MastraBase {
|
|
|
94
106
|
sendRootsListChanged(): Promise<void>;
|
|
95
107
|
private connectStdio;
|
|
96
108
|
private connectHttp;
|
|
109
|
+
/**
|
|
110
|
+
* Closes and clears any transport retained from an unfinished authorization
|
|
111
|
+
* flow. Safe to call when nothing is pending. Centralizes the cleanup so
|
|
112
|
+
* success, disconnect, and forceReconnect all release the same resource.
|
|
113
|
+
*/
|
|
114
|
+
private closePendingAuthTransport;
|
|
115
|
+
/**
|
|
116
|
+
* Records that the server rejected the connection with a 401 and keeps the
|
|
117
|
+
* transport that started the authorization flow so finishAuth can complete it.
|
|
118
|
+
*/
|
|
119
|
+
private markNeedsAuth;
|
|
120
|
+
/**
|
|
121
|
+
* OAuth authorization state of this server connection, when it has an authProvider.
|
|
122
|
+
*
|
|
123
|
+
* @internal
|
|
124
|
+
*/
|
|
125
|
+
get authState(): MCPServerAuthState | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Completes a pending OAuth authorization-code flow.
|
|
128
|
+
*
|
|
129
|
+
* Exchanges the authorization code captured at the redirect URI on the same
|
|
130
|
+
* transport that started the flow, then leaves the client ready to connect().
|
|
131
|
+
*
|
|
132
|
+
* @param authorizationCode - The authorization code captured at the redirect URI
|
|
133
|
+
* @throws {Error} If no authorization flow is pending for this server
|
|
134
|
+
*
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
finishAuth(authorizationCode: string): Promise<void>;
|
|
97
138
|
private isConnected;
|
|
98
139
|
/**
|
|
99
140
|
* Connects to the MCP server using the configured transport.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,KAAK,EAAmB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAShE,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,2BAA2B,EAE3B,kBAAkB,EAEnB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,KAAK,EAAmB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAShE,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,2BAA2B,EAE3B,kBAAkB,EAEnB,MAA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CAAC,mBAAmB;IAcrB,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IA+LhE,OAAO,CAAC,mBAAmB;CAQ5B"}
|
|
@@ -3,7 +3,7 @@ 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
5
|
import type { ElicitRequest, ElicitResult, ProgressNotification, Prompt, Resource, ResourceTemplate } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
-
import type { MastraMCPServerDefinition } from './client.js';
|
|
6
|
+
import type { MastraMCPServerDefinition, MCPServerAuthState } from './client.js';
|
|
7
7
|
/**
|
|
8
8
|
* Configuration options for creating an MCPClient instance.
|
|
9
9
|
*/
|
|
@@ -55,6 +55,15 @@ export declare class MCPClient extends MastraBase {
|
|
|
55
55
|
private defaultTimeout;
|
|
56
56
|
private mcpClientsById;
|
|
57
57
|
private disconnectPromise;
|
|
58
|
+
private authFlowsByServer;
|
|
59
|
+
private authCallbackServersByServer;
|
|
60
|
+
/**
|
|
61
|
+
* Per-server abort controllers for in-flight authorization flows. Created
|
|
62
|
+
* synchronously at the start of {@link runAuthorizationFlow} — before the
|
|
63
|
+
* callback server exists — so cancel/disconnect can interrupt the setup phase
|
|
64
|
+
* (discovery, registration, port binding) and not just the waitForCode wait.
|
|
65
|
+
*/
|
|
66
|
+
private authAbortControllersByServer;
|
|
58
67
|
/**
|
|
59
68
|
* Creates a new MCPClient instance for managing MCP server connections.
|
|
60
69
|
*
|
|
@@ -565,6 +574,67 @@ export declare class MCPClient extends MastraBase {
|
|
|
565
574
|
* ```
|
|
566
575
|
*/
|
|
567
576
|
reconnectServer(serverName: string): Promise<void>;
|
|
577
|
+
/**
|
|
578
|
+
* Runs the interactive OAuth authorization-code flow for a server.
|
|
579
|
+
*
|
|
580
|
+
* Requires the server to be configured with an MCPOAuthClientProvider whose
|
|
581
|
+
* redirect URL points at a loopback address. The flow:
|
|
582
|
+
*
|
|
583
|
+
* 1. Starts a loopback callback server on the redirect URL's port (falling
|
|
584
|
+
* back to the next sequential ports when it is in use)
|
|
585
|
+
* 2. Attempts a connection so the SDK runs discovery and dynamic client
|
|
586
|
+
* registration, delivering the authorization URL through the provider's
|
|
587
|
+
* `onRedirectToAuthorization` callback — the host directs the user there
|
|
588
|
+
* 3. Waits for the browser to deliver the authorization code, validates the
|
|
589
|
+
* OAuth state, exchanges the code for tokens, and reconnects
|
|
590
|
+
*
|
|
591
|
+
* Concurrent calls for the same server join the pending flow (the joiner's
|
|
592
|
+
* options are ignored — the pending flow keeps its own timeout); different
|
|
593
|
+
* servers authenticate independently. Each server needs its own provider
|
|
594
|
+
* instance: the flow pins session state on the provider, so sharing one
|
|
595
|
+
* MCPOAuthClientProvider across servers is not supported. Hosts with custom
|
|
596
|
+
* redirect handling (e.g. a web app with an HTTPS redirect URL) should
|
|
597
|
+
* drive MCPOAuthClientProvider directly instead.
|
|
598
|
+
*
|
|
599
|
+
* @param serverName - The name of the server to authenticate (must match a key in `servers`)
|
|
600
|
+
* @param options.timeoutMs - How long to wait for the browser callback (default 5 minutes)
|
|
601
|
+
* @throws {Error} If the server has no MCPOAuthClientProvider or its redirect URL is not loopback
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* ```typescript
|
|
605
|
+
* if (mcp.getServerAuthState('weatherServer') === 'needs-auth') {
|
|
606
|
+
* await mcp.authenticate('weatherServer');
|
|
607
|
+
* }
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
authenticate(serverName: string, options?: {
|
|
611
|
+
timeoutMs?: number;
|
|
612
|
+
}): Promise<void>;
|
|
613
|
+
/**
|
|
614
|
+
* OAuth authorization state of a configured server.
|
|
615
|
+
*
|
|
616
|
+
* Returns `undefined` for servers without an authProvider and for servers
|
|
617
|
+
* that have not attempted a connection yet.
|
|
618
|
+
*/
|
|
619
|
+
getServerAuthState(serverName: string): MCPServerAuthState | undefined;
|
|
620
|
+
private runAuthorizationFlow;
|
|
621
|
+
/**
|
|
622
|
+
* Cancels a pending {@link authenticate} flow for a server.
|
|
623
|
+
*
|
|
624
|
+
* Tears down the loopback callback server immediately — the pending
|
|
625
|
+
* authenticate() call rejects. Useful when the user closed the browser
|
|
626
|
+
* without completing consent, which the host cannot observe.
|
|
627
|
+
*
|
|
628
|
+
* The resulting auth state depends on how far the flow had progressed: a flow
|
|
629
|
+
* cancelled after the server rejected the connection with a 401 stays in the
|
|
630
|
+
* `needs-auth` state so it can be retried right away, while a flow cancelled
|
|
631
|
+
* during the setup phase (before any connection was attempted) leaves the
|
|
632
|
+
* state unchanged — typically `undefined`.
|
|
633
|
+
*
|
|
634
|
+
* @param serverName - The name of the server whose flow to cancel
|
|
635
|
+
* @returns `true` if a pending flow was cancelled, `false` when no flow was pending
|
|
636
|
+
*/
|
|
637
|
+
cancelAuthentication(serverName: string): Promise<boolean>;
|
|
568
638
|
/**
|
|
569
639
|
* Returns instructions advertised by connected MCP servers during initialize.
|
|
570
640
|
*
|
|
@@ -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,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,MAAM,EACN,QAAQ,EACR,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/client/configuration.ts"],"names":[],"mapp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EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;IAgCF;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAK9F;;;;;;;;;;;;;;;;OAgBG;IACU,sBAAsB,IAAI,OAAO,CAAC;QAC7C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QACnE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;IAgCF;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC;IAU1D;;;;;;;;;;;;;;OAcG;IACH,IAAI,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQvC;IAED;;;;;;;;OAQG;IACI,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAMzD,OAAO,CAAC,eAAe;YAQT,iBAAiB;YAiCjB,kBAAkB;IAchC,OAAO,CAAC,kBAAkB;YAyBZ,2BAA2B;YAI3B,kBAAkB;YAIlB,iBAAiB;CAuBhC"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export type { LoggingLevel, LogMessage, LogHandler, MastraMCPServerDefinition, E
|
|
|
2
2
|
export * from './client.js';
|
|
3
3
|
export * from './configuration.js';
|
|
4
4
|
export * from './oauth-provider.js';
|
|
5
|
+
export * from './oauth-callback-server.js';
|
|
5
6
|
export { MCPClientServerProxy } from './server-proxy.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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,kBAAkB,EAClB,eAAe,EACf,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,EAC1B,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
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,kBAAkB,EAClB,eAAe,EACf,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,EAC1B,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loopback OAuth Callback Server for MCP Client
|
|
3
|
+
*
|
|
4
|
+
* Provides a one-shot local HTTP server that captures the OAuth authorization
|
|
5
|
+
* code delivered to a loopback redirect URL (RFC 8252). Hosts use it together
|
|
6
|
+
* with MCPOAuthClientProvider to complete the authorization-code flow for
|
|
7
|
+
* OAuth-protected MCP servers.
|
|
8
|
+
*
|
|
9
|
+
* @see https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Options for creating an OAuth callback server.
|
|
13
|
+
*/
|
|
14
|
+
export interface OAuthCallbackServerOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The redirect URL the authorization server will send the browser back to.
|
|
17
|
+
* Its port is the preferred port to bind; if that port is in use, the next
|
|
18
|
+
* sequential ports are tried (see getCallbackUrlCandidates). The server
|
|
19
|
+
* binds the URL's hostname — prefer the literal `127.0.0.1` over
|
|
20
|
+
* `localhost` (RFC 8252 §8.3) so the browser and server agree on the
|
|
21
|
+
* address family.
|
|
22
|
+
*
|
|
23
|
+
* @example 'http://127.0.0.1:5533/oauth/callback'
|
|
24
|
+
*/
|
|
25
|
+
redirectUrl: string | URL;
|
|
26
|
+
/**
|
|
27
|
+
* The OAuth state parameter issued for this authorization request.
|
|
28
|
+
* The state authenticates the redirect (CSRF protection per OAuth 2.1):
|
|
29
|
+
* callback requests without a matching state receive an error response and
|
|
30
|
+
* never settle the flow, so a stray local request cannot abort or spoof a
|
|
31
|
+
* pending authorization.
|
|
32
|
+
*/
|
|
33
|
+
state: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The authorization code captured from the OAuth callback.
|
|
37
|
+
*/
|
|
38
|
+
export interface OAuthCallbackResult {
|
|
39
|
+
/**
|
|
40
|
+
* The authorization code to exchange for tokens.
|
|
41
|
+
*/
|
|
42
|
+
code: string;
|
|
43
|
+
/**
|
|
44
|
+
* The state parameter echoed back by the authorization server.
|
|
45
|
+
*/
|
|
46
|
+
state: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A running loopback OAuth callback server.
|
|
50
|
+
*/
|
|
51
|
+
export interface OAuthCallbackServer {
|
|
52
|
+
/**
|
|
53
|
+
* The callback URL that is actually bound (reflects any port fallback).
|
|
54
|
+
* Use this — not the preferred redirect URL — as the redirect_uri for the
|
|
55
|
+
* authorization request.
|
|
56
|
+
*/
|
|
57
|
+
url: URL;
|
|
58
|
+
/**
|
|
59
|
+
* The port the server is listening on.
|
|
60
|
+
*/
|
|
61
|
+
port: number;
|
|
62
|
+
/**
|
|
63
|
+
* Waits for the browser to deliver the authorization code.
|
|
64
|
+
*
|
|
65
|
+
* Resolves once with the code and state from the first state-matching
|
|
66
|
+
* callback request. Rejects on timeout, on a state-matching OAuth error
|
|
67
|
+
* response (`error` / `error_description` query params), or when the
|
|
68
|
+
* server is closed before a code arrives.
|
|
69
|
+
*/
|
|
70
|
+
waitForCode(options?: {
|
|
71
|
+
timeoutMs?: number;
|
|
72
|
+
}): Promise<OAuthCallbackResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Stops the server and releases the port. Rejects any pending waitForCode.
|
|
75
|
+
* Idempotent: closing an already-closed server resolves immediately.
|
|
76
|
+
*/
|
|
77
|
+
close(): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns the candidate callback URLs for a redirect URL: the URL itself on
|
|
81
|
+
* its preferred port, followed by the sequential fallback-port variants that
|
|
82
|
+
* createOAuthCallbackServer will try when the preferred port is in use.
|
|
83
|
+
*
|
|
84
|
+
* This is the single source of the candidate list: register all of these as
|
|
85
|
+
* redirect_uris during dynamic client registration so a fallback-bound
|
|
86
|
+
* callback URL always matches a registered URI.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getCallbackUrlCandidates(redirectUrl: string | URL): URL[];
|
|
89
|
+
/**
|
|
90
|
+
* Starts a one-shot loopback HTTP server that captures the OAuth
|
|
91
|
+
* authorization code.
|
|
92
|
+
*
|
|
93
|
+
* The server binds the redirect URL's hostname on its port, falling back to
|
|
94
|
+
* the next sequential ports when it is in use (see getCallbackUrlCandidates).
|
|
95
|
+
* The first state-matching request on the callback path settles the outcome;
|
|
96
|
+
* subsequent requests receive 410 Gone. Requests whose state does not match
|
|
97
|
+
* receive an error response without settling, so only the genuine redirect
|
|
98
|
+
* can complete or abort the flow. The response pages never echo the
|
|
99
|
+
* authorization code.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const callbackServer = await createOAuthCallbackServer({
|
|
104
|
+
* redirectUrl: 'http://127.0.0.1:5533/oauth/callback',
|
|
105
|
+
* state: expectedState,
|
|
106
|
+
* });
|
|
107
|
+
* try {
|
|
108
|
+
* // Direct the user to the authorization URL, then:
|
|
109
|
+
* const { code } = await callbackServer.waitForCode();
|
|
110
|
+
* await transport.finishAuth(code);
|
|
111
|
+
* } finally {
|
|
112
|
+
* await callbackServer.close();
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare function createOAuthCallbackServer(options: OAuthCallbackServerOptions): Promise<OAuthCallbackServer>;
|
|
117
|
+
//# sourceMappingURL=oauth-callback-server.d.ts.map
|
|
@@ -0,0 +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;CACf;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"}
|
|
@@ -125,12 +125,14 @@ export interface MCPOAuthClientProviderOptions {
|
|
|
125
125
|
* ```
|
|
126
126
|
*/
|
|
127
127
|
export declare class MCPOAuthClientProvider implements OAuthClientProvider {
|
|
128
|
-
private
|
|
129
|
-
private
|
|
128
|
+
private _redirectUrl;
|
|
129
|
+
private _clientMetadata;
|
|
130
130
|
private readonly storage;
|
|
131
131
|
private readonly onRedirect?;
|
|
132
132
|
private readonly generateState;
|
|
133
133
|
private _clientInfo?;
|
|
134
|
+
private _sessionState?;
|
|
135
|
+
private _sessionRedirectUrl?;
|
|
134
136
|
constructor(options: MCPOAuthClientProviderOptions);
|
|
135
137
|
/**
|
|
136
138
|
* The URL to redirect the user agent to after authorization.
|
|
@@ -142,8 +144,42 @@ export declare class MCPOAuthClientProvider implements OAuthClientProvider {
|
|
|
142
144
|
get clientMetadata(): OAuthClientMetadata;
|
|
143
145
|
/**
|
|
144
146
|
* Returns a OAuth2 state parameter.
|
|
147
|
+
*
|
|
148
|
+
* While an authorization session is active (see beginAuthorizationSession),
|
|
149
|
+
* the pinned session state is returned so a callback server can validate
|
|
150
|
+
* the redirect against a known value.
|
|
145
151
|
*/
|
|
146
152
|
state(): Promise<string>;
|
|
153
|
+
/**
|
|
154
|
+
* Pins the OAuth state parameter for the next authorization request.
|
|
155
|
+
*
|
|
156
|
+
* Hosts driving an interactive authorization flow (e.g. MCPClient.authenticate)
|
|
157
|
+
* call this before triggering the flow so the loopback callback server knows
|
|
158
|
+
* which state value to expect. Call endAuthorizationSession once the flow settles.
|
|
159
|
+
*
|
|
160
|
+
* @returns The pinned state value, generated with the configured stateGenerator
|
|
161
|
+
*/
|
|
162
|
+
beginAuthorizationSession(): Promise<string>;
|
|
163
|
+
/**
|
|
164
|
+
* Clears the pinned authorization state (see beginAuthorizationSession) and
|
|
165
|
+
* restores the configured redirect URL if applyResolvedRedirectUrl rebased
|
|
166
|
+
* it to a fallback port during the session, so the next flow starts from
|
|
167
|
+
* the preferred port again.
|
|
168
|
+
*/
|
|
169
|
+
endAuthorizationSession(): void;
|
|
170
|
+
/**
|
|
171
|
+
* Points the provider at the callback URL that is actually bound.
|
|
172
|
+
*
|
|
173
|
+
* Loopback callback servers may bind a fallback port when the preferred one
|
|
174
|
+
* is in use. Call this before triggering authorization so the authorization
|
|
175
|
+
* request's redirect_uri matches the listening server, and so dynamic client
|
|
176
|
+
* registration registers every candidate callback URL (see
|
|
177
|
+
* getCallbackUrlCandidates) rather than only the preferred one.
|
|
178
|
+
*
|
|
179
|
+
* @param redirectUrl - The callback URL that is actually bound
|
|
180
|
+
* @param registeredRedirectUris - The redirect URIs to register during dynamic client registration
|
|
181
|
+
*/
|
|
182
|
+
applyResolvedRedirectUrl(redirectUrl: string | URL, registeredRedirectUris: (string | URL)[]): void;
|
|
147
183
|
/**
|
|
148
184
|
* Loads information about this OAuth client.
|
|
149
185
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-provider.d.ts","sourceRoot":"","sources":["../../src/client/oauth-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,EAC1B,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAElC;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAEtD;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAC;IAEnE;;OAEG;IACH,MAAM,CAAC,G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AQrC;;OAEG;IACG,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB3F;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;CAYzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,GAAG,GAAG,CAAC;IAC1B,cAAc,EAAE,mBAAmB,CAAC;IACpC,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GACA,mBAAmB,CAsBrB"}
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -64,7 +64,7 @@ export const testMcpClient = new MCPClient({
|
|
|
64
64
|
|
|
65
65
|
Visit [MCPClient](https://mastra.ai/reference/tools/mcp-client) for a full list of configuration options.
|
|
66
66
|
|
|
67
|
-
> **Authentication:** For connecting to OAuth-protected MCP servers
|
|
67
|
+
> **Authentication:** For connecting to OAuth-protected MCP servers — including completing the browser-based authorization flow with `authenticate()` — see the [OAuth Authentication](https://mastra.ai/reference/tools/mcp-client) section.
|
|
68
68
|
|
|
69
69
|
## Using `MCPClient` with an agent
|
|
70
70
|
|