@probelabs/probe 0.6.0-rc121 → 0.6.0-rc122

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.
@@ -21339,8 +21339,8 @@ var require_dist_cjs59 = __commonJS({
21339
21339
  module2.exports = __toCommonJS2(index_exports);
21340
21340
  var import_property_provider2 = require_dist_cjs24();
21341
21341
  var import_shared_ini_file_loader = require_dist_cjs42();
21342
- var import_child_process9 = require("child_process");
21343
- var import_util9 = require("util");
21342
+ var import_child_process10 = require("child_process");
21343
+ var import_util10 = require("util");
21344
21344
  var import_client7 = (init_client(), __toCommonJS(client_exports));
21345
21345
  var getValidatedProcessCredentials = /* @__PURE__ */ __name((profileName, data2, profiles) => {
21346
21346
  if (data2.Version !== 1) {
@@ -21376,7 +21376,7 @@ var require_dist_cjs59 = __commonJS({
21376
21376
  if (profiles[profileName]) {
21377
21377
  const credentialProcess = profile["credential_process"];
21378
21378
  if (credentialProcess !== void 0) {
21379
- const execPromise = (0, import_util9.promisify)(import_shared_ini_file_loader.externalDataInterceptor?.getTokenRecord?.().exec ?? import_child_process9.exec);
21379
+ const execPromise = (0, import_util10.promisify)(import_shared_ini_file_loader.externalDataInterceptor?.getTokenRecord?.().exec ?? import_child_process10.exec);
21380
21380
  try {
21381
21381
  const { stdout } = await execPromise(credentialProcess);
21382
21382
  let data2;
@@ -28648,6 +28648,18 @@ var init_extract = __esm({
28648
28648
  }
28649
28649
  });
28650
28650
 
28651
+ // src/grep.js
28652
+ var import_child_process5, import_util7, execFileAsync;
28653
+ var init_grep = __esm({
28654
+ "src/grep.js"() {
28655
+ "use strict";
28656
+ import_child_process5 = require("child_process");
28657
+ import_util7 = require("util");
28658
+ init_utils2();
28659
+ execFileAsync = (0, import_util7.promisify)(import_child_process5.execFile);
28660
+ }
28661
+ });
28662
+
28651
28663
  // src/tools/common.js
28652
28664
  function parseXmlToolCall(xmlString, validTools = DEFAULT_VALID_TOOLS) {
28653
28665
  for (const toolName of validTools) {
@@ -29055,7 +29067,7 @@ async function delegate({ task, timeout = 300, debug = false, currentIteration =
29055
29067
  }
29056
29068
  return new Promise((resolve4, reject2) => {
29057
29069
  const delegationSpan = tracer ? tracer.createDelegationSpan(sessionId, task) : null;
29058
- const process2 = (0, import_child_process5.spawn)(binaryPath, args, {
29070
+ const process2 = (0, import_child_process6.spawn)(binaryPath, args, {
29059
29071
  stdio: ["pipe", "pipe", "pipe"],
29060
29072
  timeout: timeout * 1e3
29061
29073
  });
@@ -29190,11 +29202,11 @@ async function delegate({ task, timeout = 300, debug = false, currentIteration =
29190
29202
  throw new Error(`Delegation setup failed: ${error2.message}`);
29191
29203
  }
29192
29204
  }
29193
- var import_child_process5, import_crypto2;
29205
+ var import_child_process6, import_crypto2;
29194
29206
  var init_delegate = __esm({
29195
29207
  "src/delegate.js"() {
29196
29208
  "use strict";
29197
- import_child_process5 = require("child_process");
29209
+ import_child_process6 = require("child_process");
29198
29210
  import_crypto2 = require("crypto");
29199
29211
  init_utils2();
29200
29212
  init_common2();
@@ -30270,7 +30282,7 @@ async function executeBashCommand(command, options = {}) {
30270
30282
  return;
30271
30283
  }
30272
30284
  const [cmd, ...cmdArgs] = args;
30273
- const child = (0, import_child_process6.spawn)(cmd, cmdArgs, {
30285
+ const child = (0, import_child_process7.spawn)(cmd, cmdArgs, {
30274
30286
  cwd,
30275
30287
  env: processEnv,
30276
30288
  stdio: ["ignore", "pipe", "pipe"],
@@ -30454,11 +30466,11 @@ function validateExecutionOptions(options = {}) {
30454
30466
  warnings
30455
30467
  };
30456
30468
  }
30457
- var import_child_process6, import_path4, import_fs;
30469
+ var import_child_process7, import_path4, import_fs;
30458
30470
  var init_bashExecutor = __esm({
30459
30471
  "src/agent/bashExecutor.js"() {
30460
30472
  "use strict";
30461
- import_child_process6 = require("child_process");
30473
+ import_child_process7 = require("child_process");
30462
30474
  import_path4 = require("path");
30463
30475
  import_fs = require("fs");
30464
30476
  init_bashCommandUtils();
@@ -30890,15 +30902,15 @@ function shouldIgnore(filePath, ignorePatterns) {
30890
30902
  }
30891
30903
  return false;
30892
30904
  }
30893
- var import_fs2, import_path6, import_util7, import_child_process7, execAsync4;
30905
+ var import_fs2, import_path6, import_util8, import_child_process8, execAsync4;
30894
30906
  var init_file_lister = __esm({
30895
30907
  "src/utils/file-lister.js"() {
30896
30908
  "use strict";
30897
30909
  import_fs2 = __toESM(require("fs"), 1);
30898
30910
  import_path6 = __toESM(require("path"), 1);
30899
- import_util7 = require("util");
30900
- import_child_process7 = require("child_process");
30901
- execAsync4 = (0, import_util7.promisify)(import_child_process7.exec);
30911
+ import_util8 = require("util");
30912
+ import_child_process8 = require("child_process");
30913
+ execAsync4 = (0, import_util8.promisify)(import_child_process8.exec);
30902
30914
  }
30903
30915
  });
30904
30916
 
@@ -30972,13 +30984,13 @@ function createWrappedTools(baseTools) {
30972
30984
  }
30973
30985
  return wrappedTools;
30974
30986
  }
30975
- var import_child_process8, import_util8, import_crypto3, import_events, import_fs4, import_fs5, import_path8, import_glob, toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
30987
+ var import_child_process9, import_util9, import_crypto3, import_events, import_fs4, import_fs5, import_path8, import_glob, toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
30976
30988
  var init_probeTool = __esm({
30977
30989
  "src/agent/probeTool.js"() {
30978
30990
  "use strict";
30979
30991
  init_index();
30980
- import_child_process8 = require("child_process");
30981
- import_util8 = require("util");
30992
+ import_child_process9 = require("child_process");
30993
+ import_util9 = require("util");
30982
30994
  import_crypto3 = require("crypto");
30983
30995
  import_events = require("events");
30984
30996
  import_fs4 = __toESM(require("fs"), 1);
@@ -31197,6 +31209,7 @@ var init_index = __esm({
31197
31209
  init_search();
31198
31210
  init_query();
31199
31211
  init_extract();
31212
+ init_grep();
31200
31213
  init_delegate();
31201
31214
  init_utils2();
31202
31215
  init_tools();
@@ -60349,6 +60362,14 @@ function cleanSchemaResponse(response) {
60349
60362
  return response;
60350
60363
  }
60351
60364
  const trimmed = response.trim();
60365
+ const jsonBlockMatch = trimmed.match(/```json\s*\n([\s\S]*?)\n```/);
60366
+ if (jsonBlockMatch) {
60367
+ return jsonBlockMatch[1].trim();
60368
+ }
60369
+ const anyBlockMatch = trimmed.match(/```\s*\n([{\[][\s\S]*?[}\]])\s*```/);
60370
+ if (anyBlockMatch) {
60371
+ return anyBlockMatch[1].trim();
60372
+ }
60352
60373
  const codeBlockPatterns = [
60353
60374
  /```json\s*\n?([{\[][\s\S]*?[}\]])\s*\n?```/,
60354
60375
  /```\s*\n?([{\[][\s\S]*?[}\]])\s*\n?```/,
@@ -61161,8 +61182,8 @@ function loadMCPConfigurationFromPath(configPath) {
61161
61182
  try {
61162
61183
  const content = (0, import_fs6.readFileSync)(configPath, "utf8");
61163
61184
  const config = JSON.parse(content);
61164
- if (process.env.DEBUG === "1") {
61165
- console.error(`[MCP] Loaded configuration from: ${configPath}`);
61185
+ if (process.env.DEBUG === "1" || process.env.DEBUG_MCP === "1") {
61186
+ console.error(`[MCP DEBUG] Loaded configuration from: ${configPath}`);
61166
61187
  }
61167
61188
  return mergeWithEnvironment(config);
61168
61189
  } catch (error2) {
@@ -61188,12 +61209,12 @@ function loadMCPConfiguration() {
61188
61209
  try {
61189
61210
  const content = (0, import_fs6.readFileSync)(configPath, "utf8");
61190
61211
  config = JSON.parse(content);
61191
- if (process.env.DEBUG === "1") {
61192
- console.error(`[MCP] Loaded configuration from: ${configPath}`);
61212
+ if (process.env.DEBUG === "1" || process.env.DEBUG_MCP === "1") {
61213
+ console.error(`[MCP DEBUG] Loaded configuration from: ${configPath}`);
61193
61214
  }
61194
61215
  break;
61195
61216
  } catch (error2) {
61196
- console.error(`[MCP] Failed to parse config from ${configPath}:`, error2.message);
61217
+ console.error(`[MCP ERROR] Failed to parse config from ${configPath}:`, error2.message);
61197
61218
  }
61198
61219
  }
61199
61220
  }
@@ -61269,12 +61290,12 @@ function parseEnabledServers(config) {
61269
61290
  }
61270
61291
  if (server.transport === "stdio") {
61271
61292
  if (!server.command) {
61272
- console.error(`[MCP] Server ${name14} missing required 'command' for stdio transport`);
61293
+ console.error(`[MCP ERROR] Server ${name14} missing required 'command' for stdio transport`);
61273
61294
  continue;
61274
61295
  }
61275
61296
  } else if (["websocket", "sse", "http"].includes(server.transport)) {
61276
61297
  if (!server.url) {
61277
- console.error(`[MCP] Server ${name14} missing required 'url' for ${server.transport} transport`);
61298
+ console.error(`[MCP ERROR] Server ${name14} missing required 'url' for ${server.transport} transport`);
61278
61299
  continue;
61279
61300
  }
61280
61301
  }
@@ -61405,20 +61426,45 @@ var init_client2 = __esm({
61405
61426
  async initialize(config = null) {
61406
61427
  this.config = config || loadMCPConfiguration();
61407
61428
  const servers = parseEnabledServers(this.config);
61429
+ console.error(`[MCP INFO] Found ${servers.length} enabled MCP server${servers.length !== 1 ? "s" : ""}`);
61430
+ if (servers.length === 0) {
61431
+ console.error("[MCP INFO] No MCP servers configured or enabled");
61432
+ console.error("[MCP INFO] 0 MCP tools available");
61433
+ return {
61434
+ connected: 0,
61435
+ total: 0,
61436
+ tools: []
61437
+ };
61438
+ }
61408
61439
  if (this.debug) {
61409
- console.error(`[MCP] Found ${servers.length} enabled servers`);
61440
+ console.error("[MCP DEBUG] Server details:");
61441
+ servers.forEach((server) => {
61442
+ console.error(`[MCP DEBUG] - ${server.name} (${server.transport})`);
61443
+ });
61410
61444
  }
61411
61445
  const connectionPromises = servers.map(
61412
61446
  (server) => this.connectToServer(server).catch((error2) => {
61413
- console.error(`[MCP] Failed to connect to ${server.name}:`, error2.message);
61447
+ console.error(`[MCP ERROR] Failed to connect to ${server.name}:`, error2.message);
61414
61448
  return null;
61415
61449
  })
61416
61450
  );
61417
61451
  const results = await Promise.all(connectionPromises);
61418
61452
  const connectedCount = results.filter(Boolean).length;
61419
- if (this.debug) {
61420
- console.error(`[MCP] Successfully connected to ${connectedCount}/${servers.length} servers`);
61421
- console.error(`[MCP] Total tools available: ${this.tools.size}`);
61453
+ if (connectedCount === 0) {
61454
+ console.error(`[MCP ERROR] Failed to connect to all ${servers.length} server${servers.length !== 1 ? "s" : ""}`);
61455
+ console.error("[MCP INFO] 0 MCP tools available");
61456
+ } else if (connectedCount < servers.length) {
61457
+ console.error(`[MCP INFO] Successfully connected to ${connectedCount}/${servers.length} servers`);
61458
+ console.error(`[MCP INFO] ${this.tools.size} MCP tool${this.tools.size !== 1 ? "s" : ""} available`);
61459
+ } else {
61460
+ console.error(`[MCP INFO] Successfully connected to all ${connectedCount} server${connectedCount !== 1 ? "s" : ""}`);
61461
+ console.error(`[MCP INFO] ${this.tools.size} MCP tool${this.tools.size !== 1 ? "s" : ""} available`);
61462
+ }
61463
+ if (this.debug && this.tools.size > 0) {
61464
+ console.error("[MCP DEBUG] Available tools:");
61465
+ Array.from(this.tools.keys()).forEach((toolName) => {
61466
+ console.error(`[MCP DEBUG] - ${toolName}`);
61467
+ });
61422
61468
  }
61423
61469
  return {
61424
61470
  connected: connectedCount,
@@ -61434,7 +61480,7 @@ var init_client2 = __esm({
61434
61480
  const { name: name14 } = serverConfig;
61435
61481
  try {
61436
61482
  if (this.debug) {
61437
- console.error(`[MCP] Connecting to ${name14} via ${serverConfig.transport}...`);
61483
+ console.error(`[MCP DEBUG] Connecting to ${name14} via ${serverConfig.transport}...`);
61438
61484
  }
61439
61485
  const transport = createTransport(serverConfig);
61440
61486
  const client = new import_client3.Client(
@@ -61453,6 +61499,7 @@ var init_client2 = __esm({
61453
61499
  config: serverConfig
61454
61500
  });
61455
61501
  const toolsResponse = await client.listTools();
61502
+ const toolCount = toolsResponse?.tools?.length || 0;
61456
61503
  if (toolsResponse && toolsResponse.tools) {
61457
61504
  for (const tool3 of toolsResponse.tools) {
61458
61505
  const qualifiedName = `${name14}_${tool3.name}`;
@@ -61462,16 +61509,17 @@ var init_client2 = __esm({
61462
61509
  originalName: tool3.name
61463
61510
  });
61464
61511
  if (this.debug) {
61465
- console.error(`[MCP] Registered tool: ${qualifiedName}`);
61512
+ console.error(`[MCP DEBUG] Registered tool: ${qualifiedName}`);
61466
61513
  }
61467
61514
  }
61468
61515
  }
61469
- if (this.debug) {
61470
- console.error(`[MCP] Connected to ${name14} with ${toolsResponse?.tools?.length || 0} tools`);
61471
- }
61516
+ console.error(`[MCP INFO] Connected to ${name14}: ${toolCount} tool${toolCount !== 1 ? "s" : ""} loaded`);
61472
61517
  return true;
61473
61518
  } catch (error2) {
61474
- console.error(`[MCP] Error connecting to ${name14}:`, error2.message);
61519
+ console.error(`[MCP ERROR] Error connecting to ${name14}:`, error2.message);
61520
+ if (this.debug) {
61521
+ console.error(`[MCP DEBUG] Full error details:`, error2);
61522
+ }
61475
61523
  return false;
61476
61524
  }
61477
61525
  }
@@ -61491,7 +61539,7 @@ var init_client2 = __esm({
61491
61539
  }
61492
61540
  try {
61493
61541
  if (this.debug) {
61494
- console.error(`[MCP] Calling ${toolName} with args:`, args);
61542
+ console.error(`[MCP DEBUG] Calling ${toolName} with args:`, JSON.stringify(args, null, 2));
61495
61543
  }
61496
61544
  const timeout = this.config?.settings?.timeout || 3e4;
61497
61545
  const timeoutPromise = new Promise((_2, reject2) => {
@@ -61506,9 +61554,15 @@ var init_client2 = __esm({
61506
61554
  }),
61507
61555
  timeoutPromise
61508
61556
  ]);
61557
+ if (this.debug) {
61558
+ console.error(`[MCP DEBUG] Tool ${toolName} executed successfully`);
61559
+ }
61509
61560
  return result;
61510
61561
  } catch (error2) {
61511
- console.error(`[MCP] Error calling tool ${toolName}:`, error2);
61562
+ console.error(`[MCP ERROR] Error calling tool ${toolName}:`, error2.message);
61563
+ if (this.debug) {
61564
+ console.error(`[MCP DEBUG] Full error details:`, error2);
61565
+ }
61512
61566
  throw error2;
61513
61567
  }
61514
61568
  }
@@ -61553,20 +61607,32 @@ var init_client2 = __esm({
61553
61607
  */
61554
61608
  async disconnect() {
61555
61609
  const disconnectPromises = [];
61610
+ if (this.clients.size === 0) {
61611
+ if (this.debug) {
61612
+ console.error("[MCP DEBUG] No MCP clients to disconnect");
61613
+ }
61614
+ return;
61615
+ }
61616
+ if (this.debug) {
61617
+ console.error(`[MCP DEBUG] Disconnecting from ${this.clients.size} MCP server${this.clients.size !== 1 ? "s" : ""}...`);
61618
+ }
61556
61619
  for (const [name14, clientInfo] of this.clients.entries()) {
61557
61620
  disconnectPromises.push(
61558
61621
  clientInfo.client.close().then(() => {
61559
61622
  if (this.debug) {
61560
- console.error(`[MCP] Disconnected from ${name14}`);
61623
+ console.error(`[MCP DEBUG] Disconnected from ${name14}`);
61561
61624
  }
61562
61625
  }).catch((error2) => {
61563
- console.error(`[MCP] Error disconnecting from ${name14}:`, error2);
61626
+ console.error(`[MCP ERROR] Error disconnecting from ${name14}:`, error2.message);
61564
61627
  })
61565
61628
  );
61566
61629
  }
61567
61630
  await Promise.all(disconnectPromises);
61568
61631
  this.clients.clear();
61569
61632
  this.tools.clear();
61633
+ if (this.debug) {
61634
+ console.error("[MCP DEBUG] All MCP connections closed");
61635
+ }
61570
61636
  }
61571
61637
  };
61572
61638
  }
@@ -61718,31 +61784,58 @@ var init_xmlBridge = __esm({
61718
61784
  async initialize(config = null) {
61719
61785
  let mcpConfigs = null;
61720
61786
  if (!config) {
61787
+ if (this.debug) {
61788
+ console.error("[MCP DEBUG] No config provided, attempting auto-discovery...");
61789
+ }
61721
61790
  mcpConfigs = loadMCPConfiguration();
61791
+ if (!mcpConfigs || !mcpConfigs.mcpServers || Object.keys(mcpConfigs.mcpServers).length === 0) {
61792
+ console.error("[MCP WARNING] MCP enabled but no configuration found");
61793
+ console.error("[MCP INFO] To use MCP, provide configuration via:");
61794
+ console.error("[MCP INFO] - mcpConfig option when creating ProbeAgent");
61795
+ console.error("[MCP INFO] - mcpConfigPath option pointing to a config file");
61796
+ console.error("[MCP INFO] - Config file in standard locations (~/.mcp/config.json, etc.)");
61797
+ console.error("[MCP INFO] - Environment variable MCP_CONFIG_PATH");
61798
+ }
61722
61799
  } else if (Array.isArray(config)) {
61800
+ if (this.debug) {
61801
+ console.error("[MCP DEBUG] Using deprecated array config format (consider using mcpConfig object)");
61802
+ }
61723
61803
  mcpConfigs = { mcpServers: config };
61724
61804
  } else {
61805
+ if (this.debug) {
61806
+ console.error("[MCP DEBUG] Using provided MCP config object");
61807
+ }
61725
61808
  mcpConfigs = config;
61726
61809
  }
61727
61810
  if (!mcpConfigs || !mcpConfigs.mcpServers || Object.keys(mcpConfigs.mcpServers).length === 0) {
61728
- if (this.debug) {
61729
- console.error("[MCP] No MCP servers configured");
61730
- }
61811
+ console.error("[MCP INFO] 0 MCP tools available");
61731
61812
  return;
61732
61813
  }
61733
61814
  try {
61815
+ if (this.debug) {
61816
+ console.error("[MCP DEBUG] Initializing MCP client manager...");
61817
+ }
61734
61818
  this.mcpManager = new MCPClientManager({ debug: this.debug });
61735
61819
  const result = await this.mcpManager.initialize(mcpConfigs);
61736
61820
  const vercelTools = this.mcpManager.getVercelTools();
61737
61821
  this.mcpTools = vercelTools;
61822
+ const toolCount = Object.keys(vercelTools).length;
61738
61823
  for (const [name14, tool3] of Object.entries(vercelTools)) {
61739
61824
  this.xmlDefinitions[name14] = mcpToolToXmlDefinition(name14, tool3);
61740
61825
  }
61741
- if (this.debug) {
61742
- console.error(`[MCP] Loaded ${Object.keys(vercelTools).length} MCP tools from ${result.connected} server(s)`);
61826
+ if (toolCount === 0) {
61827
+ console.error("[MCP INFO] MCP initialization complete: 0 tools loaded");
61828
+ } else {
61829
+ console.error(`[MCP INFO] MCP initialization complete: ${toolCount} tool${toolCount !== 1 ? "s" : ""} loaded from ${result.connected} server${result.connected !== 1 ? "s" : ""}`);
61830
+ if (this.debug) {
61831
+ console.error("[MCP DEBUG] Tool definitions generated for XML bridge");
61832
+ }
61743
61833
  }
61744
61834
  } catch (error2) {
61745
- console.error("[MCP] Failed to initialize MCP connections:", error2);
61835
+ console.error("[MCP ERROR] Failed to initialize MCP connections:", error2.message);
61836
+ if (this.debug) {
61837
+ console.error("[MCP DEBUG] Full error details:", error2);
61838
+ }
61746
61839
  }
61747
61840
  }
61748
61841
  /**
@@ -61767,24 +61860,35 @@ var init_xmlBridge = __esm({
61767
61860
  async executeFromXml(xmlString) {
61768
61861
  const parsed = parseXmlMcpToolCall(xmlString, this.getToolNames());
61769
61862
  if (!parsed) {
61863
+ console.error("[MCP ERROR] No valid MCP tool call found in XML");
61770
61864
  throw new Error("No valid MCP tool call found in XML");
61771
61865
  }
61772
61866
  const { toolName, params } = parsed;
61773
61867
  if (this.debug) {
61774
- console.error(`[MCP] Executing MCP tool: ${toolName} with params:`, params);
61868
+ console.error(`[MCP DEBUG] Executing MCP tool: ${toolName}`);
61869
+ console.error(`[MCP DEBUG] Parameters:`, JSON.stringify(params, null, 2));
61775
61870
  }
61776
61871
  const tool3 = this.mcpTools[toolName];
61777
61872
  if (!tool3) {
61873
+ console.error(`[MCP ERROR] Unknown MCP tool: ${toolName}`);
61874
+ console.error(`[MCP ERROR] Available tools: ${this.getToolNames().join(", ")}`);
61778
61875
  throw new Error(`Unknown MCP tool: ${toolName}`);
61779
61876
  }
61780
61877
  try {
61781
61878
  const result = await tool3.execute(params);
61879
+ if (this.debug) {
61880
+ console.error(`[MCP DEBUG] Tool ${toolName} executed successfully`);
61881
+ }
61782
61882
  return {
61783
61883
  success: true,
61784
61884
  toolName,
61785
61885
  result
61786
61886
  };
61787
61887
  } catch (error2) {
61888
+ console.error(`[MCP ERROR] Tool ${toolName} execution failed:`, error2.message);
61889
+ if (this.debug) {
61890
+ console.error(`[MCP DEBUG] Full error details:`, error2);
61891
+ }
61788
61892
  return {
61789
61893
  success: false,
61790
61894
  toolName,
@@ -61918,6 +62022,7 @@ var init_ProbeAgent = __esm({
61918
62022
  this.mcpConfig = options.mcpConfig || null;
61919
62023
  this.mcpServers = options.mcpServers || null;
61920
62024
  this.mcpBridge = null;
62025
+ this._mcpInitialized = false;
61921
62026
  this.initializeModel();
61922
62027
  }
61923
62028
  /**
@@ -61925,7 +62030,8 @@ var init_ProbeAgent = __esm({
61925
62030
  * This method initializes MCP and merges MCP tools into the tool list
61926
62031
  */
61927
62032
  async initialize() {
61928
- if (this.enableMcp) {
62033
+ if (this.enableMcp && !this._mcpInitialized) {
62034
+ this._mcpInitialized = true;
61929
62035
  try {
61930
62036
  await this.initializeMCP();
61931
62037
  if (this.mcpBridge) {
@@ -61949,7 +62055,10 @@ var init_ProbeAgent = __esm({
61949
62055
  console.error("[DEBUG] ========================================\n");
61950
62056
  }
61951
62057
  } catch (error2) {
61952
- console.error("[MCP] Failed to initialize MCP:", error2);
62058
+ console.error("[MCP ERROR] Failed to initialize MCP:", error2.message);
62059
+ if (this.debug) {
62060
+ console.error("[MCP DEBUG] Full error details:", error2);
62061
+ }
61953
62062
  this.mcpBridge = null;
61954
62063
  }
61955
62064
  }
@@ -62373,13 +62482,13 @@ var init_ProbeAgent = __esm({
62373
62482
  if (this.mcpConfig) {
62374
62483
  mcpConfig = this.mcpConfig;
62375
62484
  if (this.debug) {
62376
- console.log("[DEBUG] Using provided MCP config object");
62485
+ console.error("[MCP DEBUG] Using provided MCP config object");
62377
62486
  }
62378
62487
  } else if (this.mcpConfigPath) {
62379
62488
  try {
62380
62489
  mcpConfig = loadMCPConfigurationFromPath(this.mcpConfigPath);
62381
62490
  if (this.debug) {
62382
- console.log(`[DEBUG] Loaded MCP config from: ${this.mcpConfigPath}`);
62491
+ console.error(`[MCP DEBUG] Loaded MCP config from: ${this.mcpConfigPath}`);
62383
62492
  }
62384
62493
  } catch (error2) {
62385
62494
  throw new Error(`Failed to load MCP config from ${this.mcpConfigPath}: ${error2.message}`);
@@ -62387,8 +62496,13 @@ var init_ProbeAgent = __esm({
62387
62496
  } else if (this.mcpServers) {
62388
62497
  mcpConfig = { mcpServers: this.mcpServers };
62389
62498
  if (this.debug) {
62390
- console.warn("[DEBUG] Using deprecated mcpServers option. Consider using mcpConfig instead.");
62499
+ console.error("[MCP DEBUG] Using deprecated mcpServers option. Consider using mcpConfig instead.");
62500
+ }
62501
+ } else {
62502
+ if (this.debug) {
62503
+ console.error("[MCP DEBUG] No explicit MCP config provided, will attempt auto-discovery");
62391
62504
  }
62505
+ mcpConfig = null;
62392
62506
  }
62393
62507
  this.mcpBridge = new MCPXmlBridge({ debug: this.debug });
62394
62508
  await this.mcpBridge.initialize(mcpConfig);
@@ -62396,22 +62510,25 @@ var init_ProbeAgent = __esm({
62396
62510
  const mcpToolCount = mcpToolNames.length;
62397
62511
  if (mcpToolCount > 0) {
62398
62512
  if (this.debug) {
62399
- console.error("\n[DEBUG] ========================================");
62400
- console.error(`[DEBUG] MCP Tools Initialized (${mcpToolCount} tools)`);
62401
- console.error("[DEBUG] Available MCP tools:");
62513
+ console.error("\n[MCP DEBUG] ========================================");
62514
+ console.error(`[MCP DEBUG] MCP Tools Initialized (${mcpToolCount} tools)`);
62515
+ console.error("[MCP DEBUG] Available MCP tools:");
62402
62516
  for (const toolName of mcpToolNames) {
62403
- console.error(`[DEBUG] - ${toolName}`);
62517
+ console.error(`[MCP DEBUG] - ${toolName}`);
62404
62518
  }
62405
- console.error("[DEBUG] ========================================\n");
62519
+ console.error("[MCP DEBUG] ========================================\n");
62406
62520
  }
62407
62521
  } else {
62408
62522
  if (this.debug) {
62409
- console.error("[DEBUG] No MCP tools loaded, setting bridge to null");
62523
+ console.error("[MCP DEBUG] No MCP tools loaded, setting bridge to null");
62410
62524
  }
62411
62525
  this.mcpBridge = null;
62412
62526
  }
62413
62527
  } catch (error2) {
62414
- console.error("[MCP] Error initializing MCP:", error2);
62528
+ console.error("[MCP ERROR] Error initializing MCP:", error2.message);
62529
+ if (this.debug) {
62530
+ console.error("[MCP DEBUG] Full error details:", error2);
62531
+ }
62415
62532
  this.mcpBridge = null;
62416
62533
  }
62417
62534
  }
@@ -62419,6 +62536,23 @@ var init_ProbeAgent = __esm({
62419
62536
  * Get the system message with instructions for the AI (XML Tool Format)
62420
62537
  */
62421
62538
  async getSystemMessage() {
62539
+ if (this.enableMcp && !this.mcpBridge && !this._mcpInitialized) {
62540
+ this._mcpInitialized = true;
62541
+ try {
62542
+ await this.initializeMCP();
62543
+ if (this.mcpBridge) {
62544
+ const mcpTools = this.mcpBridge.mcpTools || {};
62545
+ for (const [toolName, toolImpl] of Object.entries(mcpTools)) {
62546
+ this.toolImplementations[toolName] = toolImpl;
62547
+ }
62548
+ }
62549
+ } catch (error2) {
62550
+ console.error("[MCP ERROR] Failed to lazy-initialize MCP:", error2.message);
62551
+ if (this.debug) {
62552
+ console.error("[MCP DEBUG] Full error details:", error2);
62553
+ }
62554
+ }
62555
+ }
62422
62556
  let toolDefinitions = `
62423
62557
  ${searchToolDefinition}
62424
62558
  ${queryToolDefinition}