mcp-use 1.10.5 → 1.11.0-canary.10

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 (135) hide show
  1. package/README.md +1 -1
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/{chunk-IY632ZQS.js → chunk-3GB7G5X7.js} +2 -2
  4. package/dist/{chunk-E42PSMPK.js → chunk-5QAXQTDL.js} +1 -1
  5. package/dist/{chunk-C7WHRUWQ.js → chunk-BEGEDH6P.js} +196 -496
  6. package/dist/{chunk-MO5FM5B2.js → chunk-BLGIG2QD.js} +443 -969
  7. package/dist/{chunk-XG7SR6G4.js → chunk-CBJTHTR4.js} +3 -8
  8. package/dist/{chunk-34R6SIER.js → chunk-FRUZDWXH.js} +1 -1
  9. package/dist/chunk-GUB5GQDD.js +101 -0
  10. package/dist/chunk-GXNAXUDI.js +0 -0
  11. package/dist/{chunk-CPG2WZUL.js → chunk-JRGQRPTN.js} +1 -1
  12. package/dist/chunk-MFSO5PUW.js +1049 -0
  13. package/dist/{chunk-UD5FSFEZ.js → chunk-NXFHUS7A.js} +171 -11
  14. package/dist/chunk-ULFNVP5Z.js +12 -0
  15. package/dist/chunk-UWWLWLS2.js +62 -0
  16. package/dist/chunk-VTEYN43V.js +1055 -0
  17. package/dist/{chunk-YOHGE3NK.js → chunk-XPTKLSBC.js} +16 -2
  18. package/dist/index.cjs +5065 -4608
  19. package/dist/index.d.ts +2 -3
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +53 -1068
  22. package/dist/{langfuse-N5Y5BSXK.js → langfuse-74RGPTAH.js} +2 -2
  23. package/dist/notifications-FLGIFS56.js +9 -0
  24. package/dist/src/adapters/base.d.ts +44 -0
  25. package/dist/src/adapters/base.d.ts.map +1 -1
  26. package/dist/src/adapters/index.cjs +1346 -0
  27. package/dist/src/adapters/index.js +11 -0
  28. package/dist/src/adapters/langchain_adapter.d.ts +12 -1
  29. package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
  30. package/dist/src/agents/index.cjs +3141 -159
  31. package/dist/src/agents/index.d.ts +2 -0
  32. package/dist/src/agents/index.d.ts.map +1 -1
  33. package/dist/src/agents/index.js +10 -6
  34. package/dist/src/agents/mcp_agent.d.ts +59 -37
  35. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  36. package/dist/src/agents/remote.d.ts +25 -0
  37. package/dist/src/agents/remote.d.ts.map +1 -1
  38. package/dist/src/agents/types.d.ts +76 -0
  39. package/dist/src/agents/types.d.ts.map +1 -1
  40. package/dist/src/agents/utils/index.d.ts +1 -0
  41. package/dist/src/agents/utils/index.d.ts.map +1 -1
  42. package/dist/src/agents/utils/llm_provider.d.ts +53 -0
  43. package/dist/src/agents/utils/llm_provider.d.ts.map +1 -0
  44. package/dist/src/browser.cjs +1856 -423
  45. package/dist/src/browser.d.ts +1 -2
  46. package/dist/src/browser.d.ts.map +1 -1
  47. package/dist/src/browser.js +26 -15
  48. package/dist/src/client/base.d.ts +1 -0
  49. package/dist/src/client/base.d.ts.map +1 -1
  50. package/dist/src/client/browser.d.ts +2 -2
  51. package/dist/src/client/browser.d.ts.map +1 -1
  52. package/dist/src/client/prompts.cjs +1 -1
  53. package/dist/src/client/prompts.js +5 -4
  54. package/dist/src/client.cjs +3787 -0
  55. package/dist/src/client.js +20 -0
  56. package/dist/src/config.d.ts.map +1 -1
  57. package/dist/src/connectors/base.d.ts +8 -0
  58. package/dist/src/connectors/base.d.ts.map +1 -1
  59. package/dist/src/connectors/index.d.ts +0 -1
  60. package/dist/src/connectors/index.d.ts.map +1 -1
  61. package/dist/src/managers/server_manager.d.ts.map +1 -1
  62. package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -1
  63. package/dist/src/react/index.cjs +259 -298
  64. package/dist/src/react/index.js +6 -5
  65. package/dist/src/react/types.d.ts +42 -4
  66. package/dist/src/react/types.d.ts.map +1 -1
  67. package/dist/src/react/useMcp.d.ts.map +1 -1
  68. package/dist/src/react/useWidget.d.ts +11 -7
  69. package/dist/src/react/useWidget.d.ts.map +1 -1
  70. package/dist/src/react/widget-types.d.ts +6 -2
  71. package/dist/src/react/widget-types.d.ts.map +1 -1
  72. package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
  73. package/dist/src/server/index.cjs +1379 -208
  74. package/dist/src/server/index.d.ts +2 -0
  75. package/dist/src/server/index.d.ts.map +1 -1
  76. package/dist/src/server/index.js +1353 -249
  77. package/dist/src/server/mcp-server.d.ts +5 -1
  78. package/dist/src/server/mcp-server.d.ts.map +1 -1
  79. package/dist/src/server/notifications/index.d.ts +1 -1
  80. package/dist/src/server/notifications/index.d.ts.map +1 -1
  81. package/dist/src/server/notifications/notification-registration.d.ts +51 -0
  82. package/dist/src/server/notifications/notification-registration.d.ts.map +1 -1
  83. package/dist/src/server/sessions/index.d.ts +3 -1
  84. package/dist/src/server/sessions/index.d.ts.map +1 -1
  85. package/dist/src/server/sessions/session-manager.d.ts +36 -19
  86. package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
  87. package/dist/src/server/sessions/stores/filesystem.d.ts +121 -0
  88. package/dist/src/server/sessions/stores/filesystem.d.ts.map +1 -0
  89. package/dist/src/server/sessions/stores/index.d.ts +94 -0
  90. package/dist/src/server/sessions/stores/index.d.ts.map +1 -0
  91. package/dist/src/server/sessions/stores/memory.d.ts +82 -0
  92. package/dist/src/server/sessions/stores/memory.d.ts.map +1 -0
  93. package/dist/src/server/sessions/stores/redis.d.ts +164 -0
  94. package/dist/src/server/sessions/stores/redis.d.ts.map +1 -0
  95. package/dist/src/server/sessions/streams/index.d.ts +77 -0
  96. package/dist/src/server/sessions/streams/index.d.ts.map +1 -0
  97. package/dist/src/server/sessions/streams/memory.d.ts +76 -0
  98. package/dist/src/server/sessions/streams/memory.d.ts.map +1 -0
  99. package/dist/src/server/sessions/streams/redis.d.ts +146 -0
  100. package/dist/src/server/sessions/streams/redis.d.ts.map +1 -0
  101. package/dist/src/server/types/common.d.ts +120 -17
  102. package/dist/src/server/types/common.d.ts.map +1 -1
  103. package/dist/src/server/types/resource.d.ts +16 -0
  104. package/dist/src/server/types/resource.d.ts.map +1 -1
  105. package/dist/src/server/types/widget.d.ts +21 -2
  106. package/dist/src/server/types/widget.d.ts.map +1 -1
  107. package/dist/src/server/utils/response-helpers.d.ts +12 -6
  108. package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
  109. package/dist/src/server/widgets/index.d.ts +1 -1
  110. package/dist/src/server/widgets/index.d.ts.map +1 -1
  111. package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
  112. package/dist/src/server/widgets/setup-widget-routes.d.ts.map +1 -1
  113. package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
  114. package/dist/src/server/widgets/widget-helpers.d.ts +22 -0
  115. package/dist/src/server/widgets/widget-helpers.d.ts.map +1 -1
  116. package/dist/src/server/widgets/widget-types.d.ts +2 -0
  117. package/dist/src/server/widgets/widget-types.d.ts.map +1 -1
  118. package/dist/src/session.d.ts +16 -2
  119. package/dist/src/session.d.ts.map +1 -1
  120. package/dist/src/task_managers/index.d.ts +10 -1
  121. package/dist/src/task_managers/index.d.ts.map +1 -1
  122. package/dist/src/task_managers/sse.d.ts +34 -1
  123. package/dist/src/task_managers/sse.d.ts.map +1 -1
  124. package/dist/src/task_managers/streamable_http.d.ts +8 -2
  125. package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
  126. package/dist/src/version.d.ts +1 -1
  127. package/dist/src/version.d.ts.map +1 -1
  128. package/dist/{tool-execution-helpers-XTDKRH6N.js → tool-execution-helpers-N7R7YGAW.js} +3 -3
  129. package/dist/tsup.config.d.ts.map +1 -1
  130. package/package.json +47 -14
  131. package/dist/src/connectors/websocket.d.ts +0 -38
  132. package/dist/src/connectors/websocket.d.ts.map +0 -1
  133. package/dist/src/task_managers/websocket.d.ts +0 -18
  134. package/dist/src/task_managers/websocket.d.ts.map +0 -1
  135. /package/dist/{chunk-EW4MJSHA.js → chunk-LGDFGYRL.js} +0 -0
