mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-17 23:51:30 +00:00
fix(mcp): respect stateful routing and harden initialize detection
Ensure streamable MCP requests are dispatched via the computed target session manager, and guard initialize detection against non-object JSON bodies. Update stale-session test patches to target the stateful manager so routing assertions remain correct. Made-with: Cursor
This commit is contained in:
parent
ad887c9157
commit
1a2aa62c0f
2 changed files with 4 additions and 4 deletions
|
|
@ -2544,7 +2544,7 @@ if MCP_AVAILABLE:
|
|||
return False
|
||||
try:
|
||||
data = json.loads(body)
|
||||
return data.get("method") == "initialize"
|
||||
return isinstance(data, dict) and data.get("method") == "initialize"
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
return False
|
||||
|
||||
|
|
@ -2848,7 +2848,7 @@ if MCP_AVAILABLE:
|
|||
mcp_servers,
|
||||
_client_ip,
|
||||
):
|
||||
await session_manager.handle_request(scope, receive, send)
|
||||
await target_manager.handle_request(scope, receive, send)
|
||||
except HTTPException:
|
||||
# Re-raise HTTP exceptions to preserve status codes and details
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -384,12 +384,12 @@ async def test_valid_mcp_session_id_is_preserved():
|
|||
True,
|
||||
),
|
||||
patch.object(
|
||||
session_manager,
|
||||
session_manager_stateful,
|
||||
"handle_request",
|
||||
side_effect=mock_handle_request,
|
||||
),
|
||||
patch.object(
|
||||
session_manager,
|
||||
session_manager_stateful,
|
||||
"_server_instances",
|
||||
mock_instances,
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue