@ai-sdk/mcp 2.0.0-beta.2 → 2.0.0-beta.3

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 2.0.0-beta.3
4
+
5
+ ### Patch Changes
6
+
7
+ - b9b3899: changeset for #13384
8
+
3
9
  ## 2.0.0-beta.2
4
10
 
5
11
  ### 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
@@ -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
  {