@@ -246,7 +246,7 @@ var Logger = class {
246
246
  timestamp({ format: "HH:mm:ss" }),
247
247
  this.getFormatter()
248
248
  ),
249
- transports: []
249
+ transports: [new winston.transports.Console()]
250
250
  });
251
251
  }
252
252
  return this.instances[name];
@@ -482,6 +482,7 @@ var SseConnectionManager = class extends ConnectionManager {
482
482
  url;
483
483
  opts;
484
484
  _transport = null;
485
+ reinitializing = false;
485
486
  /**
486
487
  * Create an SSE connection manager.
487
488
  *
@@ -494,12 +495,53 @@ var SseConnectionManager = class extends ConnectionManager {
494
495
  this.opts = opts;
495
496
  }
496
497
  /**
497
- * Spawn a new `SSEClientTransport` and start the connection.
498
+ * Spawn a new `SSEClientTransport` and wrap it with 404 handling.
499
+ * Per MCP spec, clients MUST re-initialize when receiving 404 for stale sessions.
498
500
  */
499
501
  async establishConnection() {
500
- this._transport = new import_sse.SSEClientTransport(this.url, this.opts);
502
+ const transport = new import_sse.SSEClientTransport(this.url, this.opts);
503
+ const originalSend = transport.send.bind(transport);
504
+ transport.send = async (message) => {
505
+ const sendMessage = /* @__PURE__ */ __name(async (msg) => {
506
+ if (Array.isArray(msg)) {
507
+ for (const singleMsg of msg) {
508
+ await originalSend(singleMsg);
509
+ }
510
+ } else {
511
+ await originalSend(msg);
512
+ }
513
+ }, "sendMessage");
514
+ try {
515
+ await sendMessage(message);
516
+ } catch (error) {
517
+ if (error?.code === 404 && transport.sessionId && !this.reinitializing) {
518
+ logger.warn(
519
+ `[SSE] Session not found (404), re-initializing per MCP spec...`
520
+ );
521
+ this.reinitializing = true;
522
+ try {
523
+ transport.sessionId = void 0;
524
+ await this.reinitialize(transport);
525
+ logger.info(`[SSE] Re-initialization successful, retrying request`);
526
+ await sendMessage(message);
527
+ } finally {
528
+ this.reinitializing = false;
529
+ }
530
+ } else {
531
+ throw error;
532
+ }
533
+ }
534
+ };
535
+ this._transport = transport;
501
536
  logger.debug(`${this.constructor.name} connected successfully`);
502
- return this._transport;
537
+ return transport;
538
+ }
539
+ /**
540
+ * Re-initialize the transport with a new session
541
+ * This is called when the server returns 404 for a stale session
542
+ */
543
+ async reinitialize(transport) {
544
+ logger.debug(`[SSE] Re-initialization triggered`);
503
545
  }
504
546
  /**
505
547
  * Close the underlying transport and clean up resources.
@@ -876,7 +918,7 @@ function generateUUID() {
876
918
  __name(generateUUID, "generateUUID");
877
919
 
878
920
  // src/version.ts
879
- var VERSION = "1.10.5";
921
+ var VERSION = "1.11.0-canary.10";
880
922
  function getPackageVersion() {
881
923
  return VERSION;
882
924
  }
@@ -1806,6 +1848,20 @@ var BaseConnector = class {
1806
1848
  logger.debug(`Tool '${name}' returned`, res);
1807
1849
  return res;
1808
1850
  }
1851
+ /**
1852
+ * List all available tools from the MCP server.
1853
+ * This method fetches fresh tools from the server, unlike the `tools` getter which returns cached tools.
1854
+ *
1855
+ * @param options - Optional request options
1856
+ * @returns Array of available tools
1857
+ */
1858
+ async listTools(options) {
1859
+ if (!this.client) {
1860
+ throw new Error("MCP client is not connected");
1861
+ }
1862
+ const result = await this.client.listTools(void 0, options);
1863
+ return result.tools ?? [];
1864
+ }
1809
1865
  /**
1810
1866
  * List resources from the server with optional pagination
1811
1867
  *
@@ -2249,279 +2305,6 @@ var HttpConnector = class extends BaseConnector {
2249
2305
  }
2250
2306
  };
2251
2307
 
2252
- // src/task_managers/websocket.ts
2253
- var import_ws = __toESM(require("ws"), 1);
2254
- var WebSocketConnectionManager = class extends ConnectionManager {
2255
- static {
2256
- __name(this, "WebSocketConnectionManager");
2257
- }
2258
- url;
2259
- headers;
2260
- _ws = null;
2261
- /**
2262
- * @param url The WebSocket URL to connect to.
2263
- * @param headers Optional headers to include in the connection handshake.
2264
- */
2265
- constructor(url, headers = {}) {
2266
- super();
2267
- this.url = url;
2268
- this.headers = headers;
2269
- }
2270
- /** Establish a WebSocket connection and wait until it is open. */
2271
- async establishConnection() {
2272
- logger.debug(`Connecting to WebSocket: ${this.url}`);
2273
- return new Promise((resolve, reject) => {
2274
- const ws = new import_ws.default(this.url, {
2275
- headers: this.headers
2276
- });
2277
- this._ws = ws;
2278
- const onOpen = /* @__PURE__ */ __name(() => {
2279
- cleanup();
2280
- logger.debug("WebSocket connected successfully");
2281
- resolve(ws);
2282
- }, "onOpen");
2283
- const onError = /* @__PURE__ */ __name((err) => {
2284
- cleanup();
2285
- logger.error(`Failed to connect to WebSocket: ${err}`);
2286
- reject(err);
2287
- }, "onError");
2288
- const cleanup = /* @__PURE__ */ __name(() => {
2289
- ws.off("open", onOpen);
2290
- ws.off("error", onError);
2291
- }, "cleanup");
2292
- ws.on("open", onOpen);
2293
- ws.on("error", onError);
2294
- });
2295
- }
2296
- /** Cleanly close the WebSocket connection. */
2297
- async closeConnection(connection) {
2298
- logger.debug("Closing WebSocket connection");
2299
- return new Promise((resolve) => {
2300
- const onClose = /* @__PURE__ */ __name(() => {
2301
- connection.off("close", onClose);
2302
- this._ws = null;
2303
- resolve();
2304
- }, "onClose");
2305
- if (connection.readyState === import_ws.default.CLOSED) {
2306
- onClose();
2307
- return;
2308
- }
2309
- connection.on("close", onClose);
2310
- try {
2311
- connection.close();
2312
- } catch (e) {
2313
- logger.warn(`Error closing WebSocket connection: ${e}`);
2314
- onClose();
2315
- }
2316
- });
2317
- }
2318
- };
2319
-
2320
- // src/connectors/websocket.ts
2321
- var WebSocketConnector = class extends BaseConnector {
2322
- static {
2323
- __name(this, "WebSocketConnector");
2324
- }
2325
- url;
2326
- headers;
2327
- connectionManager = null;
2328
- ws = null;
2329
- receiverTask = null;
2330
- pending = /* @__PURE__ */ new Map();
2331
- toolsCache = null;
2332
- constructor(url, opts = {}) {
2333
- super();
2334
- this.url = url;
2335
- this.headers = { ...opts.headers ?? {} };
2336
- if (opts.authToken) this.headers.Authorization = `Bearer ${opts.authToken}`;
2337
- }
2338
- async connect() {
2339
- if (this.connected) {
2340
- logger.debug("Already connected to MCP implementation");
2341
- return;
2342
- }
2343
- logger.debug(`Connecting via WebSocket: ${this.url}`);
2344
- try {
2345
- this.connectionManager = new WebSocketConnectionManager(
2346
- this.url,
2347
- this.headers
2348
- );
2349
- this.ws = await this.connectionManager.start();
2350
- this.receiverTask = this.receiveLoop();
2351
- this.connected = true;
2352
- logger.debug("WebSocket connected successfully");
2353
- } catch (e) {
2354
- logger.error(`Failed to connect: ${e}`);
2355
- await this.cleanupResources();
2356
- throw e;
2357
- }
2358
- }
2359
- async disconnect() {
2360
- if (!this.connected) {
2361
- logger.debug("Not connected to MCP implementation");
2362
- return;
2363
- }
2364
- logger.debug("Disconnecting \u2026");
2365
- await this.cleanupResources();
2366
- this.connected = false;
2367
- }
2368
- sendRequest(method, params = null) {
2369
- if (!this.ws) throw new Error("WebSocket is not connected");
2370
- const id = generateUUID();
2371
- const payload = JSON.stringify({ id, method, params: params ?? {} });
2372
- return new Promise((resolve, reject) => {
2373
- this.pending.set(id, { resolve, reject });
2374
- this.ws.send(payload, (err) => {
2375
- if (err) {
2376
- this.pending.delete(id);
2377
- reject(err);
2378
- }
2379
- });
2380
- });
2381
- }
2382
- async receiveLoop() {
2383
- if (!this.ws) return;
2384
- const socket = this.ws;
2385
- const onMessage = /* @__PURE__ */ __name((msg) => {
2386
- let data;
2387
- try {
2388
- data = JSON.parse(msg.data ?? msg);
2389
- } catch (e) {
2390
- logger.warn("Received non\u2011JSON frame", e);
2391
- return;
2392
- }
2393
- const id = data.id;
2394
- if (id && this.pending.has(id)) {
2395
- const { resolve, reject } = this.pending.get(id);
2396
- this.pending.delete(id);
2397
- if ("result" in data) resolve(data.result);
2398
- else if ("error" in data) reject(data.error);
2399
- } else if (data.method && !data.id) {
2400
- logger.debug("Received notification", data.method, data.params);
2401
- this.handleNotification(data);
2402
- } else {
2403
- logger.debug("Received unsolicited message", data);
2404
- }
2405
- }, "onMessage");
2406
- if (socket.addEventListener) {
2407
- socket.addEventListener("message", onMessage);
2408
- } else {
2409
- socket.on("message", onMessage);
2410
- }
2411
- return new Promise((resolve) => {
2412
- const onClose = /* @__PURE__ */ __name(() => {
2413
- if (socket.removeEventListener) {
2414
- socket.removeEventListener("message", onMessage);
2415
- } else {
2416
- socket.off("message", onMessage);
2417
- }
2418
- this.rejectAll(new Error("WebSocket closed"));
2419
- resolve();
2420
- }, "onClose");
2421
- if (socket.addEventListener) {
2422
- socket.addEventListener("close", onClose);
2423
- } else {
2424
- socket.on("close", onClose);
2425
- }
2426
- });
2427
- }
2428
- rejectAll(err) {
2429
- for (const { reject } of this.pending.values()) reject(err);
2430
- this.pending.clear();
2431
- }
2432
- async handleNotification(data) {
2433
- switch (data.method) {
2434
- case "notifications/tools/list_changed":
2435
- await this.refreshToolsCache();
2436
- break;
2437
- case "notifications/resources/list_changed":
2438
- await this.onResourcesListChanged();
2439
- break;
2440
- case "notifications/prompts/list_changed":
2441
- await this.onPromptsListChanged();
2442
- break;
2443
- default:
2444
- break;
2445
- }
2446
- for (const handler of this.notificationHandlers) {
2447
- try {
2448
- await handler({
2449
- method: data.method,
2450
- params: data.params
2451
- });
2452
- } catch (err) {
2453
- logger.error("Error in notification handler:", err);
2454
- }
2455
- }
2456
- }
2457
- /**
2458
- * Auto-refresh tools cache when server sends tools/list_changed notification
2459
- * Override to use WebSocket-specific listTools method
2460
- */
2461
- async refreshToolsCache() {
2462
- try {
2463
- logger.debug(
2464
- "[Auto] Refreshing tools cache due to list_changed notification"
2465
- );
2466
- const tools = await this.listTools();
2467
- this.toolsCache = tools.map((t) => t);
2468
- logger.debug(
2469
- `[Auto] Refreshed tools cache: ${this.toolsCache.length} tools`
2470
- );
2471
- } catch (err) {
2472
- logger.warn("[Auto] Failed to refresh tools cache:", err);
2473
- }
2474
- }
2475
- async initialize() {
2476
- logger.debug("Initializing MCP session over WebSocket");
2477
- const result = await this.sendRequest("initialize");
2478
- const toolsList = await this.listTools();
2479
- this.toolsCache = toolsList.map((t) => t);
2480
- logger.debug(`Initialized with ${this.toolsCache.length} tools`);
2481
- return result;
2482
- }
2483
- async listTools() {
2484
- const res = await this.sendRequest("tools/list");
2485
- return res.tools ?? [];
2486
- }
2487
- async callTool(name, args) {
2488
- return await this.sendRequest("tools/call", { name, arguments: args });
2489
- }
2490
- async listResources() {
2491
- const resources = await this.sendRequest("resources/list");
2492
- return { resources: Array.isArray(resources) ? resources : [] };
2493
- }
2494
- async readResource(uri) {
2495
- const res = await this.sendRequest("resources/read", { uri });
2496
- return res;
2497
- }
2498
- async request(method, params = null) {
2499
- return await this.sendRequest(method, params);
2500
- }
2501
- get tools() {
2502
- if (!this.toolsCache) throw new Error("MCP client is not initialized");
2503
- return this.toolsCache;
2504
- }
2505
- async cleanupResources() {
2506
- if (this.receiverTask) await this.receiverTask.catch(() => {
2507
- });
2508
- this.receiverTask = null;
2509
- this.rejectAll(new Error("WebSocket disconnected"));
2510
- if (this.connectionManager) {
2511
- await this.connectionManager.stop();
2512
- this.connectionManager = null;
2513
- this.ws = null;
2514
- }
2515
- this.toolsCache = null;
2516
- }
2517
- get publicIdentifier() {
2518
- return {
2519
- type: "websocket",
2520
- url: this.url
2521
- };
2522
- }
2523
- };
2524
-
2525
2308
  // src/session.ts
