mcp-use 1.10.6 → 1.11.0-canary.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.
- package/README.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-D5WOXLJ2.js → chunk-A4WWKMPI.js} +2 -2
- package/dist/{chunk-BLWPCOUZ.js → chunk-APOF62EA.js} +3 -8
- package/dist/{chunk-FDKY2O5P.js → chunk-BE23AOUV.js} +1693 -146
- package/dist/{chunk-34R6SIER.js → chunk-FRUZDWXH.js} +1 -1
- package/dist/{chunk-CPG2WZUL.js → chunk-JRGQRPTN.js} +1 -1
- package/dist/{chunk-JH3ZOGLI.js → chunk-K6YNB2Z3.js} +2 -2
- package/dist/{chunk-EEUJZMOP.js → chunk-LHRGDQ5C.js} +1 -1
- package/dist/{chunk-44DFBJUL.js → chunk-OIXS25J5.js} +21 -372
- package/dist/chunk-QH52FRP3.js +101 -0
- package/dist/chunk-TCLI6SPF.js +12 -0
- package/dist/{chunk-KIWNNI6F.js → chunk-XXCHNDUF.js} +16 -2
- package/dist/index.cjs +4841 -4594
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -1047
- package/dist/{langfuse-N5Y5BSXK.js → langfuse-74RGPTAH.js} +2 -2
- package/dist/src/adapters/base.d.ts +44 -0
- package/dist/src/adapters/base.d.ts.map +1 -1
- package/dist/src/adapters/langchain_adapter.d.ts +12 -1
- package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
- package/dist/src/agents/index.cjs +3090 -159
- package/dist/src/agents/index.d.ts +2 -0
- package/dist/src/agents/index.d.ts.map +1 -1
- package/dist/src/agents/index.js +8 -6
- package/dist/src/agents/mcp_agent.d.ts +59 -37
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/agents/remote.d.ts +25 -0
- package/dist/src/agents/remote.d.ts.map +1 -1
- package/dist/src/agents/types.d.ts +76 -0
- package/dist/src/agents/types.d.ts.map +1 -1
- package/dist/src/agents/utils/index.d.ts +1 -0
- package/dist/src/agents/utils/index.d.ts.map +1 -1
- package/dist/src/agents/utils/llm_provider.d.ts +53 -0
- package/dist/src/agents/utils/llm_provider.d.ts.map +1 -0
- package/dist/src/browser.cjs +1878 -495
- package/dist/src/browser.d.ts +0 -1
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +21 -12
- package/dist/src/client/browser.d.ts +2 -2
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client/prompts.cjs +1 -1
- package/dist/src/client/prompts.js +5 -4
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +8 -0
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/index.d.ts +0 -1
- package/dist/src/connectors/index.d.ts.map +1 -1
- package/dist/src/managers/server_manager.d.ts.map +1 -1
- package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -1
- package/dist/src/react/index.cjs +34 -284
- package/dist/src/react/index.js +6 -5
- package/dist/src/react/types.d.ts +1 -3
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +24 -4
- package/dist/src/server/index.js +28 -8
- package/dist/src/server/sessions/session-manager.d.ts +6 -3
- package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
- package/dist/src/session.d.ts +14 -0
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/task_managers/index.d.ts +0 -1
- package/dist/src/task_managers/index.d.ts.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/{tool-execution-helpers-4X6A63AS.js → tool-execution-helpers-MZUMRG5S.js} +3 -3
- package/package.json +20 -11
- package/dist/src/connectors/websocket.d.ts +0 -38
- package/dist/src/connectors/websocket.d.ts.map +0 -1
- package/dist/src/task_managers/websocket.d.ts +0 -18
- package/dist/src/task_managers/websocket.d.ts.map +0 -1
- /package/dist/{chunk-EW4MJSHA.js → chunk-H4BZVTGK.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
logger
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FRUZDWXH.js";
|
|
4
4
|
import {
|
|
5
5
|
__name,
|
|
6
6
|
__require
|
|
@@ -92,7 +92,7 @@ function generateUUID() {
|
|
|
92
92
|
__name(generateUUID, "generateUUID");
|
|
93
93
|
|
|
94
94
|
// src/version.ts
|
|
95
|
-
var VERSION = "1.
|
|
95
|
+
var VERSION = "1.11.0-canary.4";
|
|
96
96
|
function getPackageVersion() {
|
|
97
97
|
return VERSION;
|
|
98
98
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseConnector
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XXCHNDUF.js";
|
|
4
4
|
import {
|
|
5
|
-
Tel
|
|
6
|
-
|
|
7
|
-
getPackageVersion
|
|
8
|
-
} from "./chunk-JH3ZOGLI.js";
|
|
5
|
+
Tel
|
|
6
|
+
} from "./chunk-K6YNB2Z3.js";
|
|
9
7
|
import {
|
|
10
8
|
logger
|
|
11
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-FRUZDWXH.js";
|
|
12
10
|
import {
|
|
13
11
|
__name
|
|
14
12
|
} from "./chunk-3GQAWCBQ.js";
|
|
@@ -98,6 +96,22 @@ var MCPSession = class {
|
|
|
98
96
|
get tools() {
|
|
99
97
|
return this.connector.tools;
|
|
100
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* List all available tools from the MCP server.
|
|
101
|
+
* This method fetches fresh tools from the server, unlike the `tools` getter which returns cached tools.
|
|
102
|
+
*
|
|
103
|
+
* @param options - Optional request options
|
|
104
|
+
* @returns Array of available tools
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const tools = await session.listTools();
|
|
109
|
+
* console.log(`Available tools: ${tools.map(t => t.name).join(", ")}`);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
async listTools(options) {
|
|
113
|
+
return this.connector.listTools(options);
|
|
114
|
+
}
|
|
101
115
|
/**
|
|
102
116
|
* Get the server capabilities advertised during initialization.
|
|
103
117
|
*
|
|
@@ -713,279 +727,6 @@ var HttpConnector = class extends BaseConnector {
|
|
|
713
727
|
}
|
|
714
728
|
};
|
|
715
729
|
|
|
716
|
-
// src/task_managers/websocket.ts
|
|
717
|
-
import WS from "ws";
|
|
718
|
-
var WebSocketConnectionManager = class extends ConnectionManager {
|
|
719
|
-
static {
|
|
720
|
-
__name(this, "WebSocketConnectionManager");
|
|
721
|
-
}
|
|
722
|
-
url;
|
|
723
|
-
headers;
|
|
724
|
-
_ws = null;
|
|
725
|
-
/**
|
|
726
|
-
* @param url The WebSocket URL to connect to.
|
|
727
|
-
* @param headers Optional headers to include in the connection handshake.
|
|
728
|
-
*/
|
|
729
|
-
constructor(url, headers = {}) {
|
|
730
|
-
super();
|
|
731
|
-
this.url = url;
|
|
732
|
-
this.headers = headers;
|
|
733
|
-
}
|
|
734
|
-
/** Establish a WebSocket connection and wait until it is open. */
|
|
735
|
-
async establishConnection() {
|
|
736
|
-
logger.debug(`Connecting to WebSocket: ${this.url}`);
|
|
737
|
-
return new Promise((resolve, reject) => {
|
|
738
|
-
const ws = new WS(this.url, {
|
|
739
|
-
headers: this.headers
|
|
740
|
-
});
|
|
741
|
-
this._ws = ws;
|
|
742
|
-
const onOpen = /* @__PURE__ */ __name(() => {
|
|
743
|
-
cleanup();
|
|
744
|
-
logger.debug("WebSocket connected successfully");
|
|
745
|
-
resolve(ws);
|
|
746
|
-
}, "onOpen");
|
|
747
|
-
const onError = /* @__PURE__ */ __name((err) => {
|
|
748
|
-
cleanup();
|
|
749
|
-
logger.error(`Failed to connect to WebSocket: ${err}`);
|
|
750
|
-
reject(err);
|
|
751
|
-
}, "onError");
|
|
752
|
-
const cleanup = /* @__PURE__ */ __name(() => {
|
|
753
|
-
ws.off("open", onOpen);
|
|
754
|
-
ws.off("error", onError);
|
|
755
|
-
}, "cleanup");
|
|
756
|
-
ws.on("open", onOpen);
|
|
757
|
-
ws.on("error", onError);
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
/** Cleanly close the WebSocket connection. */
|
|
761
|
-
async closeConnection(connection) {
|
|
762
|
-
logger.debug("Closing WebSocket connection");
|
|
763
|
-
return new Promise((resolve) => {
|
|
764
|
-
const onClose = /* @__PURE__ */ __name(() => {
|
|
765
|
-
connection.off("close", onClose);
|
|
766
|
-
this._ws = null;
|
|
767
|
-
resolve();
|
|
768
|
-
}, "onClose");
|
|
769
|
-
if (connection.readyState === WS.CLOSED) {
|
|
770
|
-
onClose();
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
connection.on("close", onClose);
|
|
774
|
-
try {
|
|
775
|
-
connection.close();
|
|
776
|
-
} catch (e) {
|
|
777
|
-
logger.warn(`Error closing WebSocket connection: ${e}`);
|
|
778
|
-
onClose();
|
|
779
|
-
}
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
};
|
|
783
|
-
|
|
784
|
-
// src/connectors/websocket.ts
|
|
785
|
-
var WebSocketConnector = class extends BaseConnector {
|
|
786
|
-
static {
|
|
787
|
-
__name(this, "WebSocketConnector");
|
|
788
|
-
}
|
|
789
|
-
url;
|
|
790
|
-
headers;
|
|
791
|
-
connectionManager = null;
|
|
792
|
-
ws = null;
|
|
793
|
-
receiverTask = null;
|
|
794
|
-
pending = /* @__PURE__ */ new Map();
|
|
795
|
-
toolsCache = null;
|
|
796
|
-
constructor(url, opts = {}) {
|
|
797
|
-
super();
|
|
798
|
-
this.url = url;
|
|
799
|
-
this.headers = { ...opts.headers ?? {} };
|
|
800
|
-
if (opts.authToken) this.headers.Authorization = `Bearer ${opts.authToken}`;
|
|
801
|
-
}
|
|
802
|
-
async connect() {
|
|
803
|
-
if (this.connected) {
|
|
804
|
-
logger.debug("Already connected to MCP implementation");
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
logger.debug(`Connecting via WebSocket: ${this.url}`);
|
|
808
|
-
try {
|
|
809
|
-
this.connectionManager = new WebSocketConnectionManager(
|
|
810
|
-
this.url,
|
|
811
|
-
this.headers
|
|
812
|
-
);
|
|
813
|
-
this.ws = await this.connectionManager.start();
|
|
814
|
-
this.receiverTask = this.receiveLoop();
|
|
815
|
-
this.connected = true;
|
|
816
|
-
logger.debug("WebSocket connected successfully");
|
|
817
|
-
} catch (e) {
|
|
818
|
-
logger.error(`Failed to connect: ${e}`);
|
|
819
|
-
await this.cleanupResources();
|
|
820
|
-
throw e;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
async disconnect() {
|
|
824
|
-
if (!this.connected) {
|
|
825
|
-
logger.debug("Not connected to MCP implementation");
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
logger.debug("Disconnecting \u2026");
|
|
829
|
-
await this.cleanupResources();
|
|
830
|
-
this.connected = false;
|
|
831
|
-
}
|
|
832
|
-
sendRequest(method, params = null) {
|
|
833
|
-
if (!this.ws) throw new Error("WebSocket is not connected");
|
|
834
|
-
const id = generateUUID();
|
|
835
|
-
const payload = JSON.stringify({ id, method, params: params ?? {} });
|
|
836
|
-
return new Promise((resolve, reject) => {
|
|
837
|
-
this.pending.set(id, { resolve, reject });
|
|
838
|
-
this.ws.send(payload, (err) => {
|
|
839
|
-
if (err) {
|
|
840
|
-
this.pending.delete(id);
|
|
841
|
-
reject(err);
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
async receiveLoop() {
|
|
847
|
-
if (!this.ws) return;
|
|
848
|
-
const socket = this.ws;
|
|
849
|
-
const onMessage = /* @__PURE__ */ __name((msg) => {
|
|
850
|
-
let data;
|
|
851
|
-
try {
|
|
852
|
-
data = JSON.parse(msg.data ?? msg);
|
|
853
|
-
} catch (e) {
|
|
854
|
-
logger.warn("Received non\u2011JSON frame", e);
|
|
855
|
-
return;
|
|
856
|
-
}
|
|
857
|
-
const id = data.id;
|
|
858
|
-
if (id && this.pending.has(id)) {
|
|
859
|
-
const { resolve, reject } = this.pending.get(id);
|
|
860
|
-
this.pending.delete(id);
|
|
861
|
-
if ("result" in data) resolve(data.result);
|
|
862
|
-
else if ("error" in data) reject(data.error);
|
|
863
|
-
} else if (data.method && !data.id) {
|
|
864
|
-
logger.debug("Received notification", data.method, data.params);
|
|
865
|
-
this.handleNotification(data);
|
|
866
|
-
} else {
|
|
867
|
-
logger.debug("Received unsolicited message", data);
|
|
868
|
-
}
|
|
869
|
-
}, "onMessage");
|
|
870
|
-
if (socket.addEventListener) {
|
|
871
|
-
socket.addEventListener("message", onMessage);
|
|
872
|
-
} else {
|
|
873
|
-
socket.on("message", onMessage);
|
|
874
|
-
}
|
|
875
|
-
return new Promise((resolve) => {
|
|
876
|
-
const onClose = /* @__PURE__ */ __name(() => {
|
|
877
|
-
if (socket.removeEventListener) {
|
|
878
|
-
socket.removeEventListener("message", onMessage);
|
|
879
|
-
} else {
|
|
880
|
-
socket.off("message", onMessage);
|
|
881
|
-
}
|
|
882
|
-
this.rejectAll(new Error("WebSocket closed"));
|
|
883
|
-
resolve();
|
|
884
|
-
}, "onClose");
|
|
885
|
-
if (socket.addEventListener) {
|
|
886
|
-
socket.addEventListener("close", onClose);
|
|
887
|
-
} else {
|
|
888
|
-
socket.on("close", onClose);
|
|
889
|
-
}
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
rejectAll(err) {
|
|
893
|
-
for (const { reject } of this.pending.values()) reject(err);
|
|
894
|
-
this.pending.clear();
|
|
895
|
-
}
|
|
896
|
-
async handleNotification(data) {
|
|
897
|
-
switch (data.method) {
|
|
898
|
-
case "notifications/tools/list_changed":
|
|
899
|
-
await this.refreshToolsCache();
|
|
900
|
-
break;
|
|
901
|
-
case "notifications/resources/list_changed":
|
|
902
|
-
await this.onResourcesListChanged();
|
|
903
|
-
break;
|
|
904
|
-
case "notifications/prompts/list_changed":
|
|
905
|
-
await this.onPromptsListChanged();
|
|
906
|
-
break;
|
|
907
|
-
default:
|
|
908
|
-
break;
|
|
909
|
-
}
|
|
910
|
-
for (const handler of this.notificationHandlers) {
|
|
911
|
-
try {
|
|
912
|
-
await handler({
|
|
913
|
-
method: data.method,
|
|
914
|
-
params: data.params
|
|
915
|
-
});
|
|
916
|
-
} catch (err) {
|
|
917
|
-
logger.error("Error in notification handler:", err);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* Auto-refresh tools cache when server sends tools/list_changed notification
|
|
923
|
-
* Override to use WebSocket-specific listTools method
|
|
924
|
-
*/
|
|
925
|
-
async refreshToolsCache() {
|
|
926
|
-
try {
|
|
927
|
-
logger.debug(
|
|
928
|
-
"[Auto] Refreshing tools cache due to list_changed notification"
|
|
929
|
-
);
|
|
930
|
-
const tools = await this.listTools();
|
|
931
|
-
this.toolsCache = tools.map((t) => t);
|
|
932
|
-
logger.debug(
|
|
933
|
-
`[Auto] Refreshed tools cache: ${this.toolsCache.length} tools`
|
|
934
|
-
);
|
|
935
|
-
} catch (err) {
|
|
936
|
-
logger.warn("[Auto] Failed to refresh tools cache:", err);
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
async initialize() {
|
|
940
|
-
logger.debug("Initializing MCP session over WebSocket");
|
|
941
|
-
const result = await this.sendRequest("initialize");
|
|
942
|
-
const toolsList = await this.listTools();
|
|
943
|
-
this.toolsCache = toolsList.map((t) => t);
|
|
944
|
-
logger.debug(`Initialized with ${this.toolsCache.length} tools`);
|
|
945
|
-
return result;
|
|
946
|
-
}
|
|
947
|
-
async listTools() {
|
|
948
|
-
const res = await this.sendRequest("tools/list");
|
|
949
|
-
return res.tools ?? [];
|
|
950
|
-
}
|
|
951
|
-
async callTool(name, args) {
|
|
952
|
-
return await this.sendRequest("tools/call", { name, arguments: args });
|
|
953
|
-
}
|
|
954
|
-
async listResources() {
|
|
955
|
-
const resources = await this.sendRequest("resources/list");
|
|
956
|
-
return { resources: Array.isArray(resources) ? resources : [] };
|
|
957
|
-
}
|
|
958
|
-
async readResource(uri) {
|
|
959
|
-
const res = await this.sendRequest("resources/read", { uri });
|
|
960
|
-
return res;
|
|
961
|
-
}
|
|
962
|
-
async request(method, params = null) {
|
|
963
|
-
return await this.sendRequest(method, params);
|
|
964
|
-
}
|
|
965
|
-
get tools() {
|
|
966
|
-
if (!this.toolsCache) throw new Error("MCP client is not initialized");
|
|
967
|
-
return this.toolsCache;
|
|
968
|
-
}
|
|
969
|
-
async cleanupResources() {
|
|
970
|
-
if (this.receiverTask) await this.receiverTask.catch(() => {
|
|
971
|
-
});
|
|
972
|
-
this.receiverTask = null;
|
|
973
|
-
this.rejectAll(new Error("WebSocket disconnected"));
|
|
974
|
-
if (this.connectionManager) {
|
|
975
|
-
await this.connectionManager.stop();
|
|
976
|
-
this.connectionManager = null;
|
|
977
|
-
this.ws = null;
|
|
978
|
-
}
|
|
979
|
-
this.toolsCache = null;
|
|
980
|
-
}
|
|
981
|
-
get publicIdentifier() {
|
|
982
|
-
return {
|
|
983
|
-
type: "websocket",
|
|
984
|
-
url: this.url
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
|
|
989
730
|
// src/client/base.ts
|
|
990
731
|
var BaseMCPClient = class {
|
|
991
732
|
static {
|
|
@@ -1105,101 +846,9 @@ var BaseMCPClient = class {
|
|
|
1105
846
|
}
|
|
1106
847
|
};
|
|
1107
848
|
|
|
1108
|
-
// src/client/browser.ts
|
|
1109
|
-
var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
|
|
1110
|
-
static {
|
|
1111
|
-
__name(this, "BrowserMCPClient");
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* Get the mcp-use package version.
|
|
1115
|
-
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
1116
|
-
*/
|
|
1117
|
-
static getPackageVersion() {
|
|
1118
|
-
return getPackageVersion();
|
|
1119
|
-
}
|
|
1120
|
-
constructor(config) {
|
|
1121
|
-
super(config);
|
|
1122
|
-
this._trackClientInit();
|
|
1123
|
-
}
|
|
1124
|
-
_trackClientInit() {
|
|
1125
|
-
const servers = Object.keys(this.config.mcpServers ?? {});
|
|
1126
|
-
Tel.getInstance().trackMCPClientInit({
|
|
1127
|
-
codeMode: false,
|
|
1128
|
-
// Browser client doesn't support code mode
|
|
1129
|
-
sandbox: false,
|
|
1130
|
-
// Sandbox not supported in browser
|
|
1131
|
-
allCallbacks: false,
|
|
1132
|
-
// Will be set per-server
|
|
1133
|
-
verify: false,
|
|
1134
|
-
servers,
|
|
1135
|
-
numServers: servers.length,
|
|
1136
|
-
isBrowser: true
|
|
1137
|
-
// Browser MCPClient
|
|
1138
|
-
}).catch(
|
|
1139
|
-
(e) => logger.debug(`Failed to track BrowserMCPClient init: ${e}`)
|
|
1140
|
-
);
|
|
1141
|
-
}
|
|
1142
|
-
static fromDict(cfg) {
|
|
1143
|
-
return new _BrowserMCPClient(cfg);
|
|
1144
|
-
}
|
|
1145
|
-
/**
|
|
1146
|
-
* Create a connector from server configuration (Browser version)
|
|
1147
|
-
* Supports HTTP and WebSocket connectors only
|
|
1148
|
-
*/
|
|
1149
|
-
createConnectorFromConfig(serverConfig) {
|
|
1150
|
-
const {
|
|
1151
|
-
url,
|
|
1152
|
-
transport,
|
|
1153
|
-
headers,
|
|
1154
|
-
authToken,
|
|
1155
|
-
authProvider,
|
|
1156
|
-
wrapTransport,
|
|
1157
|
-
clientOptions,
|
|
1158
|
-
samplingCallback,
|
|
1159
|
-
elicitationCallback
|
|
1160
|
-
} = serverConfig;
|
|
1161
|
-
if (!url) {
|
|
1162
|
-
throw new Error("Server URL is required");
|
|
1163
|
-
}
|
|
1164
|
-
const connectorOptions = {
|
|
1165
|
-
headers,
|
|
1166
|
-
authToken,
|
|
1167
|
-
authProvider,
|
|
1168
|
-
// ← Pass OAuth provider to connector
|
|
1169
|
-
wrapTransport,
|
|
1170
|
-
// ← Pass transport wrapper if provided
|
|
1171
|
-
clientOptions,
|
|
1172
|
-
// ← Pass client options (capabilities, etc.) to connector
|
|
1173
|
-
samplingCallback,
|
|
1174
|
-
// ← Pass sampling callback to connector
|
|
1175
|
-
elicitationCallback
|
|
1176
|
-
// ← Pass elicitation callback to connector
|
|
1177
|
-
};
|
|
1178
|
-
if (clientOptions) {
|
|
1179
|
-
console.log(
|
|
1180
|
-
"[BrowserMCPClient] Passing clientOptions to connector:",
|
|
1181
|
-
JSON.stringify(clientOptions, null, 2)
|
|
1182
|
-
);
|
|
1183
|
-
} else {
|
|
1184
|
-
console.warn(
|
|
1185
|
-
"[BrowserMCPClient] No clientOptions provided to connector!"
|
|
1186
|
-
);
|
|
1187
|
-
}
|
|
1188
|
-
if (transport === "websocket" || url.startsWith("ws://") || url.startsWith("wss://")) {
|
|
1189
|
-
return new WebSocketConnector(url, connectorOptions);
|
|
1190
|
-
} else if (transport === "http" || url.startsWith("http://") || url.startsWith("https://")) {
|
|
1191
|
-
return new HttpConnector(url, connectorOptions);
|
|
1192
|
-
} else {
|
|
1193
|
-
return new HttpConnector(url, connectorOptions);
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
};
|
|
1197
|
-
|
|
1198
849
|
export {
|
|
1199
850
|
MCPSession,
|
|
1200
851
|
BaseMCPClient,
|
|
1201
852
|
ConnectionManager,
|
|
1202
|
-
HttpConnector
|
|
1203
|
-
WebSocketConnector,
|
|
1204
|
-
BrowserMCPClient
|
|
853
|
+
HttpConnector
|
|
1205
854
|
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseMCPClient,
|
|
3
|
+
HttpConnector
|
|
4
|
+
} from "./chunk-OIXS25J5.js";
|
|
5
|
+
import {
|
|
6
|
+
Tel,
|
|
7
|
+
getPackageVersion
|
|
8
|
+
} from "./chunk-K6YNB2Z3.js";
|
|
9
|
+
import {
|
|
10
|
+
logger
|
|
11
|
+
} from "./chunk-FRUZDWXH.js";
|
|
12
|
+
import {
|
|
13
|
+
__name
|
|
14
|
+
} from "./chunk-3GQAWCBQ.js";
|
|
15
|
+
|
|
16
|
+
// src/client/browser.ts
|
|
17
|
+
var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
|
|
18
|
+
static {
|
|
19
|
+
__name(this, "BrowserMCPClient");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the mcp-use package version.
|
|
23
|
+
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
24
|
+
*/
|
|
25
|
+
static getPackageVersion() {
|
|
26
|
+
return getPackageVersion();
|
|
27
|
+
}
|
|
28
|
+
constructor(config) {
|
|
29
|
+
super(config);
|
|
30
|
+
this._trackClientInit();
|
|
31
|
+
}
|
|
32
|
+
_trackClientInit() {
|
|
33
|
+
const servers = Object.keys(this.config.mcpServers ?? {});
|
|
34
|
+
Tel.getInstance().trackMCPClientInit({
|
|
35
|
+
codeMode: false,
|
|
36
|
+
// Browser client doesn't support code mode
|
|
37
|
+
sandbox: false,
|
|
38
|
+
// Sandbox not supported in browser
|
|
39
|
+
allCallbacks: false,
|
|
40
|
+
// Will be set per-server
|
|
41
|
+
verify: false,
|
|
42
|
+
servers,
|
|
43
|
+
numServers: servers.length,
|
|
44
|
+
isBrowser: true
|
|
45
|
+
// Browser MCPClient
|
|
46
|
+
}).catch(
|
|
47
|
+
(e) => logger.debug(`Failed to track BrowserMCPClient init: ${e}`)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
static fromDict(cfg) {
|
|
51
|
+
return new _BrowserMCPClient(cfg);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a connector from server configuration (Browser version)
|
|
55
|
+
* Supports HTTP connector only
|
|
56
|
+
*/
|
|
57
|
+
createConnectorFromConfig(serverConfig) {
|
|
58
|
+
const {
|
|
59
|
+
url,
|
|
60
|
+
headers,
|
|
61
|
+
authToken,
|
|
62
|
+
authProvider,
|
|
63
|
+
wrapTransport,
|
|
64
|
+
clientOptions,
|
|
65
|
+
samplingCallback,
|
|
66
|
+
elicitationCallback
|
|
67
|
+
} = serverConfig;
|
|
68
|
+
if (!url) {
|
|
69
|
+
throw new Error("Server URL is required");
|
|
70
|
+
}
|
|
71
|
+
const connectorOptions = {
|
|
72
|
+
headers,
|
|
73
|
+
authToken,
|
|
74
|
+
authProvider,
|
|
75
|
+
// ← Pass OAuth provider to connector
|
|
76
|
+
wrapTransport,
|
|
77
|
+
// ← Pass transport wrapper if provided
|
|
78
|
+
clientOptions,
|
|
79
|
+
// ← Pass client options (capabilities, etc.) to connector
|
|
80
|
+
samplingCallback,
|
|
81
|
+
// ← Pass sampling callback to connector
|
|
82
|
+
elicitationCallback
|
|
83
|
+
// ← Pass elicitation callback to connector
|
|
84
|
+
};
|
|
85
|
+
if (clientOptions) {
|
|
86
|
+
console.log(
|
|
87
|
+
"[BrowserMCPClient] Passing clientOptions to connector:",
|
|
88
|
+
JSON.stringify(clientOptions, null, 2)
|
|
89
|
+
);
|
|
90
|
+
} else {
|
|
91
|
+
console.warn(
|
|
92
|
+
"[BrowserMCPClient] No clientOptions provided to connector!"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return new HttpConnector(url, connectorOptions);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
BrowserMCPClient
|
|
101
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Telemetry
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-K6YNB2Z3.js";
|
|
4
4
|
import {
|
|
5
5
|
logger
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FRUZDWXH.js";
|
|
7
7
|
import {
|
|
8
8
|
__name
|
|
9
9
|
} from "./chunk-3GQAWCBQ.js";
|
|
@@ -302,6 +302,20 @@ var BaseConnector = class {
|
|
|
302
302
|
logger.debug(`Tool '${name}' returned`, res);
|
|
303
303
|
return res;
|
|
304
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* List all available tools from the MCP server.
|
|
307
|
+
* This method fetches fresh tools from the server, unlike the `tools` getter which returns cached tools.
|
|
308
|
+
*
|
|
309
|
+
* @param options - Optional request options
|
|
310
|
+
* @returns Array of available tools
|
|
311
|
+
*/
|
|
312
|
+
async listTools(options) {
|
|
313
|
+
if (!this.client) {
|
|
314
|
+
throw new Error("MCP client is not connected");
|
|
315
|
+
}
|
|
316
|
+
const result = await this.client.listTools(void 0, options);
|
|
317
|
+
return result.tools ?? [];
|
|
318
|
+
}
|
|
305
319
|
/**
|
|
306
320
|
* List resources from the server with optional pagination
|
|
307
321
|
*
|