@mcp-use/client 2.0.0-beta.10 → 2.0.0-beta.11

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/dist/index.js CHANGED
@@ -1108,7 +1108,7 @@ init_connector_telemetry();
1108
1108
  init_logging();
1109
1109
 
1110
1110
  // src/utils/version.ts
1111
- var VERSION = "2.0.0-beta.9";
1111
+ var VERSION = "2.0.0-beta.10";
1112
1112
  function getPackageVersion() {
1113
1113
  return VERSION;
1114
1114
  }
@@ -2054,29 +2054,39 @@ var OAuthSessionStore = class _OAuthSessionStore {
2054
2054
  if (ctx) await this.store.set(this.credentialKey("tokens"), serialized);
2055
2055
  await this.store.remove(this.getKey("code_verifier"));
2056
2056
  await this.store.remove(this.getKey("last_auth_url"));
2057
+ await this.store.remove(this.getKey("last_auth_callback_url"));
2057
2058
  }
2058
2059
  async clientInformation(ctx) {
2060
+ if (!this.allowClientSecret) {
2061
+ const registeredRedirectUri = await this.store.get(
2062
+ this.getKey("client_info_redirect_uri")
2063
+ );
2064
+ if (registeredRedirectUri !== this.redirectUrl) {
2065
+ await this.invalidateCredentials("registration");
2066
+ console.info(
2067
+ `[${this.storageKeyPrefix}] Re-registering browser OAuth client after its Inspector callback changed or could not be verified.`
2068
+ );
2069
+ return void 0;
2070
+ }
2071
+ }
2059
2072
  const stored = await this.readCredential("client_info", ctx);
2060
2073
  if (!stored) return void 0;
2061
2074
  const { key, value: clientInfo } = stored;
2062
2075
  try {
2063
2076
  if (!this.allowClientSecret && clientInfo.client_secret) {
2064
- await this.store.remove(key);
2065
- if (ctx) await this.store.remove(this.credentialKey("client_info"));
2077
+ await this.invalidateCredentials("registration");
2066
2078
  console.warn(
2067
- `[${this.storageKeyPrefix}] Removed OAuth client information containing a browser client_secret.`
2079
+ `[${this.storageKeyPrefix}] Recovered stale browser OAuth credentials containing a client_secret.`
2068
2080
  );
2069
2081
  return void 0;
2070
2082
  }
2071
2083
  const storedRedirectUris = Array.isArray(clientInfo.redirect_uris) ? clientInfo.redirect_uris : [];
2072
- const hasMatchingRedirect = storedRedirectUris.length === 0 || storedRedirectUris.includes(this.redirectUrl);
2084
+ const hasMatchingRedirect = storedRedirectUris.length === 0 && this.allowClientSecret || storedRedirectUris.includes(this.redirectUrl);
2073
2085
  if (!hasMatchingRedirect) {
2074
2086
  console.info(
2075
- `[${this.storageKeyPrefix}] Invalidating cached OAuth client info due to redirect URI mismatch.`
2087
+ `[${this.storageKeyPrefix}] Recovering cached OAuth credentials after a redirect URI change.`
2076
2088
  );
2077
- await this.store.remove(key);
2078
- await this.store.remove(this.credentialKey("tokens", ctx));
2079
- await this.store.remove(this.getKey("last_auth_url"));
2089
+ await this.invalidateCredentials("registration");
2080
2090
  return void 0;
2081
2091
  }
2082
2092
  return clientInfo;
@@ -2094,11 +2104,20 @@ var OAuthSessionStore = class _OAuthSessionStore {
2094
2104
  "Browser OAuth clients must be public clients; client_secret persistence is not allowed."
2095
2105
  );
2096
2106
  }
2097
- const serialized = JSON.stringify(clientInformation);
2107
+ const persistedClientInformation = !this.allowClientSecret && (!("redirect_uris" in clientInformation) || !Array.isArray(
2108
+ clientInformation.redirect_uris
2109
+ ) || clientInformation.redirect_uris.length === 0) ? { ...clientInformation, redirect_uris: [this.redirectUrl] } : clientInformation;
2110
+ const serialized = JSON.stringify(persistedClientInformation);
2098
2111
  await this.store.set(this.credentialKey("client_info", ctx), serialized);
2099
2112
  if (ctx) {
2100
2113
  await this.store.set(this.credentialKey("client_info"), serialized);
2101
2114
  }
2115
+ if (!this.allowClientSecret) {
2116
+ await this.store.set(
2117
+ this.getKey("client_info_redirect_uri"),
2118
+ this.redirectUrl
2119
+ );
2120
+ }
2102
2121
  }
2103
2122
  async saveCodeVerifier(codeVerifier) {
2104
2123
  await this.store.set(this.getKey("code_verifier"), codeVerifier);
@@ -2123,11 +2142,22 @@ var OAuthSessionStore = class _OAuthSessionStore {
2123
2142
  }
2124
2143
  };
2125
2144
  switch (scope) {
2145
+ case "registration":
2146
+ await removeCredentialKeys("tokens");
2147
+ await removeCredentialKeys("client_info");
2148
+ await this.store.remove(this.getKey("code_verifier"));
2149
+ await this.store.remove(this.getKey("last_auth_url"));
2150
+ await this.store.remove(this.getKey("last_auth_callback_url"));
2151
+ await this.store.remove(this.getKey("client_info_redirect_uri"));
2152
+ await this.store.remove(this.getKey("token_endpoint"));
2153
+ break;
2126
2154
  case "all":
2127
2155
  await removeCredentialKeys("tokens");
2128
2156
  await removeCredentialKeys("client_info");
2129
2157
  await this.store.remove(this.getKey("code_verifier"));
2130
2158
  await this.store.remove(this.getKey("last_auth_url"));
2159
+ await this.store.remove(this.getKey("last_auth_callback_url"));
2160
+ await this.store.remove(this.getKey("client_info_redirect_uri"));
2131
2161
  await this.store.remove(this.getKey("discovery_state"));
2132
2162
  await this.store.remove(this.getKey("token_endpoint"));
2133
2163
  break;
@@ -2197,6 +2227,10 @@ var OAuthSessionStore = class _OAuthSessionStore {
2197
2227
  authorizationUrl.searchParams.set("state", state);
2198
2228
  const sanitizedAuthUrl = sanitizeUrl(authorizationUrl.toString());
2199
2229
  await this.store.set(stateKey, JSON.stringify(stateData));
2230
+ await this.store.set(
2231
+ this.getKey("last_auth_callback_url"),
2232
+ this.redirectUrl
2233
+ );
2200
2234
  await this.store.set(this.getKey("last_auth_url"), sanitizedAuthUrl);
2201
2235
  return sanitizedAuthUrl;
2202
2236
  }