2526
2309
  var MCPSession = class {
2527
2310
  static {
@@ -2607,6 +2390,22 @@ var MCPSession = class {
2607
2390
  get tools() {
2608
2391
  return this.connector.tools;
2609
2392
  }
2393
+ /**
2394
+ * List all available tools from the MCP server.
2395
+ * This method fetches fresh tools from the server, unlike the `tools` getter which returns cached tools.
2396
+ *
2397
+ * @param options - Optional request options
2398
+ * @returns Array of available tools
2399
+ *
2400
+ * @example
2401
+ * ```typescript
2402
+ * const tools = await session.listTools();
2403
+ * console.log(`Available tools: ${tools.map(t => t.name).join(", ")}`);
2404
+ * ```
2405
+ */
2406
+ async listTools(options) {
2407
+ return this.connector.listTools(options);
2408
+ }
2610
2409
  /**
2611
2410
  * Get the server capabilities advertised during initialization.
2612
2411
  *
@@ -2627,7 +2426,7 @@ var MCPSession = class {
2627
2426
  * Call a tool on the server.
2628
2427
  *
2629
2428
  * @param name - Name of the tool to call
2630
- * @param args - Arguments to pass to the tool
2429
+ * @param args - Arguments to pass to the tool (defaults to empty object)
2631
2430
  * @param options - Optional request options (timeout, progress handlers, etc.)
2632
2431
  * @returns Result from the tool execution
2633
2432
  *
@@ -2637,7 +2436,7 @@ var MCPSession = class {
2637
2436
  * console.log(`Result: ${result.content[0].text}`);
2638
2437
  * ```
2639
2438
  */
2640
- async callTool(name, args, options) {
2439
+ async callTool(name, args = {}, options) {
2641
2440
  return this.connector.callTool(name, args, options);
2642
2441
  }
2643
2442
  /**
@@ -2852,6 +2651,15 @@ var BaseMCPClient = class {
2852
2651
  }
2853
2652
  return session;
2854
2653
  }
2654
+ requireSession(serverName) {
2655
+ const session = this.sessions[serverName];
2656
+ if (!session) {
2657
+ throw new Error(
2658
+ `Session '${serverName}' not found. Available sessions: ${this.activeSessions.join(", ") || "none"}`
2659
+ );
2660
+ }
2661
+ return session;
2662
+ }
2855
2663
  getAllActiveSessions() {
2856
2664
  return Object.fromEntries(
2857
2665
  this.activeSessions.map((n) => [n, this.sessions[n]])
@@ -2937,12 +2745,11 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
2937
2745
  }
2938
2746
  /**
2939
2747
  * Create a connector from server configuration (Browser version)
2940
- * Supports HTTP and WebSocket connectors only
2748
+ * Supports HTTP connector only
2941
2749
  */
2942
2750
  createConnectorFromConfig(serverConfig) {
2943
2751
  const {
2944
2752
  url,
2945
- transport,
2946
2753
  headers,
2947
2754
  authToken,
2948
2755
  authProvider,
@@ -2978,13 +2785,7 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
2978
2785
  "[BrowserMCPClient] No clientOptions provided to connector!"
2979
2786
  );
2980
2787
  }
2981
- if (transport === "websocket" || url.startsWith("ws://") || url.startsWith("wss://")) {
2982
- return new WebSocketConnector(url, connectorOptions);
2983
- } else if (transport === "http" || url.startsWith("http://") || url.startsWith("https://")) {
2984
- return new HttpConnector(url, connectorOptions);
2985
- } else {
2986
- return new HttpConnector(url, connectorOptions);
2987
- }
2788
+ return new HttpConnector(url, connectorOptions);
2988
2789
  }
2989
2790
  };
2990
2791
 
@@ -3306,6 +3107,11 @@ function useMcp(options) {
3306
3107
  if (clientRef.current) {
3307
3108
  try {
3308
3109
  const serverName = "inspector-server";
3110
+ const session = clientRef.current.getSession(serverName);
3111
+ if (session && session._healthCheckCleanup) {
3112
+ session._healthCheckCleanup();
3113
+ session._healthCheckCleanup = null;
3114
+ }
3309
3115
  await clientRef.current.closeSession(serverName);
3310
3116
  } catch (err) {
3311
3117
  if (!quiet) addLog("warn", "Error closing session:", err);
@@ -3445,9 +3251,25 @@ function useMcp(options) {
3445
3251
  serverName,
3446
3252
  false
3447
3253
  );
3448
- if (onNotification) {
3449
- session.on("notification", onNotification);
3450
- }
3254
+ session.on("notification", (notification) => {
3255
+ onNotification?.(notification);
3256
+ if (notification.method === "notifications/tools/list_changed") {
3257
+ addLog("info", "Tools list changed, auto-refreshing...");
3258
+ refreshTools().catch(
3259
+ (err) => addLog("warn", "Auto-refresh tools failed:", err)
3260
+ );
3261
+ } else if (notification.method === "notifications/resources/list_changed") {
3262
+ addLog("info", "Resources list changed, auto-refreshing...");
3263
+ refreshResources().catch(
3264
+ (err) => addLog("warn", "Auto-refresh resources failed:", err)
3265
+ );
3266
+ } else if (notification.method === "notifications/prompts/list_changed") {
3267
+ addLog("info", "Prompts list changed, auto-refreshing...");
3268
+ refreshPrompts().catch(
3269
+ (err) => addLog("warn", "Auto-refresh prompts failed:", err)
3270
+ );
3271
+ }
3272
+ });
3451
3273
  await session.initialize();
3452
3274
  addLog("info", "\u2705 Successfully connected to MCP server");
3453
3275
  addLog("info", "Server info:", session.connector.serverInfo);
@@ -3463,6 +3285,63 @@ function useMcp(options) {
3463
3285
  );
3464
3286
  setState("ready");
3465
3287
  successfulTransportRef.current = transportTypeParam;
3288
+ const setupConnectionMonitoring = /* @__PURE__ */ __name(() => {
3289
+ let healthCheckInterval = null;
3290
+ let lastSuccessfulCheck = Date.now();
3291
+ const HEALTH_CHECK_INTERVAL = 1e4;
3292
+ const HEALTH_CHECK_TIMEOUT = 3e4;
3293
+ const checkConnectionHealth = /* @__PURE__ */ __name(async () => {
3294
+ if (!isMountedRef.current || stateRef.current !== "ready") {
3295
+ if (healthCheckInterval) {
3296
+ clearInterval(healthCheckInterval);
3297
+ healthCheckInterval = null;
3298
+ }
3299
+ return;
3300
+ }
3301
+ try {
3302
+ await session.connector.listTools();
3303
+ lastSuccessfulCheck = Date.now();
3304
+ } catch (err) {
3305
+ const timeSinceLastSuccess = Date.now() - lastSuccessfulCheck;
3306
+ if (timeSinceLastSuccess > HEALTH_CHECK_TIMEOUT) {
3307
+ addLog(
3308
+ "warn",
3309
+ `Connection appears to be broken (no response for ${Math.round(timeSinceLastSuccess / 1e3)}s), attempting to reconnect...`
3310
+ );
3311
+ if (healthCheckInterval) {
3312
+ clearInterval(healthCheckInterval);
3313
+ healthCheckInterval = null;
3314
+ }
3315
+ if (autoReconnectRef.current && isMountedRef.current) {
3316
+ setState("discovering");
3317
+ addLog("info", "Auto-reconnecting to MCP server...");
3318
+ setTimeout(
3319
+ () => {
3320
+ if (isMountedRef.current && stateRef.current === "discovering") {
3321
+ connect();
3322
+ }
3323
+ },
3324
+ typeof autoReconnectRef.current === "number" ? autoReconnectRef.current : DEFAULT_RECONNECT_DELAY
3325
+ );
3326
+ }
3327
+ }
3328
+ }
3329
+ }, "checkConnectionHealth");
3330
+ healthCheckInterval = setInterval(
3331
+ checkConnectionHealth,
3332
+ HEALTH_CHECK_INTERVAL
3333
+ );
3334
+ return () => {
3335
+ if (healthCheckInterval) {
3336
+ clearInterval(healthCheckInterval);
3337
+ healthCheckInterval = null;
3338
+ }
3339
+ };
3340
+ }, "setupConnectionMonitoring");
3341
+ if (autoReconnect) {
3342
+ const cleanup = setupConnectionMonitoring();
3343
+ session._healthCheckCleanup = cleanup;
3344
+ }
3466
3345
  Tel.getInstance().trackUseMcpConnection({
3467
3346
  url,
3468
3347
  transportType: transportTypeParam,
@@ -3814,6 +3693,70 @@ function useMcp(options) {
3814
3693
  throw err;
3815
3694
  }
3816
3695
  }, [state]);
3696
+ const refreshTools = (0, import_react.useCallback)(async () => {
3697
+ if (stateRef.current !== "ready" || !clientRef.current) {
3698
+ addLog("debug", "Cannot refresh tools - client not ready");
3699
+ return;
3700
+ }
3701
+ addLog("debug", "Refreshing tools list");
3702
+ try {
3703
+ const serverName = "inspector-server";
3704
+ const session = clientRef.current.getSession(serverName);
3705
+ if (!session) {
3706
+ addLog("warn", "No active session found for tools refresh");
3707
+ return;
3708
+ }
3709
+ const toolsResult = await session.connector.listTools();
3710
+ setTools(toolsResult || []);
3711
+ addLog("info", "Tools list refreshed successfully");
3712
+ } catch (err) {
3713
+ addLog("warn", "Failed to refresh tools:", err);
3714
+ }
3715
+ }, [addLog]);
3716
+ const refreshResources = (0, import_react.useCallback)(async () => {
3717
+ if (stateRef.current !== "ready" || !clientRef.current) {
3718
+ addLog("debug", "Cannot refresh resources - client not ready");
3719
+ return;
3720
+ }
3721
+ addLog("debug", "Refreshing resources list");
3722
+ try {
3723
+ const serverName = "inspector-server";
3724
+ const session = clientRef.current.getSession(serverName);
3725
+ if (!session) {
3726
+ addLog("warn", "No active session found for resources refresh");
3727
+ return;
3728
+ }
3729
+ const resourcesResult = await session.connector.listAllResources();
3730
+ setResources(resourcesResult.resources || []);
3731
+ addLog("info", "Resources list refreshed successfully");
3732
+ } catch (err) {
3733
+ addLog("warn", "Failed to refresh resources:", err);
3734
+ }
3735
+ }, [addLog]);
3736
+ const refreshPrompts = (0, import_react.useCallback)(async () => {
3737
+ if (stateRef.current !== "ready" || !clientRef.current) {
3738
+ addLog("debug", "Cannot refresh prompts - client not ready");
3739
+ return;
3740
+ }
3741
+ addLog("debug", "Refreshing prompts list");
3742
+ try {
3743
+ const serverName = "inspector-server";
3744
+ const session = clientRef.current.getSession(serverName);
3745
+ if (!session) {
3746
+ addLog("warn", "No active session found for prompts refresh");
3747
+ return;
3748
+ }
3749
+ const promptsResult = await session.connector.listPrompts();
3750
+ setPrompts(promptsResult.prompts || []);
3751
+ addLog("info", "Prompts list refreshed successfully");
3752
+ } catch (err) {
3753
+ addLog("warn", "Failed to refresh prompts:", err);
3754
+ }
3755
+ }, [addLog]);
3756
+ const refreshAll = (0, import_react.useCallback)(async () => {
3757
+ addLog("info", "Refreshing all lists (tools, resources, prompts)");
3758
+ await Promise.all([refreshTools(), refreshResources(), refreshPrompts()]);
3759
+ }, [refreshTools, refreshResources, refreshPrompts, addLog]);
3817
3760
  const getPrompt = (0, import_react.useCallback)(
3818
3761
  async (name, args) => {
3819
3762
  if (stateRef.current !== "ready" || !clientRef.current) {
@@ -3965,6 +3908,10 @@ function useMcp(options) {
3965
3908
  listResources,
3966
3909
  listPrompts,
3967
3910
  getPrompt,
3911
+ refreshTools,
3912
+ refreshResources,
3913
+ refreshPrompts,
3914
+ refreshAll,
3968
3915
  retry,
3969
3916
  disconnect,
3970
3917
  authenticate,
@@ -4270,6 +4217,15 @@ function useWidget(defaultProps) {
4270
4217
  const toolInput = provider === "openai" ? useOpenAiGlobal("toolInput") : urlParams.toolInput;
4271
4218
  const toolOutput = provider === "openai" ? useOpenAiGlobal("toolOutput") : urlParams.toolOutput;
4272
4219
  const toolResponseMetadata = useOpenAiGlobal("toolResponseMetadata");
4220
+ const widgetProps = (0, import_react4.useMemo)(() => {
4221
+ if (toolResponseMetadata && typeof toolResponseMetadata === "object") {
4222
+ const metaProps = toolResponseMetadata["mcp-use/props"];
4223
+ if (metaProps) {
4224
+ return metaProps;
4225
+ }
4226
+ }
4227
+ return defaultProps || {};
4228
+ }, [toolResponseMetadata, defaultProps]);
4273
4229
  const widgetState = useOpenAiGlobal("widgetState");
4274
4230
  const theme = useOpenAiGlobal("theme");
4275
4231
  const displayMode = useOpenAiGlobal("displayMode");
@@ -4334,9 +4290,13 @@ function useWidget(defaultProps) {
4334
4290
  },
4335
4291
  [widgetState, localWidgetState]
4336
4292
  );
4293
+ const isPending = (0, import_react4.useMemo)(() => {
4294
+ return provider === "openai" && toolResponseMetadata === null;
4295
+ }, [provider, toolResponseMetadata]);
4337
4296
  return {
4338
4297
  // Props and state (with defaults)
4339
- props: toolInput || defaultProps || {},
4298
+ props: widgetProps,
4299
+ toolInput: toolInput || {},
4340
4300
  output: toolOutput ?? null,
4341
4301
  metadata: toolResponseMetadata ?? null,
4342
4302
  state: localWidgetState,
@@ -4358,7 +4318,8 @@ function useWidget(defaultProps) {
4358
4318
  openExternal,
4359
4319
  requestDisplayMode,
4360
4320
  // Availability
4361
- isAvailable: isOpenAiAvailable
4321
+ isAvailable: isOpenAiAvailable,
4322
+ isPending
4362
4323
  };
4363
4324
  }
4364
4325
  __name(useWidget, "useWidget");
@@ -4461,7 +4422,7 @@ function WidgetControls({
4461
4422
  );
4462
4423
  const isFullscreen = displayMode === "fullscreen" && isAvailable;
4463
4424
  const isPip = displayMode === "pip" && isAvailable;
4464
- const isDevMode = typeof window !== "undefined" && window.location.pathname.includes("/inspector/api/dev-widget/");
4425
+ const isInInspector = typeof window !== "undefined" && window.location.pathname.includes("/inspector/api/");
4465
4426
  (0, import_react6.useEffect)(() => {
4466
4427
  const timeoutId = setTimeout(() => {
4467
4428
  if (typeof window !== "undefined" && window.openai) {
@@ -4793,7 +4754,7 @@ function WidgetControls({
4793
4754
  className: getPositionClasses().join(" "),
4794
4755
  style: getPositionOffsetStyles()
4795
4756
  },
4796
- !isDevMode && /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, !isFullscreen && !isPip && /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, (viewControls === true || viewControls === "fullscreen") && /* @__PURE__ */ import_react6.default.createElement(IconButton, { onClick: handleFullscreen, label: "Fullscreen" }, /* @__PURE__ */ import_react6.default.createElement("path", { d: "M15 3h6v6" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "m21 3-7 7" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "m3 21 7-7" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M9 21H3v-6" })), (viewControls === true || viewControls === "pip") && /* @__PURE__ */ import_react6.default.createElement(IconButton, { onClick: handlePip, label: "Picture in Picture" }, /* @__PURE__ */ import_react6.default.createElement("path", { d: "M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4" }), /* @__PURE__ */ import_react6.default.createElement("rect", { width: "10", height: "7", x: "12", y: "13", rx: "2" }))), enableDebugger && /* @__PURE__ */ import_react6.default.createElement(IconButton, { onClick: handleToggleOverlay, label: "Debug Info" }, /* @__PURE__ */ import_react6.default.createElement("path", { d: "M12 20v-9" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M14.12 3.88 16 2" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M21 21a4 4 0 0 0-3.81-4" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M21 5a4 4 0 0 1-3.55 3.97" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M22 13h-4" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M3 21a4 4 0 0 1 3.81-4" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M3 5a4 4 0 0 0 3.55 3.97" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M6 13H2" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "m8 2 1.88 1.88" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M9 7.13V6a3 3 0 1 1 6 0v1.13" })))
4757
+ !isInInspector && /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, !isFullscreen && !isPip && /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, (viewControls === true || viewControls === "fullscreen") && /* @__PURE__ */ import_react6.default.createElement(IconButton, { onClick: handleFullscreen, label: "Fullscreen" }, /* @__PURE__ */ import_react6.default.createElement("path", { d: "M15 3h6v6" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "m21 3-7 7" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "m3 21 7-7" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M9 21H3v-6" })), (viewControls === true || viewControls === "pip") && /* @__PURE__ */ import_react6.default.createElement(IconButton, { onClick: handlePip, label: "Picture in Picture" }, /* @__PURE__ */ import_react6.default.createElement("path", { d: "M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4" }), /* @__PURE__ */ import_react6.default.createElement("rect", { width: "10", height: "7", x: "12", y: "13", rx: "2" }))), enableDebugger && /* @__PURE__ */ import_react6.default.createElement(IconButton, { onClick: handleToggleOverlay, label: "Debug Info" }, /* @__PURE__ */ import_react6.default.createElement("path", { d: "M12 20v-9" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M14.12 3.88 16 2" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M21 21a4 4 0 0 0-3.81-4" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M21 5a4 4 0 0 1-3.55 3.97" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M22 13h-4" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M3 21a4 4 0 0 1 3.81-4" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M3 5a4 4 0 0 0 3.55 3.97" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M6 13H2" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "m8 2 1.88 1.88" }), /* @__PURE__ */ import_react6.default.createElement("path", { d: "M9 7.13V6a3 3 0 1 1 6 0v1.13" })))
4797
4758
  ),
4798
4759
  children
4799
4760
  ), isOverlayOpen && enableDebugger && /* @__PURE__ */ import_react6.default.createElement(
@@ -4945,7 +4906,7 @@ function McpUseProvider({
4945
4906
  let mounted = true;
4946
4907
  (async () => {
4947
4908
  try {
4948
- const routerModule = await import("react-router-dom");
4909
+ const routerModule = await import("react-router");
4949
4910
  if (mounted) {
4950
4911
  setBrowserRouter(() => routerModule.BrowserRouter);
4951
4912
  setIsRouterLoading(false);
@@ -4954,7 +4915,7 @@ function McpUseProvider({
4954
4915
  if (mounted) {
4955
4916
  setRouterError(
4956
4917
  new Error(
4957
- "\u274C react-router-dom not installed!\n\nTo use MCP widgets with McpUseProvider, you need to install:\n\n npm install react-router-dom\n # or\n pnpm add react-router-dom\n\nThis dependency is automatically included in projects created with 'create-mcp-use-app'."
4918
+ "\u274C react-router not installed!\n\nTo use MCP widgets with McpUseProvider, you need to install:\n\n npm install react-router\n # or\n pnpm add react-router\n\nThis dependency is automatically included in projects created with 'create-mcp-use-app'."
4958
4919
  )
4959
4920
  );
4960
4921
  setIsRouterLoading(false);