Skip to content

Conversation

@HzaRashid
Copy link
Collaborator

@HzaRashid HzaRashid commented Dec 18, 2025

introduce an environment variable to expose and set the streamable-http session manager's stateless flag in langflow's mcp server implementation

Summary by CodeRabbit

  • New Features

    • Added configuration setting to control MCP Streamable HTTP stateless mode.
  • Chores

    • Enhanced per-project MCP server management with improved lifecycle coordination and centralized error handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 18, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Introduces a settings-based configuration flag (mcp_streamable_http_stateless) to control Streamable HTTP transport behavior. Refactors MCP module to retrieve this setting and removes explicit stateless parameters from public method signatures. Adds per-project MCP server infrastructure with lazy initialization and centralized task group lifecycle management.

Changes

Cohort / File(s) Summary
Settings Configuration
src/lfx/src/lfx/services/settings/base.py
Added new boolean configuration field mcp_streamable_http_stateless (default: True) to Settings model for controlling Streamable HTTP Session Manager stateless mode.
MCP Core Module
src/backend/base/langflow/api/v1/mcp.py
Updated StreamableHTTP.start() to accept no parameters and rely on settings-based configuration. Added get_manager() accessor method. Updated start_streamable_http_manager() function signature to remove stateless parameter. Integrated settings retrieval via get_settings_service().
MCP Projects Management
src/backend/base/langflow/api/v1/mcp_projects.py
Introduced ProjectMCPServer class for per-project MCP session management. Added lifecycle functions: start_project_task_group(), stop_project_task_group(), get_project_task_group(), and get_project_mcp_server(). Added global variables settings and streamable_http_stateless. Integrated settings-driven stateless mode configuration and lazy session manager initialization.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

  • mcp_projects.py introduces substantial new infrastructure: ProjectMCPServer class with lifecycle management, global task group coordination, and lazy initialization logic. Requires careful review of per-project session manager wiring and lifecycle guarantees.
  • Cross-module integration between settings, mcp.py, and mcp_projects.py requires understanding the configuration flow and how settings propagate through the system.
  • Public API surface expansion adds multiple new functions and a new class; verify that signatures align with calling code and that error handling for edge cases (e.g., manager not started) is robust.
  • Task group and concurrency logic in mcp_projects.py should be examined for potential race conditions and proper cleanup semantics.

Pre-merge checks and finishing touches

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (2 warnings, 2 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Test File Naming And Structure ⚠️ Warning No new test files were added to cover the new functionality introduced in this PR, including new settings field, public functions, and ProjectMCPServer class. Add dedicated test files with comprehensive test coverage for settings integration, new public API, and edge cases including initialization order validation.
Test Coverage For New Implementations ❓ Inconclusive Unable to analyze test coverage without access to specific PR details, repository structure, or test files. Please provide PR details, repository structure, or specific test files to evaluate test coverage.
Test Quality And Coverage ❓ Inconclusive No PR context or verification data provided to analyze test quality and coverage. Please provide the PR details, test files, and code changes to perform test quality and coverage analysis.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing an environment variable flag to control the stateless mode for MCP's streamable-http session manager.
Excessive Mock Usage Warning ✅ Passed Test files demonstrate appropriate and focused mock usage targeting external dependencies and infrastructure with real business logic, following best practices without excessive mocking.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33.22%. Comparing base (2d02456) to head (29ecd37).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #11098   +/-   ##
=======================================
  Coverage   33.22%   33.22%           
=======================================
  Files        1391     1391           
  Lines       65849    65854    +5     
  Branches     9745     9745           
=======================================
+ Hits        21877    21883    +6     
+ Misses      42850    42849    -1     
  Partials     1122     1122           
Flag Coverage Δ
backend 52.51% <100.00%> (+<0.01%) ⬆️
frontend 15.36% <ø> (ø)
lfx 39.44% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/backend/base/langflow/api/v1/mcp.py 72.88% <100.00%> (+0.30%) ⬆️
src/backend/base/langflow/api/v1/mcp_projects.py 41.35% <100.00%> (+0.07%) ⬆️
src/lfx/src/lfx/services/settings/base.py 71.12% <100.00%> (+0.13%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
@HzaRashid HzaRashid force-pushed the feat/mcp-stateless-flag branch from bdcd801 to 4379fee Compare December 18, 2025 18:16
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d02456 and 1b98055.

📒 Files selected for processing (3)
  • src/backend/base/langflow/api/v1/mcp.py (4 hunks)
  • src/backend/base/langflow/api/v1/mcp_projects.py (2 hunks)
  • src/lfx/src/lfx/services/settings/base.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/backend/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)

src/backend/**/*.py: Use FastAPI async patterns with await for async operations in component execution methods
Use asyncio.create_task() for background tasks and implement proper cleanup with try/except for asyncio.CancelledError
Use queue.put_nowait() for non-blocking queue operations and asyncio.wait_for() with timeouts for controlled get operations

Files:

  • src/backend/base/langflow/api/v1/mcp.py
  • src/backend/base/langflow/api/v1/mcp_projects.py
src/backend/base/langflow/api/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)

