mcp-use 1.11.0-canary.12 → 1.11.0-canary.14

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 (34) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-3O4V246Q.js → chunk-2IMIUODV.js} +482 -5
  3. package/dist/{chunk-4NBH6YUZ.js → chunk-7TS5EJ4T.js} +1 -1
  4. package/dist/{chunk-UUHY7DWI.js → chunk-AEHNVFZG.js} +1 -1
  5. package/dist/{chunk-G5MS2TH6.js → chunk-JYFYHDYK.js} +4 -4
  6. package/dist/{chunk-3IK76ZAN.js → chunk-MIKDMUFS.js} +2 -2
  7. package/dist/{chunk-6M5L4OSE.js → chunk-PO6UGK4I.js} +2 -2
  8. package/dist/{chunk-ZFZPZ4GE.js → chunk-SBMQ4QZJ.js} +9 -0
  9. package/dist/{chunk-NI65CTDQ.js → chunk-U7JXQZVH.js} +197 -8
  10. package/dist/index.cjs +2 -2
  11. package/dist/index.js +26 -30
  12. package/dist/src/agents/index.cjs +2 -2
  13. package/dist/src/agents/index.d.ts +1 -1
  14. package/dist/src/agents/index.d.ts.map +1 -1
  15. package/dist/src/agents/index.js +7 -11
  16. package/dist/src/{client/prompts.d.ts → agents/prompts/index.d.ts} +3 -3
  17. package/dist/src/agents/prompts/index.d.ts.map +1 -0
  18. package/dist/src/browser.cjs +1 -1
  19. package/dist/src/browser.js +13 -16
  20. package/dist/src/client.cjs +1 -1
  21. package/dist/src/client.js +3 -5
  22. package/dist/src/react/index.cjs +1 -1
  23. package/dist/src/react/index.js +7 -8
  24. package/dist/src/server/index.cjs +1 -1
  25. package/dist/src/server/index.js +10 -10
  26. package/dist/src/version.d.ts +1 -1
  27. package/dist/{tool-execution-helpers-5CRPAL52.js → tool-execution-helpers-RRECKMIN.js} +2 -2
  28. package/package.json +31 -31
  29. package/dist/chunk-GECOPE3S.js +0 -491
  30. package/dist/chunk-QGEH5MZS.js +0 -204
  31. package/dist/chunk-SF2V4IJ7.js +0 -12
  32. package/dist/src/client/prompts.cjs +0 -407
  33. package/dist/src/client/prompts.d.ts.map +0 -1
  34. package/dist/src/client/prompts.js +0 -11
@@ -1,9 +1,7 @@
1
1
  import {
2
- BaseConnector
3
- } from "./chunk-GECOPE3S.js";
4
- import {
5
- Tel
6
- } from "./chunk-4NBH6YUZ.js";
2
+ Tel,
3
+ Telemetry
4
+ } from "./chunk-7TS5EJ4T.js";
7
5
  import {
8
6
  logger
9
7
  } from "./chunk-FRUZDWXH.js";
@@ -412,6 +410,484 @@ var BaseMCPClient = class {
412
410
  }
413
411
  };
414
412
 
