@mcp-ts/sdk 2.4.3 → 2.4.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.
Files changed (49) hide show
  1. package/dist/adapters/agui-adapter.d.mts +3 -3
  2. package/dist/adapters/agui-adapter.d.ts +3 -3
  3. package/dist/adapters/agui-middleware.d.mts +3 -3
  4. package/dist/adapters/agui-middleware.d.ts +3 -3
  5. package/dist/adapters/ai-adapter.d.mts +3 -3
  6. package/dist/adapters/ai-adapter.d.ts +3 -3
  7. package/dist/adapters/langchain-adapter.d.mts +3 -3
  8. package/dist/adapters/langchain-adapter.d.ts +3 -3
  9. package/dist/adapters/mastra-adapter.d.mts +2 -2
  10. package/dist/adapters/mastra-adapter.d.ts +2 -2
  11. package/dist/client/index.d.mts +2 -2
  12. package/dist/client/index.d.ts +2 -2
  13. package/dist/client/react.d.mts +4 -5
  14. package/dist/client/react.d.ts +4 -5
  15. package/dist/client/react.js.map +1 -1
  16. package/dist/client/react.mjs.map +1 -1
  17. package/dist/client/vue.d.mts +4 -5
  18. package/dist/client/vue.d.ts +4 -5
  19. package/dist/client/vue.js.map +1 -1
  20. package/dist/client/vue.mjs.map +1 -1
  21. package/dist/{index-B8kJSrBJ.d.ts → index-CZk2gu2E.d.ts} +1 -1
  22. package/dist/{index-DiJsm_lK.d.mts → index-CkM3p0eE.d.mts} +1 -1
  23. package/dist/index.d.mts +4 -4
  24. package/dist/index.d.ts +4 -4
  25. package/dist/index.js +36 -56
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +36 -56
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/{multi-session-client-DOBvtaQV.d.ts → multi-session-client-ChQrBZhF.d.mts} +4 -5
  30. package/dist/{multi-session-client-B6hsYO8V.d.mts → multi-session-client-QOOPdEVp.d.ts} +4 -5
  31. package/dist/server/index.d.mts +4 -4
  32. package/dist/server/index.d.ts +4 -4
  33. package/dist/server/index.js +36 -56
  34. package/dist/server/index.js.map +1 -1
  35. package/dist/server/index.mjs +36 -56
  36. package/dist/server/index.mjs.map +1 -1
  37. package/dist/shared/index.d.mts +4 -4
  38. package/dist/shared/index.d.ts +4 -4
  39. package/dist/shared/index.js.map +1 -1
  40. package/dist/shared/index.mjs.map +1 -1
  41. package/dist/{tool-router-CbG4Tum6.d.mts → tool-router-CGs3IDOJ.d.mts} +1 -1
  42. package/dist/{tool-router-ChIhPwgP.d.ts → tool-router-DQ-HrD7W.d.ts} +1 -1
  43. package/dist/{types-CjczQwNX.d.mts → types-Bf-7GOLW.d.mts} +0 -2
  44. package/dist/{types-CjczQwNX.d.ts → types-Bf-7GOLW.d.ts} +0 -2
  45. package/package.json +1 -1
  46. package/src/client/react/use-mcp.ts +0 -1
  47. package/src/client/vue/use-mcp.ts +0 -1
  48. package/src/server/mcp/oauth-client.ts +41 -76
  49. package/src/shared/events.ts +0 -2