Backend API endpoints should be organized by version (v1/, v2/) under src/backend/base/langflow/api/ with specific modules for features (chat.py, flows.py, users.py, etc.)

Files:

  • src/backend/base/langflow/api/v1/mcp.py
  • src/backend/base/langflow/api/v1/mcp_projects.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: deon-sanchez
Repo: langflow-ai/langflow PR: 9158
File: src/backend/base/langflow/api/v1/mcp_projects.py:404-404
Timestamp: 2025-07-23T21:19:22.567Z
Learning: In langflow MCP projects configuration, prefer using dynamically computed URLs (like the `sse_url` variable) over hardcoded localhost URLs to ensure compatibility across different deployment environments.
📚 Learning: 2025-10-29T03:55:50.216Z
Learnt from: ricofurtado
Repo: langflow-ai/langflow PR: 10430
File: src/backend/base/langflow/api/v2/registration.py:0-0
Timestamp: 2025-10-29T03:55:50.216Z
Learning: In the langflow project, user registration endpoints in API v2 (`src/backend/base/langflow/api/v2/registration.py`) are intentionally designed to be unauthenticated to support Desktop application initialization and onboarding flows.

Applied to files:

  • src/backend/base/langflow/api/v1/mcp_projects.py
🧬 Code graph analysis (1)
src/backend/base/langflow/api/v1/mcp.py (3)
src/lfx/src/lfx/services/interfaces.py (1)
  • settings (55-57)
src/lfx/src/lfx/services/mcp_composer/service.py (1)
  • start (450-460)
src/backend/tests/unit/base/mcp/test_mcp_util.py (1)
  • session_manager (28-33)
🪛 GitHub Actions: Ruff Style Check
src/backend/base/langflow/api/v1/mcp_projects.py

[error] 72-72: Ruff lint error (F811): Redefinition of unused 'get_settings_service' from line 23 in src/backend/base/langflow/api/v1/mcp_projects.py.

🪛 GitHub Check: Ruff Style Check (3.13)
src/backend/base/langflow/api/v1/mcp_projects.py

[failure] 72-72: Ruff (F811)
src/backend/base/langflow/api/v1/mcp_projects.py:72:49: F811 Redefinition of unused get_settings_service from line 23

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: Test Docker Images / Test docker images
  • GitHub Check: Lint Backend / Run Mypy (3.13)
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 3
  • GitHub Check: Lint Backend / Run Mypy (3.10)
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 1
  • GitHub Check: Run Backend Tests / LFX Tests - Python 3.10
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 2
  • GitHub Check: Lint Backend / Run Mypy (3.12)
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 4
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 5
  • GitHub Check: Lint Backend / Run Mypy (3.11)
  • GitHub Check: Run Backend Tests / Integration Tests - Python 3.10
  • GitHub Check: Test Starter Templates
  • GitHub Check: Run Frontend Tests / Determine Test Suites and Shard Distribution
  • GitHub Check: Update Starter Projects
  • GitHub Check: Update Component Index
  • GitHub Check: Optimize new Python code in this PR
🔇 Additional comments (5)
src/lfx/src/lfx/services/settings/base.py (1)

310-311: LGTM!

The new mcp_streamable_http_stateless setting follows the existing patterns for MCP-related configuration fields. The default value of True and the clear docstring explaining its purpose are appropriate.

src/backend/base/langflow/api/v1/mcp.py (2)

191-211: LGTM on the start method structure.

The simplified signature and the internal logic are well-structured. The lock prevents race conditions, the event-based synchronization with _mgr_ready ensures proper startup sequencing, and exceptions are properly surfaced via await self._mgr_task.


246-247: LGTM!

Removing the stateless parameter from the public API in favor of settings-driven configuration simplifies the interface and ensures consistent behavior based on environment configuration.

src/backend/base/langflow/api/v1/mcp_projects.py (2)

1254-1267: LGTM on session manager initialization.

The double-checked locking pattern (if started: return; async with lock: if started: return) correctly prevents race conditions while minimizing lock contention. The integration with ProjectTaskGroup for centralized lifecycle management is a clean design.


1295-1358: LGTM on ProjectTaskGroup lifecycle management.

The design correctly ensures that the TaskGroup's __aenter__ and __aexit__ occur within the same coroutine, which is required by anyio/asyncio. The cancellation handling via cancel_scope.cancel() followed by awaiting the task is the correct pattern for graceful shutdown.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 18, 2025

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 17%
16.67% (4695/28164) 9.99% (2179/21794) 10.94% (677/6183)

Unit Test Results

Tests Skipped Failures Errors Time
1829 0 💤 0 ❌ 0 🔥 24.387s ⏱️

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
@HzaRashid HzaRashid force-pushed the feat/mcp-stateless-flag branch from d2bc35e to f6f5a2a Compare December 18, 2025 18:33
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants