Skip to content

Commit 653bea6

Browse files
[autofix.ci] apply automated fixes (attempt 2/3)
1 parent 3daabfd commit 653bea6

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
lines changed

src/backend/base/langflow/api/v1/mcp.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,42 @@ async def handle_global_call_tool(name: str, arguments: dict) -> list[types.Text
5656

5757

5858
sse = SseServerTransport("/api/v1/mcp/")
59+
60+
5961
########################################################
6062
# SseServerTransport.connect_sse handles the full ASGI response internally
6163
# but FastAPI still expects the endpoint to return a Response,
6264
# this results in ungraceful termination of the SSE connection
6365
# We use this class to return a Response that FastAPI can handle gracefully
6466
########################################################
6567
class SSECompletedNoOp(Response):
66-
async def __call__(self, scope, receive, send) -> None: # noqa: ARG002
68+
async def __call__(self, scope, receive, send) -> None: # noqa: ARG002
6769
# connect_sse already produced the ASGI response; nothing left to send.
6870
return
6971

72+
7073
# Manage state of the Streamable HTTP session manager
7174
streamable_http_session_manager: StreamableHTTPSessionManager | None = None
7275

76+
7377
def init_streamable_http_manager(*, stateless: bool = True) -> StreamableHTTPSessionManager:
7478
"""Create and register a Streamable HTTP session manager for the global MCP server."""
75-
global streamable_http_session_manager # noqa: PLW0603
79+
global streamable_http_session_manager # noqa: PLW0603
7680
streamable_http_session_manager = StreamableHTTPSessionManager(server, stateless=stateless)
7781
return streamable_http_session_manager
7882

83+
7984
def get_streamable_http_manager() -> StreamableHTTPSessionManager:
8085
"""Fetch the active Streamable HTTP session manager or raise if it is unavailable."""
81-
global streamable_http_session_manager # noqa: PLW0602
86+
global streamable_http_session_manager # noqa: PLW0602
8287
if streamable_http_session_manager is None:
8388
raise HTTPException(status_code=503, detail="MCP Streamable HTTP transport is not initialized")
8489
return streamable_http_session_manager
8590

91+
8692
def clear_streamable_http_manager() -> None:
8793
"""Clear the currently active Streamable HTTP session manager reference."""
88-
global streamable_http_session_manager # noqa: PLW0603
94+
global streamable_http_session_manager # noqa: PLW0603
8995
streamable_http_session_manager = None
9096

9197

@@ -187,6 +193,8 @@ async def _dispatch_streamable_http(
187193

188194

189195
streamable_http_methods = ["GET", "POST", "DELETE"]
196+
197+
190198
@router.api_route("/streamable", methods=streamable_http_methods)
191199
@router.api_route("/streamable/", methods=streamable_http_methods)
192200
async def handle_streamable_http(request: Request, current_user: CurrentActiveMCPUser):

src/backend/base/langflow/api/v1/mcp_projects.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
)
7979

8080

81-
8281
async def verify_project_auth(
8382
db: AsyncSession,
8483
project_id: UUID,
@@ -213,7 +212,6 @@ def get_project_sse(project_id: UUID | None) -> SseServerTransport:
213212
return project_sse_transports[project_id_str]
214213

215214

216-
217215
async def _build_project_tools_response(
218216
project_id: UUID,
219217
current_user: CurrentActiveMCPUser,
@@ -320,7 +318,7 @@ async def im_alive(project_id: str): # noqa: ARG001
320318

321319

322320
@router.head("/{project_id}/streamable", include_in_schema=False)
323-
async def streamable_health(project_id: UUID): # noqa: ARG001
321+
async def streamable_health(project_id: UUID): # noqa: ARG001
324322
return Response()
325323

326324

@@ -345,9 +343,7 @@ async def _dispatch_project_streamable_http(
345343
except HTTPException:
346344
raise
347345
except Exception as exc:
348-
await logger.aexception(
349-
f"Error handling Streamable HTTP request for project {project_id}: {exc!s}"
350-
)
346+
await logger.aexception(f"Error handling Streamable HTTP request for project {project_id}: {exc!s}")
351347
raise HTTPException(status_code=500, detail="Internal server error in project MCP transport") from exc
352348
finally:
353349
current_request_variables_ctx.reset(request_vars_token)
@@ -433,8 +429,11 @@ async def _handle_project_sse_messages(
433429
current_project_ctx.reset(project_token)
434430
current_request_variables_ctx.reset(req_vars_token)
435431

432+
436433
# legacy SSE transport
437434
project_messages_methods = ["POST", "DELETE"]
435+
436+
438437
@router.api_route("/{project_id}", methods=project_messages_methods)
439438
@router.api_route("/{project_id}/", methods=project_messages_methods)
440439
async def handle_project_messages(
@@ -445,8 +444,11 @@ async def handle_project_messages(
445444
"""Handle POST/DELETE messages for a project-specific MCP server."""
446445
return await _handle_project_sse_messages(project_id, request, current_user)
447446

447+
448448
# Streamable HTTP transport
449449
streamable_http_methods = ["GET", "POST", "DELETE"]
450+
451+
450452
@router.api_route("/{project_id}/streamable", methods=streamable_http_methods)
451453
@router.api_route("/{project_id}/streamable/", methods=streamable_http_methods)
452454
async def handle_project_streamable_http(

src/backend/base/langflow/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,9 @@ async def delayed_init_mcp_servers():
308308
mcp_init_task = asyncio.create_task(delayed_init_mcp_servers())
309309

310310
# Start streamable-http transport session manager for MCP server
311-
from contextlib import AsyncExitStack # noqa: I001
311+
from contextlib import AsyncExitStack # noqa: I001
312312
from langflow.api.v1.mcp import init_streamable_http_manager
313+
313314
await logger.adebug("Starting MCP Server Streamable HTTP session manager")
314315
async with AsyncExitStack() as stack:
315316
await stack.enter_async_context(init_streamable_http_manager().run())

src/backend/tests/integration/test_projects_integration.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212

1313

1414
@pytest.mark.asyncio
15-
async def test_project_authentication_settings(
16-
client: AsyncClient,
17-
logged_in_headers
18-
):
15+
async def test_project_authentication_settings(client: AsyncClient, logged_in_headers):
1916
"""Integration test: Project authentication settings configuration."""
2017
# Scenario 1: AUTO_LOGIN disabled -> API key auth
2118
with patch("langflow.api.v1.projects.get_settings_service") as mock_get_settings:

src/backend/tests/unit/api/v1/test_mcp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ async def test_find_validation_error_with_pydantic_error():
192192
# Create a pydantic ValidationError by catching it
193193
validation_error = None
194194
try:
195+
195196
class TestModel(pydantic.BaseModel):
196197
required_field: str
197198

@@ -226,6 +227,7 @@ async def test_find_validation_error_with_context():
226227
# Create a pydantic ValidationError by catching it
227228
validation_error = None
228229
try:
230+
229231
class TestModel(pydantic.BaseModel):
230232
required_field: str
231233

@@ -263,8 +265,10 @@ async def test_mcp_sse_validation_error_logged():
263265
# Verify the function exists and works
264266
validation_error = None
265267
try:
268+
266269
class TestModel(pydantic.BaseModel):
267270
required_field: str
271+
268272
TestModel()
269273
except pydantic.ValidationError as e:
270274
validation_error = e

src/backend/tests/unit/api/v1/test_mcp_projects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ def _prepare_install_test_env(monkeypatch, tmp_path, filename="cursor.json"):
602602
config_path.parent.mkdir(parents=True, exist_ok=True)
603603

604604
monkeypatch.setattr("langflow.api.v1.mcp_projects.get_client_ip", lambda request: "127.0.0.1")
605+
605606
async def fake_get_config_path(client_name):
606607
return config_path
607608

src/lfx/src/lfx/services/mcp_composer/service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class MCPComposerService(Service):
7373

7474
def __init__(self):
7575
super().__init__()
76-
self.project_composers: dict[str, dict] = {} # project_id -> {process, host, port, streamable_http_url, auth_config}
76+
self.project_composers: dict[
77+
str, dict
78+
] = {} # project_id -> {process, host, port, streamable_http_url, auth_config}
7779
self._start_locks: dict[
7880
str, asyncio.Lock
7981
] = {} # Lock to prevent concurrent start operations for the same project
@@ -1045,9 +1047,7 @@ async def _do_start_project_composer(
10451047

10461048
project_host = auth_config.get("oauth_host") if auth_config else "unknown"
10471049
project_port = auth_config.get("oauth_port") if auth_config else "unknown"
1048-
await logger.adebug(
1049-
f"Starting MCP Composer for project {project_id} on {project_host}:{project_port}"
1050-
)
1050+
await logger.adebug(f"Starting MCP Composer for project {project_id} on {project_host}:{project_port}")
10511051

10521052
# Use a per-project lock to prevent race conditions
10531053
if project_id not in self._start_locks:

0 commit comments

Comments
 (0)