mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
Fix type-checker issues in SSE client and MCP connector
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -31,7 +31,7 @@ class MCPToolConnector:
|
|||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
"""Connect to the MCP SSE server for tools."""
|
"""Connect to the MCP SSE server for tools."""
|
||||||
token = self.token_manager.get_access_token()
|
token = self.token_manager.get_token()
|
||||||
if not token:
|
if not token:
|
||||||
self.logger.error("Authentication token not found. Please log in first.")
|
self.logger.error("Authentication token not found. Please log in first.")
|
||||||
raise ValueError("Authentication token not found. Please log in first.")
|
raise ValueError("Authentication token not found. Please log in first.")
|
||||||
|
|||||||
@@ -78,9 +78,9 @@ class SSEClient:
|
|||||||
stream=True,
|
stream=True,
|
||||||
timeout=self.timeout
|
timeout=self.timeout
|
||||||
)
|
)
|
||||||
self._response.raise_for_status()
|
if self._response is not None:
|
||||||
|
self._response.raise_for_status()
|
||||||
self._client = sseclient.SSEClient(self._response)
|
self._client = sseclient.SSEClient(self._response)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error connecting to SSE server: {str(e)}")
|
self.logger.error(f"Error connecting to SSE server: {str(e)}")
|
||||||
@@ -93,7 +93,7 @@ class SSEClient:
|
|||||||
)
|
)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def listen(self, event_handlers: Dict[str, Callable[[Any], None]] = None) -> None:
|
def listen(self, event_handlers: Optional[Dict[str, Callable[[Any], None]]] = None) -> None:
|
||||||
"""Listen for SSE events and process them with registered handlers.
|
"""Listen for SSE events and process them with registered handlers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -105,6 +105,10 @@ class SSEClient:
|
|||||||
event_handlers = event_handlers or {}
|
event_handlers = event_handlers or {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if self._client is None:
|
||||||
|
self.logger.error("SSE client is not initialized")
|
||||||
|
return
|
||||||
|
|
||||||
for event in self._client:
|
for event in self._client:
|
||||||
event_type = event.event or "message"
|
event_type = event.event or "message"
|
||||||
data = None
|
data = None
|
||||||
|
|||||||
Reference in New Issue
Block a user