Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/mcp/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ async def __call__(
async def _default_message_handler(
message: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception,
) -> None:
if isinstance(message, Exception):
raise message
await anyio.lowlevel.checkpoint()


Expand Down
11 changes: 11 additions & 0 deletions tests/client/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,3 +1476,14 @@ async def test_send_notification_after_close_is_dropped_silently():
finally:
for s in (s2c_send, s2c_recv, c2s_send, c2s_recv):
s.close()


@pytest.mark.anyio
async def test_default_message_handler():
from mcp.client.session import _default_message_handler

with pytest.raises(ValueError, match="test error"):
await _default_message_handler(ValueError("test error"))

# Should not raise for non-exception
await _default_message_handler(types.ToolListChangedNotification())
2 changes: 1 addition & 1 deletion tests/transports/stdio/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_fallback_process_reports_death_through_returncode_without_a_wait_call()
try:
process = FallbackProcess(popen)

os.waitid(os.P_PID, popen.pid, os.WEXITED | os.WNOWAIT)
os.waitid(os.P_PID, popen.pid, os.WEXITED | os.WNOWAIT) # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType]
assert process.returncode == 0
finally:
popen.stdin.close()
Expand Down
Loading