-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
Milestone
Description
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()callsgetMcpCapabilities()getMcpCapabilities()creates a temporary MCP connection to retrieve server capabilities- The temporary connection is immediately closed after getting capabilities
- Later,
UniversalMcpClientorPaymentChannelMcpClientcreates 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
- Remove
getMcpCapabilities()method fromServerDetector - Modify
detectCapabilities()to only return payment protocol detection results - Update
ServerDetectionResulttype to reflect partial detection (payment info only) - Adjust caching strategy for partial detection results
Phase 2: Move Capability Detection to Clients
- Add capability retrieval logic to
UniversalMcpClient.ensureInitialized() - Add capability retrieval logic to
PaymentChannelMcpClient.ensureClient() - Create utility method to merge payment info with MCP capabilities
- Update error handling for connection failures
Phase 3: Update Types and Interfaces
- Create new types for partial vs complete detection results
- Update method signatures to reflect the new flow
- Ensure backward compatibility of public APIs
Phase 4: Testing and Validation
- Write unit tests for the new detection flow
- Add integration tests to verify single connection behavior
- Performance testing to measure improvement
- Ensure all existing functionality still works
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 logicsrc/integrations/mcp/UniversalMcpClient.ts- Universal client capability handlingsrc/integrations/mcp/PaymentChannelMcpClient.ts- Payment client capability handlingsrc/integrations/mcp/types.ts- Type definitions- Test files for validation
Acceptance Criteria
- Server detection creates only one MCP connection (the official one)
- All existing functionality continues to work
- Performance improvement measurable in benchmarks
- No breaking changes to public APIs
- Comprehensive test coverage for new flow
Priority: Medium
Impact: Performance optimization, better resource utilization
Reactions are currently unavailable