@ai-sdk/mcp 1.0.91 → 1.0.92

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.91",
3
+ "version": "1.0.92",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
package/src/tool/oauth.ts CHANGED
@@ -631,8 +631,12 @@ export function buildDiscoveryUrls(
631
631
  expectedIssuer: pathIssuer,
632
632
  });
633
633
 
634
+ // Assign the path rather than resolving it as a URL reference: a pathname
635
+ // beginning with // would otherwise replace the authorization server host.
636
+ const oidcDiscoveryUrl = new URL(url.origin);
637
+ oidcDiscoveryUrl.pathname = `${pathname}/.well-known/openid-configuration`;
634
638
  urlsToTry.push({
635
- url: new URL(`${pathname}/.well-known/openid-configuration`, url.origin),
639
+ url: oidcDiscoveryUrl,
636
640
  type: 'oidc',
637
641
  expectedIssuer: pathIssuer,
638
642
  });
@@ -670,8 +674,17 @@ export async function discoverAuthorizationServerMetadata(
670
674
  ): Promise<AuthorizationServerMetadata | undefined> {
671
675
  const headers = { 'MCP-Protocol-Version': protocolVersion };
672
676
 
677
+ const authorizationServerOrigin = new URL(authorizationServerUrl).origin;
673
678
  const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
674
679
 
680
+ // Check all candidates before any request so discovery cannot bypass an
681
+ // application's authorization server validation by changing the origin.
682
+ if (urlsToTry.some(({ url }) => url.origin !== authorizationServerOrigin)) {
683
+ throw new MCPClientOAuthError({
684
+ message: 'OAuth discovery URL changed authorization-server origin',
685
+ });
686
+ }
687
+
675
688
  for (const { url: endpointUrl, type, expectedIssuer } of urlsToTry) {
676
689
  const response = await fetchWithCorsRetry(
677
690
  endpointUrl,