File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"""Core components for CodeAlive MCP server."""
22
33from .client import CodeAliveContext , get_api_key_from_context , codealive_lifespan
4- from .config import Config
4+ from .config import Config , REQUEST_TIMEOUT_SECONDS
55from .logging import setup_debug_logging , log_api_request , log_api_response
66
77__all__ = [
88 'CodeAliveContext' ,
99 'get_api_key_from_context' ,
1010 'codealive_lifespan' ,
1111 'Config' ,
12+ 'REQUEST_TIMEOUT_SECONDS' ,
1213 'setup_debug_logging' ,
1314 'log_api_request' ,
1415 'log_api_response' ,
Original file line number Diff line number Diff line change 99from fastmcp import Context , FastMCP
1010from fastmcp .server .dependencies import get_http_headers
1111
12- from .config import Config
12+ from .config import Config , REQUEST_TIMEOUT_SECONDS
1313
1414
1515@dataclass
@@ -68,7 +68,7 @@ async def codealive_lifespan(server: FastMCP) -> AsyncIterator[CodeAliveContext]
6868 "Authorization" : f"Bearer { config .api_key } " ,
6969 "Content-Type" : "application/json" ,
7070 },
71- timeout = 300.0 ,
71+ timeout = REQUEST_TIMEOUT_SECONDS ,
7272 verify = config .verify_ssl ,
7373 )
7474 else :
@@ -78,7 +78,7 @@ async def codealive_lifespan(server: FastMCP) -> AsyncIterator[CodeAliveContext]
7878 headers = {
7979 "Content-Type" : "application/json" ,
8080 },
81- timeout = 300.0 ,
81+ timeout = REQUEST_TIMEOUT_SECONDS ,
8282 verify = config .verify_ssl ,
8383 )
8484
Original file line number Diff line number Diff line change 44from dataclasses import dataclass
55from typing import Optional
66
7+ # Request timeout in seconds (5 minutes)
8+ REQUEST_TIMEOUT_SECONDS = 300.0
9+
710
811@dataclass
912class Config :
Original file line number Diff line number Diff line change 44import httpx
55from fastmcp import Context
66
7+ from core .config import REQUEST_TIMEOUT_SECONDS
8+
79
810async def handle_api_error (
911 ctx : Context ,
@@ -21,6 +23,16 @@ async def handle_api_error(
2123 Returns:
2224 User-friendly error message string
2325 """
26+ # Handle timeout errors first
27+ if isinstance (error , httpx .TimeoutException ):
28+ timeout_minutes = int (REQUEST_TIMEOUT_SECONDS // 60 )
29+ error_msg = (
30+ f"Request timeout during { operation } : The CodeAlive service did not respond within { timeout_minutes } minutes. "
31+ "This may happen due to temporarily overloaded LLMs. Please try again later."
32+ )
33+ await ctx .error (error_msg )
34+ return f"Error: { error_msg } "
35+
2436 if isinstance (error , httpx .HTTPStatusError ):
2537 error_code = error .response .status_code
2638 error_detail = error .response .text
You can’t perform that action at this time.
0 commit comments