You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Audit and refactor unit tests to use new Client class #1891
It uses anyio memory streams to wire a Server directly to a ClientSession — no subprocess, no HTTP, no stdio. Might be useful context for the refactor direction here:
@claude can you check what tests can move to use Client, as mentioned by the OP? Please apply the suggestion in case of simplification, if the test becomes more complicated, do not use Client.
Audit complete: Tests already optimally use Client class ✓
Understand the new Client class pattern by reading reference test file
Audit existing test files to identify candidates for refactoring
Assess which tests would be simplified by using Client
Refactor tests to use Client where it simplifies them
Run tests to verify changes
Push changes to branch
Summary
After a comprehensive audit of the test suite, I found that the codebase is already in excellent shape - tests are using Client where appropriate, and tests using ClientSession directly are doing so for valid technical reasons.
Tests already using Client (following best practices)
These tests correctly use the high-level Client class for E2E testing:
Activity
refactor: use Client class in tests
peytongreen-dev commentedon Mar 30, 2026
Related: I just published
mcp-testclient(https://pypi.org/project/mcp-testclient/) which provides a pytest-nativeTestClientfor the low-levelServerclass.It uses anyio memory streams to wire a
Serverdirectly to aClientSession— no subprocess, no HTTP, no stdio. Might be useful context for the refactor direction here:Repo: https://github.com/peytongreen-dev/mcp-testclient
Kludex commentedon Apr 5, 2026
@claude can you check what tests can move to use Client, as mentioned by the OP? Please apply the suggestion in case of simplification, if the test becomes more complicated, do not use Client.
claude commentedon Apr 5, 2026
Claude finished @Kludex's task in 2m 54s —— View job
Audit complete: Tests already optimally use Client class ✓
Clientclass pattern by reading reference test fileClientClientwhere it simplifies themSummary
After a comprehensive audit of the test suite, I found that the codebase is already in excellent shape - tests are using
Clientwhere appropriate, and tests usingClientSessiondirectly are doing so for valid technical reasons.Tests already using
Client(following best practices)These tests correctly use the high-level
Clientclass for E2E testing:tests/client/test_client.py- Reference implementationtests/client/test_sampling_callback.pytests/client/test_list_roots_callback.pytests/client/test_logging_callback.pytests/server/mcpserver/test_integration.pytests/server/mcpserver/test_elicitation.pytests/server/mcpserver/test_url_elicitation.pytests/server/mcpserver/test_server.pytests/server/lowlevel/test_server_listing.pytests/shared/test_progress_notifications.py(2nd test uses Client)Tests correctly using
ClientSessiondirectlyThese tests appropriately use
ClientSessionfor testing low-level functionality:Transport-specific tests:
tests/client/test_session.py- TestingClientSessioninternalstests/client/test_stdio.py- Testing stdio transport layertests/client/test_http_unicode.py- Testing HTTP Unicode handlingtests/client/test_notification_response.py- Testing HTTP error handlingtests/shared/test_streamable_http.py- Testing HTTP transport internalstests/shared/test_sse.py- Testing SSE transporttests/shared/test_ws.py- Testing WebSocket transportLow-level session tests:
tests/shared/test_progress_notifications.py(1st test) - Bidirectional progress with manual stream controltests/issues/test_88_random_error.py- Testing timeout/session edge casestests/server/test_session.py- Server session internalstests/server/test_cancel_handling.py- Cancellation handlingtests/server/test_*(various) - Low-level server behaviorExperimental features:
tests/experimental/tasks/client/test_handlers.py- Task handler internalstests/experimental/tasks/test_elicitation_scenarios.py- Task integration scenariosOther valid reasons:
tests/client/test_session_group.py- TestingClientSessionGroup(different abstraction)tests/issues/test_scope_bug_1630.py- OAuth authentication (no MCP client/server)tests/issues/test_100_tool_listing.py- Direct server testing (no client needed)Conclusion
No refactoring needed. The test suite already follows the guidance from CLAUDE.md:
The tests using
Clientdo so for E2E testing, while tests usingClientSessiondirectly are appropriately testing:The codebase demonstrates good separation of concerns between high-level E2E tests (using
Client) and low-level unit tests (usingClientSession).