@ai-sdk/mcp 1.0.31 → 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/CHANGELOG.md +6 -0
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/tool/oauth.ts +7 -3
- package/src/util/oauth-util.ts +13 -0
package/package.json
CHANGED
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(
|
|
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
|
|
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
|
|
769
|
+
params.set('resource', resourceUrlStripSlash(resource));
|
|
766
770
|
}
|
|
767
771
|
|
|
768
772
|
const response = await (fetchFn ?? fetch)(tokenUrl, {
|
package/src/util/oauth-util.ts
CHANGED
|
@@ -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,
|