413
+ // src/connectors/base.ts
414
+ import {
415
+ ListRootsRequestSchema,
416
+ CreateMessageRequestSchema,
417
+ ElicitRequestSchema
418
+ } from "@mcp-use/modelcontextprotocol-sdk/types.js";
419
+ var BaseConnector = class {
420
+ static {
421
+ __name(this, "BaseConnector");
422
+ }
423
+ client = null;
424
+ connectionManager = null;
425
+ toolsCache = null;
426
+ capabilitiesCache = null;
427
+ serverInfoCache = null;
428
+ connected = false;
429
+ opts;
430
+ notificationHandlers = [];
431
+ rootsCache = [];
432
+ constructor(opts = {}) {
433
+ this.opts = opts;
434
+ if (opts.roots) {
435
+ this.rootsCache = [...opts.roots];
436
+ }
437
+ }
438
+ /**
439
+ * Track connector initialization event
440
+ * Should be called by subclasses after successful connection
441
+ */
442
+ trackConnectorInit(data) {
443
+ const connectorType = this.constructor.name;
444
+ Telemetry.getInstance().trackConnectorInit({
445
+ connectorType,
446
+ ...data
447
+ }).catch((e) => logger.debug(`Failed to track connector init: ${e}`));
448
+ }
449
+ /**
450
+ * Register a handler for server notifications
451
+ *
452
+ * @param handler - Function to call when a notification is received
453
+ *
454
+ * @example
455
+ * ```typescript
456
+ * connector.onNotification((notification) => {
457
+ * console.log(`Received: ${notification.method}`, notification.params);
458
+ * });
459
+ * ```
460
+ */
461
+ onNotification(handler) {
462
+ this.notificationHandlers.push(handler);
463
+ if (this.client) {
464
+ this.setupNotificationHandler();
465
+ }
466
+ }
467
+ /**
468
+ * Internal: wire notification handlers to the SDK client
469
+ * Includes automatic handling for list_changed notifications per MCP spec
470
+ */
471
+ setupNotificationHandler() {
472
+ if (!this.client) return;
473
+ this.client.fallbackNotificationHandler = async (notification) => {
474
+ switch (notification.method) {
475
+ case "notifications/tools/list_changed":
476
+ await this.refreshToolsCache();
477
+ break;
478
+ case "notifications/resources/list_changed":
479
+ await this.onResourcesListChanged();
480
+ break;
481
+ case "notifications/prompts/list_changed":
482
+ await this.onPromptsListChanged();
483
+ break;
484
+ default:
485
+ break;
486
+ }
487
+ for (const handler of this.notificationHandlers) {
488
+ try {
489
+ await handler(notification);
490
+ } catch (err) {
491
+ logger.error("Error in notification handler:", err);
492
+ }
493
+ }
494
+ };
495
+ }
496
+ /**
497
+ * Auto-refresh tools cache when server sends tools/list_changed notification
498
+ */
499
+ async refreshToolsCache() {
500
+ if (!this.client) return;
501
+ try {
502
+ logger.debug(
503
+ "[Auto] Refreshing tools cache due to list_changed notification"
504
+ );
505
+ const result = await this.client.listTools();
506
+ this.toolsCache = result.tools ?? [];
507
+ logger.debug(
508
+ `[Auto] Refreshed tools cache: ${this.toolsCache.length} tools`
509
+ );
510
+ } catch (err) {
511
+ logger.warn("[Auto] Failed to refresh tools cache:", err);
512
+ }
513
+ }
514
+ /**
515
+ * Called when server sends resources/list_changed notification
516
+ * Resources aren't cached by default, but we log for user awareness
517
+ */
518
+ async onResourcesListChanged() {
519
+ logger.debug(
520
+ "[Auto] Resources list changed - clients should re-fetch if needed"
521
+ );
522
+ }
523
+ /**
524
+ * Called when server sends prompts/list_changed notification
525
+ * Prompts aren't cached by default, but we log for user awareness
526
+ */
527
+ async onPromptsListChanged() {
528
+ logger.debug(
529
+ "[Auto] Prompts list changed - clients should re-fetch if needed"
530
+ );
531
+ }
532
+ /**
533
+ * Set roots and notify the server.
534
+ * Roots represent directories or files that the client has access to.
535
+ *
536
+ * @param roots - Array of Root objects with `uri` (must start with "file://") and optional `name`
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * await connector.setRoots([
541
+ * { uri: "file:///home/user/project", name: "My Project" },
542
+ * { uri: "file:///home/user/data" }
543
+ * ]);
544
+ * ```
545
+ */
546
+ async setRoots(roots) {
547
+ this.rootsCache = [...roots];
548
+ if (this.client) {
549
+ logger.debug(
550
+ `Sending roots/list_changed notification with ${roots.length} root(s)`
551
+ );
552
+ await this.client.sendRootsListChanged();
553
+ }
554
+ }
555
+ /**
556
+ * Get the current roots.
557
+ */
558
+ getRoots() {
559
+ return [...this.rootsCache];
560
+ }
561
+ /**
562
+ * Internal: set up roots/list request handler.
563
+ * This is called after the client connects to register the handler for server requests.
564
+ */
565
+ setupRootsHandler() {
566
+ if (!this.client) return;
567
+ this.client.setRequestHandler(
568
+ ListRootsRequestSchema,
569
+ async (_request, _extra) => {
570
+ logger.debug(
571
+ `Server requested roots list, returning ${this.rootsCache.length} root(s)`
572
+ );
573
+ return { roots: this.rootsCache };
574
+ }
575
+ );
576
+ }
577
+ /**
578
+ * Internal: set up sampling/createMessage request handler.
579
+ * This is called after the client connects to register the handler for sampling requests.
580
+ */
581
+ setupSamplingHandler() {
582
+ if (!this.client) {
583
+ logger.debug("setupSamplingHandler: No client available");
584
+ return;
585
+ }
586
+ if (!this.opts.samplingCallback) {
587
+ logger.debug("setupSamplingHandler: No sampling callback provided");
588
+ return;
589
+ }
590
+ logger.debug("setupSamplingHandler: Setting up sampling request handler");
591
+ this.client.setRequestHandler(
592
+ CreateMessageRequestSchema,
593
+ async (request, _extra) => {
594
+ logger.debug("Server requested sampling, forwarding to callback");
595
+ return await this.opts.samplingCallback(request.params);
596
+ }
597
+ );
598
+ logger.debug(
599
+ "setupSamplingHandler: Sampling handler registered successfully"
600
+ );
601
+ }
602
+ /**
603
+ * Internal: set up elicitation/create request handler.
604
+ * This is called after the client connects to register the handler for elicitation requests.
605
+ */
606
+ setupElicitationHandler() {
607
+ if (!this.client) {
608
+ logger.debug("setupElicitationHandler: No client available");
609
+ return;
610
+ }
611
+ if (!this.opts.elicitationCallback) {
612
+ logger.debug("setupElicitationHandler: No elicitation callback provided");
613
+ return;
614
+ }
615
+ logger.debug(
616
+ "setupElicitationHandler: Setting up elicitation request handler"
617
+ );
618
+ this.client.setRequestHandler(
619
+ ElicitRequestSchema,
620
+ async (request, _extra) => {
621
+ logger.debug("Server requested elicitation, forwarding to callback");
622
+ return await this.opts.elicitationCallback(request.params);
623
+ }
624
+ );
625
+ logger.debug(
626
+ "setupElicitationHandler: Elicitation handler registered successfully"
627
+ );
628
+ }
629
+ /** Disconnect and release resources. */
630
+ async disconnect() {
631
+ if (!this.connected) {
632
+ logger.debug("Not connected to MCP implementation");
633
+ return;
634
+ }
635
+ logger.debug("Disconnecting from MCP implementation");
636
+ await this.cleanupResources();
637
+ this.connected = false;
638
+ logger.debug("Disconnected from MCP implementation");
639
+ }
640
+ /** Check if the client is connected */
641
+ get isClientConnected() {
642
+ return this.client != null;
643
+ }
644
+ /**
645
+ * Initialise the MCP session **after** `connect()` has succeeded.
646
+ *
647
+ * In the SDK, `Client.connect(transport)` automatically performs the
648
+ * protocol‑level `initialize` handshake, so we only need to cache the list of
649
+ * tools and expose some server info.
650
+ */
651
+ async initialize(defaultRequestOptions = this.opts.defaultRequestOptions ?? {}) {
652
+ if (!this.client) {
653
+ throw new Error("MCP client is not connected");
654
+ }
655
+ logger.debug("Caching server capabilities & tools");
656
+ const capabilities = this.client.getServerCapabilities();
657
+ this.capabilitiesCache = capabilities || null;
658
+ const serverInfo = this.client.getServerVersion();
659
+ this.serverInfoCache = serverInfo || null;
660
+ const listToolsRes = await this.client.listTools(
661
+ void 0,
662
+ defaultRequestOptions
663
+ );
664
+ this.toolsCache = listToolsRes.tools ?? [];
665
+ logger.debug(`Fetched ${this.toolsCache.length} tools from server`);
666
+ logger.debug("Server capabilities:", capabilities);
667
+ logger.debug("Server info:", serverInfo);
668
+ return capabilities;
669
+ }
670
+ /** Lazily expose the cached tools list. */
671
+ get tools() {
672
+ if (!this.toolsCache) {
673
+ throw new Error("MCP client is not initialized; call initialize() first");
674
+ }
675
+ return this.toolsCache;
676
+ }
677
+ /** Expose cached server capabilities. */
678
+ get serverCapabilities() {
679
+ return this.capabilitiesCache || {};
680
+ }
681
+ /** Expose cached server info. */
682
+ get serverInfo() {
683
+ return this.serverInfoCache;
684
+ }
685
+ /** Call a tool on the server. */
686
+ async callTool(name, args, options) {
687
+ if (!this.client) {
688
+ throw new Error("MCP client is not connected");
689
+ }
690
+ const enhancedOptions = options ? { ...options } : void 0;
691
+ if (enhancedOptions?.resetTimeoutOnProgress && !enhancedOptions.onprogress) {
692
+ enhancedOptions.onprogress = () => {
693
+ };
694
+ logger.debug(
695
+ `[BaseConnector] Added onprogress callback for tool '${name}' to enable progressToken`
696
+ );
697
+ }
698
+ logger.debug(`Calling tool '${name}' with args`, args);
699
+ const res = await this.client.callTool(
700
+ { name, arguments: args },
701
+ void 0,
702
+ enhancedOptions
703
+ );
704
+ logger.debug(`Tool '${name}' returned`, res);
705
+ return res;
706
+ }
707
+ /**
708
+ * List all available tools from the MCP server.
709
+ * This method fetches fresh tools from the server, unlike the `tools` getter which returns cached tools.
710
+ *
711
+ * @param options - Optional request options
712
+ * @returns Array of available tools
713
+ */
714
+ async listTools(options) {
715
+ if (!this.client) {
716
+ throw new Error("MCP client is not connected");
717
+ }
718
+ const result = await this.client.listTools(void 0, options);
719
+ return result.tools ?? [];
720
+ }
721
+ /**
722
+ * List resources from the server with optional pagination
723
+ *
724
+ * @param cursor - Optional cursor for pagination
725
+ * @param options - Request options
726
+ * @returns Resource list with optional nextCursor for pagination
727
+ */
728
+ async listResources(cursor, options) {
729
+ if (!this.client) {
730
+ throw new Error("MCP client is not connected");
731
+ }
732
+ logger.debug("Listing resources", cursor ? `with cursor: ${cursor}` : "");
733
+ return await this.client.listResources({ cursor }, options);
734
+ }
735
+ /**
736
+ * List all resources from the server, automatically handling pagination
737
+ *
738
+ * @param options - Request options
739
+ * @returns Complete list of all resources
740
+ */
741
+ async listAllResources(options) {
742
+ if (!this.client) {
743
+ throw new Error("MCP client is not connected");
744
+ }
745
+ if (!this.capabilitiesCache?.resources) {
746
+ logger.debug("Server does not advertise resources capability, skipping");
747
+ return { resources: [] };
748
+ }
749
+ try {
750
+ logger.debug("Listing all resources (with auto-pagination)");
751
+ const allResources = [];
752
+ let cursor = void 0;
753
+ do {
754
+ const result = await this.client.listResources({ cursor }, options);
755
+ allResources.push(...result.resources || []);
756
+ cursor = result.nextCursor;
757
+ } while (cursor);
758
+ return { resources: allResources };
759
+ } catch (err) {
760
+ const error = err;
761
+ if (error.code === -32601) {
762
+ logger.debug("Server advertised resources but method not found");
763
+ return { resources: [] };
764
+ }
765
+ throw err;
766
+ }
767
+ }
768
+ /**
769
+ * List resource templates from the server
770
+ *
771
+ * @param options - Request options
772
+ * @returns List of available resource templates
773
+ */
774
+ async listResourceTemplates(options) {
775
+ if (!this.client) {
776
+ throw new Error("MCP client is not connected");
777
+ }
778
+ logger.debug("Listing resource templates");
779
+ return await this.client.listResourceTemplates(void 0, options);
780
+ }
781
+ /** Read a resource by URI. */
782
+ async readResource(uri, options) {
783
+ if (!this.client) {
784
+ throw new Error("MCP client is not connected");
785
+ }
786
+ logger.debug(`Reading resource ${uri}`);
787
+ const res = await this.client.readResource({ uri }, options);
788
+ return res;
789
+ }
790
+ /**
791
+ * Subscribe to resource updates
792
+ *
793
+ * @param uri - URI of the resource to subscribe to
794
+ * @param options - Request options
795
+ */
796
+ async subscribeToResource(uri, options) {
797
+ if (!this.client) {
798
+ throw new Error("MCP client is not connected");
799
+ }
800
+ logger.debug(`Subscribing to resource: ${uri}`);
801
+ return await this.client.subscribeResource({ uri }, options);
802
+ }
803
+ /**
804
+ * Unsubscribe from resource updates
805
+ *
806
+ * @param uri - URI of the resource to unsubscribe from
807
+ * @param options - Request options
808
+ */
809
+ async unsubscribeFromResource(uri, options) {
810
+ if (!this.client) {
811
+ throw new Error("MCP client is not connected");
812
+ }
813
+ logger.debug(`Unsubscribing from resource: ${uri}`);
814
+ return await this.client.unsubscribeResource({ uri }, options);
815
+ }
816
+ async listPrompts() {
817
+ if (!this.client) {
818
+ throw new Error("MCP client is not connected");
819
+ }
820
+ if (!this.capabilitiesCache?.prompts) {
821
+ logger.debug("Server does not advertise prompts capability, skipping");
822
+ return { prompts: [] };
823
+ }
824
+ try {
825
+ logger.debug("Listing prompts");
826
+ return await this.client.listPrompts();
827
+ } catch (err) {
828
+ const error = err;
829
+ if (error.code === -32601) {
830
+ logger.debug("Server advertised prompts but method not found");
831
+ return { prompts: [] };
832
+ }
833
+ throw err;
834
+ }
835
+ }
836
+ async getPrompt(name, args) {
837
+ if (!this.client) {
838
+ throw new Error("MCP client is not connected");
839
+ }
840
+ logger.debug(`Getting prompt ${name}`);
841
+ return await this.client.getPrompt({ name, arguments: args });
842
+ }
843
+ /** Send a raw request through the client. */
844
+ async request(method, params = null, options) {
845
+ if (!this.client) {
846
+ throw new Error("MCP client is not connected");
847
+ }
848
+ logger.debug(`Sending raw request '${method}' with params`, params);
849
+ return await this.client.request(
850
+ { method, params: params ?? {} },
851
+ void 0,
852
+ options
853
+ );
854
+ }
855
+ /**
856
+ * Helper to tear down the client & connection manager safely.
857
+ */
858
+ async cleanupResources() {
859
+ const issues = [];
860
+ if (this.client) {
861
+ try {
862
+ if (typeof this.client.close === "function") {
863
+ await this.client.close();
864
+ }
865
+ } catch (e) {
866
+ const msg = `Error closing client: ${e}`;
867
+ logger.warn(msg);
868
+ issues.push(msg);
869
+ } finally {
870
+ this.client = null;
871
+ }
872
+ }
873
+ if (this.connectionManager) {
874
+ try {
875
+ await this.connectionManager.stop();
876
+ } catch (e) {
877
+ const msg = `Error stopping connection manager: ${e}`;
878
+ logger.warn(msg);
879
+ issues.push(msg);
880
+ } finally {
881
+ this.connectionManager = null;
882
+ }
883
+ }
884
+ this.toolsCache = null;
885
+ if (issues.length) {
886
+ logger.warn(`Resource cleanup finished with ${issues.length} issue(s)`);
887
+ }
888
+ }
889
+ };
890
+
415
891
  // src/connectors/http.ts
