@ai-sdk/mcp 1.0.30 → 1.0.32

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.30",
3
+ "version": "1.0.32",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -33,8 +33,8 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "pkce-challenge": "^5.0.0",
36
- "@ai-sdk/provider": "3.0.8",
37
- "@ai-sdk/provider-utils": "4.0.21"
36
+ "@ai-sdk/provider-utils": "4.0.22",
37
+ "@ai-sdk/provider": "3.0.8"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "20.17.24",
@@ -70,9 +70,7 @@
70
70
  "build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
71
71
  "build:watch": "pnpm clean && tsup --watch",
72
72
  "clean": "rm -rf dist *.tsbuildinfo",
73
- "lint": "eslint \"./**/*.ts*\"",
74
73
  "type-check": "tsc --build",
75
- "prettier-check": "prettier --check \"./**/*.ts*\"",
76
74
  "test": "pnpm test:node && pnpm test:edge",
77
75
  "test:update": "pnpm test:node -u",
78
76
  "test:watch": "vitest --config vitest.node.config.js",
package/src/tool/oauth.ts CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  import {
25
25
  resourceUrlFromServerUrl,
26
26
  checkResourceAllowed,
27
+ resourceUrlStripSlash,
27
28
  } from '../util/oauth-util';
28
29
  import { LATEST_PROTOCOL_VERSION } from './types';
29
30
  import { FetchFunction } from '@ai-sdk/provider-utils';
@@ -451,7 +452,10 @@ export async function startAuthorization(
451
452
  }
452
453
 
453
454
  if (resource) {
454
- authorizationUrl.searchParams.set('resource', resource.href);
455
+ authorizationUrl.searchParams.set(
456
+ 'resource',
457
+ resourceUrlStripSlash(resource),
458
+ );
455
459
  }
456
460
 
457
461
  return { authorizationUrl, codeVerifier };
@@ -675,7 +679,7 @@ export async function exchangeAuthorization(
675
679
  }
676
680
 
677
681
  if (resource) {
678
- params.set('resource', resource.href);
682
+ params.set('resource', resourceUrlStripSlash(resource));
679
683
  }
680
684
 
681
685
  const response = await (fetchFn ?? fetch)(tokenUrl, {
@@ -762,7 +766,7 @@ export async function refreshAuthorization(
762
766
  }
763
767
 
764
768
  if (resource) {
765
- params.set('resource', resource.href);
769
+ params.set('resource', resourceUrlStripSlash(resource));
766
770
  }
767
771
 
768
772
  const response = await (fetchFn ?? fetch)(tokenUrl, {
@@ -14,6 +14,19 @@ export function resourceUrlFromServerUrl(url: URL | string): URL {
14
14
  return resourceURL;
15
15
  }
16
16
 
17
+ /**
18
+ * Serializes a resource URL to a string, removing the trailing slash that
19
+ * URL.href adds to pathless URLs. Per the MCP spec, implementations SHOULD
20
+ * use the form without the trailing slash for better interoperability.
21
+ */
22
+ export function resourceUrlStripSlash(resource: URL): string {
23
+ const href = resource.href;
24
+ if (resource.pathname === '/' && href.endsWith('/')) {
25
+ return href.slice(0, -1);
26
+ }
27
+ return href;
28
+ }
29
+
17
30
  /**
18
31
  * Checks if a requested resource URL matches a configured resource URL.
19
32
  * A requested resource matches if it has the same scheme, domain, port,