|
23 | 23 | import structlog |
24 | 24 | from unittest.mock import patch, MagicMock, AsyncMock |
25 | 25 |
|
| 26 | +import httpx |
26 | 27 | import jwt as pyjwt |
27 | 28 | from jwt import PyJWKClient, PyJWKClientError, ExpiredSignatureError |
28 | 29 | from mcp.server.lowlevel.server import request_ctx |
@@ -423,6 +424,34 @@ def test_streamable_http_transport_is_stateless(self): |
423 | 424 |
|
424 | 425 | assert mcp.settings.stateless_http is True |
425 | 426 |
|
| 427 | + @pytest.mark.asyncio |
| 428 | + async def test_transport_logging_wraps_unauthorized_responses(self, caplog): |
| 429 | + with patch("dremioai.servers.mcp.tools.get_tools", return_value=[]), patch( |
| 430 | + "dremioai.servers.mcp.tools.get_resources", return_value=[] |
| 431 | + ): |
| 432 | + mcp = init( |
| 433 | + mode=None, |
| 434 | + transport=Transports.streamable_http, |
| 435 | + host="127.0.0.1", |
| 436 | + port=8000, |
| 437 | + mock=True, |
| 438 | + ) |
| 439 | + |
| 440 | + app = mcp.streamable_http_app() |
| 441 | + transport = httpx.ASGITransport(app=app) |
| 442 | + async with httpx.AsyncClient( |
| 443 | + transport=transport, base_url="http://testserver" |
| 444 | + ) as client: |
| 445 | + with caplog.at_level(logging.INFO): |
| 446 | + response = await client.post("/mcp") |
| 447 | + |
| 448 | + assert response.status_code == 401 |
| 449 | + messages = [str(r.message) for r in caplog.records if r.levelno >= logging.INFO] |
| 450 | + assert any("Unauthorized request rejected" in msg for msg in messages) |
| 451 | + assert any( |
| 452 | + "MCP transport request failed" in msg and "401" in msg for msg in messages |
| 453 | + ) |
| 454 | + |
426 | 455 |
|
427 | 456 | class TestMakeLoggedInvoke: |
428 | 457 | """Tests for make_logged_invoke WARNING logging on tool exceptions.""" |
|
0 commit comments