Problem
The current ServerDetector implementation creates an unnecessary additional MCP connection during server capability detection, leading to performance overhead and resource waste.
Current Flow
ServerDetector.detectCapabilities() calls getMcpCapabilities()
getMcpCapabilities() creates a temporary MCP connection to retrieve server capabilities
- The temporary connection is immediately closed after getting capabilities
- Later,
UniversalMcpClient or PaymentChannelMcpClient creates another "official" connection
- Result: 2 connections total - 1 temporary + 1 official
Issues
- Performance Impact: Extra network round-trips and connection overhead
- Resource Waste: Temporary connections consume server resources unnecessarily
- Latency: Additional connection establishment delays the overall process
- Server Load: Unnecessary connection churn on MCP servers
Proposed Solution
Refactor the detection flow to eliminate the temporary connection by deferring MCP capability retrieval until after the official connection is established.
New Flow
ServerDetector.detectCapabilities() only checks payment protocol support via well-known endpoint
- Official MCP connection is established by client (
UniversalMcpClient/PaymentChannelMcpClient)
- MCP capabilities are retrieved from the established connection
- Payment info and MCP capabilities are merged to determine final server type
- Result: 1 connection total - only the official connection
Implementation Plan
Phase 1: Refactor ServerDetector
Phase 2: Move Capability Detection to Clients
Phase 3: Update Types and Interfaces
Phase 4: Testing and Validation
Benefits
- Performance: ~50% reduction in connection overhead during detection
- Resource Efficiency: Eliminates temporary connections
- Cleaner Architecture: Clearer separation between detection and connection phases
- Backward Compatibility: Public APIs remain unchanged
Files to Modify
src/integrations/mcp/ServerDetector.ts - Core detection logic
src/integrations/mcp/UniversalMcpClient.ts - Universal client capability handling
src/integrations/mcp/PaymentChannelMcpClient.ts - Payment client capability handling
src/integrations/mcp/types.ts - Type definitions
- Test files for validation
Acceptance Criteria
Priority: Medium
Impact: Performance optimization, better resource utilization
Problem
The current
ServerDetectorimplementation creates an unnecessary additional MCP connection during server capability detection, leading to performance overhead and resource waste.Current Flow
ServerDetector.detectCapabilities()callsgetMcpCapabilities()getMcpCapabilities()creates a temporary MCP connection to retrieve server capabilitiesUniversalMcpClientorPaymentChannelMcpClientcreates another "official" connectionIssues
Proposed Solution
Refactor the detection flow to eliminate the temporary connection by deferring MCP capability retrieval until after the official connection is established.
New Flow
ServerDetector.detectCapabilities()only checks payment protocol support via well-known endpointUniversalMcpClient/PaymentChannelMcpClient)Implementation Plan
Phase 1: Refactor ServerDetector
getMcpCapabilities()method fromServerDetectordetectCapabilities()to only return payment protocol detection resultsServerDetectionResulttype to reflect partial detection (payment info only)Phase 2: Move Capability Detection to Clients
UniversalMcpClient.ensureInitialized()PaymentChannelMcpClient.ensureClient()Phase 3: Update Types and Interfaces
Phase 4: Testing and Validation
Benefits
Files to Modify
src/integrations/mcp/ServerDetector.ts- Core detection logicsrc/integrations/mcp/UniversalMcpClient.ts- Universal client capability handlingsrc/integrations/mcp/PaymentChannelMcpClient.ts- Payment client capability handlingsrc/integrations/mcp/types.ts- Type definitionsAcceptance Criteria
Priority: Medium
Impact: Performance optimization, better resource utilization