From 86154f8f13d74a590a0872bb9b52b5c23196d4a7 Mon Sep 17 00:00:00 2001 From: Yug Borana Date: Wed, 29 Apr 2026 13:24:15 +0530 Subject: [PATCH] Update litellm/proxy/_experimental/mcp_server/server.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- litellm/proxy/_experimental/mcp_server/server.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/_experimental/mcp_server/server.py index a7f68f00b1c..8028bd295cb 100644 --- a/litellm/proxy/_experimental/mcp_server/server.py +++ b/litellm/proxy/_experimental/mcp_server/server.py @@ -2718,6 +2718,20 @@ if MCP_AVAILABLE: from starlette.responses import JSONResponse from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR + error_response = JSONResponse( + status_code=HTTP_500_INTERNAL_SERVER_ERROR, + content={"error": "MCP request failed", "details": str(e)}, + ) + except HTTPException: + raise + except Exception as e: + verbose_logger.exception(f"Error handling MCP request: {e}") + # Instead of re-raising, try to send a graceful error response + try: + # Send a proper HTTP error response instead of letting the exception bubble up + from starlette.responses import JSONResponse + from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR + error_response = JSONResponse( status_code=HTTP_500_INTERNAL_SERVER_ERROR, content={"error": "MCP request failed", "details": str(e)},