mcp-use 1.11.0-canary.8 → 1.11.0

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 (91) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-5RTMAOZ6.js → chunk-A4QJRN7Z.js} +5 -1041
  3. package/dist/{chunk-4LZSXUFM.js → chunk-B7AGEK7F.js} +1 -1
  4. package/dist/{chunk-TAEHPLGV.js → chunk-GN5HOAV3.js} +664 -136
  5. package/dist/chunk-QPIDKGV4.js +1246 -0
  6. package/dist/chunk-UWWLWLS2.js +62 -0
  7. package/dist/{chunk-ZFZPZ4GE.js → chunk-V77WS6CS.js} +9 -0
  8. package/dist/{chunk-EBSNALCB.js → chunk-VRHAF2WT.js} +10 -4
  9. package/dist/{chunk-X7JKFBPN.js → chunk-Y2HHHJQB.js} +159 -8
  10. package/dist/{chunk-JPKFN73V.js → chunk-ZLZOOXMJ.js} +96 -43
  11. package/dist/index.cjs +316 -53
  12. package/dist/index.js +22 -24
  13. package/dist/notifications-FLGIFS56.js +9 -0
  14. package/dist/src/agents/index.cjs +153 -47
  15. package/dist/src/agents/index.d.ts +1 -1
  16. package/dist/src/agents/index.d.ts.map +1 -1
  17. package/dist/src/agents/index.js +7 -10
  18. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  19. package/dist/src/{client/prompts.d.ts → agents/prompts/index.d.ts} +3 -3
  20. package/dist/src/agents/prompts/index.d.ts.map +1 -0
  21. package/dist/src/browser.cjs +160 -48
  22. package/dist/src/browser.js +10 -12
  23. package/dist/src/client/browser.d.ts.map +1 -1
  24. package/dist/src/client.cjs +3852 -0
  25. package/dist/src/client.d.ts +2 -0
  26. package/dist/src/client.d.ts.map +1 -1
  27. package/dist/src/client.js +21 -0
  28. package/dist/src/config.d.ts.map +1 -1
  29. package/dist/src/connectors/http.d.ts +2 -0
  30. package/dist/src/connectors/http.d.ts.map +1 -1
  31. package/dist/src/react/index.cjs +313 -52
  32. package/dist/src/react/index.js +7 -8
  33. package/dist/src/react/types.d.ts +41 -1
  34. package/dist/src/react/types.d.ts.map +1 -1
  35. package/dist/src/react/useMcp.d.ts.map +1 -1
  36. package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
  37. package/dist/src/server/index.cjs +1339 -256
  38. package/dist/src/server/index.d.ts +2 -0
  39. package/dist/src/server/index.d.ts.map +1 -1
  40. package/dist/src/server/index.js +1119 -156
  41. package/dist/src/server/mcp-server.d.ts +4 -1
  42. package/dist/src/server/mcp-server.d.ts.map +1 -1
  43. package/dist/src/server/notifications/index.d.ts +1 -1
  44. package/dist/src/server/notifications/index.d.ts.map +1 -1
  45. package/dist/src/server/notifications/notification-registration.d.ts +51 -0
  46. package/dist/src/server/notifications/notification-registration.d.ts.map +1 -1
  47. package/dist/src/server/sessions/index.d.ts +3 -1
  48. package/dist/src/server/sessions/index.d.ts.map +1 -1
  49. package/dist/src/server/sessions/session-manager.d.ts +30 -16
  50. package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
  51. package/dist/src/server/sessions/stores/filesystem.d.ts +121 -0
  52. package/dist/src/server/sessions/stores/filesystem.d.ts.map +1 -0
  53. package/dist/src/server/sessions/stores/index.d.ts +94 -0
  54. package/dist/src/server/sessions/stores/index.d.ts.map +1 -0
  55. package/dist/src/server/sessions/stores/memory.d.ts +82 -0
  56. package/dist/src/server/sessions/stores/memory.d.ts.map +1 -0
  57. package/dist/src/server/sessions/stores/redis.d.ts +164 -0
  58. package/dist/src/server/sessions/stores/redis.d.ts.map +1 -0
  59. package/dist/src/server/sessions/streams/index.d.ts +77 -0
  60. package/dist/src/server/sessions/streams/index.d.ts.map +1 -0
  61. package/dist/src/server/sessions/streams/memory.d.ts +76 -0
  62. package/dist/src/server/sessions/streams/memory.d.ts.map +1 -0
  63. package/dist/src/server/sessions/streams/redis.d.ts +146 -0
  64. package/dist/src/server/sessions/streams/redis.d.ts.map +1 -0
  65. package/dist/src/server/types/common.d.ts +82 -28
  66. package/dist/src/server/types/common.d.ts.map +1 -1
  67. package/dist/src/server/types/widget.d.ts +2 -2
  68. package/dist/src/server/types/widget.d.ts.map +1 -1
  69. package/dist/src/server/utils/response-helpers.d.ts +4 -2
  70. package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
  71. package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
  72. package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
  73. package/dist/src/task_managers/index.d.ts +10 -0
  74. package/dist/src/task_managers/index.d.ts.map +1 -1
  75. package/dist/src/task_managers/sse.d.ts +34 -1
  76. package/dist/src/task_managers/sse.d.ts.map +1 -1
  77. package/dist/src/task_managers/streamable_http.d.ts +8 -2
  78. package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
  79. package/dist/src/telemetry/telemetry.d.ts +1 -0
  80. package/dist/src/telemetry/telemetry.d.ts.map +1 -1
  81. package/dist/src/version.d.ts +1 -1
  82. package/dist/src/version.d.ts.map +1 -1
  83. package/dist/{tool-execution-helpers-EYAIJERC.js → tool-execution-helpers-ZUA5D5IO.js} +2 -2
  84. package/dist/tsup.config.d.ts.map +1 -1
  85. package/package.json +62 -52
  86. package/dist/chunk-GVU7C2ZD.js +0 -12
  87. package/dist/chunk-JZNXOM7C.js +0 -204
  88. package/dist/chunk-XKTBHYNM.js +0 -491
  89. package/dist/src/client/prompts.cjs +0 -407
  90. package/dist/src/client/prompts.d.ts.map +0 -1
  91. package/dist/src/client/prompts.js +0 -11
package/dist/index.cjs CHANGED
@@ -2790,7 +2790,7 @@ __name(generateUUID, "generateUUID");
2790
2790
  init_logging();
2791
2791
 
2792
2792
  // src/version.ts
2793
- var VERSION = "1.11.0-canary.8";
2793
+ var VERSION = "1.11.0";
2794
2794
  function getPackageVersion() {
2795
2795
  return VERSION;
2796
2796
  }
@@ -2829,6 +2829,20 @@ function extractModelInfo(llm) {
2829
2829
  __name(extractModelInfo, "extractModelInfo");
2830
2830
 
2831
2831
  // src/telemetry/telemetry.ts
2832
+ function secureRandomString() {
2833
+ if (typeof window !== "undefined" && window.crypto && typeof window.crypto.getRandomValues === "function") {
2834
+ const array = new Uint8Array(8);
2835
+ window.crypto.getRandomValues(array);
2836
+ return Array.from(array, (v) => v.toString(16).padStart(2, "0")).join("");
2837
+ }
2838
+ try {
2839
+ const crypto = require("crypto");
2840
+ return crypto.randomBytes(8).toString("hex");
2841
+ } catch (e) {
2842
+ return Math.random().toString(36).substring(2, 15);
2843
+ }
2844
+ }
2845
+ __name(secureRandomString, "secureRandomString");
2832
2846
  var USER_ID_STORAGE_KEY = "mcp_use_user_id";
2833
2847
  function detectRuntimeEnvironment() {
2834
2848
  try {
@@ -2960,12 +2974,26 @@ var Telemetry = class _Telemetry {
2960
2974
  "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
2961
2975
  );
2962
2976
  this._posthogLoading = this._initPostHog();
2963
- try {
2964
- this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
2965
- } catch (e) {
2966
- logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
2977
+ if (this._runtimeEnvironment !== "browser") {
2978
+ try {
2979
+ this._scarfClient = new ScarfEventLogger(
2980
+ this.SCARF_GATEWAY_URL,
2981
+ 3e3
2982
+ );
2983
+ } catch (e) {
2984
+ logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
2985
+ this._scarfClient = null;
2986
+ }
2987
+ } else {
2967
2988
  this._scarfClient = null;
2968
2989
  }
2990
+ if (this._storageCapability === "filesystem" && this._scarfClient) {
2991
+ setTimeout(() => {
2992
+ this.trackPackageDownload({ triggered_by: "initialization" }).catch(
2993
+ (e) => logger.debug(`Failed to track package download: ${e}`)
2994
+ );
2995
+ }, 0);
2996
+ }
2969
2997
  }
2970
2998
  }
2971
2999
  _checkTelemetryDisabled() {
@@ -3090,47 +3118,65 @@ var Telemetry = class _Telemetry {
3090
3118
  break;
3091
3119
  case "session-only":
3092
3120
  default:
3093
- this._currUserId = `session-${generateUUID()}`;
3094
- logger.debug(
3095
- `Using session-based user ID (${this._runtimeEnvironment} environment)`
3096
- );
3121
+ try {
3122
+ this._currUserId = `session-${generateUUID()}`;
3123
+ } catch (uuidError) {
3124
+ this._currUserId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
3125
+ }
3097
3126
  break;
3098
3127
  }
3099
- if (this._storageCapability === "filesystem" && this._currUserId) {
3100
- this._trackPackageDownloadInternal(this._currUserId, {
3101
- triggered_by: "user_id_property"
3102
- }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
3103
- }
3104
3128
  } catch (e) {
3105
- logger.debug(`Failed to get/create user ID: ${e}`);
3106
3129
  this._currUserId = this.UNKNOWN_USER_ID;
3107
3130
  }
3108
3131
  return this._currUserId;
3109
3132
  }
3110
3133
  /**
3111
3134
  * Get or create user ID from filesystem (Node.js/Bun)
3135
+ * Falls back to session ID if filesystem operations fail
3112
3136
  */
3113
3137
  _getUserIdFromFilesystem() {
3114
- const fs2 = require("fs");
3115
- const os = require("os");
3116
- const path2 = require("path");
3117
- if (!this._userIdPath) {
3118
- this._userIdPath = path2.join(
3119
- this._getCacheHome(os, path2),
3120
- "mcp_use_3",
3121
- "telemetry_user_id"
3122
- );
3123
- }
3124
- const isFirstTime = !fs2.existsSync(this._userIdPath);
3125
- if (isFirstTime) {
3126
- logger.debug(`Creating user ID path: ${this._userIdPath}`);
3127
- fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
3128
- const newUserId = generateUUID();
3129
- fs2.writeFileSync(this._userIdPath, newUserId);
3130
- logger.debug(`User ID path created: ${this._userIdPath}`);
3131
- return newUserId;
3138
+ try {
3139
+ let fs2, os, path2;
3140
+ try {
3141
+ fs2 = require("fs");
3142
+ os = require("os");
3143
+ path2 = require("path");
3144
+ } catch (requireError) {
3145
+ try {
3146
+ const sessionId = `session-${generateUUID()}`;
3147
+ return sessionId;
3148
+ } catch (uuidError) {
3149
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
3150
+ }
3151
+ }
3152
+ if (!this._userIdPath) {
3153
+ this._userIdPath = path2.join(
3154
+ this._getCacheHome(os, path2),
3155
+ "mcp_use_3",
3156
+ "telemetry_user_id"
3157
+ );
3158
+ }
3159
+ const isFirstTime = !fs2.existsSync(this._userIdPath);
3160
+ if (isFirstTime) {
3161
+ fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
3162
+ let newUserId;
3163
+ try {
3164
+ newUserId = generateUUID();
3165
+ } catch (uuidError) {
3166
+ newUserId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
3167
+ }
3168
+ fs2.writeFileSync(this._userIdPath, newUserId);
3169
+ return newUserId;
3170
+ }
3171
+ const userId = fs2.readFileSync(this._userIdPath, "utf-8").trim();
3172
+ return userId;
3173
+ } catch (e) {
3174
+ try {
3175
+ return `session-${generateUUID()}`;
3176
+ } catch (uuidError) {
3177
+ return `session-${Date.now()}-${secureRandomString()}`;
3178
+ }
3132
3179
  }
3133
- return fs2.readFileSync(this._userIdPath, "utf-8").trim();
3134
3180
  }
3135
3181
  /**
3136
3182
  * Get or create user ID from localStorage (Browser)
@@ -3139,14 +3185,22 @@ var Telemetry = class _Telemetry {
3139
3185
  try {
3140
3186
  let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
3141
3187
  if (!userId) {
3142
- userId = generateUUID();
3188
+ try {
3189
+ userId = generateUUID();
3190
+ } catch (uuidError) {
3191
+ userId = `${Date.now()}-${secureRandomString()}`;
3192
+ }
3143
3193
  localStorage.setItem(USER_ID_STORAGE_KEY, userId);
3144
- logger.debug(`Created new browser user ID`);
3145
3194
  }
3146
3195
  return userId;
3147
3196
  } catch (e) {
3148
- logger.debug(`localStorage access failed: ${e}`);
3149
- return `session-${generateUUID()}`;
3197
+ let sessionId;
3198
+ try {
3199
+ sessionId = `session-${generateUUID()}`;
3200
+ } catch (uuidError) {
3201
+ sessionId = `session-${Date.now()}-${secureRandomString()}`;
3202
+ }
3203
+ return sessionId;
3150
3204
  }
3151
3205
  }
3152
3206
  _getCacheHome(os, path2) {
@@ -3175,6 +3229,7 @@ var Telemetry = class _Telemetry {
3175
3229
  if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
3176
3230
  return;
3177
3231
  }
3232
+ const currentUserId = this.userId;
3178
3233
  const properties = { ...event.properties };
3179
3234
  properties.mcp_use_version = getPackageVersion();
3180
3235
  properties.language = "typescript";
@@ -3182,9 +3237,8 @@ var Telemetry = class _Telemetry {
3182
3237
  properties.runtime = this._runtimeEnvironment;
3183
3238
  if (this._posthogNodeClient) {
3184
3239
  try {
3185
- logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
3186
3240
  this._posthogNodeClient.capture({
3187
- distinctId: this.userId,
3241
+ distinctId: currentUserId,
3188
3242
  event: event.name,
3189
3243
  properties
3190
3244
  });
@@ -3194,10 +3248,9 @@ var Telemetry = class _Telemetry {
3194
3248
  }
3195
3249
  if (this._posthogBrowserClient) {
3196
3250
  try {
3197
- logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
3198
3251
  this._posthogBrowserClient.capture(event.name, {
3199
3252
  ...properties,
3200
- distinct_id: this.userId
3253
+ distinct_id: currentUserId
3201
3254
  });
3202
3255
  } catch (e) {
3203
3256
  logger.debug(
@@ -3209,7 +3262,7 @@ var Telemetry = class _Telemetry {
3209
3262
  try {
3210
3263
  const scarfProperties = {
3211
3264
  ...properties,
3212
- user_id: this.userId,
3265
+ user_id: currentUserId,
3213
3266
  event: event.name
3214
3267
  };
3215
3268
  await this._scarfClient.logEvent(scarfProperties);
@@ -5033,6 +5086,7 @@ var SseConnectionManager = class extends ConnectionManager {
5033
5086
  url;
5034
5087
  opts;
5035
5088
  _transport = null;
5089
+ reinitializing = false;
5036
5090
  /**
5037
5091
  * Create an SSE connection manager.
5038
5092
  *
@@ -5045,12 +5099,53 @@ var SseConnectionManager = class extends ConnectionManager {
5045
5099
  this.opts = opts;
5046
5100
  }
5047
5101
  /**
5048
- * Spawn a new `SSEClientTransport` and start the connection.
5102
+ * Spawn a new `SSEClientTransport` and wrap it with 404 handling.
5103
+ * Per MCP spec, clients MUST re-initialize when receiving 404 for stale sessions.
5049
5104
  */
5050
5105
  async establishConnection() {
5051
- this._transport = new import_sse.SSEClientTransport(this.url, this.opts);
5106
+ const transport = new import_sse.SSEClientTransport(this.url, this.opts);
5107
+ const originalSend = transport.send.bind(transport);
5108
+ transport.send = async (message) => {
5109
+ const sendMessage = /* @__PURE__ */ __name(async (msg) => {
5110
+ if (Array.isArray(msg)) {
5111
+ for (const singleMsg of msg) {
5112
+ await originalSend(singleMsg);
5113
+ }
5114
+ } else {
5115
+ await originalSend(msg);
5116
+ }
5117
+ }, "sendMessage");
5118
+ try {
5119
+ await sendMessage(message);
5120
+ } catch (error) {
5121
+ if (error?.code === 404 && transport.sessionId && !this.reinitializing) {
5122
+ logger.warn(
5123
+ `[SSE] Session not found (404), re-initializing per MCP spec...`
5124
+ );
5125
+ this.reinitializing = true;
5126
+ try {
5127
+ transport.sessionId = void 0;
5128
+ await this.reinitialize(transport);
5129
+ logger.info(`[SSE] Re-initialization successful, retrying request`);
5130
+ await sendMessage(message);
5131
+ } finally {
5132
+ this.reinitializing = false;
5133
+ }
5134
+ } else {
5135
+ throw error;
5136
+ }
5137
+ }
5138
+ };
5139
+ this._transport = transport;
5052
5140
  logger.debug(`${this.constructor.name} connected successfully`);
5053
- return this._transport;
5141
+ return transport;
5142
+ }
5143
+ /**
5144
+ * Re-initialize the transport with a new session
5145
+ * This is called when the server returns 404 for a stale session
5146
+ */
5147
+ async reinitialize(transport) {
5148
+ logger.debug(`[SSE] Re-initialization triggered`);
5054
5149
  }
5055
5150
  /**
5056
5151
  * Close the underlying transport and clean up resources.
@@ -5079,6 +5174,7 @@ var HttpConnector = class extends BaseConnector {
5079
5174
  sseReadTimeout;
5080
5175
  clientInfo;
5081
5176
  preferSse;
5177
+ disableSseFallback;
5082
5178
  transportType = null;
5083
5179
  streamableTransport = null;
5084
5180
  constructor(baseUrl, opts = {}) {
@@ -5095,6 +5191,7 @@ var HttpConnector = class extends BaseConnector {
5095
5191
  version: "1.0.0"
5096
5192
  };
5097
5193
  this.preferSse = opts.preferSse ?? false;
5194
+ this.disableSseFallback = opts.disableSseFallback ?? false;
5098
5195
  }
5099
5196
  /** Establish connection to the MCP implementation via HTTP (streamable or SSE). */
5100
5197
  async connect() {
@@ -5151,6 +5248,13 @@ var HttpConnector = class extends BaseConnector {
5151
5248
  authError.code = 401;
5152
5249
  throw authError;
5153
5250
  }
5251
+ if (this.disableSseFallback) {
5252
+ logger.info("SSE fallback disabled - failing connection");
5253
+ await this.cleanupResources();
5254
+ throw new Error(
5255
+ `Streamable HTTP connection failed: ${fallbackReason}. SSE fallback is disabled.`
5256
+ );
5257
+ }
5154
5258
  logger.info("\u{1F504} Falling back to SSE transport...");
5155
5259
  try {
5156
5260
  await this.connectWithSse(baseUrl);
@@ -5517,6 +5621,8 @@ function createConnectorFromConfig(serverConfig, connectorOptions) {
5517
5621
  authToken: serverConfig.auth_token || serverConfig.authToken,
5518
5622
  // Only force SSE if explicitly requested
5519
5623
  preferSse: serverConfig.preferSse || transport === "sse",
5624
+ // Disable SSE fallback if explicitly disabled in config
5625
+ disableSseFallback: serverConfig.disableSseFallback,
5520
5626
  ...connectorOptions
5521
5627
  });
5522
5628
  }
@@ -9276,7 +9382,9 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
9276
9382
  wrapTransport,
9277
9383
  clientOptions,
9278
9384
  samplingCallback,
9279
- elicitationCallback
9385
+ elicitationCallback,
9386
+ disableSseFallback,
9387
+ preferSse
9280
9388
  } = serverConfig;
9281
9389
  if (!url) {
9282
9390
  throw new Error("Server URL is required");
@@ -9292,8 +9400,12 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
9292
9400
  // ← Pass client options (capabilities, etc.) to connector
9293
9401
  samplingCallback,
9294
9402
  // ← Pass sampling callback to connector
9295
- elicitationCallback
9403
+ elicitationCallback,
9296
9404
  // ← Pass elicitation callback to connector
9405
+ disableSseFallback,
9406
+ // ← Disable automatic SSE fallback
9407
+ preferSse
9408
+ // ← Use SSE transport directly
9297
9409
  };
9298
9410
  if (clientOptions) {
9299
9411
  console.log(
@@ -9395,6 +9507,11 @@ function useMcp(options) {
9395
9507
  if (clientRef.current) {
9396
9508
  try {
9397
9509
  const serverName = "inspector-server";
9510
+ const session = clientRef.current.getSession(serverName);
9511
+ if (session && session._healthCheckCleanup) {
9512
+ session._healthCheckCleanup();
9513
+ session._healthCheckCleanup = null;
9514
+ }
9398
9515
  await clientRef.current.closeSession(serverName);
9399
9516
  } catch (err) {
9400
9517
  if (!quiet) addLog("warn", "Error closing session:", err);
@@ -9496,7 +9613,12 @@ function useMcp(options) {
9496
9613
  const serverName = "inspector-server";
9497
9614
  const serverConfig = {
9498
9615
  url,
9499
- transport: transportTypeParam === "sse" ? "http" : transportTypeParam
9616
+ transport: transportTypeParam === "sse" ? "http" : transportTypeParam,
9617
+ // Disable SSE fallback when using explicit HTTP transport (not SSE)
9618
+ // This prevents automatic HTTP → SSE fallback at the connector level
9619
+ disableSseFallback: transportTypeParam === "http",
9620
+ // Use SSE transport when explicitly requested
9621
+ preferSse: transportTypeParam === "sse"
9500
9622
  };
9501
9623
  if (customHeaders && Object.keys(customHeaders).length > 0) {
9502
9624
  serverConfig.headers = customHeaders;
@@ -9534,9 +9656,25 @@ function useMcp(options) {
9534
9656
  serverName,
9535
9657
  false
9536
9658
  );
9537
- if (onNotification) {
9538
- session.on("notification", onNotification);
9539
- }
9659
+ session.on("notification", (notification) => {
9660
+ onNotification?.(notification);
9661
+ if (notification.method === "notifications/tools/list_changed") {
9662
+ addLog("info", "Tools list changed, auto-refreshing...");
9663
+ refreshTools().catch(
9664
+ (err) => addLog("warn", "Auto-refresh tools failed:", err)
9665
+ );
9666
+ } else if (notification.method === "notifications/resources/list_changed") {
9667
+ addLog("info", "Resources list changed, auto-refreshing...");
9668
+ refreshResources().catch(
9669
+ (err) => addLog("warn", "Auto-refresh resources failed:", err)
9670
+ );
9671
+ } else if (notification.method === "notifications/prompts/list_changed") {
9672
+ addLog("info", "Prompts list changed, auto-refreshing...");
9673
+ refreshPrompts().catch(
9674
+ (err) => addLog("warn", "Auto-refresh prompts failed:", err)
9675
+ );
9676
+ }
9677
+ });
9540
9678
  await session.initialize();
9541
9679
  addLog("info", "\u2705 Successfully connected to MCP server");
9542
9680
  addLog("info", "Server info:", session.connector.serverInfo);
@@ -9552,6 +9690,63 @@ function useMcp(options) {
9552
9690
  );
9553
9691
  setState("ready");
9554
9692
  successfulTransportRef.current = transportTypeParam;
9693
+ const setupConnectionMonitoring = /* @__PURE__ */ __name(() => {
9694
+ let healthCheckInterval = null;
9695
+ let lastSuccessfulCheck = Date.now();
9696
+ const HEALTH_CHECK_INTERVAL = 1e4;
9697
+ const HEALTH_CHECK_TIMEOUT = 3e4;
9698
+ const checkConnectionHealth = /* @__PURE__ */ __name(async () => {
9699
+ if (!isMountedRef.current || stateRef.current !== "ready") {
9700
+ if (healthCheckInterval) {
9701
+ clearInterval(healthCheckInterval);
9702
+ healthCheckInterval = null;
9703
+ }
9704
+ return;
9705
+ }
9706
+ try {
9707
+ await session.connector.listTools();
9708
+ lastSuccessfulCheck = Date.now();
9709
+ } catch (err) {
9710
+ const timeSinceLastSuccess = Date.now() - lastSuccessfulCheck;
9711
+ if (timeSinceLastSuccess > HEALTH_CHECK_TIMEOUT) {
9712
+ addLog(
9713
+ "warn",
9714
+ `Connection appears to be broken (no response for ${Math.round(timeSinceLastSuccess / 1e3)}s), attempting to reconnect...`
9715
+ );
9716
+ if (healthCheckInterval) {
9717
+ clearInterval(healthCheckInterval);
9718
+ healthCheckInterval = null;
9719
+ }
9720
+ if (autoReconnectRef.current && isMountedRef.current) {
9721
+ setState("discovering");
9722
+ addLog("info", "Auto-reconnecting to MCP server...");
9723
+ setTimeout(
9724
+ () => {
9725
+ if (isMountedRef.current && stateRef.current === "discovering") {
9726
+ connect();
9727
+ }
9728
+ },
9729
+ typeof autoReconnectRef.current === "number" ? autoReconnectRef.current : DEFAULT_RECONNECT_DELAY
9730
+ );
9731
+ }
9732
+ }
9733
+ }
9734
+ }, "checkConnectionHealth");
9735
+ healthCheckInterval = setInterval(
9736
+ checkConnectionHealth,
9737
+ HEALTH_CHECK_INTERVAL
9738
+ );
9739
+ return () => {
9740
+ if (healthCheckInterval) {
9741
+ clearInterval(healthCheckInterval);
9742
+ healthCheckInterval = null;
9743
+ }
9744
+ };
9745
+ }, "setupConnectionMonitoring");
9746
+ if (autoReconnect) {
9747
+ const cleanup = setupConnectionMonitoring();
9748
+ session._healthCheckCleanup = cleanup;
9749
+ }
9555
9750
  Tel.getInstance().trackUseMcpConnection({
9556
9751
  url,
9557
9752
  transportType: transportTypeParam,
@@ -9903,6 +10098,70 @@ function useMcp(options) {
9903
10098
  throw err;
9904
10099
  }
9905
10100
  }, [state]);
10101
+ const refreshTools = (0, import_react.useCallback)(async () => {
10102
+ if (stateRef.current !== "ready" || !clientRef.current) {
10103
+ addLog("debug", "Cannot refresh tools - client not ready");
10104
+ return;
10105
+ }
10106
+ addLog("debug", "Refreshing tools list");
10107
+ try {
10108
+ const serverName = "inspector-server";
10109
+ const session = clientRef.current.getSession(serverName);
10110
+ if (!session) {
10111
+ addLog("warn", "No active session found for tools refresh");
10112
+ return;
10113
+ }
10114
+ const toolsResult = await session.connector.listTools();
10115
+ setTools(toolsResult || []);
10116
+ addLog("info", "Tools list refreshed successfully");
10117
+ } catch (err) {
10118
+ addLog("warn", "Failed to refresh tools:", err);
10119
+ }
10120
+ }, [addLog]);
10121
+ const refreshResources = (0, import_react.useCallback)(async () => {
10122
+ if (stateRef.current !== "ready" || !clientRef.current) {
10123
+ addLog("debug", "Cannot refresh resources - client not ready");
10124
+ return;
10125
+ }
10126
+ addLog("debug", "Refreshing resources list");
10127
+ try {
10128
+ const serverName = "inspector-server";
10129
+ const session = clientRef.current.getSession(serverName);
10130
+ if (!session) {
10131
+ addLog("warn", "No active session found for resources refresh");
10132
+ return;
10133
+ }
10134
+ const resourcesResult = await session.connector.listAllResources();
10135
+ setResources(resourcesResult.resources || []);
10136
+ addLog("info", "Resources list refreshed successfully");
10137
+ } catch (err) {
10138
+ addLog("warn", "Failed to refresh resources:", err);
10139
+ }
10140
+ }, [addLog]);
10141
+ const refreshPrompts = (0, import_react.useCallback)(async () => {
10142
+ if (stateRef.current !== "ready" || !clientRef.current) {
10143
+ addLog("debug", "Cannot refresh prompts - client not ready");
10144
+ return;
10145
+ }
10146
+ addLog("debug", "Refreshing prompts list");
10147
+ try {
10148
+ const serverName = "inspector-server";
10149
+ const session = clientRef.current.getSession(serverName);
10150
+ if (!session) {
10151
+ addLog("warn", "No active session found for prompts refresh");
10152
+ return;
10153
+ }
10154
+ const promptsResult = await session.connector.listPrompts();
10155
+ setPrompts(promptsResult.prompts || []);
10156
+ addLog("info", "Prompts list refreshed successfully");
10157
+ } catch (err) {
10158
+ addLog("warn", "Failed to refresh prompts:", err);
10159
+ }
10160
+ }, [addLog]);
10161
+ const refreshAll = (0, import_react.useCallback)(async () => {
10162
+ addLog("info", "Refreshing all lists (tools, resources, prompts)");
10163
+ await Promise.all([refreshTools(), refreshResources(), refreshPrompts()]);
10164
+ }, [refreshTools, refreshResources, refreshPrompts, addLog]);
9906
10165
  const getPrompt = (0, import_react.useCallback)(
9907
10166
  async (name, args) => {
9908
10167
  if (stateRef.current !== "ready" || !clientRef.current) {
@@ -10054,6 +10313,10 @@ function useMcp(options) {
10054
10313
  listResources,
10055
10314
  listPrompts,
10056
10315
  getPrompt,
10316
+ refreshTools,
10317
+ refreshResources,
10318
+ refreshPrompts,
10319
+ refreshAll,
10057
10320
  retry,
10058
10321
  disconnect,
10059
10322
  authenticate,
@@ -10995,7 +11258,7 @@ function McpUseProvider({
10995
11258
  }
10996
11259
  __name(McpUseProvider, "McpUseProvider");
10997
11260
 
10998
- // src/client/prompts.ts
11261
+ // src/agents/prompts/index.ts
10999
11262
  var PROMPTS = {
11000
11263
  CODE_MODE: CODE_MODE_AGENT_PROMPT
11001
11264
  };
package/dist/index.js CHANGED
@@ -9,38 +9,38 @@ import {
9
9
  streamEventsToAISDKWithTools
10
10
  } from "./chunk-LGDFGYRL.js";
11
11
  import "./chunk-GXNAXUDI.js";
12
- import "./chunk-ZFZPZ4GE.js";
12
+ import {
13
+ PROMPTS
14
+ } from "./chunk-V77WS6CS.js";
13
15
  import {
14
16
  AcquireActiveMCPServerTool,
15
17
  AddMCPServerFromConfigTool,
16
- BaseCodeExecutor,
17
18
  ConnectMCPServerTool,
18
- E2BCodeExecutor,
19
19
  ListMCPServersTool,
20
20
  MCPAgent,
21
- MCPClient,
22
21
  ObservabilityManager,
23
22
  ReleaseMCPServerConnectionTool,
24
23
  RemoteAgent,
25
24
  ServerManager,
26
- StdioConnector,
27
- VMCodeExecutor,
28
25
  createLLMFromString,
29
26
  getSupportedProviders,
30
- isVMAvailable,
31
27
  isValidLLMString,
32
- loadConfigFile,
33
28
  parseLLMString
34
- } from "./chunk-5RTMAOZ6.js";
29
+ } from "./chunk-A4QJRN7Z.js";
35
30
  import "./chunk-JRGQRPTN.js";
31
+ import {
32
+ BaseCodeExecutor,
33
+ E2BCodeExecutor,
34
+ MCPClient,
35
+ StdioConnector,
36
+ VMCodeExecutor,
37
+ isVMAvailable,
38
+ loadConfigFile
39
+ } from "./chunk-QPIDKGV4.js";
36
40
  import {
37
41
  BaseAdapter
38
42
  } from "./chunk-MFSO5PUW.js";
39
43
  import "./chunk-JQKKMUCT.js";
40
- import {
41
- PROMPTS
42
- } from "./chunk-GVU7C2ZD.js";
43
- import "./chunk-JZNXOM7C.js";
44
44
  import {
45
45
  ErrorBoundary,
46
46
  Image,
@@ -52,30 +52,28 @@ import {
52
52
  useWidgetProps,
53
53
  useWidgetState,
54
54
  useWidgetTheme
55
- } from "./chunk-X7JKFBPN.js";
56
- import "./chunk-EBSNALCB.js";
55
+ } from "./chunk-Y2HHHJQB.js";
56
+ import "./chunk-VRHAF2WT.js";
57
57
  import {
58
+ BaseConnector,
58
59
  HttpConnector,
59
60
  MCPSession
60
- } from "./chunk-TAEHPLGV.js";
61
- import {
62
- BrowserOAuthClientProvider,
63
- onMcpAuthorization
64
- } from "./chunk-J75I2C26.js";
65
- import {
66
- BaseConnector
67
- } from "./chunk-XKTBHYNM.js";
61
+ } from "./chunk-GN5HOAV3.js";
68
62
  import {
69
63
  Tel,
70
64
  Telemetry,
71
65
  VERSION,
72
66
  getPackageVersion,
73
67
  setTelemetrySource
74
- } from "./chunk-JPKFN73V.js";
68
+ } from "./chunk-ZLZOOXMJ.js";
75
69
  import {
76
70
  Logger,
77
71
  logger
78
72
  } from "./chunk-FRUZDWXH.js";
73
+ import {
74
+ BrowserOAuthClientProvider,
75
+ onMcpAuthorization
76
+ } from "./chunk-J75I2C26.js";
79
77
  import {
80
78
  __name
81
79
  } from "./chunk-3GQAWCBQ.js";
@@ -0,0 +1,9 @@
1
+ import {
2
+ sendNotificationToAll,
3
+ sendNotificationToSession
4
+ } from "./chunk-UWWLWLS2.js";
5
+ import "./chunk-3GQAWCBQ.js";
6
+ export {
7
+ sendNotificationToAll,
8
+ sendNotificationToSession
9
+ };