@mcp-use/agent 2.0.0-beta.18 → 2.0.0-beta.19

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 (70) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/adapters/base.d.ts +31 -28
  3. package/dist/adapters/base.d.ts.map +1 -1
  4. package/dist/adapters/index.d.ts +1 -1
  5. package/dist/adapters/index.d.ts.map +1 -1
  6. package/dist/adapters/langchain_adapter.d.ts +10 -0
  7. package/dist/adapters/langchain_adapter.d.ts.map +1 -1
  8. package/dist/adapters/native_adapter.d.ts +27 -2
  9. package/dist/adapters/native_adapter.d.ts.map +1 -1
  10. package/dist/agents/agent_options.d.ts +47 -4
  11. package/dist/agents/agent_options.d.ts.map +1 -1
  12. package/dist/agents/mcp_agent.d.ts +85 -14
  13. package/dist/agents/mcp_agent.d.ts.map +1 -1
  14. package/dist/agents/mcp_agent_langchain.d.ts +102 -37
  15. package/dist/agents/mcp_agent_langchain.d.ts.map +1 -1
  16. package/dist/agents/prompts/index.d.ts +7 -0
  17. package/dist/agents/prompts/index.d.ts.map +1 -1
  18. package/dist/agents/remote.d.ts +39 -14
  19. package/dist/agents/remote.d.ts.map +1 -1
  20. package/dist/agents/run_options.d.ts +15 -0
  21. package/dist/agents/run_options.d.ts.map +1 -1
  22. package/dist/agents/types.d.ts +45 -23
  23. package/dist/agents/types.d.ts.map +1 -1
  24. package/dist/agents/utils/ai_sdk.d.ts +14 -5
  25. package/dist/agents/utils/ai_sdk.d.ts.map +1 -1
  26. package/dist/agents/utils/index.d.ts +1 -1
  27. package/dist/agents/utils/index.d.ts.map +1 -1
  28. package/dist/agents/utils/llm_provider.d.ts +31 -23
  29. package/dist/agents/utils/llm_provider.d.ts.map +1 -1
  30. package/dist/index.d.ts +10 -5
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +100 -21
  33. package/dist/index.js.map +1 -1
  34. package/dist/langchain.d.ts +6 -2
  35. package/dist/langchain.d.ts.map +1 -1
  36. package/dist/langchain.js +195 -44
  37. package/dist/langchain.js.map +1 -1
  38. package/dist/llm/chat.d.ts +8 -1
  39. package/dist/llm/chat.d.ts.map +1 -1
  40. package/dist/llm/messageFormat.d.ts +36 -6
  41. package/dist/llm/messageFormat.d.ts.map +1 -1
  42. package/dist/llm/provider_config.d.ts +25 -1
  43. package/dist/llm/provider_config.d.ts.map +1 -1
  44. package/dist/llm/providers/ollama/utils.d.ts +22 -0
  45. package/dist/llm/providers/ollama/utils.d.ts.map +1 -1
  46. package/dist/llm/providers/openai-chat-completions.d.ts +8 -1
  47. package/dist/llm/providers/openai-chat-completions.d.ts.map +1 -1
  48. package/dist/llm/types.d.ts +85 -18
  49. package/dist/llm/types.d.ts.map +1 -1
  50. package/dist/managers/server_manager.d.ts +30 -0
  51. package/dist/managers/server_manager.d.ts.map +1 -1
  52. package/dist/managers/tools/acquire_active_mcp_server.d.ts +5 -0
  53. package/dist/managers/tools/acquire_active_mcp_server.d.ts.map +1 -1
  54. package/dist/managers/tools/add_server_from_config.d.ts +12 -0
  55. package/dist/managers/tools/add_server_from_config.d.ts.map +1 -1
  56. package/dist/managers/tools/base.d.ts +7 -0
  57. package/dist/managers/tools/base.d.ts.map +1 -1
  58. package/dist/managers/tools/connect_mcp_server.d.ts +9 -0
  59. package/dist/managers/tools/connect_mcp_server.d.ts.map +1 -1
  60. package/dist/managers/tools/list_mcp_servers.d.ts +5 -0
  61. package/dist/managers/tools/list_mcp_servers.d.ts.map +1 -1
  62. package/dist/managers/tools/release_mcp_server_connection.d.ts +5 -0
  63. package/dist/managers/tools/release_mcp_server_connection.d.ts.map +1 -1
  64. package/dist/managers/types.d.ts +9 -0
  65. package/dist/managers/types.d.ts.map +1 -1
  66. package/dist/observability/index.d.ts +1 -1
  67. package/dist/observability/index.d.ts.map +1 -1
  68. package/dist/observability/manager.d.ts +20 -8
  69. package/dist/observability/manager.d.ts.map +1 -1
  70. package/package.json +1 -2
