FFFF.....................................                                [100%]
================================== FAILURES ===================================
___________ TestCookbookIntegration.test_financial_data_integration ___________

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
>           yield

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:101: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:250: in handle_request
    resp = self._pool.handle_request(req)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection_pool.py:256: in handle_request
    raise exc from None
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection_pool.py:236: in handle_request
    response = connection.handle_request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:101: in handle_request
    raise exc
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:78: in handle_request
    stream = self._connect(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:124: in _connect
    stream = self._network_backend.connect_tcp(**kwargs)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_backends\sync.py:207: in connect_tcp
    with map_exceptions(exc_map):
..\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:158: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

map = {<class 'TimeoutError'>: <class 'httpcore.ConnectTimeout'>, <class 'OSError'>: <class 'httpcore.ConnectError'>}

    @contextlib.contextmanager
    def map_exceptions(map: ExceptionMapping) -> typing.Iterator[None]:
        try:
            yield
        except Exception as exc:  # noqa: PIE786
            for from_exc, to_exc in map.items():
                if isinstance(exc, from_exc):
>                   raise to_exc(exc) from exc
E                   httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_exceptions.py:14: ConnectError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D30145950>
request = {'id': 1, 'jsonrpc': '2.0', 'method': 'initialize', 'params': {'capabilities': {'roots': {'listChanged': True}}, 'clientInfo': {'name': 'semantica', 'version': '1.0.0'}, 'protocolVersion': '2024-11-05'}}

    def _send_request(self, request: Dict[str, Any]) -> Optional[Dict[str, Any]]:
        """
        Send JSON-RPC request to MCP server.
    
        Args:
            request: JSON-RPC request dictionary
    
        Returns:
            Response dictionary or None
        """
        if not self._connected:
            raise ProcessingError("Not connected to MCP server")
    
        try:
            if self.transport == "stdio":
                return self._send_request_stdio(request)
            elif self.transport == "http":
>               return self._send_request_http(request)

semantica\ingest\mcp_client.py:314: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
semantica\ingest\mcp_client.py:348: in _send_request_http
    response = httpx.post(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_api.py:304: in post
    return request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_api.py:109: in request
    return client.request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:825: in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:914: in send
    response = self._send_handling_auth(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:942: in _send_handling_auth
    response = self._send_handling_redirects(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:979: in _send_handling_redirects
    response = self._send_single_request(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:1014: in _send_single_request
    response = transport.handle_request(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:249: in handle_request
    with map_httpcore_exceptions():
..\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:158: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
            yield
        except Exception as exc:
            mapped_exc = None
    
            for from_exc, to_exc in HTTPCORE_EXC_MAP.items():
                if not isinstance(exc, from_exc):
                    continue
                # We want to map to the most specific exception we can find.
                # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
                # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
                if mapped_exc is None or issubclass(to_exc, mapped_exc):
                    mapped_exc = to_exc
    
            if mapped_exc is None:  # pragma: no cover
                raise
    
            message = str(exc)
>           raise mapped_exc(message) from exc
E           httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:118: ConnectError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D30145950>

    def connect(self) -> bool:
        """
        Connect to MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
        """
        try:
            if self.transport == "http":
>               return self._connect_http()

semantica\ingest\mcp_client.py:191: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
semantica\ingest\mcp_client.py:228: in _connect_http
    return self._initialize()
semantica\ingest\mcp_client.py:259: in _initialize
    response = self._send_request(request)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D30145950>
request = {'id': 1, 'jsonrpc': '2.0', 'method': 'initialize', 'params': {'capabilities': {'roots': {'listChanged': True}}, 'clientInfo': {'name': 'semantica', 'version': '1.0.0'}, 'protocolVersion': '2024-11-05'}}

    def _send_request(self, request: Dict[str, Any]) -> Optional[Dict[str, Any]]:
        """
        Send JSON-RPC request to MCP server.
    
        Args:
            request: JSON-RPC request dictionary
    
        Returns:
            Response dictionary or None
        """
        if not self._connected:
            raise ProcessingError("Not connected to MCP server")
    
        try:
            if self.transport == "stdio":
                return self._send_request_stdio(request)
            elif self.transport == "http":
                return self._send_request_http(request)
            elif self.transport == "sse":
                return self._send_request_sse(request)
            else:
                raise ValidationError(f"Unsupported transport: {self.transport}")
        except Exception as e:
            self.logger.error(f"Failed to send request: {e}")
>           raise ProcessingError(f"Failed to send request: {e}") from e
E           semantica.utils.exceptions.ProcessingError: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_client.py:321: ProcessingError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_ingestor.MCPIngestor object at 0x0000016D305E6850>
server_name = 'financial_server', url = 'http://localhost:8000/mcp'
headers = {'Authorization': 'Bearer token'}, config = {}
client = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D30145950>

    def connect(
        self,
        server_name: str,
        url: Optional[str] = None,
        headers: Optional[Dict[str, str]] = None,
        **config,
    ) -> bool:
        """
        Connect to an MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
        Users can bring their own Python/FastMCP MCP servers via URL.
    
        Args:
            server_name: Unique name for this MCP server connection
            url: MCP server URL (primary parameter)
                - http://localhost:8000/mcp
                - https://api.example.com/mcp
                - mcp://server-name
            headers: Custom headers for authentication (e.g., {"Authorization": "Bearer token"})
            **config: Additional configuration options (timeout, etc.)
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
            ValidationError: If URL is not provided or invalid
    
        Example:
            >>> ingestor = MCPIngestor()
            >>> ingestor.connect("db_server", url="http://localhost:8000/mcp")
            >>> ingestor.connect("api_server", url="https://api.example.com/mcp", headers={"Authorization": "Bearer token"})
        """
        try:
            # Check if already connected
            if server_name in self._clients:
                self.logger.warning(
                    f"Server {server_name} already connected, reconnecting..."
                )
                self.disconnect(server_name)
    
            # Validate URL
            if not url:
                raise ValidationError(
                    f"URL is required for MCP server connection. "
                    f"Provide MCP server URL: http://, https://, or mcp://"
                )
    
            # Create and connect client (transport auto-detected from URL)
            client = MCPClient(url=url, headers=headers, **config)
    
>           if client.connect():

semantica\ingest\mcp_ingestor.py:168: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D30145950>

    def connect(self) -> bool:
        """
        Connect to MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
        """
        try:
            if self.transport == "http":
                return self._connect_http()
            elif self.transport == "sse":
                return self._connect_sse()
            else:
                raise ValidationError(f"Unsupported transport: {self.transport}")
        except Exception as e:
            self.logger.error(f"Failed to connect to MCP server: {e}")
>           raise ProcessingError(f"Failed to connect to MCP server: {e}") from e
E           semantica.utils.exceptions.ProcessingError: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_client.py:198: ProcessingError

The above exception was the direct cause of the following exception:

self = <tests.ingest.test_cookbook_integration.TestCookbookIntegration object at 0x0000016D2DED8C90>
mock_mcp_server = <MagicMock name='post' id='1568440729296'>

    def test_financial_data_integration(self, mock_mcp_server):
        """
        Validates the logic from cookbook/use_cases/finance/01_Financial_Data_Integration.ipynb
        """
        # 1. Initialize MCP ingestor
        mcp_ingestor = MCPIngestor()
    
        # 2. Connect to financial data MCP server
        financial_mcp_url = "http://localhost:8000/mcp"
    
        # Patching progress tracker to avoid console output issues during testing if needed
        # But MCPIngestor now handles it gracefully or we can let it run.
        # We need to mock get_progress_tracker to avoid 'NoneType' errors if not initialized properly in some envs
        # although my previous fixes should handle it. Let's patch it to be safe and clean.
        with patch("semantica.ingest.mcp_ingestor.get_progress_tracker") as mock_tracker:
            tracker_instance = MagicMock()
            mock_tracker.return_value = tracker_instance
    
>           mcp_ingestor.connect(
                "financial_server",
                url=financial_mcp_url,
                headers={"Authorization": "Bearer token"}
            )

tests\ingest\test_cookbook_integration.py:101: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_ingestor.MCPIngestor object at 0x0000016D305E6850>
server_name = 'financial_server', url = 'http://localhost:8000/mcp'
headers = {'Authorization': 'Bearer token'}, config = {}
client = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D30145950>

    def connect(
        self,
        server_name: str,
        url: Optional[str] = None,
        headers: Optional[Dict[str, str]] = None,
        **config,
    ) -> bool:
        """
        Connect to an MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
        Users can bring their own Python/FastMCP MCP servers via URL.
    
        Args:
            server_name: Unique name for this MCP server connection
            url: MCP server URL (primary parameter)
                - http://localhost:8000/mcp
                - https://api.example.com/mcp
                - mcp://server-name
            headers: Custom headers for authentication (e.g., {"Authorization": "Bearer token"})
            **config: Additional configuration options (timeout, etc.)
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
            ValidationError: If URL is not provided or invalid
    
        Example:
            >>> ingestor = MCPIngestor()
            >>> ingestor.connect("db_server", url="http://localhost:8000/mcp")
            >>> ingestor.connect("api_server", url="https://api.example.com/mcp", headers={"Authorization": "Bearer token"})
        """
        try:
            # Check if already connected
            if server_name in self._clients:
                self.logger.warning(
                    f"Server {server_name} already connected, reconnecting..."
                )
                self.disconnect(server_name)
    
            # Validate URL
            if not url:
                raise ValidationError(
                    f"URL is required for MCP server connection. "
                    f"Provide MCP server URL: http://, https://, or mcp://"
                )
    
            # Create and connect client (transport auto-detected from URL)
            client = MCPClient(url=url, headers=headers, **config)
    
            if client.connect():
                self._clients[server_name] = client
                self.logger.info(f"Connected to MCP server: {server_name} at {url}")
                return True
            else:
                raise ProcessingError(f"Failed to connect to MCP server: {server_name}")
        except Exception as e:
            self.logger.error(f"Failed to connect to MCP server {server_name}: {e}")
>           raise ProcessingError(
                f"Failed to connect to MCP server {server_name}: {e}"
            ) from e
E           semantica.utils.exceptions.ProcessingError: Failed to connect to MCP server financial_server: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_ingestor.py:176: ProcessingError
------------------------------ Captured log call ------------------------------
ERROR    semantica.mcp_client:mcp_client.py:375 Failed to send HTTP request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:320 Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:272 Failed to initialize MCP protocol: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:230 Failed to connect via HTTP: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:197 Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_ingestor:mcp_ingestor.py:175 Failed to connect to MCP server financial_server: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
_________ TestCookbookIntegration.test_supply_chain_data_integration __________

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
>           yield

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:101: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:250: in handle_request
    resp = self._pool.handle_request(req)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection_pool.py:256: in handle_request
    raise exc from None
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection_pool.py:236: in handle_request
    response = connection.handle_request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:101: in handle_request
    raise exc
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:78: in handle_request
    stream = self._connect(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:124: in _connect
    stream = self._network_backend.connect_tcp(**kwargs)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_backends\sync.py:207: in connect_tcp
    with map_exceptions(exc_map):
..\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:158: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

map = {<class 'TimeoutError'>: <class 'httpcore.ConnectTimeout'>, <class 'OSError'>: <class 'httpcore.ConnectError'>}

    @contextlib.contextmanager
    def map_exceptions(map: ExceptionMapping) -> typing.Iterator[None]:
        try:
            yield
        except Exception as exc:  # noqa: PIE786
            for from_exc, to_exc in map.items():
                if isinstance(exc, from_exc):
>                   raise to_exc(exc) from exc
E                   httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_exceptions.py:14: ConnectError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32900AD0>
request = {'id': 1, 'jsonrpc': '2.0', 'method': 'initialize', 'params': {'capabilities': {'roots': {'listChanged': True}}, 'clientInfo': {'name': 'semantica', 'version': '1.0.0'}, 'protocolVersion': '2024-11-05'}}

    def _send_request(self, request: Dict[str, Any]) -> Optional[Dict[str, Any]]:
        """
        Send JSON-RPC request to MCP server.
    
        Args:
            request: JSON-RPC request dictionary
    
        Returns:
            Response dictionary or None
        """
        if not self._connected:
            raise ProcessingError("Not connected to MCP server")
    
        try:
            if self.transport == "stdio":
                return self._send_request_stdio(request)
            elif self.transport == "http":
>               return self._send_request_http(request)

semantica\ingest\mcp_client.py:314: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
semantica\ingest\mcp_client.py:348: in _send_request_http
    response = httpx.post(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_api.py:304: in post
    return request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_api.py:109: in request
    return client.request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:825: in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:914: in send
    response = self._send_handling_auth(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:942: in _send_handling_auth
    response = self._send_handling_redirects(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:979: in _send_handling_redirects
    response = self._send_single_request(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:1014: in _send_single_request
    response = transport.handle_request(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:249: in handle_request
    with map_httpcore_exceptions():
..\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:158: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
            yield
        except Exception as exc:
            mapped_exc = None
    
            for from_exc, to_exc in HTTPCORE_EXC_MAP.items():
                if not isinstance(exc, from_exc):
                    continue
                # We want to map to the most specific exception we can find.
                # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
                # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
                if mapped_exc is None or issubclass(to_exc, mapped_exc):
                    mapped_exc = to_exc
    
            if mapped_exc is None:  # pragma: no cover
                raise
    
            message = str(exc)
>           raise mapped_exc(message) from exc
E           httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:118: ConnectError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32900AD0>

    def connect(self) -> bool:
        """
        Connect to MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
        """
        try:
            if self.transport == "http":
>               return self._connect_http()

semantica\ingest\mcp_client.py:191: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
semantica\ingest\mcp_client.py:228: in _connect_http
    return self._initialize()
semantica\ingest\mcp_client.py:259: in _initialize
    response = self._send_request(request)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32900AD0>
request = {'id': 1, 'jsonrpc': '2.0', 'method': 'initialize', 'params': {'capabilities': {'roots': {'listChanged': True}}, 'clientInfo': {'name': 'semantica', 'version': '1.0.0'}, 'protocolVersion': '2024-11-05'}}

    def _send_request(self, request: Dict[str, Any]) -> Optional[Dict[str, Any]]:
        """
        Send JSON-RPC request to MCP server.
    
        Args:
            request: JSON-RPC request dictionary
    
        Returns:
            Response dictionary or None
        """
        if not self._connected:
            raise ProcessingError("Not connected to MCP server")
    
        try:
            if self.transport == "stdio":
                return self._send_request_stdio(request)
            elif self.transport == "http":
                return self._send_request_http(request)
            elif self.transport == "sse":
                return self._send_request_sse(request)
            else:
                raise ValidationError(f"Unsupported transport: {self.transport}")
        except Exception as e:
            self.logger.error(f"Failed to send request: {e}")
>           raise ProcessingError(f"Failed to send request: {e}") from e
E           semantica.utils.exceptions.ProcessingError: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_client.py:321: ProcessingError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_ingestor.MCPIngestor object at 0x0000016D32903390>
server_name = 'supply_chain_server', url = 'http://localhost:8000/mcp'
headers = {'Authorization': 'Bearer token'}, config = {}
client = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32900AD0>

    def connect(
        self,
        server_name: str,
        url: Optional[str] = None,
        headers: Optional[Dict[str, str]] = None,
        **config,
    ) -> bool:
        """
        Connect to an MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
        Users can bring their own Python/FastMCP MCP servers via URL.
    
        Args:
            server_name: Unique name for this MCP server connection
            url: MCP server URL (primary parameter)
                - http://localhost:8000/mcp
                - https://api.example.com/mcp
                - mcp://server-name
            headers: Custom headers for authentication (e.g., {"Authorization": "Bearer token"})
            **config: Additional configuration options (timeout, etc.)
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
            ValidationError: If URL is not provided or invalid
    
        Example:
            >>> ingestor = MCPIngestor()
            >>> ingestor.connect("db_server", url="http://localhost:8000/mcp")
            >>> ingestor.connect("api_server", url="https://api.example.com/mcp", headers={"Authorization": "Bearer token"})
        """
        try:
            # Check if already connected
            if server_name in self._clients:
                self.logger.warning(
                    f"Server {server_name} already connected, reconnecting..."
                )
                self.disconnect(server_name)
    
            # Validate URL
            if not url:
                raise ValidationError(
                    f"URL is required for MCP server connection. "
                    f"Provide MCP server URL: http://, https://, or mcp://"
                )
    
            # Create and connect client (transport auto-detected from URL)
            client = MCPClient(url=url, headers=headers, **config)
    
>           if client.connect():

semantica\ingest\mcp_ingestor.py:168: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32900AD0>

    def connect(self) -> bool:
        """
        Connect to MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
        """
        try:
            if self.transport == "http":
                return self._connect_http()
            elif self.transport == "sse":
                return self._connect_sse()
            else:
                raise ValidationError(f"Unsupported transport: {self.transport}")
        except Exception as e:
            self.logger.error(f"Failed to connect to MCP server: {e}")
>           raise ProcessingError(f"Failed to connect to MCP server: {e}") from e
E           semantica.utils.exceptions.ProcessingError: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_client.py:198: ProcessingError

The above exception was the direct cause of the following exception:

self = <tests.ingest.test_cookbook_integration.TestCookbookIntegration object at 0x0000016D2DDCE390>
mock_mcp_server = <MagicMock name='post' id='1568511371984'>

    def test_supply_chain_data_integration(self, mock_mcp_server):
        """
        Validates the logic from cookbook/use_cases/supply_chain/01_Supply_Chain_Data_Integration.ipynb
        """
        mcp_ingestor = MCPIngestor()
        supply_chain_mcp_url = "http://localhost:8000/mcp"
    
        with patch("semantica.ingest.mcp_ingestor.get_progress_tracker") as mock_tracker:
            tracker_instance = MagicMock()
            mock_tracker.return_value = tracker_instance
    
>           mcp_ingestor.connect(
                "supply_chain_server",
                url=supply_chain_mcp_url,
                headers={"Authorization": "Bearer token"}
            )

tests\ingest\test_cookbook_integration.py:137: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_ingestor.MCPIngestor object at 0x0000016D32903390>
server_name = 'supply_chain_server', url = 'http://localhost:8000/mcp'
headers = {'Authorization': 'Bearer token'}, config = {}
client = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32900AD0>

    def connect(
        self,
        server_name: str,
        url: Optional[str] = None,
        headers: Optional[Dict[str, str]] = None,
        **config,
    ) -> bool:
        """
        Connect to an MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
        Users can bring their own Python/FastMCP MCP servers via URL.
    
        Args:
            server_name: Unique name for this MCP server connection
            url: MCP server URL (primary parameter)
                - http://localhost:8000/mcp
                - https://api.example.com/mcp
                - mcp://server-name
            headers: Custom headers for authentication (e.g., {"Authorization": "Bearer token"})
            **config: Additional configuration options (timeout, etc.)
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
            ValidationError: If URL is not provided or invalid
    
        Example:
            >>> ingestor = MCPIngestor()
            >>> ingestor.connect("db_server", url="http://localhost:8000/mcp")
            >>> ingestor.connect("api_server", url="https://api.example.com/mcp", headers={"Authorization": "Bearer token"})
        """
        try:
            # Check if already connected
            if server_name in self._clients:
                self.logger.warning(
                    f"Server {server_name} already connected, reconnecting..."
                )
                self.disconnect(server_name)
    
            # Validate URL
            if not url:
                raise ValidationError(
                    f"URL is required for MCP server connection. "
                    f"Provide MCP server URL: http://, https://, or mcp://"
                )
    
            # Create and connect client (transport auto-detected from URL)
            client = MCPClient(url=url, headers=headers, **config)
    
            if client.connect():
                self._clients[server_name] = client
                self.logger.info(f"Connected to MCP server: {server_name} at {url}")
                return True
            else:
                raise ProcessingError(f"Failed to connect to MCP server: {server_name}")
        except Exception as e:
            self.logger.error(f"Failed to connect to MCP server {server_name}: {e}")
>           raise ProcessingError(
                f"Failed to connect to MCP server {server_name}: {e}"
            ) from e
E           semantica.utils.exceptions.ProcessingError: Failed to connect to MCP server supply_chain_server: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_ingestor.py:176: ProcessingError
------------------------------ Captured log call ------------------------------
ERROR    semantica.mcp_client:mcp_client.py:375 Failed to send HTTP request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:320 Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:272 Failed to initialize MCP protocol: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:230 Failed to connect via HTTP: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:197 Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_ingestor:mcp_ingestor.py:175 Failed to connect to MCP server supply_chain_server: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
__________ TestCookbookIntegration.test_medical_database_integration __________

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
>           yield

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:101: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:250: in handle_request
    resp = self._pool.handle_request(req)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection_pool.py:256: in handle_request
    raise exc from None
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection_pool.py:236: in handle_request
    response = connection.handle_request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:101: in handle_request
    raise exc
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:78: in handle_request
    stream = self._connect(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:124: in _connect
    stream = self._network_backend.connect_tcp(**kwargs)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_backends\sync.py:207: in connect_tcp
    with map_exceptions(exc_map):
..\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:158: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

map = {<class 'TimeoutError'>: <class 'httpcore.ConnectTimeout'>, <class 'OSError'>: <class 'httpcore.ConnectError'>}

    @contextlib.contextmanager
    def map_exceptions(map: ExceptionMapping) -> typing.Iterator[None]:
        try:
            yield
        except Exception as exc:  # noqa: PIE786
            for from_exc, to_exc in map.items():
                if isinstance(exc, from_exc):
>                   raise to_exc(exc) from exc
E                   httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_exceptions.py:14: ConnectError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32924A90>
request = {'id': 1, 'jsonrpc': '2.0', 'method': 'initialize', 'params': {'capabilities': {'roots': {'listChanged': True}}, 'clientInfo': {'name': 'semantica', 'version': '1.0.0'}, 'protocolVersion': '2024-11-05'}}

    def _send_request(self, request: Dict[str, Any]) -> Optional[Dict[str, Any]]:
        """
        Send JSON-RPC request to MCP server.
    
        Args:
            request: JSON-RPC request dictionary
    
        Returns:
            Response dictionary or None
        """
        if not self._connected:
            raise ProcessingError("Not connected to MCP server")
    
        try:
            if self.transport == "stdio":
                return self._send_request_stdio(request)
            elif self.transport == "http":
>               return self._send_request_http(request)

semantica\ingest\mcp_client.py:314: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
semantica\ingest\mcp_client.py:348: in _send_request_http
    response = httpx.post(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_api.py:304: in post
    return request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_api.py:109: in request
    return client.request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:825: in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:914: in send
    response = self._send_handling_auth(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:942: in _send_handling_auth
    response = self._send_handling_redirects(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:979: in _send_handling_redirects
    response = self._send_single_request(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:1014: in _send_single_request
    response = transport.handle_request(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:249: in handle_request
    with map_httpcore_exceptions():
..\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:158: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
            yield
        except Exception as exc:
            mapped_exc = None
    
            for from_exc, to_exc in HTTPCORE_EXC_MAP.items():
                if not isinstance(exc, from_exc):
                    continue
                # We want to map to the most specific exception we can find.
                # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
                # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
                if mapped_exc is None or issubclass(to_exc, mapped_exc):
                    mapped_exc = to_exc
    
            if mapped_exc is None:  # pragma: no cover
                raise
    
            message = str(exc)
>           raise mapped_exc(message) from exc
E           httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:118: ConnectError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32924A90>

    def connect(self) -> bool:
        """
        Connect to MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
        """
        try:
            if self.transport == "http":
>               return self._connect_http()

semantica\ingest\mcp_client.py:191: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
semantica\ingest\mcp_client.py:228: in _connect_http
    return self._initialize()
semantica\ingest\mcp_client.py:259: in _initialize
    response = self._send_request(request)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32924A90>
request = {'id': 1, 'jsonrpc': '2.0', 'method': 'initialize', 'params': {'capabilities': {'roots': {'listChanged': True}}, 'clientInfo': {'name': 'semantica', 'version': '1.0.0'}, 'protocolVersion': '2024-11-05'}}

    def _send_request(self, request: Dict[str, Any]) -> Optional[Dict[str, Any]]:
        """
        Send JSON-RPC request to MCP server.
    
        Args:
            request: JSON-RPC request dictionary
    
        Returns:
            Response dictionary or None
        """
        if not self._connected:
            raise ProcessingError("Not connected to MCP server")
    
        try:
            if self.transport == "stdio":
                return self._send_request_stdio(request)
            elif self.transport == "http":
                return self._send_request_http(request)
            elif self.transport == "sse":
                return self._send_request_sse(request)
            else:
                raise ValidationError(f"Unsupported transport: {self.transport}")
        except Exception as e:
            self.logger.error(f"Failed to send request: {e}")
>           raise ProcessingError(f"Failed to send request: {e}") from e
E           semantica.utils.exceptions.ProcessingError: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_client.py:321: ProcessingError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_ingestor.MCPIngestor object at 0x0000016D329269D0>
server_name = 'medical_server', url = 'http://localhost:8000/mcp'
headers = None, config = {}
client = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32924A90>

    def connect(
        self,
        server_name: str,
        url: Optional[str] = None,
        headers: Optional[Dict[str, str]] = None,
        **config,
    ) -> bool:
        """
        Connect to an MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
        Users can bring their own Python/FastMCP MCP servers via URL.
    
        Args:
            server_name: Unique name for this MCP server connection
            url: MCP server URL (primary parameter)
                - http://localhost:8000/mcp
                - https://api.example.com/mcp
                - mcp://server-name
            headers: Custom headers for authentication (e.g., {"Authorization": "Bearer token"})
            **config: Additional configuration options (timeout, etc.)
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
            ValidationError: If URL is not provided or invalid
    
        Example:
            >>> ingestor = MCPIngestor()
            >>> ingestor.connect("db_server", url="http://localhost:8000/mcp")
            >>> ingestor.connect("api_server", url="https://api.example.com/mcp", headers={"Authorization": "Bearer token"})
        """
        try:
            # Check if already connected
            if server_name in self._clients:
                self.logger.warning(
                    f"Server {server_name} already connected, reconnecting..."
                )
                self.disconnect(server_name)
    
            # Validate URL
            if not url:
                raise ValidationError(
                    f"URL is required for MCP server connection. "
                    f"Provide MCP server URL: http://, https://, or mcp://"
                )
    
            # Create and connect client (transport auto-detected from URL)
            client = MCPClient(url=url, headers=headers, **config)
    
>           if client.connect():

semantica\ingest\mcp_ingestor.py:168: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32924A90>

    def connect(self) -> bool:
        """
        Connect to MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
        """
        try:
            if self.transport == "http":
                return self._connect_http()
            elif self.transport == "sse":
                return self._connect_sse()
            else:
                raise ValidationError(f"Unsupported transport: {self.transport}")
        except Exception as e:
            self.logger.error(f"Failed to connect to MCP server: {e}")
>           raise ProcessingError(f"Failed to connect to MCP server: {e}") from e
E           semantica.utils.exceptions.ProcessingError: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_client.py:198: ProcessingError

The above exception was the direct cause of the following exception:

self = <tests.ingest.test_cookbook_integration.TestCookbookIntegration object at 0x0000016D2E0B6450>
mock_mcp_server = <MagicMock name='post' id='1568511519248'>

    def test_medical_database_integration(self, mock_mcp_server):
        """
        Validates the logic from cookbook/use_cases/healthcare/05_Medical_Database_Integration.ipynb
        """
        mcp_ingestor = MCPIngestor()
        medical_mcp_url = "http://localhost:8000/mcp"
    
        with patch("semantica.ingest.mcp_ingestor.get_progress_tracker") as mock_tracker:
            tracker_instance = MagicMock()
            mock_tracker.return_value = tracker_instance
    
>           mcp_ingestor.connect(
                "medical_server",
                url=medical_mcp_url
            )

tests\ingest\test_cookbook_integration.py:171: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_ingestor.MCPIngestor object at 0x0000016D329269D0>
server_name = 'medical_server', url = 'http://localhost:8000/mcp'
headers = None, config = {}
client = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32924A90>

    def connect(
        self,
        server_name: str,
        url: Optional[str] = None,
        headers: Optional[Dict[str, str]] = None,
        **config,
    ) -> bool:
        """
        Connect to an MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
        Users can bring their own Python/FastMCP MCP servers via URL.
    
        Args:
            server_name: Unique name for this MCP server connection
            url: MCP server URL (primary parameter)
                - http://localhost:8000/mcp
                - https://api.example.com/mcp
                - mcp://server-name
            headers: Custom headers for authentication (e.g., {"Authorization": "Bearer token"})
            **config: Additional configuration options (timeout, etc.)
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
            ValidationError: If URL is not provided or invalid
    
        Example:
            >>> ingestor = MCPIngestor()
            >>> ingestor.connect("db_server", url="http://localhost:8000/mcp")
            >>> ingestor.connect("api_server", url="https://api.example.com/mcp", headers={"Authorization": "Bearer token"})
        """
        try:
            # Check if already connected
            if server_name in self._clients:
                self.logger.warning(
                    f"Server {server_name} already connected, reconnecting..."
                )
                self.disconnect(server_name)
    
            # Validate URL
            if not url:
                raise ValidationError(
                    f"URL is required for MCP server connection. "
                    f"Provide MCP server URL: http://, https://, or mcp://"
                )
    
            # Create and connect client (transport auto-detected from URL)
            client = MCPClient(url=url, headers=headers, **config)
    
            if client.connect():
                self._clients[server_name] = client
                self.logger.info(f"Connected to MCP server: {server_name} at {url}")
                return True
            else:
                raise ProcessingError(f"Failed to connect to MCP server: {server_name}")
        except Exception as e:
            self.logger.error(f"Failed to connect to MCP server {server_name}: {e}")
>           raise ProcessingError(
                f"Failed to connect to MCP server {server_name}: {e}"
            ) from e
E           semantica.utils.exceptions.ProcessingError: Failed to connect to MCP server medical_server: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_ingestor.py:176: ProcessingError
------------------------------ Captured log call ------------------------------
ERROR    semantica.mcp_client:mcp_client.py:375 Failed to send HTTP request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:320 Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:272 Failed to initialize MCP protocol: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:230 Failed to connect via HTTP: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:197 Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_ingestor:mcp_ingestor.py:175 Failed to connect to MCP server medical_server: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
________ TestCookbookIntegration.test_threat_intelligence_integration _________

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
>           yield

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:101: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:250: in handle_request
    resp = self._pool.handle_request(req)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection_pool.py:256: in handle_request
    raise exc from None
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection_pool.py:236: in handle_request
    response = connection.handle_request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:101: in handle_request
    raise exc
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:78: in handle_request
    stream = self._connect(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_sync\connection.py:124: in _connect
    stream = self._network_backend.connect_tcp(**kwargs)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_backends\sync.py:207: in connect_tcp
    with map_exceptions(exc_map):
..\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:158: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

map = {<class 'TimeoutError'>: <class 'httpcore.ConnectTimeout'>, <class 'OSError'>: <class 'httpcore.ConnectError'>}

    @contextlib.contextmanager
    def map_exceptions(map: ExceptionMapping) -> typing.Iterator[None]:
        try:
            yield
        except Exception as exc:  # noqa: PIE786
            for from_exc, to_exc in map.items():
                if isinstance(exc, from_exc):
>                   raise to_exc(exc) from exc
E                   httpcore.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpcore\_exceptions.py:14: ConnectError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32948590>
request = {'id': 1, 'jsonrpc': '2.0', 'method': 'initialize', 'params': {'capabilities': {'roots': {'listChanged': True}}, 'clientInfo': {'name': 'semantica', 'version': '1.0.0'}, 'protocolVersion': '2024-11-05'}}

    def _send_request(self, request: Dict[str, Any]) -> Optional[Dict[str, Any]]:
        """
        Send JSON-RPC request to MCP server.
    
        Args:
            request: JSON-RPC request dictionary
    
        Returns:
            Response dictionary or None
        """
        if not self._connected:
            raise ProcessingError("Not connected to MCP server")
    
        try:
            if self.transport == "stdio":
                return self._send_request_stdio(request)
            elif self.transport == "http":
>               return self._send_request_http(request)

semantica\ingest\mcp_client.py:314: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
semantica\ingest\mcp_client.py:348: in _send_request_http
    response = httpx.post(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_api.py:304: in post
    return request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_api.py:109: in request
    return client.request(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:825: in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:914: in send
    response = self._send_handling_auth(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:942: in _send_handling_auth
    response = self._send_handling_redirects(
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:979: in _send_handling_redirects
    response = self._send_single_request(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_client.py:1014: in _send_single_request
    response = transport.handle_request(request)
..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:249: in handle_request
    with map_httpcore_exceptions():
..\AppData\Local\Programs\Python\Python311\Lib\contextlib.py:158: in __exit__
    self.gen.throw(typ, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
            yield
        except Exception as exc:
            mapped_exc = None
    
            for from_exc, to_exc in HTTPCORE_EXC_MAP.items():
                if not isinstance(exc, from_exc):
                    continue
                # We want to map to the most specific exception we can find.
                # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
                # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
                if mapped_exc is None or issubclass(to_exc, mapped_exc):
                    mapped_exc = to_exc
    
            if mapped_exc is None:  # pragma: no cover
                raise
    
            message = str(exc)
>           raise mapped_exc(message) from exc
E           httpx.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it

..\AppData\Local\Programs\Python\Python311\Lib\site-packages\httpx\_transports\default.py:118: ConnectError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32948590>

    def connect(self) -> bool:
        """
        Connect to MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
        """
        try:
            if self.transport == "http":
>               return self._connect_http()

semantica\ingest\mcp_client.py:191: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
semantica\ingest\mcp_client.py:228: in _connect_http
    return self._initialize()
semantica\ingest\mcp_client.py:259: in _initialize
    response = self._send_request(request)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32948590>
request = {'id': 1, 'jsonrpc': '2.0', 'method': 'initialize', 'params': {'capabilities': {'roots': {'listChanged': True}}, 'clientInfo': {'name': 'semantica', 'version': '1.0.0'}, 'protocolVersion': '2024-11-05'}}

    def _send_request(self, request: Dict[str, Any]) -> Optional[Dict[str, Any]]:
        """
        Send JSON-RPC request to MCP server.
    
        Args:
            request: JSON-RPC request dictionary
    
        Returns:
            Response dictionary or None
        """
        if not self._connected:
            raise ProcessingError("Not connected to MCP server")
    
        try:
            if self.transport == "stdio":
                return self._send_request_stdio(request)
            elif self.transport == "http":
                return self._send_request_http(request)
            elif self.transport == "sse":
                return self._send_request_sse(request)
            else:
                raise ValidationError(f"Unsupported transport: {self.transport}")
        except Exception as e:
            self.logger.error(f"Failed to send request: {e}")
>           raise ProcessingError(f"Failed to send request: {e}") from e
E           semantica.utils.exceptions.ProcessingError: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_client.py:321: ProcessingError

The above exception was the direct cause of the following exception:

self = <semantica.ingest.mcp_ingestor.MCPIngestor object at 0x0000016D32949DD0>
server_name = 'threat_server', url = 'http://localhost:8000/mcp', headers = None
config = {}
client = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32948590>

    def connect(
        self,
        server_name: str,
        url: Optional[str] = None,
        headers: Optional[Dict[str, str]] = None,
        **config,
    ) -> bool:
        """
        Connect to an MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
        Users can bring their own Python/FastMCP MCP servers via URL.
    
        Args:
            server_name: Unique name for this MCP server connection
            url: MCP server URL (primary parameter)
                - http://localhost:8000/mcp
                - https://api.example.com/mcp
                - mcp://server-name
            headers: Custom headers for authentication (e.g., {"Authorization": "Bearer token"})
            **config: Additional configuration options (timeout, etc.)
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
            ValidationError: If URL is not provided or invalid
    
        Example:
            >>> ingestor = MCPIngestor()
            >>> ingestor.connect("db_server", url="http://localhost:8000/mcp")
            >>> ingestor.connect("api_server", url="https://api.example.com/mcp", headers={"Authorization": "Bearer token"})
        """
        try:
            # Check if already connected
            if server_name in self._clients:
                self.logger.warning(
                    f"Server {server_name} already connected, reconnecting..."
                )
                self.disconnect(server_name)
    
            # Validate URL
            if not url:
                raise ValidationError(
                    f"URL is required for MCP server connection. "
                    f"Provide MCP server URL: http://, https://, or mcp://"
                )
    
            # Create and connect client (transport auto-detected from URL)
            client = MCPClient(url=url, headers=headers, **config)
    
>           if client.connect():

semantica\ingest\mcp_ingestor.py:168: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32948590>

    def connect(self) -> bool:
        """
        Connect to MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
        """
        try:
            if self.transport == "http":
                return self._connect_http()
            elif self.transport == "sse":
                return self._connect_sse()
            else:
                raise ValidationError(f"Unsupported transport: {self.transport}")
        except Exception as e:
            self.logger.error(f"Failed to connect to MCP server: {e}")
>           raise ProcessingError(f"Failed to connect to MCP server: {e}") from e
E           semantica.utils.exceptions.ProcessingError: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_client.py:198: ProcessingError

The above exception was the direct cause of the following exception:

self = <tests.ingest.test_cookbook_integration.TestCookbookIntegration object at 0x0000016D2E0B6B50>
mock_mcp_server = <MagicMock name='post' id='1568511663504'>

    def test_threat_intelligence_integration(self, mock_mcp_server):
        """
        Validates the logic from cookbook/use_cases/cybersecurity/05_Threat_Intelligence_Integration.ipynb
        """
        mcp_ingestor = MCPIngestor()
        threat_mcp_url = "http://localhost:8000/mcp"
    
        with patch("semantica.ingest.mcp_ingestor.get_progress_tracker") as mock_tracker:
            tracker_instance = MagicMock()
            mock_tracker.return_value = tracker_instance
    
>           mcp_ingestor.connect(
                "threat_server",
                url=threat_mcp_url
            )

tests\ingest\test_cookbook_integration.py:190: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <semantica.ingest.mcp_ingestor.MCPIngestor object at 0x0000016D32949DD0>
server_name = 'threat_server', url = 'http://localhost:8000/mcp', headers = None
config = {}
client = <semantica.ingest.mcp_client.MCPClient object at 0x0000016D32948590>

    def connect(
        self,
        server_name: str,
        url: Optional[str] = None,
        headers: Optional[Dict[str, str]] = None,
        **config,
    ) -> bool:
        """
        Connect to an MCP server via URL.
    
        **IMPORTANT**: Supports only Python MCP servers and FastMCP servers.
        Users can bring their own Python/FastMCP MCP servers via URL.
    
        Args:
            server_name: Unique name for this MCP server connection
            url: MCP server URL (primary parameter)
                - http://localhost:8000/mcp
                - https://api.example.com/mcp
                - mcp://server-name
            headers: Custom headers for authentication (e.g., {"Authorization": "Bearer token"})
            **config: Additional configuration options (timeout, etc.)
    
        Returns:
            bool: True if connection successful
    
        Raises:
            ProcessingError: If connection fails
            ValidationError: If URL is not provided or invalid
    
        Example:
            >>> ingestor = MCPIngestor()
            >>> ingestor.connect("db_server", url="http://localhost:8000/mcp")
            >>> ingestor.connect("api_server", url="https://api.example.com/mcp", headers={"Authorization": "Bearer token"})
        """
        try:
            # Check if already connected
            if server_name in self._clients:
                self.logger.warning(
                    f"Server {server_name} already connected, reconnecting..."
                )
                self.disconnect(server_name)
    
            # Validate URL
            if not url:
                raise ValidationError(
                    f"URL is required for MCP server connection. "
                    f"Provide MCP server URL: http://, https://, or mcp://"
                )
    
            # Create and connect client (transport auto-detected from URL)
            client = MCPClient(url=url, headers=headers, **config)
    
            if client.connect():
                self._clients[server_name] = client
                self.logger.info(f"Connected to MCP server: {server_name} at {url}")
                return True
            else:
                raise ProcessingError(f"Failed to connect to MCP server: {server_name}")
        except Exception as e:
            self.logger.error(f"Failed to connect to MCP server {server_name}: {e}")
>           raise ProcessingError(
                f"Failed to connect to MCP server {server_name}: {e}"
            ) from e
E           semantica.utils.exceptions.ProcessingError: Failed to connect to MCP server threat_server: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it

semantica\ingest\mcp_ingestor.py:176: ProcessingError
------------------------------ Captured log call ------------------------------
ERROR    semantica.mcp_client:mcp_client.py:375 Failed to send HTTP request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:320 Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:272 Failed to initialize MCP protocol: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:230 Failed to connect via HTTP: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_client:mcp_client.py:197 Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
ERROR    semantica.mcp_ingestor:mcp_ingestor.py:175 Failed to connect to MCP server threat_server: Failed to connect to MCP server: Failed to send request: [WinError 10061] No connection could be made because the target machine actively refused it
=========================== short test summary info ===========================
FAILED tests/ingest/test_cookbook_integration.py::TestCookbookIntegration::test_financial_data_integration
FAILED tests/ingest/test_cookbook_integration.py::TestCookbookIntegration::test_supply_chain_data_integration
FAILED tests/ingest/test_cookbook_integration.py::TestCookbookIntegration::test_medical_database_integration
FAILED tests/ingest/test_cookbook_integration.py::TestCookbookIntegration::test_threat_intelligence_integration
4 failed, 37 passed in 26.17s
