@ai-sdk/mcp 2.0.65 → 2.0.67
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 +18 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/error/oauth-error.ts +18 -0
- package/src/index.ts +5 -0
- package/src/tool/mcp-sse-transport.ts +9 -1
- package/src/tool/oauth.ts +7 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/mcp",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.67",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ai-sdk/provider": "4.0.
|
|
35
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
34
|
+
"@ai-sdk/provider": "4.0.22",
|
|
35
|
+
"@ai-sdk/provider-utils": "5.0.54",
|
|
36
36
|
"cross-spawn": "^7.0.6",
|
|
37
37
|
"pkce-challenge": "^5.0.1"
|
|
38
38
|
},
|
package/src/error/oauth-error.ts
CHANGED
|
@@ -42,6 +42,24 @@ export class UnauthorizedClientError extends MCPClientOAuthError {
|
|
|
42
42
|
static errorCode = 'unauthorized_client';
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
const mismatchName = 'AI_AuthorizationServerMismatchError';
|
|
46
|
+
const mismatchMarker = `vercel.ai.error.${mismatchName}`;
|
|
47
|
+
const mismatchSymbol = Symbol.for(mismatchMarker);
|
|
48
|
+
|
|
49
|
+
export class AuthorizationServerMismatchError extends MCPClientOAuthError {
|
|
50
|
+
private readonly [mismatchSymbol] = true;
|
|
51
|
+
|
|
52
|
+
static errorCode = 'authorization_server_mismatch';
|
|
53
|
+
|
|
54
|
+
constructor({ message, cause }: { message: string; cause?: unknown }) {
|
|
55
|
+
super({ name: 'AuthorizationServerMismatchError', message, cause });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static isInstance(error: unknown): error is AuthorizationServerMismatchError {
|
|
59
|
+
return AISDKError.hasMarker(error, mismatchMarker);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
45
63
|
export const OAUTH_ERRORS = {
|
|
46
64
|
[ServerError.errorCode]: ServerError,
|
|
47
65
|
[InvalidClientError.errorCode]: InvalidClientError,
|
package/src/index.ts
CHANGED
|
@@ -41,6 +41,11 @@ export type {
|
|
|
41
41
|
ClientCapabilities as MCPClientCapabilities,
|
|
42
42
|
} from './tool/types';
|
|
43
43
|
export { auth, UnauthorizedError } from './tool/oauth';
|
|
44
|
+
export {
|
|
45
|
+
MCPClientOAuthError,
|
|
46
|
+
AuthorizationServerMismatchError,
|
|
47
|
+
} from './error/oauth-error';
|
|
48
|
+
export { MCPClientError } from './error/mcp-client-error';
|
|
44
49
|
export type {
|
|
45
50
|
OAuthAuthorizationServerInformation,
|
|
46
51
|
OAuthClientProvider,
|
|
@@ -190,6 +190,10 @@ export class SseMCPTransport implements MCPTransport {
|
|
|
190
190
|
const { done, value } = await reader.read();
|
|
191
191
|
|
|
192
192
|
if (done) {
|
|
193
|
+
if (this.abortController?.signal.aborted) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
193
197
|
if (this.connected) {
|
|
194
198
|
this.connected = false;
|
|
195
199
|
throw new MCPClientError({
|
|
@@ -197,7 +201,11 @@ export class SseMCPTransport implements MCPTransport {
|
|
|
197
201
|
'MCP SSE Transport Error: Connection closed unexpectedly',
|
|
198
202
|
});
|
|
199
203
|
}
|
|
200
|
-
|
|
204
|
+
|
|
205
|
+
throw new MCPClientError({
|
|
206
|
+
message:
|
|
207
|
+
'MCP SSE Transport Error: Connection closed before endpoint event was received',
|
|
208
|
+
});
|
|
201
209
|
}
|
|
202
210
|
|
|
203
211
|
const { event, data } = value;
|
package/src/tool/oauth.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
InvalidClientError,
|
|
21
21
|
InvalidGrantError,
|
|
22
22
|
UnauthorizedClientError,
|
|
23
|
+
AuthorizationServerMismatchError,
|
|
23
24
|
} from '../error/oauth-error';
|
|
24
25
|
import {
|
|
25
26
|
resourceUrlFromServerUrl,
|
|
@@ -360,7 +361,7 @@ function assertAuthorizationServerInformationMatches({
|
|
|
360
361
|
storedAuthorizationServerInformation.tokenEndpoint !==
|
|
361
362
|
currentAuthorizationServerInformation.tokenEndpoint
|
|
362
363
|
) {
|
|
363
|
-
throw new
|
|
364
|
+
throw new AuthorizationServerMismatchError({
|
|
364
365
|
message:
|
|
365
366
|
'OAuth authorization server metadata does not match the metadata that issued the stored credentials',
|
|
366
367
|
});
|
|
@@ -1284,14 +1285,11 @@ export async function auth(
|
|
|
1284
1285
|
|
|
1285
1286
|
await provider.invalidateCredentials?.('all');
|
|
1286
1287
|
return await authInternal(provider, options);
|
|
1287
|
-
} else if (error instanceof InvalidGrantError) {
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
} else {
|
|
1293
|
-
await provider.invalidateCredentials?.('tokens');
|
|
1294
|
-
}
|
|
1288
|
+
} else if (error instanceof InvalidGrantError && refreshAttempt.tokens) {
|
|
1289
|
+
// Only invalidate the tokens used by a failed refresh.
|
|
1290
|
+
await provider.invalidateCredentials?.('tokens', {
|
|
1291
|
+
tokens: refreshAttempt.tokens,
|
|
1292
|
+
});
|
|
1295
1293
|
return await authInternal(provider, options);
|
|
1296
1294
|
}
|
|
1297
1295
|
|