@@ -31,14 +31,15 @@ def get_event_loop():
3131class SSEMCPTool :
3232 """A wrapper for an MCP tool that can be used with praisonaiagents."""
3333
34- def __init__ (self , name : str , description : str , session : ClientSession , input_schema : Optional [Dict [str , Any ]] = None ):
34+ def __init__ (self , name : str , description : str , session : ClientSession , input_schema : Optional [Dict [str , Any ]] = None , timeout : int = 60 ):
3535 self .name = name
3636 self .__name__ = name # Required for Agent to recognize it as a tool
3737 self .__qualname__ = name # Required for Agent to recognize it as a tool
3838 self .__doc__ = description # Required for Agent to recognize it as a tool
3939 self .description = description
4040 self .session = session
4141 self .input_schema = input_schema or {}
42+ self .timeout = timeout
4243
4344 # Create a signature based on input schema
4445 params = []
@@ -66,7 +67,7 @@ def __call__(self, **kwargs):
6667 future = asyncio .run_coroutine_threadsafe (self ._async_call (** kwargs ), loop )
6768 try :
6869 # Wait for the result with a timeout
69- return future .result (timeout = 30 )
70+ return future .result (timeout = self . timeout )
7071 except Exception as e :
7172 logger .error (f"Error calling tool { self .name } : { e } " )
7273 return f"Error: { str (e )} "
@@ -102,16 +103,18 @@ def to_openai_tool(self):
102103class SSEMCPClient :
103104 """A client for connecting to an MCP server over SSE."""
104105
105- def __init__ (self , server_url : str , debug : bool = False ):
106+ def __init__ (self , server_url : str , debug : bool = False , timeout : int = 60 ):
106107 """
107108 Initialize an SSE MCP client.
108109
109110 Args:
110111 server_url: The URL of the SSE MCP server
111112 debug: Whether to enable debug logging
113+ timeout: Timeout in seconds for operations (default: 60)
112114 """
113115 self .server_url = server_url
114116 self .debug = debug
117+ self .timeout = timeout
115118 self .session = None
116119 self .tools = []
117120
@@ -139,7 +142,7 @@ def run_event_loop():
139142
140143 # Run the initialization in the event loop
141144 future = asyncio .run_coroutine_threadsafe (self ._async_initialize (), loop )
142- self .tools = future .result (timeout = 30 )
145+ self .tools = future .result (timeout = self . timeout )
143146
144147 async def _async_initialize (self ):
145148 """Asynchronously initialize the connection and tools."""
@@ -169,7 +172,8 @@ async def _async_initialize(self):
169172 name = tool .name ,
170173 description = tool .description if hasattr (tool , 'description' ) else f"Call the { tool .name } tool" ,
171174 session = self .session ,
172- input_schema = input_schema
175+ input_schema = input_schema ,
176+ timeout = self .timeout
173177 )
174178 tools .append (wrapper )
175179
0 commit comments