{"record":{"id":"5da88cfcd9b30763","repo":"langflow-ai/langflow","slug":"project-id-is-required-to-start-mcp-server","errorCode":null,"errorMessage":"Project ID is required to start MCP server","messagePattern":"Project ID is required to start MCP server","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"src/backend/base/langflow/api/v1/mcp_projects.py","lineNumber":281,"sourceCode":"        ).first()\n\n        if not project_access:\n            raise HTTPException(status_code=404, detail=\"Project not found\")\n\n        return user\n\n\n# Create project-specific context variable\ncurrent_project_ctx: ContextVar[UUID | None] = ContextVar(\"current_project_ctx\", default=None)\n\n# Mapping of project-specific SSE transports\nproject_sse_transports: dict[str, SseServerTransport] = {}\n\n\ndef get_project_sse(project_id: UUID | None) -> SseServerTransport:\n    \"\"\"Get or create an SSE transport for a specific project.\"\"\"\n    if not project_id:\n        raise HTTPException(status_code=400, detail=\"Project ID is required to start MCP server\")\n\n    project_id_str = str(project_id)\n    if project_id_str not in project_sse_transports:\n        project_sse_transports[project_id_str] = SseServerTransport(f\"/api/v1/mcp/project/{project_id_str}/\")\n    return project_sse_transports[project_id_str]\n\n\nasync def _build_project_tools_response(\n    project_id: UUID,\n    current_user: CurrentActiveMCPUser,\n    *,\n    mcp_enabled: bool,\n) -> MCPProjectResponse:\n    \"\"\"Return tool metadata for a project.\"\"\"\n    tools: list[MCPSettings] = []\n    try:\n        async with session_scope() as session:\n            # Fetch the project first to verify it exists and belongs to the current user","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/mcp_projects.py#L263-L299","documentation":"400 from get_project_sse: it was called with a falsy project_id (None or empty), so it cannot build the project-scoped SSE transport path /api/v1/mcp/project/{id}/. In practice the id should come from the request path; reaching this with None indicates the project context variable was never set — a server-side wiring bug or a route mounted without the project parameter resolved, not a client formatting mistake.","triggerScenarios":"An SSE connect request where the project_id dependency resolved to None (route mismatch, misconfigured path parameter, or code calling get_project_sse(current_project_ctx.get()) before the context var was set).","commonSituations":"Custom deployments or forks that mount the MCP project routes under a different path pattern; race where the SSE connect handler runs before _bind_project_context; tests invoking handlers directly without the path param.","solutions":["Use the stock route path /api/v1/mcp/project/{project_id}/sse so FastAPI injects the id.","If you forked/mounted routes, ensure the {project_id} path parameter name matches the endpoint signature.","In tests, pass an explicit project UUID rather than relying on the context var.","Check that auth dependencies that set current_project_ctx run before the SSE handler."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def has_project_id(pid) -> bool:\n    return pid is not None and str(pid) != ''","typeGuard":null,"tryCatchPattern":"except 400 'Project ID is required': this is a routing/wiring defect — verify the endpoint path includes the project UUID; no client retry helps.","preventionTips":["Use the stock /api/v1/mcp/project/{project_id}/sse route shape.","In tests, pass explicit UUIDs instead of relying on context variables."],"tags":["mcp","sse","http-400","routing","internal-error"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}