Skip to content

Add warning log when rejecting request with unknown/expired session ID#2212

Open
rameshreddy-adutla wants to merge 2 commits intomodelcontextprotocol:mainfrom
rameshreddy-adutla:fix/2204-log-unknown-session-id
Open

Add warning log when rejecting request with unknown/expired session ID#2212
rameshreddy-adutla wants to merge 2 commits intomodelcontextprotocol:mainfrom
rameshreddy-adutla:fix/2204-log-unknown-session-id

Conversation

@rameshreddy-adutla
Copy link

Summary

Add a logger.warning() call in the else branch of StreamableHTTPSessionManager._handle_stateful_request() when rejecting a request with an unknown or expired session ID.

Problem

The else branch silently returns HTTP 404 without any logging. The other two branches both log:

  • logger.debug("Session already exists...") (existing session)
  • logger.info("Created new transport...") (new session)

This made it very difficult to diagnose connection failures in production — for example, after a server restart when clients continued sending stale mcp-session-id headers. Operators had to wrap the ASGI app in custom middleware just to see why requests were being rejected.

Fix

Add logger.warning() with the rejected session ID before returning the 404 response. Using warning level (not debug/info) since this typically indicates a problem that operators should investigate.

Testing

Existing test test_unknown_session_id_returns_404 passes and now shows the warning in log output:

WARNING mcp.server.streamable_http_manager: Rejected request with unknown or expired session ID: non-existent-session-id

Fixes #2204

rameshreddy-adutla and others added 2 commits March 4, 2026 21:18
The else branch in _handle_stateful_request() silently returns 404
when a request has an unknown or expired session ID. The other two
branches (existing session, new session) both log at debug/info level.

Add a logger.warning() call so operators can diagnose why client
connections are being rejected, e.g. after a server restart when
clients send stale session IDs.

Fixes modelcontextprotocol#2204

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

No logging in _handle_stateful_request when session ID is unknown/expired

1 participant