{"record":{"id":"8c10f585d7308a07","repo":"langflow-ai/langflow","slug":"internal-server-error-e","errorCode":null,"errorMessage":"Internal server error: {e}","messagePattern":"Internal server error: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/backend/base/langflow/api/v1/mcp.py","lineNumber":240,"sourceCode":"            except Exception as e:\n                msg = f\"Error in MCP: {e!s}\"\n                await logger.aexception(msg)\n                raise\n    finally:\n        current_user_ctx.reset(token)\n\n\n@router.post(\"/\", dependencies=[Depends(raise_error_if_astra_cloud_env)])\nasync def handle_messages(request: Request, current_user: CurrentActiveMCPUser):\n    _bind_mcp_transport_user(request, current_user)\n    try:\n        await sse.handle_post_message(request.scope, request.receive, request._send)  # noqa: SLF001\n    except (BrokenResourceError, BrokenPipeError) as e:\n        await logger.ainfo(\"MCP Server disconnected\")\n        raise HTTPException(status_code=404, detail=f\"MCP Server disconnected, error: {e}\") from e\n    except Exception as e:\n        await logger.aerror(f\"Internal server error: {e}\")\n        raise HTTPException(status_code=500, detail=f\"Internal server error: {e}\") from e\n\n\n################################################################################\n# Streamable HTTP Transport\n################################################################################\nclass StreamableHTTP:\n    def __init__(self) -> None:\n        self.session_manager: StreamableHTTPSessionManager | None = None\n        self._started = False\n        self._start_stop_lock = asyncio.Lock()\n        # own the lifecycle of the session manager\n        # inside an asyncio task to ensure that\n        # __aenter__ and __aexit__ happen in the same task\n        self._mgr_task: asyncio.Task | None = None\n        self._mgr_ready: asyncio.Event | None = None\n        self._mgr_close: asyncio.Event | None = None\n\n    async def _start_session_manager(self) -> None:","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/mcp.py#L222-L258","documentation":"Catch-all 500 from the MCP SSE POST handler (POST /api/v1/mcp/): any exception other than BrokenResourceError/BrokenPipeError while processing an MCP message escapes sse.handle_post_message. The real cause is only in the server log (logger.aexception with 'Internal server error: {e}'), the response body carries no details.","triggerScenarios":"Malformed JSON-RPC bodies that break the MCP SDK session handler; bugs in a tool implementation invoked during the message; session state corruption when the POST references an unknown/expired session_id; DB errors while resolving the bound user.","commonSituations":"Custom MCP tools raising unhandled exceptions; sending a POST with a session_id from a previous server restart; SDK version mismatch between client and server MCP protocol versions.","solutions":["Inspect the Langflow server logs for the 'Internal server error: {e}' line — the detail= message is deliberately generic.","Confirm the session_id matches a live SSE session created by GET /api/v1/mcp/ on the same server process.","Reproduce with a minimal JSON-RPC message (initialize, tools/list) to isolate tool bugs from transport bugs.","Fix or wrap the failing tool so it returns a JSON-RPC error instead of raising."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import json\n\ndef well_formed_jsonrpc(body: bytes) -> bool:\n    try:\n        obj = json.loads(body)\n        return isinstance(obj, dict) and 'jsonrpc' in obj and 'method' in obj\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"Catch HTTPError with status 500 on the MCP POST; log server-side exception id from logs, do not retry blindly (non-idempotent tool calls).","preventionTips":["Always correlate client failures with the server log line 'Internal server error: {e}'.","Make MCP tool implementations return JSON-RPC errors instead of raising."],"tags":["mcp","sse","http-500","server-error","logging"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}