langflow-ai/langflow · error · HTTPException

MCP Streamable HTTP transport is not initialized

Error message

MCP Streamable HTTP transport is not initialized

What it means

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.

Source

Thrown at src/backend/base/langflow/api/v1/mcp.py:294

                await logger.adebug("Streamable HTTP session manager already running; skipping start")
                return
            try:
                self.session_manager = StreamableHTTPSessionManager(server, stateless=stateless)
                self._mgr_ready = asyncio.Event()
                self._mgr_close = asyncio.Event()
                self._mgr_task = asyncio.create_task(self._start_session_manager())
                await self._mgr_ready.wait()
                if not self._started:  # did not start properly
                    await self._mgr_task  # await to surface the exception
            except Exception as e:
                self._cleanup()
                await logger.aexception(f"Error starting Streamable HTTP session manager: {e}")
                raise

    def get_manager(self) -> StreamableHTTPSessionManager:
        """Fetch the active Streamable HTTP session manager or raise if it is unavailable."""
        if not self._started or self.session_manager is None:
            raise HTTPException(status_code=503, detail="MCP Streamable HTTP transport is not initialized")
        return self.session_manager

    async def stop(self) -> None:
        """Close the Streamable HTTP session manager context."""
        async with self._start_stop_lock:
            if not self._started:
                return
            try:
                self._mgr_close.set()  # type: ignore[union-attr]
                await self._mgr_task  # type: ignore[misc]
            except Exception as e:
                await logger.aexception(f"Error stopping Streamable HTTP session manager: {e}")
                raise
            finally:
                self._cleanup()
                await logger.adebug("Streamable HTTP session manager stopped")

    def _cleanup(self) -> None:

View on GitHub (pinned to 976ec789d2)

Solutions

  1. Retry with backoff — the transport becomes available once the lifespan startup completes.
  2. Ensure your deployment/test harness runs the FastAPI lifespan (TestClient(context_manager=...) or httpx ASGITransport with lifespan), not just the app routes.
  3. Check server logs for 'Error starting Streamable HTTP session manager' if the 503 persists — the manager failed to start, not still starting.
  4. Delay MCP traffic until your readiness probe reports healthy.

Example fix

# test harness: ensure lifespan runs
# before
client = TestClient(app)  # may skip lifespan depending on version

# after
with TestClient(app) as client:  # runs startup/shutdown
    client.post("/api/v1/mcp/streamable", json=initialize_msg)
Defensive patterns

Strategy: retry

Try / catch

resp = await client.post(endpoint, json=msg)
if resp.status_code == 503 and 'not initialized' in resp.text: await asyncio.sleep(0.5); retry with backoff (max ~10s)

Prevention

When it happens

Trigger: 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.

Common situations: 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').

Related errors


AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14). Data as JSON: /api/errors/05cb6199a4916f32. Report an issue: GitHub.