416
892
  import { Client } from "@mcp-use/modelcontextprotocol-sdk/client/index.js";
417
893
  import {
@@ -900,6 +1376,7 @@ var HttpConnector = class extends BaseConnector {
900
1376
  export {
901
1377
  MCPSession,
902
1378
  BaseMCPClient,
1379
+ BaseConnector,
903
1380
  ConnectionManager,
904
1381
  HttpConnector
905
1382
  };
@@ -92,7 +92,7 @@ function generateUUID() {
92
92
  __name(generateUUID, "generateUUID");
93
93
 
94
94
  // src/version.ts
95
- var VERSION = "1.11.0-canary.12";
95
+ var VERSION = "1.11.0-canary.14";
96
96
  function getPackageVersion() {
97
97
  return VERSION;
98
98
  }
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  Telemetry,
6
6
  generateUUID
7
- } from "./chunk-4NBH6YUZ.js";
7
+ } from "./chunk-7TS5EJ4T.js";
8
8
  import {
9
9
  __name
10
10
  } from "./chunk-3GQAWCBQ.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  BrowserMCPClient
3
- } from "./chunk-6M5L4OSE.js";
3
+ } from "./chunk-PO6UGK4I.js";
4
+ import {
5
+ Tel
6
+ } from "./chunk-7TS5EJ4T.js";
4
7
  import {
5
8
  BrowserOAuthClientProvider,
6
9
  sanitizeUrl
7
10
  } from "./chunk-J75I2C26.js";
