1- """Context7 Handler Implementation
1+ """Context7 Client Implementation
22
33This handler preserves all the experimental results and optimizations
44for Context7 service, including prompt templates, timm library special
55handling, caching mechanisms, and error handling logic.
66
7- Now inherits from GeneralMCPHandler to use unified LiteLLM backend.
7+ Now inherits from MCPClient to use unified LiteLLM backend.
88"""
99
1010from typing import Optional
1111
12+ from rdagent .components .mcp .client import MCPClient
1213from rdagent .components .mcp .connector import MCPConnectionError , StreamableHTTPConfig
13- from rdagent .components .mcp .general_handler import GeneralMCPHandler
1414from rdagent .log import rdagent_logger as logger
1515from rdagent .utils .agent .tpl import T
1616
1717
18- class Context7Handler ( GeneralMCPHandler ):
19- """Context7 MCP service handler with all experimental optimizations.
18+ class Context7Client ( MCPClient ):
19+ """Context7 MCP service client with experimental optimizations.
2020
21- This handler preserves all the research results including :
21+ This client extends MCPClient with Context7-specific features :
2222 - Enhanced prompt templates for better documentation search
2323 - Special handling for timm library (3+ mentions trigger)
2424 - Intelligent error handling for documentation not found cases
25- - All common functionality now handled by GeneralMCPHandler + LiteLLM
25+ - Tool response validation for Context7's specific format
2626 """
2727
2828 # Tool response validation rules for Context7
@@ -40,27 +40,27 @@ class Context7Handler(GeneralMCPHandler):
4040
4141 # TODO: Consider making these configurable based on server response time patterns
4242 # Override parent class retry wait times to fit within Context7's 75-second session window
43- # These directly override GeneralMCPHandler 's class attributes
43+ # These directly override MCPClient 's class attributes
4444 RATE_LIMIT_WAIT_TIMES = [15 , 20 , 25 ] # Maximum total: 60 seconds
4545 NORMAL_RETRY_WAIT_TIMES = [5 , 8 , 10 ] # For non-rate-limit errors
4646
4747 def __init__ (self , service_name : str = "context7" , service_url : str = "http://localhost:8123/mcp" , ** config ):
48- # Initialize with GeneralMCPHandler - uses LiteLLM backend
48+ # Initialize with MCPClient - uses LiteLLM backend
4949 super ().__init__ (service_name , ** config )
5050
5151 # Store MCP service URL (from registry config)
5252 self .mcp_url = service_url
5353
5454 # Log that we're using LiteLLM backend
5555 logger .info (
56- f"Context7Handler initialized with session_timeout={ self .SESSION_TIMEOUT } s, "
56+ f"Context7Client initialized with session_timeout={ self .SESSION_TIMEOUT } s, "
5757 f"rate_limit_waits={ self .RATE_LIMIT_WAIT_TIMES } " ,
5858 tag = "context7_config" ,
5959 )
6060
6161 # Configuration is now handled by LiteLLM backend - no need for separate resolution
6262
63- # process_query is now handled by GeneralMCPHandler - we implement the abstract methods
63+ # process_query is now handled by MCPClient - we implement the abstract methods
6464
6565 def preprocess_query (self , query : str , ** kwargs ) -> str :
6666 """Preprocess query with Context7 specific enhancements.
@@ -148,7 +148,7 @@ def _build_enhanced_query(self, error_message: str, full_code: Optional[str] = N
148148
149149 return enhanced_query
150150
151- # All common functionality is now handled by GeneralMCPHandler
151+ # All common functionality is now handled by MCPClient
152152
153153 def customize_connector_config (self , config : "StreamableHTTPConfig" ) -> "StreamableHTTPConfig" :
154154 """Customize connector configuration for Context7's 75-second session limit.
0 commit comments