@ai-sdk/mcp 2.0.0-beta.2 → 2.0.0-beta.4
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 +14 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -0
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.js +3 -3
- package/dist/mcp-stdio/index.mjs +1 -1
- package/package.json +6 -6
- package/src/tool/oauth.ts +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/mcp
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [5c2a5a2]
|
|
8
|
+
- @ai-sdk/provider@4.0.0-beta.1
|
|
9
|
+
- @ai-sdk/provider-utils@5.0.0-beta.2
|
|
10
|
+
|
|
11
|
+
## 2.0.0-beta.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- b9b3899: fix(mcp): validate state param in oauth flow
|
|
16
|
+
|
|
3
17
|
## 2.0.0-beta.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -182,6 +182,8 @@ interface OAuthClientProvider {
|
|
|
182
182
|
clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
|
|
183
183
|
saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
|
|
184
184
|
state?(): string | Promise<string>;
|
|
185
|
+
saveState?(state: string): void | Promise<void>;
|
|
186
|
+
storedState?(): string | undefined | Promise<string | undefined>;
|
|
185
187
|
validateResourceURL?(serverUrl: string | URL, resource?: string): Promise<URL | undefined>;
|
|
186
188
|
}
|
|
187
189
|
declare class UnauthorizedError extends Error {
|
|
@@ -190,6 +192,7 @@ declare class UnauthorizedError extends Error {
|
|
|
190
192
|
declare function auth(provider: OAuthClientProvider, options: {
|
|
191
193
|
serverUrl: string | URL;
|
|
192
194
|
authorizationCode?: string;
|
|
195
|
+
callbackState?: string;
|
|
193
196
|
scope?: string;
|
|
194
197
|
resourceMetadataUrl?: URL;
|
|
195
198
|
fetchFn?: FetchFunction;
|
package/dist/index.d.ts
CHANGED
|
@@ -182,6 +182,8 @@ interface OAuthClientProvider {
|
|
|
182
182
|
clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
|
|
183
183
|
saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
|
|
184
184
|
state?(): string | Promise<string>;
|
|
185
|
+
saveState?(state: string): void | Promise<void>;
|
|
186
|
+
storedState?(): string | undefined | Promise<string | undefined>;
|
|
185
187
|
validateResourceURL?(serverUrl: string | URL, resource?: string): Promise<URL | undefined>;
|
|
186
188
|
}
|
|
187
189
|
declare class UnauthorizedError extends Error {
|
|
@@ -190,6 +192,7 @@ declare class UnauthorizedError extends Error {
|
|
|
190
192
|
declare function auth(provider: OAuthClientProvider, options: {
|
|
191
193
|
serverUrl: string | URL;
|
|
192
194
|
authorizationCode?: string;
|
|
195
|
+
callbackState?: string;
|
|
193
196
|
scope?: string;
|
|
194
197
|
resourceMetadataUrl?: URL;
|
|
195
198
|
fetchFn?: FetchFunction;
|
package/dist/index.js
CHANGED
|
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
ElicitResultSchema: () => ElicitResultSchema,
|
|
34
34
|
ElicitationRequestSchema: () => ElicitationRequestSchema,
|
|
35
35
|
UnauthorizedError: () => UnauthorizedError,
|
|
@@ -37,7 +37,7 @@ __export(src_exports, {
|
|
|
37
37
|
createMCPClient: () => createMCPClient,
|
|
38
38
|
experimental_createMCPClient: () => createMCPClient
|
|
39
39
|
});
|
|
40
|
-
module.exports = __toCommonJS(
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
41
|
|
|
42
42
|
// src/tool/mcp-client.ts
|
|
43
43
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
@@ -949,6 +949,7 @@ async function selectResourceURL(serverUrl, provider, resourceMetadata) {
|
|
|
949
949
|
async function authInternal(provider, {
|
|
950
950
|
serverUrl,
|
|
951
951
|
authorizationCode,
|
|
952
|
+
callbackState,
|
|
952
953
|
scope,
|
|
953
954
|
resourceMetadataUrl,
|
|
954
955
|
fetchFn
|
|
@@ -1001,6 +1002,14 @@ async function authInternal(provider, {
|
|
|
1001
1002
|
clientInformation = fullInformation;
|
|
1002
1003
|
}
|
|
1003
1004
|
if (authorizationCode !== void 0) {
|
|
1005
|
+
if (provider.storedState) {
|
|
1006
|
+
const expectedState = await provider.storedState();
|
|
1007
|
+
if (expectedState !== void 0 && expectedState !== callbackState) {
|
|
1008
|
+
throw new Error(
|
|
1009
|
+
"OAuth state parameter mismatch - possible CSRF attack"
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1004
1013
|
const codeVerifier2 = await provider.codeVerifier();
|
|
1005
1014
|
const tokens2 = await exchangeAuthorization(authorizationServerUrl, {
|
|
1006
1015
|
metadata,
|
|
@@ -1039,6 +1048,9 @@ async function authInternal(provider, {
|
|
|
1039
1048
|
}
|
|
1040
1049
|
}
|
|
1041
1050
|
const state = provider.state ? await provider.state() : void 0;
|
|
1051
|
+
if (state && provider.saveState) {
|
|
1052
|
+
await provider.saveState(state);
|
|
1053
|
+
}
|
|
1042
1054
|
const { authorizationUrl, codeVerifier } = await startAuthorization(
|
|
1043
1055
|
authorizationServerUrl,
|
|
1044
1056
|
{
|