Skip to content

Commit 8638fc2

Browse files
authored
fix: include root cause in MCPClientInitializationError message (#2238)
1 parent a245e6d commit 8638fc2

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/strands/tools/mcp/mcp_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def start(self) -> "MCPClient":
220220
logger.exception("client failed to initialize")
221221
# Pass None for exc_type, exc_val, exc_tb since this isn't a context manager exit
222222
self.stop(None, None, None)
223-
raise MCPClientInitializationError("the client initialization failed") from e
223+
raise MCPClientInitializationError(f"the client initialization failed: {e}") from e
224224
return self
225225

226226
# ToolProvider interface methods

tests/strands/tools/mcp/test_mcp_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,10 @@ def test_enter_with_initialization_exception(mock_transport):
386386
client = MCPClient(mock_transport["transport_callable"])
387387

388388
with patch.object(client, "stop") as mock_stop:
389-
with pytest.raises(MCPClientInitializationError, match="the client initialization failed"):
389+
with pytest.raises(
390+
MCPClientInitializationError,
391+
match="the client initialization failed: Transport initialization failed",
392+
):
390393
client.start()
391394

392395
# Verify stop() was called for cleanup

0 commit comments

Comments
 (0)