package/dist/index.js CHANGED
@@ -2224,7 +2224,7 @@ var MCPClient = class {
2224
2224
  * @param options - Client configuration options
2225
2225
  */
2226
2226
  constructor(options) {
2227
- __publicField(this, "client", null);
2227
+ __publicField(this, "client");
2228
2228
  __publicField(this, "oauthProvider", null);
2229
2229
  __publicField(this, "transport", null);
2230
2230
  __publicField(this, "userId");
@@ -2265,6 +2265,21 @@ var MCPClient = class {
2265
2265
  this.clientUri = options.clientUri;
2266
2266
  this.logoUri = options.logoUri;
2267
2267
  this.policyUri = options.policyUri;
2268
+ this.client = new index_js.Client(
2269
+ {
2270
+ name: MCP_CLIENT_NAME,
2271
+ version: MCP_CLIENT_VERSION
2272
+ },
2273
+ {
2274
+ capabilities: {
2275
+ extensions: {
2276
+ "io.modelcontextprotocol/ui": {
2277
+ mimeTypes: ["text/html+mcp"]
2278
+ }
2279
+ }
2280
+ }
2281
+ }
2282
+ );
2268
2283
  }
2269
2284
  /**
2270
2285
  * Emit a connection state change event
@@ -2390,13 +2405,12 @@ var MCPClient = class {
2390
2405
  }
2391
2406
  }
2392
2407
  /**
2393
- * Initializes client components (client, transport, OAuth provider)
2394
- * Loads missing configuration from Redis session store if needed
2395
- * This method is idempotent and safe to call multiple times
2408
+ * Ensures session metadata and OAuth provider are loaded.
2409
+ * Does NOT create the SDK Client callers that need one create it themselves.
2396
2410
  * @private
2397
2411
  */
2398
- async initialize() {
2399
- if (this.client && this.oauthProvider) {
2412
+ async ensureSession() {
2413
+ if (this.oauthProvider) {
2400
2414
  return;
2401
2415
  }
2402
2416
  this.emitStateChange("INITIALIZING");
@@ -2439,23 +2453,6 @@ var MCPClient = class {
2439
2453
  }
2440
2454
  });
2441
2455
  }
2442
- if (!this.client) {
2443
- this.client = new index_js.Client(
2444
- {
2445
- name: MCP_CLIENT_NAME,
2446
- version: MCP_CLIENT_VERSION
2447
- },
2448
- {
2449
- capabilities: {
2450
- extensions: {
2451
- "io.modelcontextprotocol/ui": {
2452
- mimeTypes: ["text/html+mcp"]
2453
- }
2454
- }
2455
- }
2456
- }
2457
- );
2458
- }
2459
2456
  if (existingSession === null) {
2460
2457
  existingSession = await sessions.get(this.userId, this.sessionId);
2461
2458
  }
@@ -2572,17 +2569,16 @@ var MCPClient = class {
2572
2569
  * @throws {Error} When connection fails for other reasons
2573
2570
  */
2574
2571
  async connect() {
2575
- if (this.client?.transport) {
2572
+ if (this.client.transport) {
2576
2573
  this.transport = null;
2577
2574
  try {
2578
2575
  await this.client.close();
2579
2576
  } catch {
2580
2577
  }
2581
- this.client = null;
2582
2578
  }
2583
- await this.initialize();
2584
- if (!this.client || !this.oauthProvider) {
2585
- const error = "Client or OAuth provider not initialized";
2579
+ await this.ensureSession();
2580
+ if (!this.oauthProvider) {
2581
+ const error = "OAuth provider not initialized";
2586
2582
  this.emitError(error, "connection");
2587
2583
  this.emitStateChange("FAILED");
2588
2584
  throw new Error(error);
@@ -2649,7 +2645,7 @@ var MCPClient = class {
2649
2645
  async finishAuth(authCode, state) {
2650
2646
  this.emitStateChange("AUTHENTICATING");
2651
2647
  this.emitProgress("Exchanging authorization code for tokens...");
2652
- await this.initialize();
2648
+ await this.ensureSession();
2653
2649
  if (!this.oauthProvider) {
2654
2650
  const error = "OAuth provider not initialized";
2655
2651
  this.emitError(error, "auth");
@@ -2949,13 +2945,12 @@ var MCPClient = class {
2949
2945
  return await fn();
2950
2946
  } catch (error) {
2951
2947
  if (!(error instanceof Error && error.message.includes("MCP_SESSION_EXPIRED"))) throw error;
2952
- if (this.client) {
2948
+ if (this.client.transport) {
2953
2949
  try {
2954
2950
  await this.client.close();
2955
2951
  } catch {
2956
2952
  }
2957
2953
  this.transport = null;
2958
- this.client = null;
2959
2954
  }
2960
2955
  await this.reconnect();
2961
2956
  return await fn();
@@ -2968,26 +2963,9 @@ var MCPClient = class {
2968
2963
  * @throws {Error} When OAuth provider is not initialized
2969
2964
  */
2970
2965
  async reconnect() {
2971
- await this.initialize();
2972
- if (!this.oauthProvider) {
2973
- throw new Error("OAuth provider not initialized");
2974
- }
2975
- if (this.client) {
2976
- try {
2977
- await this.client.close();
2978
- } catch {
2979
- }
2980
- }
2981
- this.client = new index_js.Client(
2982
- {
2983
- name: MCP_CLIENT_NAME,
2984
- version: MCP_CLIENT_VERSION
2985
- },
2986
- { capabilities: {} }
2987
- );
2988
- const tt = this.transportType || "streamable-http";
2989
- this.transport = this.getTransport(tt);
2990
- await this.client.connect(this.transport);
2966
+ await this.ensureSession();
2967
+ if (!this.oauthProvider) throw new Error("OAuth provider not initialized");
2968
+ await this.connect();
2991
2969
  }
2992
2970
  /**
2993
2971
  * Completely removes the session from Redis including all OAuth data
@@ -2995,7 +2973,7 @@ var MCPClient = class {
2995
2973
  */
2996
2974
  async clearSession() {
2997
2975
  try {
2998
- await this.initialize();
2976
+ await this.ensureSession();
2999
2977
  } catch (error) {
3000
2978
  console.warn("[MCPClient] Initialization failed during clearSession:", error);
3001
2979
  }
@@ -3010,7 +2988,7 @@ var MCPClient = class {
3010
2988
  * @returns True if connected, false otherwise
3011
2989
  */
3012
2990
  isConnected() {
3013
- return this.client !== null;
2991
+ return this.client.transport !== void 0;
3014
2992
  }
3015
2993
  /**
3016
2994
  * Disconnects from the MCP server and cleans up resources.
@@ -3028,10 +3006,12 @@ var MCPClient = class {
3028
3006
  } catch {
3029
3007
  }
3030
3008
  }
3031
- if (this.client) {
3032
- this.client.close();
3009
+ if (this.client.transport) {
3010
+ try {
3011
+ await this.client.close();
3012
+ } catch {
3013
+ }
3033
3014
  }
3034
- this.client = null;
3035
3015
  this.oauthProvider = null;
3036
3016
  this.transport = null;
3037
3017
  if (this.serverId) {