8
- import {
9
- Tel
10
- } from "./chunk-4NBH6YUZ.js";
11
11
  import {
12
12
  __name
13
13
  } from "./chunk-3GQAWCBQ.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MCPClient
3
- } from "./chunk-NI65CTDQ.js";
3
+ } from "./chunk-U7JXQZVH.js";
4
4
  import {
5
5
  LangChainAdapter
6
6
  } from "./chunk-MFSO5PUW.js";
@@ -8,7 +8,7 @@ import {
8
8
  Telemetry,
9
9
  extractModelInfo,
10
10
  getPackageVersion
11
- } from "./chunk-4NBH6YUZ.js";
11
+ } from "./chunk-7TS5EJ4T.js";
12
12
  import {
13
13
  logger
14
14
  } from "./chunk-FRUZDWXH.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  BaseMCPClient,
3
3
  HttpConnector
4
- } from "./chunk-3O4V246Q.js";
4
+ } from "./chunk-2IMIUODV.js";
5
5
  import {
6
6
  Tel,
7
7
  getPackageVersion
8
- } from "./chunk-4NBH6YUZ.js";
8
+ } from "./chunk-7TS5EJ4T.js";
9
9
  import {
10
10
  logger
11
11
  } from "./chunk-FRUZDWXH.js";
@@ -1,7 +1,15 @@
1
+ import {
2
+ CODE_MODE_AGENT_PROMPT
3
+ } from "./chunk-U7JXQZVH.js";
1
4
  import {
2
5
  __name
3
6
  } from "./chunk-3GQAWCBQ.js";
4
7
 
8
+ // src/agents/prompts/index.ts
9
+ var PROMPTS = {
10
+ CODE_MODE: CODE_MODE_AGENT_PROMPT
11
+ };
12
+
5
13
  // src/agents/base.ts
6
14
  var BaseAgent = class {
7
15
  static {
@@ -17,5 +25,6 @@ var BaseAgent = class {
17
25
  };
18
26
 
19
27
  export {
28
+ PROMPTS,
20
29
  BaseAgent
21
30
  };