{"record":{"id":"05cb6199a4916f32","repo":"langflow-ai/langflow","slug":"mcp-streamable-http-transport-is-not-initialized","errorCode":null,"errorMessage":"MCP Streamable HTTP transport is not initialized","messagePattern":"MCP Streamable HTTP transport is not initialized","errorType":"http","errorClass":"HTTPException","httpStatus":503,"severity":"error","filePath":"src/backend/base/langflow/api/v1/mcp.py","lineNumber":294,"sourceCode":"                await logger.adebug(\"Streamable HTTP session manager already running; skipping start\")\n                return\n            try:\n                self.session_manager = StreamableHTTPSessionManager(server, stateless=stateless)\n                self._mgr_ready = asyncio.Event()\n                self._mgr_close = asyncio.Event()\n                self._mgr_task = asyncio.create_task(self._start_session_manager())\n                await self._mgr_ready.wait()\n                if not self._started:  # did not start properly\n                    await self._mgr_task  # await to surface the exception\n            except Exception as e:\n                self._cleanup()\n                await logger.aexception(f\"Error starting Streamable HTTP session manager: {e}\")\n                raise\n\n    def get_manager(self) -> StreamableHTTPSessionManager:\n        \"\"\"Fetch the active Streamable HTTP session manager or raise if it is unavailable.\"\"\"\n        if not self._started or self.session_manager is None:\n            raise HTTPException(status_code=503, detail=\"MCP Streamable HTTP transport is not initialized\")\n        return self.session_manager\n\n    async def stop(self) -> None:\n        \"\"\"Close the Streamable HTTP session manager context.\"\"\"\n        async with self._start_stop_lock:\n            if not self._started:\n                return\n            try:\n                self._mgr_close.set()  # type: ignore[union-attr]\n                await self._mgr_task  # type: ignore[misc]\n            except Exception as e:\n                await logger.aexception(f\"Error stopping Streamable HTTP session manager: {e}\")\n                raise\n            finally:\n                self._cleanup()\n                await logger.adebug(\"Streamable HTTP session manager stopped\")\n\n    def _cleanup(self) -> None:","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/mcp.py#L276-L312","documentation":"StreamableHTTP.get_manager() raises HTTP 503 when the Streamable HTTP session manager has not been started (self._started is False or session_manager is None). The manager starts asynchronously in a background task at application lifespan; any request arriving before startup completes — or after a failed/cleaned-up startup — gets this 503.","triggerScenarios":"A Streamable HTTP MCP request (POST/GET/DELETE on the streamable endpoint) hitting the server during startup before the lifespan task finishes; a startup failure that ran _cleanup(); tests that mount the router without running the FastAPI lifespan; a stop()/restart cycle leaving _started false.","commonSituations":"Health-check or load-balancer probes firing immediately at pod boot; unit/integration tests using TestClient without lifespan; a crashed session-manager task after an exception (logged as 'Error starting Streamable HTTP session manager').","solutions":["Retry with backoff — the transport becomes available once the lifespan startup completes.","Ensure your deployment/test harness runs the FastAPI lifespan (TestClient(context_manager=...) or httpx ASGITransport with lifespan), not just the app routes.","Check server logs for 'Error starting Streamable HTTP session manager' if the 503 persists — the manager failed to start, not still starting.","Delay MCP traffic until your readiness probe reports healthy."],"exampleFix":"# test harness: ensure lifespan runs\n# before\nclient = TestClient(app)  # may skip lifespan depending on version\n\n# after\nwith TestClient(app) as client:  # runs startup/shutdown\n    client.post(\"/api/v1/mcp/streamable\", json=initialize_msg)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"resp = await client.post(endpoint, json=msg)\nif resp.status_code == 503 and 'not initialized' in resp.text: await asyncio.sleep(0.5); retry with backoff (max ~10s)","preventionTips":["Gate MCP traffic on a readiness probe so requests only arrive after lifespan startup.","In tests, always run the app via its lifespan context manager."],"tags":["mcp","http-503","startup","lifespan","streamable-http"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}