mcp-use 1.10.1-canary.2 → 1.10.3
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/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-OTZ32HGI.js → chunk-F3OL33Q5.js} +1 -1
- package/dist/{chunk-FAELBZOW.js → chunk-GGQJK3MJ.js} +12 -228
- package/dist/{chunk-4NC7PPVE.js → chunk-KXRR57PO.js} +1 -1
- package/dist/{chunk-KFTQ3UL5.js → chunk-OCPN5DA5.js} +2 -2
- package/dist/{chunk-VTNHO2TS.js → chunk-PQSSHWOE.js} +1 -1
- package/dist/{chunk-QNZMNQCY.js → chunk-STIWKBWZ.js} +1 -1
- package/dist/{chunk-CFX74U7W.js → chunk-VCDYZLOT.js} +2 -2
- package/dist/index.cjs +12 -228
- package/dist/index.js +6 -6
- package/dist/src/adapters/base.d.ts +0 -44
- package/dist/src/adapters/base.d.ts.map +1 -1
- package/dist/src/adapters/langchain_adapter.d.ts +1 -12
- package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
- package/dist/src/agents/index.cjs +12 -228
- package/dist/src/agents/index.js +4 -4
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/browser.cjs +12 -228
- package/dist/src/browser.js +4 -4
- package/dist/src/client/prompts.js +3 -3
- 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 +1 -1
- package/dist/src/react/index.js +4 -4
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +3 -23
- package/dist/src/server/index.js +7 -27
- package/dist/src/server/sessions/session-manager.d.ts +3 -6
- package/dist/src/server/sessions/session-manager.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-PQGEPYY3.js → tool-execution-helpers-VGI7F3ZO.js} +2 -2
- package/package.json +5 -6
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
Telemetry,
|
|
3
3
|
extractModelInfo,
|
|
4
4
|
getPackageVersion
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-PQSSHWOE.js";
|
|
6
6
|
import {
|
|
7
7
|
logger
|
|
8
8
|
} from "./chunk-34R6SIER.js";
|
|
@@ -93,98 +93,6 @@ var BaseAdapter = class {
|
|
|
93
93
|
logger.debug(`Available tools: ${tools.length}`);
|
|
94
94
|
return tools;
|
|
95
95
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Dynamically load resources for a specific connector.
|
|
98
|
-
*
|
|
99
|
-
* @param connector The connector to load resources for.
|
|
100
|
-
* @returns The list of resources that were loaded in the target framework's format.
|
|
101
|
-
*/
|
|
102
|
-
async loadResourcesForConnector(connector) {
|
|
103
|
-
const connectorResources = [];
|
|
104
|
-
const success = await this.ensureConnectorInitialized(connector);
|
|
105
|
-
if (!success) {
|
|
106
|
-
return [];
|
|
107
|
-
}
|
|
108
|
-
try {
|
|
109
|
-
const resourcesResult = await connector.listAllResources();
|
|
110
|
-
const resources = resourcesResult?.resources || [];
|
|
111
|
-
if (this.convertResource) {
|
|
112
|
-
for (const resource of resources) {
|
|
113
|
-
const converted = this.convertResource(resource, connector);
|
|
114
|
-
if (converted) {
|
|
115
|
-
connectorResources.push(converted);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
logger.debug(
|
|
120
|
-
`Loaded ${connectorResources.length} new resources for connector: ${connectorResources.map((r) => r?.name ?? String(r)).join(", ")}`
|
|
121
|
-
);
|
|
122
|
-
} catch (err) {
|
|
123
|
-
logger.warn(`Error loading resources for connector: ${err}`);
|
|
124
|
-
}
|
|
125
|
-
return connectorResources;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Dynamically load prompts for a specific connector.
|
|
129
|
-
*
|
|
130
|
-
* @param connector The connector to load prompts for.
|
|
131
|
-
* @returns The list of prompts that were loaded in the target framework's format.
|
|
132
|
-
*/
|
|
133
|
-
async loadPromptsForConnector(connector) {
|
|
134
|
-
const connectorPrompts = [];
|
|
135
|
-
const success = await this.ensureConnectorInitialized(connector);
|
|
136
|
-
if (!success) {
|
|
137
|
-
return [];
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
const promptsResult = await connector.listPrompts();
|
|
141
|
-
const prompts = promptsResult?.prompts || [];
|
|
142
|
-
if (this.convertPrompt) {
|
|
143
|
-
for (const prompt of prompts) {
|
|
144
|
-
const converted = this.convertPrompt(prompt, connector);
|
|
145
|
-
if (converted) {
|
|
146
|
-
connectorPrompts.push(converted);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
logger.debug(
|
|
151
|
-
`Loaded ${connectorPrompts.length} new prompts for connector: ${connectorPrompts.map((p) => p?.name ?? String(p)).join(", ")}`
|
|
152
|
-
);
|
|
153
|
-
} catch (err) {
|
|
154
|
-
logger.warn(`Error loading prompts for connector: ${err}`);
|
|
155
|
-
}
|
|
156
|
-
return connectorPrompts;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Create resources from MCP resources in all provided connectors.
|
|
160
|
-
*
|
|
161
|
-
* @param connectors List of MCP connectors to create resources from.
|
|
162
|
-
* @returns A promise that resolves with all converted resources.
|
|
163
|
-
*/
|
|
164
|
-
async createResourcesFromConnectors(connectors) {
|
|
165
|
-
const resources = [];
|
|
166
|
-
for (const connector of connectors) {
|
|
167
|
-
const connectorResources = await this.loadResourcesForConnector(connector);
|
|
168
|
-
resources.push(...connectorResources);
|
|
169
|
-
}
|
|
170
|
-
logger.debug(`Available resources: ${resources.length}`);
|
|
171
|
-
return resources;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Create prompts from MCP prompts in all provided connectors.
|
|
175
|
-
*
|
|
176
|
-
* @param connectors List of MCP connectors to create prompts from.
|
|
177
|
-
* @returns A promise that resolves with all converted prompts.
|
|
178
|
-
*/
|
|
179
|
-
async createPromptsFromConnectors(connectors) {
|
|
180
|
-
const prompts = [];
|
|
181
|
-
for (const connector of connectors) {
|
|
182
|
-
const connectorPrompts = await this.loadPromptsForConnector(connector);
|
|
183
|
-
prompts.push(...connectorPrompts);
|
|
184
|
-
}
|
|
185
|
-
logger.debug(`Available prompts: ${prompts.length}`);
|
|
186
|
-
return prompts;
|
|
187
|
-
}
|
|
188
96
|
/**
|
|
189
97
|
* Check if a connector is initialized and has tools.
|
|
190
98
|
*
|
|
@@ -953,99 +861,6 @@ var LangChainAdapter = class extends BaseAdapter {
|
|
|
953
861
|
});
|
|
954
862
|
return tool;
|
|
955
863
|
}
|
|
956
|
-
/**
|
|
957
|
-
* Convert a single MCP resource into a LangChainJS structured tool.
|
|
958
|
-
* Each resource becomes an async tool that returns its content when called.
|
|
959
|
-
*/
|
|
960
|
-
convertResource(mcpResource, connector) {
|
|
961
|
-
const sanitizeName = /* @__PURE__ */ __name((name) => {
|
|
962
|
-
return name.replace(/[^A-Za-z0-9_]+/g, "_").toLowerCase().replace(/^_+|_+$/g, "");
|
|
963
|
-
}, "sanitizeName");
|
|
964
|
-
const resourceName = sanitizeName(
|
|
965
|
-
mcpResource.name || `resource_${mcpResource.uri}`
|
|
966
|
-
);
|
|
967
|
-
const resourceUri = mcpResource.uri;
|
|
968
|
-
const tool = new DynamicStructuredTool({
|
|
969
|
-
name: resourceName,
|
|
970
|
-
description: mcpResource.description || `Return the content of the resource located at URI ${resourceUri}.`,
|
|
971
|
-
schema: z2.object({}).optional(),
|
|
972
|
-
// Resources take no arguments
|
|
973
|
-
func: /* @__PURE__ */ __name(async () => {
|
|
974
|
-
logger.debug(`Resource tool: "${resourceName}" called`);
|
|
975
|
-
try {
|
|
976
|
-
const result = await connector.readResource(resourceUri);
|
|
977
|
-
if (result.contents && result.contents.length > 0) {
|
|
978
|
-
return result.contents.map((content) => {
|
|
979
|
-
if (typeof content === "string") {
|
|
980
|
-
return content;
|
|
981
|
-
}
|
|
982
|
-
if (content.text) {
|
|
983
|
-
return content.text;
|
|
984
|
-
}
|
|
985
|
-
if (content.uri) {
|
|
986
|
-
return content.uri;
|
|
987
|
-
}
|
|
988
|
-
return JSON.stringify(content);
|
|
989
|
-
}).join("\n");
|
|
990
|
-
}
|
|
991
|
-
return "Resource is empty or unavailable";
|
|
992
|
-
} catch (err) {
|
|
993
|
-
logger.error(`Error reading resource: ${err.message}`);
|
|
994
|
-
return `Error reading resource: ${String(err)}`;
|
|
995
|
-
}
|
|
996
|
-
}, "func")
|
|
997
|
-
});
|
|
998
|
-
return tool;
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* Convert a single MCP prompt into a LangChainJS structured tool.
|
|
1002
|
-
* The resulting tool executes getPrompt on the connector with the prompt's name
|
|
1003
|
-
* and the user-provided arguments (if any).
|
|
1004
|
-
*/
|
|
1005
|
-
convertPrompt(mcpPrompt, connector) {
|
|
1006
|
-
let argsSchema = z2.object({}).optional();
|
|
1007
|
-
if (mcpPrompt.arguments && mcpPrompt.arguments.length > 0) {
|
|
1008
|
-
const schemaFields = {};
|
|
1009
|
-
for (const arg of mcpPrompt.arguments) {
|
|
1010
|
-
const zodType = z2.string();
|
|
1011
|
-
if (arg.required !== false) {
|
|
1012
|
-
schemaFields[arg.name] = zodType;
|
|
1013
|
-
} else {
|
|
1014
|
-
schemaFields[arg.name] = zodType.optional();
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
argsSchema = Object.keys(schemaFields).length > 0 ? z2.object(schemaFields) : z2.object({}).optional();
|
|
1018
|
-
}
|
|
1019
|
-
const tool = new DynamicStructuredTool({
|
|
1020
|
-
name: mcpPrompt.name,
|
|
1021
|
-
description: mcpPrompt.description || "",
|
|
1022
|
-
schema: argsSchema,
|
|
1023
|
-
func: /* @__PURE__ */ __name(async (input) => {
|
|
1024
|
-
logger.debug(
|
|
1025
|
-
`Prompt tool: "${mcpPrompt.name}" called with args: ${JSON.stringify(input)}`
|
|
1026
|
-
);
|
|
1027
|
-
try {
|
|
1028
|
-
const result = await connector.getPrompt(mcpPrompt.name, input);
|
|
1029
|
-
if (result.messages && result.messages.length > 0) {
|
|
1030
|
-
return result.messages.map((msg) => {
|
|
1031
|
-
if (typeof msg === "string") {
|
|
1032
|
-
return msg;
|
|
1033
|
-
}
|
|
1034
|
-
if (msg.content) {
|
|
1035
|
-
return typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
1036
|
-
}
|
|
1037
|
-
return JSON.stringify(msg);
|
|
1038
|
-
}).join("\n");
|
|
1039
|
-
}
|
|
1040
|
-
return "Prompt returned no messages";
|
|
1041
|
-
} catch (err) {
|
|
1042
|
-
logger.error(`Error getting prompt: ${err.message}`);
|
|
1043
|
-
return `Error getting prompt: ${String(err)}`;
|
|
1044
|
-
}
|
|
1045
|
-
}, "func")
|
|
1046
|
-
});
|
|
1047
|
-
return tool;
|
|
1048
|
-
}
|
|
1049
864
|
};
|
|
1050
865
|
|
|
1051
866
|
// src/managers/tools/acquire_active_mcp_server.ts
|
|
@@ -1177,21 +992,15 @@ var ConnectMCPServerTool = class extends MCPServerTool {
|
|
|
1177
992
|
session = await this.manager.client.createSession(serverName);
|
|
1178
993
|
}
|
|
1179
994
|
this.manager.activeServer = serverName;
|
|
1180
|
-
if (
|
|
995
|
+
if (this.manager.serverTools[serverName]) {
|
|
1181
996
|
const connector = session.connector;
|
|
1182
997
|
const tools = await this.manager.adapter.createToolsFromConnectors([connector]);
|
|
1183
|
-
|
|
1184
|
-
const prompts = await this.manager.adapter.createPromptsFromConnectors([connector]);
|
|
1185
|
-
const allItems = [...tools, ...resources, ...prompts];
|
|
1186
|
-
this.manager.serverTools[serverName] = allItems;
|
|
998
|
+
this.manager.serverTools[serverName] = tools;
|
|
1187
999
|
this.manager.initializedServers[serverName] = true;
|
|
1188
|
-
logger.debug(
|
|
1189
|
-
`Loaded ${allItems.length} items for server '${serverName}': ${tools.length} tools, ${resources.length} resources, ${prompts.length} prompts`
|
|
1190
|
-
);
|
|
1191
1000
|
}
|
|
1192
1001
|
const serverTools = this.manager.serverTools[serverName] || [];
|
|
1193
1002
|
const numTools = serverTools.length;
|
|
1194
|
-
return `Connected to MCP server '${serverName}'. ${numTools} tools
|
|
1003
|
+
return `Connected to MCP server '${serverName}'. ${numTools} tools are now available.`;
|
|
1195
1004
|
} catch (error) {
|
|
1196
1005
|
logger.error(
|
|
1197
1006
|
`Error connecting to server '${serverName}': ${String(error)}`
|
|
@@ -1352,30 +1161,21 @@ var ServerManager = class {
|
|
|
1352
1161
|
if (session) {
|
|
1353
1162
|
const connector = session.connector;
|
|
1354
1163
|
let tools = [];
|
|
1355
|
-
let resources = [];
|
|
1356
|
-
let prompts = [];
|
|
1357
1164
|
try {
|
|
1358
1165
|
tools = await this.adapter.createToolsFromConnectors([connector]);
|
|
1359
|
-
resources = await this.adapter.createResourcesFromConnectors([
|
|
1360
|
-
connector
|
|
1361
|
-
]);
|
|
1362
|
-
prompts = await this.adapter.createPromptsFromConnectors([
|
|
1363
|
-
connector
|
|
1364
|
-
]);
|
|
1365
1166
|
} catch (toolFetchError) {
|
|
1366
1167
|
logger.error(
|
|
1367
|
-
`Failed to create tools
|
|
1168
|
+
`Failed to create tools from connector for server '${serverName}': ${toolFetchError}`
|
|
1368
1169
|
);
|
|
1369
1170
|
continue;
|
|
1370
1171
|
}
|
|
1371
|
-
const allItems = [...tools, ...resources, ...prompts];
|
|
1372
1172
|
const cachedTools = this.serverTools[serverName];
|
|
1373
|
-
const toolsChanged = !cachedTools || !isEqual(cachedTools,
|
|
1173
|
+
const toolsChanged = !cachedTools || !isEqual(cachedTools, tools);
|
|
1374
1174
|
if (toolsChanged) {
|
|
1375
|
-
this.serverTools[serverName] =
|
|
1175
|
+
this.serverTools[serverName] = tools;
|
|
1376
1176
|
this.initializedServers[serverName] = true;
|
|
1377
1177
|
logger.debug(
|
|
1378
|
-
`Prefetched ${
|
|
1178
|
+
`Prefetched ${tools.length} tools for server '${serverName}'.`
|
|
1379
1179
|
);
|
|
1380
1180
|
} else {
|
|
1381
1181
|
logger.debug(
|
|
@@ -2123,18 +1923,9 @@ var MCPAgent = class {
|
|
|
2123
1923
|
);
|
|
2124
1924
|
}
|
|
2125
1925
|
} else {
|
|
2126
|
-
|
|
2127
|
-
Object.values(this.sessions).map((session) => session.connector)
|
|
2128
|
-
);
|
|
2129
|
-
const resources = await this.adapter.createResourcesFromConnectors(
|
|
2130
|
-
Object.values(this.sessions).map((session) => session.connector)
|
|
2131
|
-
);
|
|
2132
|
-
const prompts = await this.adapter.createPromptsFromConnectors(
|
|
2133
|
-
Object.values(this.sessions).map((session) => session.connector)
|
|
2134
|
-
);
|
|
2135
|
-
this._tools = [...tools, ...resources, ...prompts];
|
|
1926
|
+
this._tools = await LangChainAdapter.createTools(this.client);
|
|
2136
1927
|
logger.info(
|
|
2137
|
-
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain
|
|
1928
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain tools from client`
|
|
2138
1929
|
);
|
|
2139
1930
|
}
|
|
2140
1931
|
this._tools.push(...this.additionalTools);
|
|
@@ -2147,19 +1938,12 @@ var MCPAgent = class {
|
|
|
2147
1938
|
await connector.connect();
|
|
2148
1939
|
}
|
|
2149
1940
|
}
|
|
2150
|
-
|
|
2151
|
-
this.connectors
|
|
2152
|
-
);
|
|
2153
|
-
const resources = await this.adapter.createResourcesFromConnectors(
|
|
2154
|
-
this.connectors
|
|
2155
|
-
);
|
|
2156
|
-
const prompts = await this.adapter.createPromptsFromConnectors(
|
|
1941
|
+
this._tools = await this.adapter.createToolsFromConnectors(
|
|
2157
1942
|
this.connectors
|
|
2158
1943
|
);
|
|
2159
|
-
this._tools = [...tools, ...resources, ...prompts];
|
|
2160
1944
|
this._tools.push(...this.additionalTools);
|
|
2161
1945
|
logger.info(
|
|
2162
|
-
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain
|
|
1946
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain tools from connectors`
|
|
2163
1947
|
);
|
|
2164
1948
|
}
|
|
2165
1949
|
logger.info(`\u{1F9F0} Found ${this._tools.length} tools across all connectors`);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseConnector
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KXRR57PO.js";
|
|
4
4
|
import {
|
|
5
5
|
Tel,
|
|
6
6
|
generateUUID,
|
|
7
7
|
getPackageVersion
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-PQSSHWOE.js";
|
|
9
9
|
import {
|
|
10
10
|
logger
|
|
11
11
|
} from "./chunk-34R6SIER.js";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BrowserMCPClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OCPN5DA5.js";
|
|
4
4
|
import {
|
|
5
5
|
BrowserOAuthClientProvider,
|
|
6
6
|
sanitizeUrl
|
|
7
7
|
} from "./chunk-J75I2C26.js";
|
|
8
8
|
import {
|
|
9
9
|
Tel
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-PQSSHWOE.js";
|
|
11
11
|
import {
|
|
12
12
|
__name
|
|
13
13
|
} from "./chunk-3GQAWCBQ.js";
|
package/dist/index.cjs
CHANGED
|
@@ -1884,98 +1884,6 @@ var BaseAdapter = class {
|
|
|
1884
1884
|
logger.debug(`Available tools: ${tools.length}`);
|
|
1885
1885
|
return tools;
|
|
1886
1886
|
}
|
|
1887
|
-
/**
|
|
1888
|
-
* Dynamically load resources for a specific connector.
|
|
1889
|
-
*
|
|
1890
|
-
* @param connector The connector to load resources for.
|
|
1891
|
-
* @returns The list of resources that were loaded in the target framework's format.
|
|
1892
|
-
*/
|
|
1893
|
-
async loadResourcesForConnector(connector) {
|
|
1894
|
-
const connectorResources = [];
|
|
1895
|
-
const success = await this.ensureConnectorInitialized(connector);
|
|
1896
|
-
if (!success) {
|
|
1897
|
-
return [];
|
|
1898
|
-
}
|
|
1899
|
-
try {
|
|
1900
|
-
const resourcesResult = await connector.listAllResources();
|
|
1901
|
-
const resources = resourcesResult?.resources || [];
|
|
1902
|
-
if (this.convertResource) {
|
|
1903
|
-
for (const resource of resources) {
|
|
1904
|
-
const converted = this.convertResource(resource, connector);
|
|
1905
|
-
if (converted) {
|
|
1906
|
-
connectorResources.push(converted);
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
logger.debug(
|
|
1911
|
-
`Loaded ${connectorResources.length} new resources for connector: ${connectorResources.map((r) => r?.name ?? String(r)).join(", ")}`
|
|
1912
|
-
);
|
|
1913
|
-
} catch (err) {
|
|
1914
|
-
logger.warn(`Error loading resources for connector: ${err}`);
|
|
1915
|
-
}
|
|
1916
|
-
return connectorResources;
|
|
1917
|
-
}
|
|
1918
|
-
/**
|
|
1919
|
-
* Dynamically load prompts for a specific connector.
|
|
1920
|
-
*
|
|
1921
|
-
* @param connector The connector to load prompts for.
|
|
1922
|
-
* @returns The list of prompts that were loaded in the target framework's format.
|
|
1923
|
-
*/
|
|
1924
|
-
async loadPromptsForConnector(connector) {
|
|
1925
|
-
const connectorPrompts = [];
|
|
1926
|
-
const success = await this.ensureConnectorInitialized(connector);
|
|
1927
|
-
if (!success) {
|
|
1928
|
-
return [];
|
|
1929
|
-
}
|
|
1930
|
-
try {
|
|
1931
|
-
const promptsResult = await connector.listPrompts();
|
|
1932
|
-
const prompts = promptsResult?.prompts || [];
|
|
1933
|
-
if (this.convertPrompt) {
|
|
1934
|
-
for (const prompt of prompts) {
|
|
1935
|
-
const converted = this.convertPrompt(prompt, connector);
|
|
1936
|
-
if (converted) {
|
|
1937
|
-
connectorPrompts.push(converted);
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
logger.debug(
|
|
1942
|
-
`Loaded ${connectorPrompts.length} new prompts for connector: ${connectorPrompts.map((p) => p?.name ?? String(p)).join(", ")}`
|
|
1943
|
-
);
|
|
1944
|
-
} catch (err) {
|
|
1945
|
-
logger.warn(`Error loading prompts for connector: ${err}`);
|
|
1946
|
-
}
|
|
1947
|
-
return connectorPrompts;
|
|
1948
|
-
}
|
|
1949
|
-
/**
|
|
1950
|
-
* Create resources from MCP resources in all provided connectors.
|
|
1951
|
-
*
|
|
1952
|
-
* @param connectors List of MCP connectors to create resources from.
|
|
1953
|
-
* @returns A promise that resolves with all converted resources.
|
|
1954
|
-
*/
|
|
1955
|
-
async createResourcesFromConnectors(connectors) {
|
|
1956
|
-
const resources = [];
|
|
1957
|
-
for (const connector of connectors) {
|
|
1958
|
-
const connectorResources = await this.loadResourcesForConnector(connector);
|
|
1959
|
-
resources.push(...connectorResources);
|
|
1960
|
-
}
|
|
1961
|
-
logger.debug(`Available resources: ${resources.length}`);
|
|
1962
|
-
return resources;
|
|
1963
|
-
}
|
|
1964
|
-
/**
|
|
1965
|
-
* Create prompts from MCP prompts in all provided connectors.
|
|
1966
|
-
*
|
|
1967
|
-
* @param connectors List of MCP connectors to create prompts from.
|
|
1968
|
-
* @returns A promise that resolves with all converted prompts.
|
|
1969
|
-
*/
|
|
1970
|
-
async createPromptsFromConnectors(connectors) {
|
|
1971
|
-
const prompts = [];
|
|
1972
|
-
for (const connector of connectors) {
|
|
1973
|
-
const connectorPrompts = await this.loadPromptsForConnector(connector);
|
|
1974
|
-
prompts.push(...connectorPrompts);
|
|
1975
|
-
}
|
|
1976
|
-
logger.debug(`Available prompts: ${prompts.length}`);
|
|
1977
|
-
return prompts;
|
|
1978
|
-
}
|
|
1979
1887
|
/**
|
|
1980
1888
|
* Check if a connector is initialized and has tools.
|
|
1981
1889
|
*
|
|
@@ -2054,99 +1962,6 @@ var LangChainAdapter = class extends BaseAdapter {
|
|
|
2054
1962
|
});
|
|
2055
1963
|
return tool;
|
|
2056
1964
|
}
|
|
2057
|
-
/**
|
|
2058
|
-
* Convert a single MCP resource into a LangChainJS structured tool.
|
|
2059
|
-
* Each resource becomes an async tool that returns its content when called.
|
|
2060
|
-
*/
|
|
2061
|
-
convertResource(mcpResource, connector) {
|
|
2062
|
-
const sanitizeName = /* @__PURE__ */ __name((name) => {
|
|
2063
|
-
return name.replace(/[^A-Za-z0-9_]+/g, "_").toLowerCase().replace(/^_+|_+$/g, "");
|
|
2064
|
-
}, "sanitizeName");
|
|
2065
|
-
const resourceName = sanitizeName(
|
|
2066
|
-
mcpResource.name || `resource_${mcpResource.uri}`
|
|
2067
|
-
);
|
|
2068
|
-
const resourceUri = mcpResource.uri;
|
|
2069
|
-
const tool = new import_tools.DynamicStructuredTool({
|
|
2070
|
-
name: resourceName,
|
|
2071
|
-
description: mcpResource.description || `Return the content of the resource located at URI ${resourceUri}.`,
|
|
2072
|
-
schema: import_zod2.z.object({}).optional(),
|
|
2073
|
-
// Resources take no arguments
|
|
2074
|
-
func: /* @__PURE__ */ __name(async () => {
|
|
2075
|
-
logger.debug(`Resource tool: "${resourceName}" called`);
|
|
2076
|
-
try {
|
|
2077
|
-
const result = await connector.readResource(resourceUri);
|
|
2078
|
-
if (result.contents && result.contents.length > 0) {
|
|
2079
|
-
return result.contents.map((content) => {
|
|
2080
|
-
if (typeof content === "string") {
|
|
2081
|
-
return content;
|
|
2082
|
-
}
|
|
2083
|
-
if (content.text) {
|
|
2084
|
-
return content.text;
|
|
2085
|
-
}
|
|
2086
|
-
if (content.uri) {
|
|
2087
|
-
return content.uri;
|
|
2088
|
-
}
|
|
2089
|
-
return JSON.stringify(content);
|
|
2090
|
-
}).join("\n");
|
|
2091
|
-
}
|
|
2092
|
-
return "Resource is empty or unavailable";
|
|
2093
|
-
} catch (err) {
|
|
2094
|
-
logger.error(`Error reading resource: ${err.message}`);
|
|
2095
|
-
return `Error reading resource: ${String(err)}`;
|
|
2096
|
-
}
|
|
2097
|
-
}, "func")
|
|
2098
|
-
});
|
|
2099
|
-
return tool;
|
|
2100
|
-
}
|
|
2101
|
-
/**
|
|
2102
|
-
* Convert a single MCP prompt into a LangChainJS structured tool.
|
|
2103
|
-
* The resulting tool executes getPrompt on the connector with the prompt's name
|
|
2104
|
-
* and the user-provided arguments (if any).
|
|
2105
|
-
*/
|
|
2106
|
-
convertPrompt(mcpPrompt, connector) {
|
|
2107
|
-
let argsSchema = import_zod2.z.object({}).optional();
|
|
2108
|
-
if (mcpPrompt.arguments && mcpPrompt.arguments.length > 0) {
|
|
2109
|
-
const schemaFields = {};
|
|
2110
|
-
for (const arg of mcpPrompt.arguments) {
|
|
2111
|
-
const zodType = import_zod2.z.string();
|
|
2112
|
-
if (arg.required !== false) {
|
|
2113
|
-
schemaFields[arg.name] = zodType;
|
|
2114
|
-
} else {
|
|
2115
|
-
schemaFields[arg.name] = zodType.optional();
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
argsSchema = Object.keys(schemaFields).length > 0 ? import_zod2.z.object(schemaFields) : import_zod2.z.object({}).optional();
|
|
2119
|
-
}
|
|
2120
|
-
const tool = new import_tools.DynamicStructuredTool({
|
|
2121
|
-
name: mcpPrompt.name,
|
|
2122
|
-
description: mcpPrompt.description || "",
|
|
2123
|
-
schema: argsSchema,
|
|
2124
|
-
func: /* @__PURE__ */ __name(async (input) => {
|
|
2125
|
-
logger.debug(
|
|
2126
|
-
`Prompt tool: "${mcpPrompt.name}" called with args: ${JSON.stringify(input)}`
|
|
2127
|
-
);
|
|
2128
|
-
try {
|
|
2129
|
-
const result = await connector.getPrompt(mcpPrompt.name, input);
|
|
2130
|
-
if (result.messages && result.messages.length > 0) {
|
|
2131
|
-
return result.messages.map((msg) => {
|
|
2132
|
-
if (typeof msg === "string") {
|
|
2133
|
-
return msg;
|
|
2134
|
-
}
|
|
2135
|
-
if (msg.content) {
|
|
2136
|
-
return typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
2137
|
-
}
|
|
2138
|
-
return JSON.stringify(msg);
|
|
2139
|
-
}).join("\n");
|
|
2140
|
-
}
|
|
2141
|
-
return "Prompt returned no messages";
|
|
2142
|
-
} catch (err) {
|
|
2143
|
-
logger.error(`Error getting prompt: ${err.message}`);
|
|
2144
|
-
return `Error getting prompt: ${String(err)}`;
|
|
2145
|
-
}
|
|
2146
|
-
}, "func")
|
|
2147
|
-
});
|
|
2148
|
-
return tool;
|
|
2149
|
-
}
|
|
2150
1965
|
};
|
|
2151
1966
|
|
|
2152
1967
|
// src/agents/mcp_agent.ts
|
|
@@ -2286,21 +2101,15 @@ var ConnectMCPServerTool = class extends MCPServerTool {
|
|
|
2286
2101
|
session = await this.manager.client.createSession(serverName);
|
|
2287
2102
|
}
|
|
2288
2103
|
this.manager.activeServer = serverName;
|
|
2289
|
-
if (
|
|
2104
|
+
if (this.manager.serverTools[serverName]) {
|
|
2290
2105
|
const connector = session.connector;
|
|
2291
2106
|
const tools = await this.manager.adapter.createToolsFromConnectors([connector]);
|
|
2292
|
-
|
|
2293
|
-
const prompts = await this.manager.adapter.createPromptsFromConnectors([connector]);
|
|
2294
|
-
const allItems = [...tools, ...resources, ...prompts];
|
|
2295
|
-
this.manager.serverTools[serverName] = allItems;
|
|
2107
|
+
this.manager.serverTools[serverName] = tools;
|
|
2296
2108
|
this.manager.initializedServers[serverName] = true;
|
|
2297
|
-
logger.debug(
|
|
2298
|
-
`Loaded ${allItems.length} items for server '${serverName}': ${tools.length} tools, ${resources.length} resources, ${prompts.length} prompts`
|
|
2299
|
-
);
|
|
2300
2109
|
}
|
|
2301
2110
|
const serverTools = this.manager.serverTools[serverName] || [];
|
|
2302
2111
|
const numTools = serverTools.length;
|
|
2303
|
-
return `Connected to MCP server '${serverName}'. ${numTools} tools
|
|
2112
|
+
return `Connected to MCP server '${serverName}'. ${numTools} tools are now available.`;
|
|
2304
2113
|
} catch (error) {
|
|
2305
2114
|
logger.error(
|
|
2306
2115
|
`Error connecting to server '${serverName}': ${String(error)}`
|
|
@@ -2462,30 +2271,21 @@ var ServerManager = class {
|
|
|
2462
2271
|
if (session) {
|
|
2463
2272
|
const connector = session.connector;
|
|
2464
2273
|
let tools = [];
|
|
2465
|
-
let resources = [];
|
|
2466
|
-
let prompts = [];
|
|
2467
2274
|
try {
|
|
2468
2275
|
tools = await this.adapter.createToolsFromConnectors([connector]);
|
|
2469
|
-
resources = await this.adapter.createResourcesFromConnectors([
|
|
2470
|
-
connector
|
|
2471
|
-
]);
|
|
2472
|
-
prompts = await this.adapter.createPromptsFromConnectors([
|
|
2473
|
-
connector
|
|
2474
|
-
]);
|
|
2475
2276
|
} catch (toolFetchError) {
|
|
2476
2277
|
logger.error(
|
|
2477
|
-
`Failed to create tools
|
|
2278
|
+
`Failed to create tools from connector for server '${serverName}': ${toolFetchError}`
|
|
2478
2279
|
);
|
|
2479
2280
|
continue;
|
|
2480
2281
|
}
|
|
2481
|
-
const allItems = [...tools, ...resources, ...prompts];
|
|
2482
2282
|
const cachedTools = this.serverTools[serverName];
|
|
2483
|
-
const toolsChanged = !cachedTools || !isEqual(cachedTools,
|
|
2283
|
+
const toolsChanged = !cachedTools || !isEqual(cachedTools, tools);
|
|
2484
2284
|
if (toolsChanged) {
|
|
2485
|
-
this.serverTools[serverName] =
|
|
2285
|
+
this.serverTools[serverName] = tools;
|
|
2486
2286
|
this.initializedServers[serverName] = true;
|
|
2487
2287
|
logger.debug(
|
|
2488
|
-
`Prefetched ${
|
|
2288
|
+
`Prefetched ${tools.length} tools for server '${serverName}'.`
|
|
2489
2289
|
);
|
|
2490
2290
|
} else {
|
|
2491
2291
|
logger.debug(
|
|
@@ -3076,7 +2876,7 @@ __name(generateUUID, "generateUUID");
|
|
|
3076
2876
|
init_logging();
|
|
3077
2877
|
|
|
3078
2878
|
// src/version.ts
|
|
3079
|
-
var VERSION = "1.10.
|
|
2879
|
+
var VERSION = "1.10.3";
|
|
3080
2880
|
function getPackageVersion() {
|
|
3081
2881
|
return VERSION;
|
|
3082
2882
|
}
|
|
@@ -4260,18 +4060,9 @@ var MCPAgent = class {
|
|
|
4260
4060
|
);
|
|
4261
4061
|
}
|
|
4262
4062
|
} else {
|
|
4263
|
-
|
|
4264
|
-
Object.values(this.sessions).map((session) => session.connector)
|
|
4265
|
-
);
|
|
4266
|
-
const resources = await this.adapter.createResourcesFromConnectors(
|
|
4267
|
-
Object.values(this.sessions).map((session) => session.connector)
|
|
4268
|
-
);
|
|
4269
|
-
const prompts = await this.adapter.createPromptsFromConnectors(
|
|
4270
|
-
Object.values(this.sessions).map((session) => session.connector)
|
|
4271
|
-
);
|
|
4272
|
-
this._tools = [...tools, ...resources, ...prompts];
|
|
4063
|
+
this._tools = await LangChainAdapter.createTools(this.client);
|
|
4273
4064
|
logger.info(
|
|
4274
|
-
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain
|
|
4065
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain tools from client`
|
|
4275
4066
|
);
|
|
4276
4067
|
}
|
|
4277
4068
|
this._tools.push(...this.additionalTools);
|
|
@@ -4284,19 +4075,12 @@ var MCPAgent = class {
|
|
|
4284
4075
|
await connector.connect();
|
|
4285
4076
|
}
|
|
4286
4077
|
}
|
|
4287
|
-
|
|
4288
|
-
this.connectors
|
|
4289
|
-
);
|
|
4290
|
-
const resources = await this.adapter.createResourcesFromConnectors(
|
|
4291
|
-
this.connectors
|
|
4292
|
-
);
|
|
4293
|
-
const prompts = await this.adapter.createPromptsFromConnectors(
|
|
4078
|
+
this._tools = await this.adapter.createToolsFromConnectors(
|
|
4294
4079
|
this.connectors
|
|
4295
4080
|
);
|
|
4296
|
-
this._tools = [...tools, ...resources, ...prompts];
|
|
4297
4081
|
this._tools.push(...this.additionalTools);
|
|
4298
4082
|
logger.info(
|
|
4299
|
-
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain
|
|
4083
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain tools from connectors`
|
|
4300
4084
|
);
|
|
4301
4085
|
}
|
|
4302
4086
|
logger.info(`\u{1F9F0} Found ${this._tools.length} tools across all connectors`);
|