@mcp-use/client 2.4.4 → 2.4.5-canary.1

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
@@ -1659,7 +1659,7 @@ init_connector_telemetry();
1659
1659
  init_logging();
1660
1660
 
1661
1661
  // src/utils/version.ts
1662
- var VERSION = "2.4.4";
1662
+ var VERSION = "2.4.5-canary.1";
1663
1663
  function getPackageVersion() {
1664
1664
  return VERSION;
1665
1665
  }
@@ -2438,7 +2438,11 @@ var OAuthSessionStore = class _OAuthSessionStore {
2438
2438
  return (await this.readCredential("tokens", ctx))?.value;
2439
2439
  }
2440
2440
  async saveTokens(tokens, ctx) {
2441
- const serialized = JSON.stringify(tokens);
2441
+ const stored = typeof tokens.expires_in === "number" ? {
2442
+ ...tokens,
2443
+ mcp_use_expires_at: Date.now() + tokens.expires_in * 1e3
2444
+ } : tokens;
2445
+ const serialized = JSON.stringify(stored);
2442
2446
  await this.store.set(this.credentialKey("tokens", ctx), serialized);
2443
2447
  if (ctx) await this.store.set(this.credentialKey("tokens"), serialized);
2444
2448
  await this.store.remove(this.getKey("code_verifier"));
@@ -2999,30 +3003,38 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2999
3003
  throw err;
3000
3004
  }
3001
3005
  }
3002
- stopLoopback() {
3006
+ stopLoopback(callbackSocket) {
3003
3007
  if (this.pendingTimer) {
3004
3008
  clearTimeout(this.pendingTimer);
3005
3009
  this.pendingTimer = null;
3006
3010
  }
3007
3011
  if (this.server) {
3008
- this.server.close();
3012
+ const server = this.server;
3009
3013
  this.server = null;
3014
+ server.close();
3015
+ if (callbackSocket && !callbackSocket.destroyed) {
3016
+ callbackSocket.once("close", () => server.closeAllConnections());
3017
+ } else {
3018
+ server.closeAllConnections();
3019
+ }
3010
3020
  }
3011
3021
  this.authorizationUrl = null;
3012
3022
  }
3013
- resolvePending(response) {
3023
+ resolvePending(response, callbackSocket) {
3014
3024
  const p = this.pending;
3015
3025
  this.pending = null;
3016
- this.stopLoopback();
3026
+ this.stopLoopback(callbackSocket);
3017
3027
  p?.resolve(response);
3018
3028
  }
3019
- rejectPending(err) {
3029
+ rejectPending(err, callbackSocket) {
3020
3030
  const p = this.pending;
3021
3031
  this.pending = null;
3022
- this.stopLoopback();
3032
+ this.stopLoopback(callbackSocket);
3023
3033
  p?.reject(err);
3024
3034
  }
3025
3035
  handleCallback(rawUrl, res) {
3036
+ const callbackSocket = res.socket ?? void 0;
3037
+ res.setHeader("connection", "close");
3026
3038
  const url = new URL(rawUrl, `http://127.0.0.1:${this.port}`);
3027
3039
  if (url.pathname === "/authorize") {
3028
3040
  if (this.authorizationUrl === null || this.pending === null) {
@@ -3051,7 +3063,7 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
3051
3063
  res.statusCode = 400;
3052
3064
  res.setHeader("content-type", "text/html; charset=utf-8");
3053
3065
  res.end(FAILURE_HTML(err, errDesc));
3054
- this.rejectPending(new OAuthFlowError(err, errDesc));
3066
+ this.rejectPending(new OAuthFlowError(err, errDesc), callbackSocket);
3055
3067
  return;
3056
3068
  }
3057
3069
  if (!code || !state) {
@@ -3062,7 +3074,10 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
3062
3074
  res.statusCode = 200;
3063
3075
  res.setHeader("content-type", "text/html; charset=utf-8");
3064
3076
  res.end(SUCCESS_HTML);
3065
- this.resolvePending({ code, ...iss !== void 0 ? { iss } : {} });
3077
+ this.resolvePending(
3078
+ { code, ...iss !== void 0 ? { iss } : {} },
3079
+ callbackSocket
3080
+ );
3066
3081
  }
3067
3082
  };
3068
3083
  async function defaultOpener(url) {