@ai-sdk/mcp 1.0.79 → 1.0.81

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/mcp",
3
- "version": "1.0.79",
3
+ "version": "1.0.81",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -34,8 +34,8 @@
34
34
  "dependencies": {
35
35
  "cross-spawn": "^7.0.6",
36
36
  "pkce-challenge": "^5.0.0",
37
- "@ai-sdk/provider": "3.0.15",
38
- "@ai-sdk/provider-utils": "4.0.50"
37
+ "@ai-sdk/provider": "3.0.16",
38
+ "@ai-sdk/provider-utils": "4.0.51"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/cross-spawn": "^6.0.6",
package/src/tool/oauth.ts CHANGED
@@ -1199,6 +1199,10 @@ async function authInternal(
1199
1199
  ): Promise<AuthResult> {
1200
1200
  let resourceMetadata: OAuthProtectedResourceMetadata | undefined;
1201
1201
  let authorizationServerUrl: string | URL | undefined;
1202
+ let clientInformation: OAuthClientInformation | undefined;
1203
+ let callbackAuthorizationServerInformation:
1204
+ | OAuthAuthorizationServerInformation
1205
+ | undefined;
1202
1206
 
1203
1207
  /** Reject Protected Resource Metadata URLs outside the configured MCP server origin. */
1204
1208
  assertResourceMetadataUrlSameOrigin(serverUrl, resourceMetadataUrl);
@@ -1218,9 +1222,27 @@ async function authInternal(
1218
1222
  }
1219
1223
  } catch {}
1220
1224
 
1221
- /** Fall back to legacy MCP behavior where the MCP server is the Authorization Server */
1225
+ /**
1226
+ * A callback may not have the original PRM URL from the authentication
1227
+ * challenge. Use the authorization server pinned before redirecting when
1228
+ * rediscovery does not select one.
1229
+ */
1230
+ if (authorizationCode !== undefined) {
1231
+ clientInformation = await Promise.resolve(provider.clientInformation());
1232
+ if (clientInformation) {
1233
+ callbackAuthorizationServerInformation =
1234
+ await getStoredAuthorizationServerInformation({
1235
+ provider,
1236
+ clientInformation,
1237
+ });
1238
+ }
1239
+ }
1240
+
1241
+ /** Reuse the callback pin, then fall back to the legacy MCP-as-AS behavior. */
1222
1242
  if (!authorizationServerUrl) {
1223
- authorizationServerUrl = serverUrl;
1243
+ authorizationServerUrl =
1244
+ callbackAuthorizationServerInformation?.authorizationServerUrl ??
1245
+ serverUrl;
1224
1246
  }
1225
1247
 
1226
1248
  /** Validate and select the resource value sent to the AS */
@@ -1253,7 +1275,9 @@ async function authInternal(
1253
1275
  });
1254
1276
 
1255
1277
  /** Load or register client credentials with the AS pin attached. */
1256
- let clientInformation = await Promise.resolve(provider.clientInformation());
1278
+ if (authorizationCode === undefined) {
1279
+ clientInformation = await Promise.resolve(provider.clientInformation());
1280
+ }
1257
1281
  if (!clientInformation) {
1258
1282
  if (authorizationCode !== undefined) {
1259
1283
  throw new Error(
@@ -1295,10 +1319,11 @@ async function authInternal(
1295
1319
  }
1296
1320
 
1297
1321
  const storedAuthorizationServerInformation =
1298
- await getStoredAuthorizationServerInformation({
1322
+ callbackAuthorizationServerInformation ??
1323
+ (await getStoredAuthorizationServerInformation({
1299
1324
  provider,
1300
1325
  clientInformation,
1301
- });
1326
+ }));
1302
1327
  if (!storedAuthorizationServerInformation) {
1303
1328
  throw new MCPClientOAuthError({
1304
1329
  message: