@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
@@ -2079,7 +2079,7 @@ var MCPClient = class {
2079
2079
  * @param options - Client configuration options
2080
2080
  */
2081
2081
  constructor(options) {
2082
- __publicField(this, "client", null);
2082
+ __publicField(this, "client");
2083
2083
  __publicField(this, "oauthProvider", null);
2084
2084
  __publicField(this, "transport", null);
2085
2085
  __publicField(this, "userId");
@@ -2120,6 +2120,21 @@ var MCPClient = class {
2120
2120
  this.clientUri = options.clientUri;
2121
2121
  this.logoUri = options.logoUri;
2122
2122
  this.policyUri = options.policyUri;
2123
+ this.client = new Client(
2124
+ {
2125
+ name: MCP_CLIENT_NAME,
2126
+ version: MCP_CLIENT_VERSION
2127
+ },
2128
+ {
2129
+ capabilities: {
2130
+ extensions: {
2131
+ "io.modelcontextprotocol/ui": {
2132
+ mimeTypes: ["text/html+mcp"]
2133
+ }
2134
+ }
2135
+ }
2136
+ }
2137
+ );
2123
2138
  }
2124
2139
  /**
2125
2140
  * Emit a connection state change event
@@ -2245,13 +2260,12 @@ var MCPClient = class {
2245
2260
  }
2246
2261
  }
2247
2262
  /**
2248
- * Initializes client components (client, transport, OAuth provider)
2249
- * Loads missing configuration from Redis session store if needed
2250
- * This method is idempotent and safe to call multiple times
2263
+ * Ensures session metadata and OAuth provider are loaded.
2264
+ * Does NOT create the SDK Client callers that need one create it themselves.
2251
2265
  * @private
2252
2266
  */
2253
- async initialize() {
2254
- if (this.client && this.oauthProvider) {
2267
+ async ensureSession() {
2268
+ if (this.oauthProvider) {
2255
2269
  return;
2256
2270
  }
2257
2271
  this.emitStateChange("INITIALIZING");
@@ -2294,23 +2308,6 @@ var MCPClient = class {
2294
2308
  }
2295
2309
  });
2296
2310
  }
2297
- if (!this.client) {
2298
- this.client = new Client(
2299
- {
2300
- name: MCP_CLIENT_NAME,
2301
- version: MCP_CLIENT_VERSION
2302
- },
2303
- {
2304
- capabilities: {
2305
- extensions: {
2306
- "io.modelcontextprotocol/ui": {
2307
- mimeTypes: ["text/html+mcp"]
2308
- }
2309
- }
2310
- }
2311
- }
2312
- );
2313
- }
2314
2311
  if (existingSession === null) {
2315
2312
  existingSession = await sessions.get(this.userId, this.sessionId);
2316
2313
  }
@@ -2427,17 +2424,16 @@ var MCPClient = class {
2427
2424
  * @throws {Error} When connection fails for other reasons
2428
2425
  */
2429
2426
  async connect() {
2430
- if (this.client?.transport) {
2427
+ if (this.client.transport) {
2431
2428
  this.transport = null;
2432
2429
  try {
2433
2430
  await this.client.close();
2434
2431
  } catch {
2435
2432
  }
2436
- this.client = null;
2437
2433
  }
2438
- await this.initialize();
2439
- if (!this.client || !this.oauthProvider) {
2440
- const error = "Client or OAuth provider not initialized";
2434
+ await this.ensureSession();
2435
+ if (!this.oauthProvider) {
2436
+ const error = "OAuth provider not initialized";
2441
2437
  this.emitError(error, "connection");
2442
2438
  this.emitStateChange("FAILED");
2443
2439
  throw new Error(error);
@@ -2504,7 +2500,7 @@ var MCPClient = class {
2504
2500
  async finishAuth(authCode, state) {
2505
2501
  this.emitStateChange("AUTHENTICATING");
2506
2502
  this.emitProgress("Exchanging authorization code for tokens...");
2507
- await this.initialize();
2503
+ await this.ensureSession();
2508
2504
  if (!this.oauthProvider) {
2509
2505
  const error = "OAuth provider not initialized";
2510
2506
  this.emitError(error, "auth");
@@ -2804,13 +2800,12 @@ var MCPClient = class {
2804
2800
  return await fn();
2805
2801
  } catch (error) {
2806
2802
  if (!(error instanceof Error && error.message.includes("MCP_SESSION_EXPIRED"))) throw error;
2807
- if (this.client) {
2803
+ if (this.client.transport) {
2808
2804
  try {
2809
2805
  await this.client.close();
2810
2806
  } catch {
2811
2807
  }
2812
2808
  this.transport = null;
2813
- this.client = null;
2814
2809
  }
2815
2810
  await this.reconnect();
2816
2811
  return await fn();
@@ -2823,26 +2818,9 @@ var MCPClient = class {
2823
2818
  * @throws {Error} When OAuth provider is not initialized
2824
2819
  */
2825
2820
  async reconnect() {
2826
- await this.initialize();
2827
- if (!this.oauthProvider) {
2828
- throw new Error("OAuth provider not initialized");
2829
- }
2830
- if (this.client) {
2831
- try {
2832
- await this.client.close();
2833
- } catch {
2834
- }
2835
- }
2836
- this.client = new Client(
2837
- {
2838
- name: MCP_CLIENT_NAME,
2839
- version: MCP_CLIENT_VERSION
2840
- },
2841
- { capabilities: {} }
2842
- );
2843
- const tt = this.transportType || "streamable-http";
2844
- this.transport = this.getTransport(tt);
2845
- await this.client.connect(this.transport);
2821
+ await this.ensureSession();
2822
+ if (!this.oauthProvider) throw new Error("OAuth provider not initialized");
2823
+ await this.connect();
2846
2824
  }
2847
2825
  /**
2848
2826
  * Completely removes the session from Redis including all OAuth data
@@ -2850,7 +2828,7 @@ var MCPClient = class {
2850
2828
  */
2851
2829
  async clearSession() {
2852
2830
  try {
2853
- await this.initialize();
2831
+ await this.ensureSession();
2854
2832
  } catch (error) {
2855
2833
  console.warn("[MCPClient] Initialization failed during clearSession:", error);
2856
2834
  }
@@ -2865,7 +2843,7 @@ var MCPClient = class {
2865
2843
  * @returns True if connected, false otherwise
2866
2844
  */
2867
2845
  isConnected() {
2868
- return this.client !== null;
2846
+ return this.client.transport !== void 0;
2869
2847
  }
2870
2848
  /**
2871
2849
  * Disconnects from the MCP server and cleans up resources.
@@ -2883,10 +2861,12 @@ var MCPClient = class {
2883
2861
  } catch {
2884
2862
  }
2885
2863
  }
2886
- if (this.client) {
2887
- this.client.close();
2864
+ if (this.client.transport) {
2865
+ try {
2866
+ await this.client.close();
2867
+ } catch {
2868
+ }
2888
2869
  }
2889
- this.client = null;
2890
2870
  this.oauthProvider = null;
2891
2871
  this.transport = null;
2892
2872
  if (this.serverId) {