pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/modelcontextprotocol/python-sdk/commit/eaf971cf252692c94d3f76d3b9063eaddc7f5eb4

crossorigen="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-b40ec823a1a6a1af.css" /> Add warning log when rejecting request with unknown/expired session I… · modelcontextprotocol/python-sdk@eaf971c · GitHub
Skip to content

Commit eaf971c

Browse files
rameshreddy-adutlaCopilotmaxisbey
authored
Add warning log when rejecting request with unknown/expired session ID (#2212)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
1 parent 92f1b15 commit eaf971c

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/mcp/server/streamable_http_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ 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.info(f"Rejected request with unknown or expired session ID: {request_mcp_session_id[:64]}")
275276
error_response = JSONRPCError(
276277
jsonrpc="2.0",
277278
id=None,

tests/server/test_streamable_http_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for StreamableHTTPSessionManager."""
22

33
import json
4+
import logging
45
from typing import Any
56
from unittest.mock import AsyncMock, patch
67

@@ -269,7 +270,7 @@ async def mock_receive():
269270

270271

271272
@pytest.mark.anyio
272-
async def test_unknown_session_id_returns_404():
273+
async def test_unknown_session_id_returns_404(caplog: pytest.LogCaptureFixture):
273274
"""Test that requests with unknown session IDs return HTTP 404 per MCP spec."""
274275
app = Server("test-unknown-session")
275276
manager = StreamableHTTPSessionManager(app=app)
@@ -299,7 +300,8 @@ async def mock_send(message: Message):
299300
async def mock_receive():
300301
return {"type": "http.request", "body": b"{}", "more_body": False} # pragma: no cover
301302

302-
await manager.handle_request(scope, mock_receive, mock_send)
303+
with caplog.at_level(logging.INFO):
304+
await manager.handle_request(scope, mock_receive, mock_send)
303305

304306
# Find the response start message
305307
response_start = next(
@@ -315,6 +317,7 @@ async def mock_receive():
315317
assert error_data["id"] is None
316318
assert error_data["error"]["code"] == INVALID_REQUEST
317319
assert error_data["error"]["message"] == "Session not found"
320+
assert "Rejected request with unknown or expired session ID: non-existent-session-id" in caplog.text
318321

319322

320323
@pytest.mark.anyio

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy