mcp-use 1.10.0 → 1.10.1-canary.1
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-EKIKWKIM.js → chunk-3WQPXSMB.js} +228 -12
- package/dist/{chunk-J76TXLP2.js → chunk-BO2DLS2U.js} +2 -2
- package/dist/{chunk-TWQ72HSN.js → chunk-BXYYBPWE.js} +2 -2
- package/dist/{chunk-X5EWD2UY.js → chunk-ES5N2BQY.js} +1 -1
- package/dist/{chunk-BLIJYL2F.js → chunk-IVXE5QZD.js} +1 -1
- package/dist/{chunk-UZJK3IKC.js → chunk-K6EZ46MT.js} +1 -1
- package/dist/{chunk-D3GIGCHA.js → chunk-NS7PNUAI.js} +1 -1
- package/dist/index.cjs +228 -12
- package/dist/index.js +11 -11
- 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 +228 -12
- package/dist/src/agents/index.js +4 -4
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/browser.cjs +228 -12
- 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/index.cjs +1 -1
- package/dist/src/server/index.js +5 -5
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/{tool-execution-helpers-IMWBWRMK.js → tool-execution-helpers-G74FG2CI.js} +2 -2
- package/package.json +5 -4
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
Telemetry,
|
|
3
3
|
extractModelInfo,
|
|
4
4
|
getPackageVersion
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ES5N2BQY.js";
|
|
6
6
|
import {
|
|
7
7
|
logger
|
|
8
8
|
} from "./chunk-34R6SIER.js";
|
|
@@ -93,6 +93,98 @@ 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
|
+
}
|
|
96
188
|
/**
|
|
97
189
|
* Check if a connector is initialized and has tools.
|
|
98
190
|
*
|
|
@@ -861,6 +953,99 @@ var LangChainAdapter = class extends BaseAdapter {
|
|
|
861
953
|
});
|
|
862
954
|
return tool;
|
|
863
955
|
}
|
|
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
|
+
}
|
|
864
1049
|
};
|
|
865
1050
|
|
|
866
1051
|
// src/managers/tools/acquire_active_mcp_server.ts
|
|
@@ -992,15 +1177,21 @@ var ConnectMCPServerTool = class extends MCPServerTool {
|
|
|
992
1177
|
session = await this.manager.client.createSession(serverName);
|
|
993
1178
|
}
|
|
994
1179
|
this.manager.activeServer = serverName;
|
|
995
|
-
if (this.manager.serverTools[serverName]) {
|
|
1180
|
+
if (!this.manager.serverTools[serverName]) {
|
|
996
1181
|
const connector = session.connector;
|
|
997
1182
|
const tools = await this.manager.adapter.createToolsFromConnectors([connector]);
|
|
998
|
-
this.manager.
|
|
1183
|
+
const resources = await this.manager.adapter.createResourcesFromConnectors([connector]);
|
|
1184
|
+
const prompts = await this.manager.adapter.createPromptsFromConnectors([connector]);
|
|
1185
|
+
const allItems = [...tools, ...resources, ...prompts];
|
|
1186
|
+
this.manager.serverTools[serverName] = allItems;
|
|
999
1187
|
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
|
+
);
|
|
1000
1191
|
}
|
|
1001
1192
|
const serverTools = this.manager.serverTools[serverName] || [];
|
|
1002
1193
|
const numTools = serverTools.length;
|
|
1003
|
-
return `Connected to MCP server '${serverName}'. ${numTools} tools are now available.`;
|
|
1194
|
+
return `Connected to MCP server '${serverName}'. ${numTools} tools, resources, and prompts are now available.`;
|
|
1004
1195
|
} catch (error) {
|
|
1005
1196
|
logger.error(
|
|
1006
1197
|
`Error connecting to server '${serverName}': ${String(error)}`
|
|
@@ -1161,21 +1352,30 @@ var ServerManager = class {
|
|
|
1161
1352
|
if (session) {
|
|
1162
1353
|
const connector = session.connector;
|
|
1163
1354
|
let tools = [];
|
|
1355
|
+
let resources = [];
|
|
1356
|
+
let prompts = [];
|
|
1164
1357
|
try {
|
|
1165
1358
|
tools = await this.adapter.createToolsFromConnectors([connector]);
|
|
1359
|
+
resources = await this.adapter.createResourcesFromConnectors([
|
|
1360
|
+
connector
|
|
1361
|
+
]);
|
|
1362
|
+
prompts = await this.adapter.createPromptsFromConnectors([
|
|
1363
|
+
connector
|
|
1364
|
+
]);
|
|
1166
1365
|
} catch (toolFetchError) {
|
|
1167
1366
|
logger.error(
|
|
1168
|
-
`Failed to create tools from connector for server '${serverName}': ${toolFetchError}`
|
|
1367
|
+
`Failed to create tools/resources/prompts from connector for server '${serverName}': ${toolFetchError}`
|
|
1169
1368
|
);
|
|
1170
1369
|
continue;
|
|
1171
1370
|
}
|
|
1371
|
+
const allItems = [...tools, ...resources, ...prompts];
|
|
1172
1372
|
const cachedTools = this.serverTools[serverName];
|
|
1173
|
-
const toolsChanged = !cachedTools || !isEqual(cachedTools,
|
|
1373
|
+
const toolsChanged = !cachedTools || !isEqual(cachedTools, allItems);
|
|
1174
1374
|
if (toolsChanged) {
|
|
1175
|
-
this.serverTools[serverName] =
|
|
1375
|
+
this.serverTools[serverName] = allItems;
|
|
1176
1376
|
this.initializedServers[serverName] = true;
|
|
1177
1377
|
logger.debug(
|
|
1178
|
-
`Prefetched ${
|
|
1378
|
+
`Prefetched ${allItems.length} items for server '${serverName}': ${tools.length} tools, ${resources.length} resources, ${prompts.length} prompts.`
|
|
1179
1379
|
);
|
|
1180
1380
|
} else {
|
|
1181
1381
|
logger.debug(
|
|
@@ -1923,9 +2123,18 @@ var MCPAgent = class {
|
|
|
1923
2123
|
);
|
|
1924
2124
|
}
|
|
1925
2125
|
} else {
|
|
1926
|
-
|
|
2126
|
+
const tools = await this.adapter.createToolsFromConnectors(
|
|
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];
|
|
1927
2136
|
logger.info(
|
|
1928
|
-
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain
|
|
2137
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain items from client: ${tools.length} tools, ${resources.length} resources, ${prompts.length} prompts`
|
|
1929
2138
|
);
|
|
1930
2139
|
}
|
|
1931
2140
|
this._tools.push(...this.additionalTools);
|
|
@@ -1938,12 +2147,19 @@ var MCPAgent = class {
|
|
|
1938
2147
|
await connector.connect();
|
|
1939
2148
|
}
|
|
1940
2149
|
}
|
|
1941
|
-
|
|
2150
|
+
const tools = await this.adapter.createToolsFromConnectors(
|
|
2151
|
+
this.connectors
|
|
2152
|
+
);
|
|
2153
|
+
const resources = await this.adapter.createResourcesFromConnectors(
|
|
2154
|
+
this.connectors
|
|
2155
|
+
);
|
|
2156
|
+
const prompts = await this.adapter.createPromptsFromConnectors(
|
|
1942
2157
|
this.connectors
|
|
1943
2158
|
);
|
|
2159
|
+
this._tools = [...tools, ...resources, ...prompts];
|
|
1944
2160
|
this._tools.push(...this.additionalTools);
|
|
1945
2161
|
logger.info(
|
|
1946
|
-
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain
|
|
2162
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain items from connectors: ${tools.length} tools, ${resources.length} resources, ${prompts.length} prompts`
|
|
1947
2163
|
);
|
|
1948
2164
|
}
|
|
1949
2165
|
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-NS7PNUAI.js";
|
|
4
4
|
import {
|
|
5
5
|
Tel,
|
|
6
6
|
generateUUID,
|
|
7
7
|
getPackageVersion
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ES5N2BQY.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-BO2DLS2U.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-ES5N2BQY.js";
|
|
11
11
|
import {
|
|
12
12
|
__name
|
|
13
13
|
} from "./chunk-3GQAWCBQ.js";
|
package/dist/index.cjs
CHANGED
|
@@ -1884,6 +1884,98 @@ 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
|
+
}
|
|
1887
1979
|
/**
|
|
1888
1980
|
* Check if a connector is initialized and has tools.
|
|
1889
1981
|
*
|
|
@@ -1962,6 +2054,99 @@ var LangChainAdapter = class extends BaseAdapter {
|
|
|
1962
2054
|
});
|
|
1963
2055
|
return tool;
|
|
1964
2056
|
}
|
|
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
|
+
}
|
|
1965
2150
|
};
|
|
1966
2151
|
|
|
1967
2152
|
// src/agents/mcp_agent.ts
|
|
@@ -2101,15 +2286,21 @@ var ConnectMCPServerTool = class extends MCPServerTool {
|
|
|
2101
2286
|
session = await this.manager.client.createSession(serverName);
|
|
2102
2287
|
}
|
|
2103
2288
|
this.manager.activeServer = serverName;
|
|
2104
|
-
if (this.manager.serverTools[serverName]) {
|
|
2289
|
+
if (!this.manager.serverTools[serverName]) {
|
|
2105
2290
|
const connector = session.connector;
|
|
2106
2291
|
const tools = await this.manager.adapter.createToolsFromConnectors([connector]);
|
|
2107
|
-
this.manager.
|
|
2292
|
+
const resources = await this.manager.adapter.createResourcesFromConnectors([connector]);
|
|
2293
|
+
const prompts = await this.manager.adapter.createPromptsFromConnectors([connector]);
|
|
2294
|
+
const allItems = [...tools, ...resources, ...prompts];
|
|
2295
|
+
this.manager.serverTools[serverName] = allItems;
|
|
2108
2296
|
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
|
+
);
|
|
2109
2300
|
}
|
|
2110
2301
|
const serverTools = this.manager.serverTools[serverName] || [];
|
|
2111
2302
|
const numTools = serverTools.length;
|
|
2112
|
-
return `Connected to MCP server '${serverName}'. ${numTools} tools are now available.`;
|
|
2303
|
+
return `Connected to MCP server '${serverName}'. ${numTools} tools, resources, and prompts are now available.`;
|
|
2113
2304
|
} catch (error) {
|
|
2114
2305
|
logger.error(
|
|
2115
2306
|
`Error connecting to server '${serverName}': ${String(error)}`
|
|
@@ -2271,21 +2462,30 @@ var ServerManager = class {
|
|
|
2271
2462
|
if (session) {
|
|
2272
2463
|
const connector = session.connector;
|
|
2273
2464
|
let tools = [];
|
|
2465
|
+
let resources = [];
|
|
2466
|
+
let prompts = [];
|
|
2274
2467
|
try {
|
|
2275
2468
|
tools = await this.adapter.createToolsFromConnectors([connector]);
|
|
2469
|
+
resources = await this.adapter.createResourcesFromConnectors([
|
|
2470
|
+
connector
|
|
2471
|
+
]);
|
|
2472
|
+
prompts = await this.adapter.createPromptsFromConnectors([
|
|
2473
|
+
connector
|
|
2474
|
+
]);
|
|
2276
2475
|
} catch (toolFetchError) {
|
|
2277
2476
|
logger.error(
|
|
2278
|
-
`Failed to create tools from connector for server '${serverName}': ${toolFetchError}`
|
|
2477
|
+
`Failed to create tools/resources/prompts from connector for server '${serverName}': ${toolFetchError}`
|
|
2279
2478
|
);
|
|
2280
2479
|
continue;
|
|
2281
2480
|
}
|
|
2481
|
+
const allItems = [...tools, ...resources, ...prompts];
|
|
2282
2482
|
const cachedTools = this.serverTools[serverName];
|
|
2283
|
-
const toolsChanged = !cachedTools || !isEqual(cachedTools,
|
|
2483
|
+
const toolsChanged = !cachedTools || !isEqual(cachedTools, allItems);
|
|
2284
2484
|
if (toolsChanged) {
|
|
2285
|
-
this.serverTools[serverName] =
|
|
2485
|
+
this.serverTools[serverName] = allItems;
|
|
2286
2486
|
this.initializedServers[serverName] = true;
|
|
2287
2487
|
logger.debug(
|
|
2288
|
-
`Prefetched ${
|
|
2488
|
+
`Prefetched ${allItems.length} items for server '${serverName}': ${tools.length} tools, ${resources.length} resources, ${prompts.length} prompts.`
|
|
2289
2489
|
);
|
|
2290
2490
|
} else {
|
|
2291
2491
|
logger.debug(
|
|
@@ -2876,7 +3076,7 @@ __name(generateUUID, "generateUUID");
|
|
|
2876
3076
|
init_logging();
|
|
2877
3077
|
|
|
2878
3078
|
// src/version.ts
|
|
2879
|
-
var VERSION = "1.10.
|
|
3079
|
+
var VERSION = "1.10.1-canary.1";
|
|
2880
3080
|
function getPackageVersion() {
|
|
2881
3081
|
return VERSION;
|
|
2882
3082
|
}
|
|
@@ -4060,9 +4260,18 @@ var MCPAgent = class {
|
|
|
4060
4260
|
);
|
|
4061
4261
|
}
|
|
4062
4262
|
} else {
|
|
4063
|
-
|
|
4263
|
+
const tools = await this.adapter.createToolsFromConnectors(
|
|
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];
|
|
4064
4273
|
logger.info(
|
|
4065
|
-
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain
|
|
4274
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain items from client: ${tools.length} tools, ${resources.length} resources, ${prompts.length} prompts`
|
|
4066
4275
|
);
|
|
4067
4276
|
}
|
|
4068
4277
|
this._tools.push(...this.additionalTools);
|
|
@@ -4075,12 +4284,19 @@ var MCPAgent = class {
|
|
|
4075
4284
|
await connector.connect();
|
|
4076
4285
|
}
|
|
4077
4286
|
}
|
|
4078
|
-
|
|
4287
|
+
const tools = await this.adapter.createToolsFromConnectors(
|
|
4288
|
+
this.connectors
|
|
4289
|
+
);
|
|
4290
|
+
const resources = await this.adapter.createResourcesFromConnectors(
|
|
4291
|
+
this.connectors
|
|
4292
|
+
);
|
|
4293
|
+
const prompts = await this.adapter.createPromptsFromConnectors(
|
|
4079
4294
|
this.connectors
|
|
4080
4295
|
);
|
|
4296
|
+
this._tools = [...tools, ...resources, ...prompts];
|
|
4081
4297
|
this._tools.push(...this.additionalTools);
|
|
4082
4298
|
logger.info(
|
|
4083
|
-
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain
|
|
4299
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain items from connectors: ${tools.length} tools, ${resources.length} resources, ${prompts.length} prompts`
|
|
4084
4300
|
);
|
|
4085
4301
|
}
|
|
4086
4302
|
logger.info(`\u{1F9F0} Found ${this._tools.length} tools across all connectors`);
|