@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.mjs CHANGED
@@ -2151,7 +2151,7 @@ var MCPClient = class {
2151
2151
  * @param options - Client configuration options
2152
2152
  */
2153
2153
  constructor(options) {
2154
- __publicField(this, "client", null);
2154
+ __publicField(this, "client");
2155
2155
  __publicField(this, "oauthProvider", null);
2156
2156
  __publicField(this, "transport", null);
2157
2157
  __publicField(this, "userId");
@@ -2192,6 +2192,21 @@ var MCPClient = class {
2192
2192
  this.clientUri = options.clientUri;
2193
2193
  this.logoUri = options.logoUri;
2194
2194
  this.policyUri = options.policyUri;
2195
+ this.client = new Client(
2196
+ {
2197
+ name: MCP_CLIENT_NAME,
2198
+ version: MCP_CLIENT_VERSION
2199
+ },
2200
+ {
2201
+ capabilities: {
2202
+ extensions: {
2203
+ "io.modelcontextprotocol/ui": {
2204
+ mimeTypes: ["text/html+mcp"]
2205
+ }
2206
+ }
2207
+ }
2208
+ }
2209
+ );
2195
2210
  }
2196
2211
  /**
2197
2212
  * Emit a connection state change event
@@ -2317,13 +2332,12 @@ var MCPClient = class {
2317
2332
  }
2318
2333
  }
2319
2334
  /**
2320
- * Initializes client components (client, transport, OAuth provider)
2321
- * Loads missing configuration from Redis session store if needed
2322
- * This method is idempotent and safe to call multiple times
2335
+ * Ensures session metadata and OAuth provider are loaded.
2336
+ * Does NOT create the SDK Client callers that need one create it themselves.
2323
2337
  * @private
2324
2338
  */
2325
- async initialize() {
2326
- if (this.client && this.oauthProvider) {
2339
+ async ensureSession() {
2340
+ if (this.oauthProvider) {
2327
2341
  return;
2328
2342
  }
2329
2343
  this.emitStateChange("INITIALIZING");
@@ -2366,23 +2380,6 @@ var MCPClient = class {
2366
2380
  }
2367
2381
  });
2368
2382
  }
2369
- if (!this.client) {
2370
- this.client = new Client(
2371
- {
2372
- name: MCP_CLIENT_NAME,
2373
- version: MCP_CLIENT_VERSION
2374
- },
2375
- {
2376
- capabilities: {
2377
- extensions: {
2378
- "io.modelcontextprotocol/ui": {
2379
- mimeTypes: ["text/html+mcp"]
2380
- }
2381
- }
2382
- }
2383
- }
2384
- );
2385
- }
2386
2383
  if (existingSession === null) {
2387
2384
  existingSession = await sessions.get(this.userId, this.sessionId);
2388
2385
  }
@@ -2499,17 +2496,16 @@ var MCPClient = class {
2499
2496
  * @throws {Error} When connection fails for other reasons
2500
2497
  */
2501
2498
  async connect() {
2502
- if (this.client?.transport) {
2499
+ if (this.client.transport) {
2503
2500
  this.transport = null;
2504
2501
  try {
2505
2502
  await this.client.close();
2506
2503
  } catch {
2507
2504
  }
2508
- this.client = null;
2509
2505
  }
2510
- await this.initialize();
2511
- if (!this.client || !this.oauthProvider) {
2512
- const error = "Client or OAuth provider not initialized";
2506
+ await this.ensureSession();
2507
+ if (!this.oauthProvider) {
2508
+ const error = "OAuth provider not initialized";
2513
2509
  this.emitError(error, "connection");
2514
2510
  this.emitStateChange("FAILED");
2515
2511
  throw new Error(error);
@@ -2576,7 +2572,7 @@ var MCPClient = class {
2576
2572
  async finishAuth(authCode, state) {
2577
2573
  this.emitStateChange("AUTHENTICATING");
2578
2574
  this.emitProgress("Exchanging authorization code for tokens...");
2579
- await this.initialize();
2575
+ await this.ensureSession();
2580
2576
  if (!this.oauthProvider) {
2581
2577
  const error = "OAuth provider not initialized";
2582
2578
  this.emitError(error, "auth");
@@ -2876,13 +2872,12 @@ var MCPClient = class {
2876
2872
  return await fn();
2877
2873
  } catch (error) {
2878
2874
  if (!(error instanceof Error && error.message.includes("MCP_SESSION_EXPIRED"))) throw error;
2879
- if (this.client) {
2875
+ if (this.client.transport) {
2880
2876
  try {
2881
2877
  await this.client.close();
2882
2878
  } catch {
2883
2879
  }
2884
2880
  this.transport = null;
2885
- this.client = null;
2886
2881
  }
2887
2882
  await this.reconnect();
2888
2883
  return await fn();
@@ -2895,26 +2890,9 @@ var MCPClient = class {
2895
2890
  * @throws {Error} When OAuth provider is not initialized
2896
2891
  */
2897
2892
  async reconnect() {
2898
- await this.initialize();
2899
- if (!this.oauthProvider) {
2900
- throw new Error("OAuth provider not initialized");
2901
- }
2902
- if (this.client) {
2903
- try {
2904
- await this.client.close();
2905
- } catch {
2906
- }
2907
- }
2908
- this.client = new Client(
2909
- {
2910
- name: MCP_CLIENT_NAME,
2911
- version: MCP_CLIENT_VERSION
2912
- },
2913
- { capabilities: {} }
2914
- );
2915
- const tt = this.transportType || "streamable-http";
2916
- this.transport = this.getTransport(tt);
2917
- await this.client.connect(this.transport);
2893
+ await this.ensureSession();
2894
+ if (!this.oauthProvider) throw new Error("OAuth provider not initialized");
2895
+ await this.connect();
2918
2896
  }
2919
2897
  /**
2920
2898
  * Completely removes the session from Redis including all OAuth data
@@ -2922,7 +2900,7 @@ var MCPClient = class {
2922
2900
  */
2923
2901
  async clearSession() {
2924
2902
  try {
2925
- await this.initialize();
2903
+ await this.ensureSession();
2926
2904
  } catch (error) {
2927
2905
  console.warn("[MCPClient] Initialization failed during clearSession:", error);
2928
2906
  }
@@ -2937,7 +2915,7 @@ var MCPClient = class {
2937
2915
  * @returns True if connected, false otherwise
2938
2916
  */
2939
2917
  isConnected() {
2940
- return this.client !== null;
2918
+ return this.client.transport !== void 0;
2941
2919
  }
2942
2920
  /**
2943
2921
  * Disconnects from the MCP server and cleans up resources.
@@ -2955,10 +2933,12 @@ var MCPClient = class {
2955
2933
  } catch {
2956
2934
  }
2957
2935
  }
2958
- if (this.client) {
2959
- this.client.close();
2936
+ if (this.client.transport) {
2937
+ try {
2938
+ await this.client.close();
2939
+ } catch {
2940
+ }
2960
2941
  }
2961
- this.client = null;
2962
2942
  this.oauthProvider = null;
2963
2943
  this.transport = null;
2964
2944
  if (this.serverId) {