@@ -1,14 +1,18 @@
1
1
  /**
2
- * LangChain bridge for @mcp-use/agent.
2
+ * LangChain bridge for `@mcp-use/agent`.
3
3
  */
4
4
  export { MCPAgent } from "./agents/mcp_agent_langchain.js";
5
5
  /** @deprecated Import `MCPAgent` from `@mcp-use/agent/langchain` instead. */
6
6
  export { MCPAgent as LangChainMCPAgent } from "./agents/mcp_agent_langchain.js";
7
7
  export { PROMPTS } from "./agents/prompts/index.js";
8
+ export type { AgentStep as LangChainAgentStep, LangChainAgentAction, } from "./agents/mcp_agent_langchain.js";
9
+ export type { BaseMessage, CommonAgentOptions, ExplicitModeOptions, LanguageModel, MCPAgentOptions, MCPServerConfig, SimplifiedModeOptions, } from "./agents/types.js";
10
+ export type { RunOptions } from "./agents/run_options.js";
8
11
  export { LangChainAdapter } from "./adapters/langchain_adapter.js";
9
12
  export { ServerManager } from "./managers/server_manager.js";
13
+ export type { IServerManager } from "./managers/types.js";
10
14
  export * from "./managers/tools/index.js";
11
15
  export * from "./agents/utils/index.js";
12
- export { type ObservabilityConfig, ObservabilityManager, } from "./observability/index.js";
16
+ export { type ObservabilityConfig, ObservabilityManager, type ObservabilityStatus, } from "./observability/index.js";
13
17
  export { createLLMFromString, parseLLMString, getSupportedProviders, } from "./agents/utils/llm_provider.js";
14
18
  //# sourceMappingURL=langchain.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"langchain.d.ts","sourceRoot":"","sources":["../src/langchain.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,6EAA6E;AAC7E,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,KAAK,mBAAmB,EACxB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,qBAAqB,GACtB,MAAM,gCAAgC,CAAC"}
1
+ {"version":3,"file":"langchain.d.ts","sourceRoot":"","sources":["../src/langchain.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,6EAA6E;AAC7E,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,YAAY,EACV,SAAS,IAAI,kBAAkB,EAC/B,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,eAAe,EACf,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,KAAK,mBAAmB,EACxB,oBAAoB,EACpB,KAAK,mBAAmB,GACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,qBAAqB,GACtB,MAAM,gCAAgC,CAAC"}
package/dist/langchain.js CHANGED
@@ -692,6 +692,9 @@ var BaseAdapter = class {
692
692
  * generated for it.
693
693
  */
694
694
  connectorToolMap = /* @__PURE__ */ new Map();
695
+ /**
696
+ * @param disallowedTools - MCP tool names to omit during conversion.
697
+ */
695
698
  constructor(disallowedTools) {
696
699
  this.disallowedTools = disallowedTools ?? [];
697
700
  }
@@ -701,9 +704,9 @@ var BaseAdapter = class {
701
704
  * This is the recommended way to create tools from an MCPClient, as it handles
702
705
  * session creation and connector extraction automatically.
703
706
  *
704
- * @param client The MCPClient to extract tools from.
705
- * @param disallowedTools Optional list of tool names to exclude.
706
- * @returns A promise that resolves with a list of converted tools.
707
+ * @param client - The MCPClient to extract tools from.
708
+ * @param disallowedTools - Optional list of tool names to exclude.
709
+ * @returns A promise that resolves with a list of converted tools.
707
710
  */
708
711
  static async createTools(client, disallowedTools) {
709
712
  const adapter = new this(disallowedTools);
@@ -720,8 +723,8 @@ var BaseAdapter = class {
720
723
  /**
721
724
  * Dynamically load tools for a specific connector.
722
725
  *
723
- * @param connector The connector to load tools for.
724
- * @returns The list of tools that were loaded in the target framework's format.
726
+ * @param connector - The connector to load tools for.
727
+ * @returns The list of tools that were loaded in the target framework's format.
725
728
  */
726
729
  async loadToolsForConnector(connector) {
727
730
  if (this.connectorToolMap.has(connector)) {
@@ -749,8 +752,8 @@ var BaseAdapter = class {
749
752
  /**
750
753
  * Create tools from MCP tools in all provided connectors.
751
754
  *
752
- * @param connectors List of MCP connectors to create tools from.
753
- * @returns A promise that resolves with all converted tools.
755
+ * @param connectors - List of MCP connectors to create tools from.
756
+ * @returns A promise that resolves with all converted tools.
754
757
  */
755
758
  async createToolsFromConnectors(connectors) {
756
759
  const tools = [];
@@ -764,8 +767,8 @@ var BaseAdapter = class {
764
767
  /**
765
768
  * Dynamically load resources for a specific connector.
766
769
  *
767
- * @param connector The connector to load resources for.
768
- * @returns The list of resources that were loaded in the target framework's format.
770
+ * @param connector - The connector to load resources for.
771
+ * @returns The list of resources that were loaded in the target framework's format.
769
772
  */
770
773
  async loadResourcesForConnector(connector) {
771
774
  const connectorResources = [];
@@ -795,8 +798,8 @@ var BaseAdapter = class {
795
798
  /**
796
799
  * Dynamically load prompts for a specific connector.
797
800
  *
798
- * @param connector The connector to load prompts for.
799
- * @returns The list of prompts that were loaded in the target framework's format.
801
+ * @param connector - The connector to load prompts for.
802
+ * @returns The list of prompts that were loaded in the target framework's format.
800
803
  */
801
804
  async loadPromptsForConnector(connector) {
802
805
  const connectorPrompts = [];
@@ -826,8 +829,8 @@ var BaseAdapter = class {
826
829
  /**
827
830
  * Create resources from MCP resources in all provided connectors.
828
831
  *
829
- * @param connectors List of MCP connectors to create resources from.
830
- * @returns A promise that resolves with all converted resources.
832
+ * @param connectors - List of MCP connectors to create resources from.
833
+ * @returns A promise that resolves with all converted resources.
831
834
  */
832
835
  async createResourcesFromConnectors(connectors) {
833
836
  const resources = [];
@@ -841,8 +844,8 @@ var BaseAdapter = class {
841
844
  /**
842
845
  * Create prompts from MCP prompts in all provided connectors.
843
846
  *
844
- * @param connectors List of MCP connectors to create prompts from.
845
- * @returns A promise that resolves with all converted prompts.
847
+ * @param connectors - List of MCP connectors to create prompts from.
848
+ * @returns A promise that resolves with all converted prompts.
846
849
  */
847
850
  async createPromptsFromConnectors(connectors) {
848
851
  const prompts = [];
@@ -856,8 +859,8 @@ var BaseAdapter = class {
856
859
  /**
857
860
  * Check if a connector is initialized and has tools.
858
861
  *
859
- * @param connector The connector to check.
860
- * @returns True if the connector is initialized and has tools, false otherwise.
862
+ * @param connector - The connector to check.
863
+ * @returns True if the connector is initialized and has tools, false otherwise.
861
864
  */
862
865
  checkConnectorInitialized(connector) {
863
866
  return Boolean(connector.tools && connector.tools.length);
@@ -865,8 +868,8 @@ var BaseAdapter = class {
865
868
  /**
866
869
  * Ensure a connector is initialized.
867
870
  *
868
- * @param connector The connector to initialize.
869
- * @returns True if initialization succeeded, false otherwise.
871
+ * @param connector - The connector to initialize.
872
+ * @returns True if initialization succeeded, false otherwise.
870
873
  */
871
874
  async ensureConnectorInitialized(connector) {
872
875
  if (!this.checkConnectorInitialized(connector)) {
@@ -897,6 +900,9 @@ function sanitizeToolName(name) {
897
900
  }
898
901
  var LangChainAdapter = class extends BaseAdapter {
899
902
  usedToolNames = /* @__PURE__ */ new Set();
903
+ /**
904
+ * @param disallowedTools - MCP tool names to omit during conversion.
905
+ */
900
906
  constructor(disallowedTools = []) {
901
907
  super(disallowedTools);
902
908
  }
@@ -923,6 +929,12 @@ var LangChainAdapter = class extends BaseAdapter {
923
929
  this.usedToolNames.add(fallback);
924
930
  return fallback;
925
931
  }
932
+ /**
933
+ * Converts MCP tools from all connectors and resets name deduplication.
934
+ *
935
+ * @param connectors - Connected MCP connectors.
936
+ * @returns LangChain structured tools.
937
+ */
926
938
  async createToolsFromConnectors(connectors) {
927
939
  this.usedToolNames.clear();
928
940
  return super.createToolsFromConnectors(connectors);
@@ -1064,10 +1076,16 @@ import { z as z2 } from "zod";
1064
1076
  // src/managers/tools/base.ts
1065
1077
  import { StructuredTool } from "@langchain/core/tools";
1066
1078
  var MCPServerTool = class extends StructuredTool {
1079
+ /** Default tool name. Subclasses replace this value. */
1067
1080
  name = "mcp_server_tool";
1081
+ /** Default tool description. Subclasses replace this value. */
1068
1082
  description = "Base tool for MCP server operations.";
1083
+ /** Input schema supplied by the concrete management tool. */
1069
1084
  schema;
1070
1085
  _manager;
1086
+ /**
1087
+ * @param manager - Server manager operated by this tool.
1088
+ */
1071
1089
  constructor(manager) {
1072
1090
  super();
1073
1091
  this._manager = manager;
@@ -1075,6 +1093,7 @@ var MCPServerTool = class extends StructuredTool {
1075
1093
  async _call(_arg, _runManager, _parentConfig) {
1076
1094
  throw new Error("Method not implemented.");
1077
1095
  }
1096
+ /** @returns The server manager operated by this tool. */
1078
1097
  get manager() {
1079
1098
  return this._manager;
1080
1099
  }
@@ -1083,12 +1102,16 @@ var MCPServerTool = class extends StructuredTool {
1083
1102
  // src/managers/tools/acquire_active_mcp_server.ts
1084
1103
  var PresentActiveServerSchema = z2.object({});
1085
1104
  var AcquireActiveMCPServerTool = class extends MCPServerTool {
1105
+ /** Tool name exposed to the model. */
1086
1106
  name = "get_active_mcp_server";
1107
+ /** Tool description exposed to the model. */
1087
1108
  description = "Get the currently active MCP (Model Context Protocol) server";
1109
+ /** Empty input schema. */
1088
1110
  schema = PresentActiveServerSchema;
1089
1111
  constructor(manager) {
1090
1112
  super(manager);
1091
1113
  }
1114
+ /** @returns A message identifying the active server, or stating there is none. */
1092
1115
  async _call() {
1093
1116
  if (!this.manager.activeServer) {
1094
1117
  return `No MCP server is currently active. Use connect_to_mcp_server to connect to a server.`;
@@ -1102,19 +1125,32 @@ import { StructuredTool as StructuredTool2 } from "@langchain/core/tools";
1102
1125
  import { z as z3 } from "zod";
1103
1126
  import { logger as logger3 } from "@mcp-use/client";
1104
1127
  var AddMCPServerFromConfigTool = class extends StructuredTool2 {
1128
+ /** Tool name exposed to the model. */
1105
1129
  name = "add_mcp_server_from_config";
1130
+ /** Tool description exposed to the model. */
1106
1131
  description = "Adds a new MCP server to the client from a configuration object and connects to it, making its tools available.";
1132
+ /** Input schema for the server name and transport configuration. */
1107
1133
  schema = z3.object({
1134
+ /** Name used to register the server with the MCP client. */
1108
1135
  serverName: z3.string().describe("The name for the new MCP server."),
1136
+ /** MCP transport configuration without a top-level `mcpServers` key. */
1109
1137
  serverConfig: z3.any().describe(
1110
1138
  'The configuration object for the server. This should not include the top-level "mcpServers" key.'
1111
1139
  )
1112
1140
  });
1113
1141
  manager;
1142
+ /**
1143
+ * @param manager - Server manager that receives the new server.
1144
+ */
1114
1145
  constructor(manager) {
1115
1146
  super();
1116
1147
  this.manager = manager;
1117
1148
  }
1149
+ /**
1150
+ * Adds the server, opens a session, and makes the server active.
1151
+ *
1152
+ * @returns A success message with loaded tool names, or an error message.
1153
+ */
1118
1154
  async _call({
1119
1155
  serverName,
1120
1156
  serverConfig
@@ -1151,15 +1187,24 @@ ${tools.map((t) => t.name).join("\n")}`;
1151
1187
  import { z as z4 } from "zod";
1152
1188
  import { logger as logger4 } from "@mcp-use/client";
1153
1189
  var ConnectMCPServerSchema = z4.object({
1190
+ /** Name of a configured MCP server. */
1154
1191
  serverName: z4.string().describe("The name of the MCP server.")
1155
1192
  });
1156
1193
  var ConnectMCPServerTool = class extends MCPServerTool {
1194
+ /** Tool name exposed to the model. */
1157
1195
  name = "connect_to_mcp_server";
1196
+ /** Tool description exposed to the model. */
1158
1197
  description = "Connect to a specific MCP (Model Context Protocol) server to use its tools. Use this tool to connect to a specific server and use its tools.";
1198
+ /** Input schema containing the server name. */
1159
1199
  schema = ConnectMCPServerSchema;
1160
1200
  constructor(manager) {
1161
1201
  super(manager);
1162
1202
  }
1203
+ /**
1204
+ * Activates a configured server and loads its capabilities if needed.
1205
+ *
1206
+ * @returns A human-readable success or error message.
1207
+ */
1163
1208
  async _call({ serverName }) {
1164
1209
  const serverNames = this.manager.client.getServerNames();
1165
1210
  if (!serverNames.includes(serverName)) {
@@ -1206,12 +1251,16 @@ import { z as z5 } from "zod";
1206
1251
  import { logger as logger5 } from "@mcp-use/client";
1207
1252
  var EnumerateServersSchema = z5.object({});
1208
1253
  var ListMCPServersTool = class extends MCPServerTool {
1254
+ /** Tool name exposed to the model. */
1209
1255
  name = "list_mcp_servers";
1256
+ /** Tool description exposed to the model. */
1210
1257
  description = `Lists all available MCP (Model Context Protocol) servers that can be connected to, along with the tools available on each server. Use this tool to discover servers and see what functionalities they offer.`;
1258
+ /** Empty input schema. */
1211
1259
  schema = EnumerateServersSchema;
1212
1260
  constructor(manager) {
1213
1261
  super(manager);
1214
1262
  }
1263
+ /** @returns A formatted list of configured servers and capability counts. */
1215
1264
  async _call() {
1216
1265
  const serverNames = this.manager.client.getServerNames();
1217
1266
  if (serverNames.length === 0) {
@@ -1241,12 +1290,16 @@ var ListMCPServersTool = class extends MCPServerTool {
1241
1290
  import { z as z6 } from "zod";
1242
1291
  var ReleaseConnectionSchema = z6.object({});
1243
1292
  var ReleaseMCPServerConnectionTool = class extends MCPServerTool {
1293
+ /** Tool name exposed to the model. */
1244
1294
  name = "disconnect_from_mcp_server";
1295
+ /** Tool description exposed to the model. */
1245
1296
  description = "Disconnect from the currently active MCP (Model Context Protocol) server";
1297
+ /** Empty input schema. */
1246
1298
  schema = ReleaseConnectionSchema;
1247
1299
  constructor(manager) {
1248
1300
  super(manager);
1249
1301
  }
1302
+ /** @returns A message identifying the deactivated server, or stating there is none. */
1250
1303
  async _call() {
1251
1304
  if (!this.manager.activeServer) {
1252
1305
  return `No MCP server is currently active, so there's nothing to disconnect from.`;
@@ -1280,23 +1333,44 @@ function isEqual(a, b) {
1280
1333
  return false;
1281
1334
  }
1282
1335
  var ServerManager = class {
1336
+ /** Whether capabilities have been loaded for each configured server. */
1283
1337
  initializedServers = {};
1338
+ /** Cached LangChain tools, resources, and prompts by server name. */
1284
1339
  serverTools = {};
1340
+ /** MCP client that owns server configurations and sessions. */
1285
1341
  client;
1342
+ /** Adapter used to create LangChain tools. */
1286
1343
  adapter;
1344
+ /** Server whose cached tools are currently exposed. */
1287
1345
  activeServer = null;
1288
1346
  overrideManagementTools;
1347
+ /**
1348
+ * @param client - MCP client that owns the managed servers.
1349
+ * @param adapter - Adapter used to convert MCP capabilities.
1350
+ * @param managementTools - Optional replacement for the built-in server
1351
+ * management tools.
1352
+ */
1289
1353
  constructor(client, adapter, managementTools) {
1290
1354
  this.client = client;
1291
1355
  this.adapter = adapter;
1292
1356
  this.overrideManagementTools = managementTools;
1293
1357
  }
1358
+ /**
1359
+ * Replaces the management tools returned by {@link ServerManager.tools}.
1360
+ *
1361
+ * @param tools - Complete replacement tool list.
1362
+ */
1294
1363
  setManagementTools(tools) {
1295
1364
  this.overrideManagementTools = tools;
1296
1365
  logger6.debug(
1297
1366
  `Overriding default management tools with a new set of ${tools.length} tools.`
1298
1367
  );
1299
1368
  }
1369
+ /**
1370
+ * Writes current connection and tool-cache state at debug level.
1371
+ *
1372
+ * @param context - Label describing why the state was logged.
1373
+ */
1300
1374
  logState(context) {
1301
1375
  const allServerNames = this.client.getServerNames();
1302
1376
  const activeSessionNames = Object.keys(this.client.getAllActiveSessions());
@@ -1314,12 +1388,17 @@ var ServerManager = class {
1314
1388
  logger6.debug(`Server Manager State: [${context}]`);
1315
1389
  console.table(tableData);
1316
1390
  }
1391
+ /** Validates that the client contains at least one server configuration. */
1317
1392
  initialize() {
1318
1393
  const serverNames = this.client.getServerNames?.();
1319
1394
  if (serverNames.length === 0) {
1320
1395
  logger6.warn("No MCP servers defined in client configuration");
1321
1396
  }
1322
1397
  }
1398
+ /**
1399
+ * Connects configured servers as needed and caches all tools, resources, and
1400
+ * prompts.
1401
+ */
1323
1402
  async prefetchServerTools() {
1324
1403
  const servers = this.client.getServerNames();
1325
1404
  for (const serverName of servers) {
@@ -1381,6 +1460,9 @@ var ServerManager = class {
1381
1460
  }
1382
1461
  }
1383
1462
  }
1463
+ /**
1464
+ * @returns Management tools plus cached tools from the active server, if any.
1465
+ */
1384
1466
  get tools() {
1385
1467
  if (logger6.level === "debug") {
1386
1468
  this.logState("Providing tools to agent");
@@ -1419,6 +1501,9 @@ var ObservabilityManager = class {
1419
1501
  metadata;
1420
1502
  metadataProvider;
1421
1503
  tagsProvider;
1504
+ /**
1505
+ * @param config - Callback selection and trace metadata settings.
1506
+ */
1422
1507
  constructor(config = {}) {
1423
1508
  this.customCallbacks = config.customCallbacks;
1424
1509
  this.verbose = config.verbose ?? false;
@@ -1536,7 +1621,7 @@ var ObservabilityManager = class {
1536
1621
  }
1537
1622
  /**
1538
1623
  * Add a callback to the custom callbacks list.
1539
- * @param callback The callback to add.
1624
+ * @param callback - The callback to add.
1540
1625
  */
1541
1626
  addCallback(callback) {
1542
1627
  if (!this.customCallbacks) {
@@ -1595,7 +1680,7 @@ var ObservabilityManager = class {
1595
1680
  };
1596
1681
 
1597
1682
  // src/version.ts
1598
- var VERSION = "2.0.0-beta.18";
1683
+ var VERSION = "2.0.0-beta.19";
1599
1684
  function getPackageVersion() {
1600
1685
  return VERSION;
1601
1686
  }
@@ -1749,6 +1834,11 @@ var RemoteAgent = class {
1749
1834
  apiKey;
1750
1835
  baseUrl;
1751
1836
  chatId = null;
1837
+ /**
1838
+ * @param options - Hosted agent identifier and API connection settings.
1839
+ * @throws Error if no API key is supplied or available from
1840
+ * `MCP_USE_API_KEY`.
1841
+ */
1752
1842
  constructor(options) {
1753
1843
  this.agentId = options.agentId;
1754
1844
  this.baseUrl = options.baseUrl ?? "https://cloud.manufact.com";
@@ -1974,6 +2064,7 @@ Raw error: ${result}`
1974
2064
  );
1975
2065
  return result;
1976
2066
  }
2067
+ /** Releases local remote-agent state. */
1977
2068
  async close() {
1978
2069
  logger9.debug("\u{1F50C} Remote agent client closed");
1979
2070
  }
@@ -2153,6 +2244,7 @@ var MCPAgent = class {
2153
2244
  memoryEnabled;
2154
2245
  disallowedTools;
2155
2246
  additionalTools;
2247
+ /** Names of tools invoked during the current or most recent execution. */
2156
2248
  toolsUsedNames = [];
2157
2249
  exposeResourcesAsTools = true;
2158
2250
  exposePromptsAsTools = true;
@@ -2174,6 +2266,7 @@ var MCPAgent = class {
2174
2266
  modelProvider;
2175
2267
  modelName;
2176
2268
  // Observability support
2269
+ /** Observability callbacks and trace lifecycle manager. */
2177
2270
  observabilityManager;
2178
2271
  callbacks = [];
2179
2272
  metadata = {};
@@ -2187,6 +2280,13 @@ var MCPAgent = class {
2187
2280
  llmConfig;
2188
2281
  mcpServersConfig;
2189
2282
  clientOwnedByAgent = false;
2283
+ /**
2284
+ * Creates a LangChain MCP agent.
2285
+ *
2286
+ * @param options - Model, MCP servers, tools, and execution settings.
2287
+ * @throws Error if local execution does not include a model and MCP client,
2288
+ * connectors, or server configurations.
2289
+ */
2190
2290
  constructor(options) {
2191
2291
  if (options.agentId) {
2192
2292
  this.isRemote = true;
@@ -2312,6 +2412,12 @@ var MCPAgent = class {
2312
2412
  configurable: true
2313
2413
  });
2314
2414
  }
2415
+ /**
2416
+ * Creates configured clients and models, connects MCP servers, loads tools,
2417
+ * and builds the LangChain executor.
2418
+ *
2419
+ * @throws Error if a configured model or MCP server cannot be initialized.
2420
+ */
2315
2421
  async initialize() {
2316
2422
  if (this.isRemote) {
2317
2423
  this._initialized = true;
@@ -2487,18 +2593,26 @@ var MCPAgent = class {
2487
2593
  );
2488
2594
  return agent;
2489
2595
  }
2596
+ /** @returns A shallow copy of the stored LangChain message history. */
2490
2597
  getConversationHistory() {
2491
2598
  return [...this.conversationHistory];
2492
2599
  }
2600
+ /** Clears stored history, retaining the system message when memory is enabled. */
2493
2601
  clearConversationHistory() {
2494
2602
  this.conversationHistory = this.memoryEnabled && this.systemMessage ? [this.systemMessage] : [];
2495
2603
  }
2496
2604
  addToHistory(message) {
2497
2605
  if (this.memoryEnabled) this.conversationHistory.push(message);
2498
2606
  }
2607
+ /** @returns The current LangChain system message, or `null` before creation. */
2499
2608
  getSystemMessage() {
2500
2609
  return this.systemMessage;
2501
2610
  }
2611
+ /**
2612
+ * Replaces the system instruction and rebuilds an initialized executor.
2613
+ *
2614
+ * @param message - New system instruction.
2615
+ */
2502
2616
  setSystemMessage(message) {
2503
2617
  this.systemMessage = new SystemMessage2(message);
2504
2618
  if (this.memoryEnabled) {
@@ -2512,6 +2626,11 @@ var MCPAgent = class {
2512
2626
  logger11.debug("Agent recreated with new system message");
2513
2627
  }
2514
2628
  }
2629
+ /**
2630
+ * Replaces the tool denylist for the next initialization.
2631
+ *
2632
+ * @param disallowedTools - MCP tool names to omit.
2633
+ */
2515
2634
  setDisallowedTools(disallowedTools) {
2516
2635
  this.disallowedTools = disallowedTools;
2517
2636
  this.adapter = new LangChainAdapter(this.disallowedTools);
@@ -2521,6 +2640,7 @@ var MCPAgent = class {
2521
2640
  );
2522
2641
  }
2523
2642
  }
2643
+ /** @returns The configured MCP tool denylist. */
2524
2644
  getDisallowedTools() {
2525
2645
  return this.disallowedTools;
2526
2646
  }
@@ -2710,20 +2830,28 @@ var MCPAgent = class {
2710
2830
  * serialization/deserialization across module boundaries or version mismatches.
2711
2831
  *
2712
2832
  * @example
2713
- * // Real AIMessage instance (standard case)
2714
- * _isAIMessageLike(new AIMessage("hello")) // => true
2833
+ * ```ts
2834
+ * // Real AIMessage instance (standard case).
2835
+ * _isAIMessageLike(new AIMessage("hello")); // true
2836
+ * ```
2715
2837
  *
2716
2838
  * @example
2717
- * // Plain object after serialization (fixes issue #446)
2718
- * _isAIMessageLike({ type: "ai", content: "hello" }) // => true
2839
+ * ```ts
2840
+ * // Plain object after serialization (fixes issue #446).
2841
+ * _isAIMessageLike({ type: "ai", content: "hello" }); // true
2842
+ * ```
2719
2843
  *
2720
2844
  * @example
2721
- * // OpenAI-style format with role
2722
- * _isAIMessageLike({ role: "assistant", content: "hello" }) // => true
2845
+ * ```ts
2846
+ * // OpenAI-style format with role.
2847
+ * _isAIMessageLike({ role: "assistant", content: "hello" }); // true
2848
+ * ```
2723
2849
  *
2724
2850
  * @example
2725
- * // Object with getType() method
2726
- * _isAIMessageLike({ getType: () => "ai", content: "hello" }) // => true
2851
+ * ```ts
2852
+ * // Object with getType() method.
2853
+ * _isAIMessageLike({ getType: () => "ai", content: "hello" }); // true
2854
+ * ```
2727
2855
  *
2728
2856
  * @param message - The message object to check
2729
2857
  * @returns true if the message represents an AI/assistant message
@@ -2767,17 +2895,26 @@ var MCPAgent = class {
2767
2895
  * Safely checks for tool_calls array presence.
2768
2896
  *
2769
2897
  * @example
2770
- * // AIMessage with tool calls
2771
- * const msg = new AIMessage({ content: "", tool_calls: [{ name: "add", args: {} }] });
2772
- * _messageHasToolCalls(msg) // => true
2898
+ * ```ts
2899
+ * const message = new AIMessage({
2900
+ * content: "",
2901
+ * tool_calls: [{ name: "add", args: {} }],
2902
+ * });
2903
+ * _messageHasToolCalls(message); // true
2904
+ * ```
2773
2905
  *
2774
2906
  * @example
2775
- * // Plain object with tool calls
2776
- * _messageHasToolCalls({ type: "ai", tool_calls: [{ name: "add" }] }) // => true
2907
+ * ```ts
2908
+ * _messageHasToolCalls({
2909
+ * type: "ai",
2910
+ * tool_calls: [{ name: "add" }],
2911
+ * }); // true
2912
+ * ```
2777
2913
  *
2778
2914
  * @example
2779
- * // Message without tool calls
2780
- * _messageHasToolCalls({ type: "ai", content: "hello" }) // => false
2915
+ * ```ts
2916
+ * _messageHasToolCalls({ type: "ai", content: "hello" }); // false
2917
+ * ```
2781
2918
  *
2782
2919
  * @param message - The message object to check
2783
2920
  * @returns true if the message has non-empty tool_calls array
@@ -2793,8 +2930,10 @@ var MCPAgent = class {
2793
2930
  * Handles both class instances and plain objects from serialization.
2794
2931
  *
2795
2932
  * @example
2796
- * _isHumanMessageLike(new HumanMessage("hello")) // => true
2797
- * _isHumanMessageLike({ type: "human", content: "hello" }) // => true
2933
+ * ```ts
2934
+ * _isHumanMessageLike(new HumanMessage("hello")); // true
2935
+ * _isHumanMessageLike({ type: "human", content: "hello" }); // true
2936
+ * ```
2798
2937
  *
2799
2938
  * @param message - The message object to check
2800
2939
  * @returns true if the message represents a human message
@@ -2829,8 +2968,14 @@ var MCPAgent = class {
2829
2968
  * Handles both class instances and plain objects from serialization.
2830
2969
  *
2831
2970
  * @example
2832
- * _isToolMessageLike(new ToolMessage({ content: "result", tool_call_id: "123" })) // => true
2833
- * _isToolMessageLike({ type: "tool", content: "result" }) // => true
2971
+ * ```ts
2972
+ * const message = new ToolMessage({
2973
+ * content: "result",
2974
+ * tool_call_id: "123",
2975
+ * });
2976
+ * _isToolMessageLike(message); // true
2977
+ * _isToolMessageLike({ type: "tool", content: "result" }); // true
2978
+ * ```
2834
2979
  *
2835
2980
  * @param message - The message object to check
2836
2981
  * @returns true if the message represents a tool message
@@ -2861,12 +3006,14 @@ var MCPAgent = class {
2861
3006
  * Extract content from a message, handling both AIMessage instances and plain objects.
2862
3007
  *
2863
3008
  * @example
2864
- * // From AIMessage instance
2865
- * _getMessageContent(new AIMessage("hello")) // => "hello"
3009
+ * ```ts
3010
+ * _getMessageContent(new AIMessage("hello")); // "hello"
3011
+ * ```
2866
3012
  *
2867
3013
  * @example
2868
- * // From plain object
2869
- * _getMessageContent({ type: "ai", content: "hello" }) // => "hello"
3014
+ * ```ts
3015
+ * _getMessageContent({ type: "ai", content: "hello" }); // "hello"
3016
+ * ```
2870
3017
  *
2871
3018
  * @param message - The message object to extract content from
2872
3019
  * @returns The content of the message, or undefined if not present
@@ -3209,6 +3356,9 @@ var MCPAgent = class {
3209
3356
  logger11.debug("Flushing observability traces...");
3210
3357
  await this.observabilityManager.flush();
3211
3358
  }
3359
+ /**
3360
+ * Flushes observability, closes owned MCP resources, and resets the executor.
3361
+ */
3212
3362
  async close() {
3213
3363
  if (this.isRemote && this.remoteAgent) {
3214
3364
  await this.remoteAgent.close();
@@ -3686,6 +3836,7 @@ ${formatPrompt}`
3686
3836
  // src/agents/prompts/index.ts
3687
3837
  var CODE_MODE_PROMPT = "Use code execution mode to discover and call MCP tools programmatically.";
3688
3838
  var PROMPTS = {
3839
+ /** Instruction used to enable code-based MCP tool discovery and calls. */
3689
3840
  CODE_MODE: CODE_MODE_PROMPT
3690
3841
  };
3691
3842