@probelabs/probe 0.6.0-rc121 → 0.6.0-rc123

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -86,12 +86,16 @@ import { ProbeAgent } from '@buger/probe';
86
86
 
87
87
  // Create an AI agent for your project
88
88
  const agent = new ProbeAgent({
89
- sessionId: 'my-session', // Optional: for conversation continuity
89
+ sessionId: 'my-session', // Optional: for conversation continuity
90
90
  path: '/path/to/your/project',
91
91
  provider: 'anthropic', // or 'openai', 'google'
92
92
  model: 'claude-3-5-sonnet-20241022', // Optional: override model
93
93
  allowEdit: false, // Optional: enable code modification
94
- debug: true // Optional: enable debug logging
94
+ debug: true, // Optional: enable debug logging
95
+ enableMcp: true, // Optional: enable MCP tool integration
96
+ mcpConfig: { // Optional: MCP configuration (see MCP section below)
97
+ mcpServers: {...}
98
+ }
95
99
  });
96
100
 
97
101
  // Ask questions about your codebase
@@ -157,6 +161,36 @@ Add to your AI assistant's MCP configuration:
157
161
  }
158
162
  ```
159
163
 
164
+ ### Using MCP with ProbeAgent SDK
165
+
166
+ When using ProbeAgent programmatically, you can integrate MCP servers to extend the agent's capabilities:
167
+
168
+ ```javascript
169
+ const agent = new ProbeAgent({
170
+ enableMcp: true, // Enable MCP support
171
+
172
+ // Option 1: Provide MCP configuration directly
173
+ mcpConfig: {
174
+ mcpServers: {
175
+ 'my-server': {
176
+ command: 'node',
177
+ args: ['path/to/server.js'],
178
+ transport: 'stdio',
179
+ enabled: true
180
+ }
181
+ }
182
+ },
183
+
184
+ // Option 2: Load from config file
185
+ mcpConfigPath: '/path/to/mcp-config.json',
186
+
187
+ // Option 3: Auto-discovery from standard locations
188
+ // (~/.mcp/config.json, or via MCP_CONFIG_PATH env var)
189
+ });
190
+ ```
191
+
192
+ **Note:** MCP tools are automatically initialized when needed (lazy initialization), so you don't need to call `agent.initialize()` when using the SDK.
193
+
160
194
  ## API Reference
161
195
 
162
196
  ### Search
@@ -141,6 +141,7 @@ export class ProbeAgent {
141
141
  this.mcpConfig = options.mcpConfig || null;
142
142
  this.mcpServers = options.mcpServers || null; // Deprecated, keep for backward compatibility
143
143
  this.mcpBridge = null;
144
+ this._mcpInitialized = false; // Track if MCP initialization has been attempted
144
145
 
145
146
  // Initialize the AI model
146
147
  this.initializeModel();
@@ -154,8 +155,9 @@ export class ProbeAgent {
154
155
  * This method initializes MCP and merges MCP tools into the tool list
155
156
  */
156
157
  async initialize() {
157
- // Initialize MCP if enabled
158
- if (this.enableMcp) {
158
+ // Initialize MCP if enabled and not already initialized
159
+ if (this.enableMcp && !this._mcpInitialized) {
160
+ this._mcpInitialized = true; // Prevent multiple initialization attempts
159
161
  try {
160
162
  await this.initializeMCP();
161
163
 
@@ -184,7 +186,10 @@ export class ProbeAgent {
184
186
  console.error('[DEBUG] ========================================\n');
185
187
  }
186
188
  } catch (error) {
187
- console.error('[MCP] Failed to initialize MCP:', error);
189
+ console.error('[MCP ERROR] Failed to initialize MCP:', error.message);
190
+ if (this.debug) {
191
+ console.error('[MCP DEBUG] Full error details:', error);
192
+ }
188
193
  this.mcpBridge = null;
189
194
  }
190
195
  }
@@ -742,14 +747,14 @@ export class ProbeAgent {
742
747
  // Direct config object provided (SDK usage)
743
748
  mcpConfig = this.mcpConfig;
744
749
  if (this.debug) {
745
- console.log('[DEBUG] Using provided MCP config object');
750
+ console.error('[MCP DEBUG] Using provided MCP config object');
746
751
  }
747
752
  } else if (this.mcpConfigPath) {
748
753
  // Explicit config path provided
749
754
  try {
750
755
  mcpConfig = loadMCPConfigurationFromPath(this.mcpConfigPath);
751
756
  if (this.debug) {
752
- console.log(`[DEBUG] Loaded MCP config from: ${this.mcpConfigPath}`);
757
+ console.error(`[MCP DEBUG] Loaded MCP config from: ${this.mcpConfigPath}`);
753
758
  }
754
759
  } catch (error) {
755
760
  throw new Error(`Failed to load MCP config from ${this.mcpConfigPath}: ${error.message}`);
@@ -758,10 +763,17 @@ export class ProbeAgent {
758
763
  // Backward compatibility: convert old mcpServers format
759
764
  mcpConfig = { mcpServers: this.mcpServers };
760
765
  if (this.debug) {
761
- console.warn('[DEBUG] Using deprecated mcpServers option. Consider using mcpConfig instead.');
766
+ console.error('[MCP DEBUG] Using deprecated mcpServers option. Consider using mcpConfig instead.');
762
767
  }
768
+ } else {
769
+ // No explicit config provided - will attempt auto-discovery
770
+ // This is important for CLI usage where config files may exist
771
+ if (this.debug) {
772
+ console.error('[MCP DEBUG] No explicit MCP config provided, will attempt auto-discovery');
773
+ }
774
+ // Pass null to trigger auto-discovery in MCPXmlBridge
775
+ mcpConfig = null;
763
776
  }
764
- // Note: auto-discovery fallback is removed - user must explicitly provide config
765
777
 
766
778
  // Initialize the MCP XML bridge
767
779
  this.mcpBridge = new MCPXmlBridge({ debug: this.debug });
@@ -771,24 +783,27 @@ export class ProbeAgent {
771
783
  const mcpToolCount = mcpToolNames.length;
772
784
  if (mcpToolCount > 0) {
773
785
  if (this.debug) {
774
- console.error('\n[DEBUG] ========================================');
775
- console.error(`[DEBUG] MCP Tools Initialized (${mcpToolCount} tools)`);
776
- console.error('[DEBUG] Available MCP tools:');
786
+ console.error('\n[MCP DEBUG] ========================================');
787
+ console.error(`[MCP DEBUG] MCP Tools Initialized (${mcpToolCount} tools)`);
788
+ console.error('[MCP DEBUG] Available MCP tools:');
777
789
  for (const toolName of mcpToolNames) {
778
- console.error(`[DEBUG] - ${toolName}`);
790
+ console.error(`[MCP DEBUG] - ${toolName}`);
779
791
  }
780
- console.error('[DEBUG] ========================================\n');
792
+ console.error('[MCP DEBUG] ========================================\n');
781
793
  }
782
794
  } else {
783
795
  // For backward compatibility: if no tools were loaded, set bridge to null
784
796
  // This maintains the behavior expected by existing tests
785
797
  if (this.debug) {
786
- console.error('[DEBUG] No MCP tools loaded, setting bridge to null');
798
+ console.error('[MCP DEBUG] No MCP tools loaded, setting bridge to null');
787
799
  }
788
800
  this.mcpBridge = null;
789
801
  }
790
802
  } catch (error) {
791
- console.error('[MCP] Error initializing MCP:', error);
803
+ console.error('[MCP ERROR] Error initializing MCP:', error.message);
804
+ if (this.debug) {
805
+ console.error('[MCP DEBUG] Full error details:', error);
806
+ }
792
807
  this.mcpBridge = null;
793
808
  }
794
809
  }
@@ -797,6 +812,27 @@ export class ProbeAgent {
797
812
  * Get the system message with instructions for the AI (XML Tool Format)
798
813
  */
799
814
  async getSystemMessage() {
815
+ // Lazy initialize MCP if enabled but not yet initialized
816
+ if (this.enableMcp && !this.mcpBridge && !this._mcpInitialized) {
817
+ this._mcpInitialized = true; // Prevent multiple initialization attempts
818
+ try {
819
+ await this.initializeMCP();
820
+
821
+ // Merge MCP tools into toolImplementations for unified access
822
+ if (this.mcpBridge) {
823
+ const mcpTools = this.mcpBridge.mcpTools || {};
824
+ for (const [toolName, toolImpl] of Object.entries(mcpTools)) {
825
+ this.toolImplementations[toolName] = toolImpl;
826
+ }
827
+ }
828
+ } catch (error) {
829
+ console.error('[MCP ERROR] Failed to lazy-initialize MCP:', error.message);
830
+ if (this.debug) {
831
+ console.error('[MCP DEBUG] Full error details:', error);
832
+ }
833
+ }
834
+ }
835
+
800
836
  // Build tool definitions
801
837
  let toolDefinitions = `
802
838
  ${searchToolDefinition}