Skip to content

fix(streamable-http): reduce stateless termination log noise#2357

Open
BlocksecPHD wants to merge 3 commits intomodelcontextprotocol:mainfrom
BlocksecPHD:fix/stateless-termination-log-2329
Open

fix(streamable-http): reduce stateless termination log noise#2357
BlocksecPHD wants to merge 3 commits intomodelcontextprotocol:mainfrom
BlocksecPHD:fix/stateless-termination-log-2329

Conversation

@BlocksecPHD
Copy link
Copy Markdown

Summary

This PR adjusts termination logging in StreamableHTTPServerTransport for stateless mode.

  • Keep INFO log for stateful session termination (session id exists)
  • Emit DEBUG log for stateless transport cleanup (mcp_session_id is None)
  • Update wording to reflect normal request completion in stateless mode

This addresses confusion reported in #2329 where users interpret Terminating session: None as an error condition.

Changes

  • src/mcp/server/streamable_http.py
    • Conditional log level/message in terminate()
  • tests/server/test_streamable_http_manager.py
    • Add regression test to assert:
      • debug message exists for stateless cleanup
      • info-style Terminating session: None message is not emitted

Validation

Ran targeted tests locally:

python -m pytest tests/server/test_streamable_http_manager.py \
  -k 'stateless_requests_memory_cleanup or stateless_termination_logs_debug_not_info'

Result: 2 passed

@km-anthropic
Copy link
Copy Markdown

@claude review

@dgenio
Copy link
Copy Markdown

dgenio commented Apr 9, 2026

The change is focused and correct. A few observations:

Code change: The conditional log level is the right approach — DEBUG for routine cleanup, INFO only for named session termination. The wording "Stateless request completed, cleaning up transport" is much clearer than "Terminating session: None".

Test: Well-structured and mirrors the existing test_stateless_requests_memory_cleanup pattern in the file. Using caplog.at_level(logging.DEBUG, ...) to capture the debug message is correct.

One minor nit: the del message in mock_send is a bit unusual — pass or ... is more idiomatic for a stub that just suppresses lint. Non-blocking though.

For context: #1696 / #1697 is a docs PR covering stateless mode semantics more broadly — this fix and that documentation would complement each other well for users trying to understand what stateless mode does and doesn't do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants