Skip to content

Commit ed2141b

Browse files
author
Alberto Farah
committed
fix: add warning log for unknown/expired session ID in _handle_stateful_request
When a request arrives with an unknown or expired session ID, the server now logs a warning before returning 404. This helps operators diagnose stale session issues in production. Closes #2204
1 parent b33c811 commit ed2141b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/mcp/server/streamable_http_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ async def run_server(*, task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORE
272272
# Unknown or expired session ID - return 404 per MCP spec
273273
# TODO: Align error code once spec clarifies
274274
# See: https://github.com/modelcontextprotocol/python-sdk/issues/1821
275+
logger.warning(
276+
"Rejected request with unknown or expired session ID: %s",
277+
session_id,
278+
)
275279
error_response = JSONRPCError(
276280
jsonrpc="2.0",
277281
id=None,

0 commit comments

Comments
 (0)