Skip to content

fix(mcp): fix validation, session isolation, and update_flow_from_spec parity - #12528

Merged
ogabrielluiz merged 10 commits into
release-1.10.0from
fix/mcp-server-bugs
May 27, 2026
Merged

fix(mcp): fix validation, session isolation, and update_flow_from_spec parity#12528
ogabrielluiz merged 10 commits into
release-1.10.0from
fix/mcp-server-bugs

Conversation

@ogabrielluiz

@ogabrielluiz ogabrielluiz commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • create_flow_from_spec(validate=True) now actually waits for validation to complete instead of fire-and-forget
  • validate_flow filters poll results by job_id so stale builds from prior runs are not picked up
  • update_flow_from_spec now uses server-side tools (configure_component, connect_components) for feature parity with create_flow_from_spec, including dynamic template refresh, prompt variable creation, and component_as_tool auto-enable. Includes rollback on failure to restore original flow data
  • login() only closes the current session's client, no longer disrupts other concurrent SSE sessions
  • _set_client invalidates the shared registry when the client changes to prevent stale registries after server switch
  • validate_flow returns consistent errors list format so callers get proper error messages

Summary by CodeRabbit

  • Bug Fixes

    • Improved session isolation ensuring per-session client operations don't affect other sessions.
    • Enhanced flow validation with detailed error messaging for invalid flows.
    • Fixed flow update operations with automatic rollback on failures.
  • Improvements

    • Strengthened flow update workflow with more robust error handling.
  • Dependencies

    • Updated multiple package versions including OpenAI, Langchain, and Google API client libraries.

@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

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.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c8f7caaa-ddf5-4725-9fe6-5ea52a02fb2b

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR contains dependency version updates across multiple packages in component_index.json, alongside a significant refactoring of MCP server session management, flow validation, creation, and update operations, supported by comprehensive new test coverage.

Changes

Dependency Updates

Layer / File(s) Summary
Package Versions
src/lfx/src/lfx/_assets/component_index.json
Multiple dependencies updated: openai (2.32.0 → 2.33.0), couchbase (4.6.0 → 4.6.1), googleapiclient (2.194.0 → 2.195.0), langchain (1.2.15 → 1.2.17), langchain_google_vertexai (3.2.2 → 3.2.3), git (3.1.43 → 3.1.47), toolguard (0.2.16 → 0.2.17). SHA256 hash updated.

MCP Server Flow Management

Layer / File(s) Summary
Session & Client Management
src/lfx/src/lfx/mcp/server.py
Added copy import. _set_client now atomically updates both shared client and registry. login closes only per-session client, instantiates new session-scoped client, and clears only session-scoped registry, preserving shared state.
Flow Validation & Creation
src/lfx/src/lfx/mcp/server.py
create_flow_from_spec now validates flows via server-side validate_flow and raises detailed errors on failure, rather than proceeding unconditionally.
Flow Update with Rollback
src/lfx/src/lfx/mcp/server.py
update_flow_from_spec rewritten to deep-copy original flow data, clear existing nodes/edges, rebuild via server-side tools (add_component, configure_component, connect_components), and restore original data on failure with error-handling and event emission.
Public Tool Mapping
src/lfx/src/lfx/mcp/server.py
Public tool layout_flow now resolves to layout_flow_tool function instead of layout_flow directly, preserving external API name while updating implementation.
Test Infrastructure & Helpers
src/lfx/tests/unit/mcp/test_server_bugs.py
New comprehensive test module with helpers (_make_mock_client, _mock_flow, MOCK_REGISTRY) covering registry invalidation on client change, login session isolation, validation behavior, and rollback semantics.
Bug Fix Test Coverage
src/lfx/tests/unit/mcp/test_server_bugs.py
Tests verify: shared registry invalidation, per-session client closure, validation failure handling with skip option, original data restoration on rollback, and flow_settled event emission.
Event Test Updates
src/lfx/tests/unit/mcp/test_server_events.py
Added test helpers for layout_flow_tool and revised update_flow_from_spec. Updated TOOL_CASES to expect flow_settled instead of flow_updated. Patched validate_flow in TestCreateFlowFromSpecEmitsSettled.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 6 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Test Quality And Coverage ⚠️ Warning Tests lack state isolation. test_server_bugs.py mutates module-level state without restoration, causing potential test order dependency and flakiness as noted in review comments. Add @pytest.fixture(autouse=True) to restore module state (_shared_client, _shared_registry, _client_var, _registry_var) before/after each test to prevent test pollution.
Test File Naming And Structure ⚠️ Warning test_server_bugs.py lacks state isolation. Tests mutate module-level state without restoring it, violating test isolation best practices and causing order-dependent execution. Add @pytest.fixture(autouse=True) to restore module-level state (srv._shared_client, srv._shared_registry, srv._client_var, srv._registry_var) after each test using try/finally pattern, as shown in review comment lines 63-90.
Excessive Mock Usage Warning ⚠️ Warning Test uses 4.7 mocks per test on average, mocking core logic. Tests assert mock calls instead of actual behavior. Order-dependent due to unrestored module globals. Add autouse fixture to restore module state. Test actual behavior vs mocks. Use integration tests for rollback/validation. Reduce mock count.
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately reflects the main changes: it specifies three key fixes (validation, session isolation, and update_flow_from_spec parity) that align with the primary objectives described in the PR summary and file changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Test Coverage For New Implementations ✅ Passed Tests added cover all code changes: validation, rollback, session isolation. Proper test_*.py naming conventions. 16 test methods with mocking and assertions. Not placeholder tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mcp-server-bugs

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 the community Pull Request from an external contributor label Apr 6, 2026
@ogabrielluiz
ogabrielluiz requested a review from Cristhianzl April 6, 2026 19:09
@ogabrielluiz ogabrielluiz removed the community Pull Request from an external contributor label Apr 6, 2026
@ogabrielluiz
ogabrielluiz requested a review from erichare April 6, 2026 19:09
@ogabrielluiz
ogabrielluiz enabled auto-merge April 6, 2026 19:09
@github-actions github-actions Bot added the bug Something isn't working label Apr 6, 2026
@codecov

codecov Bot commented Apr 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 43.61702% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.90%. Comparing base (e080805) to head (da3e0a3).
⚠️ Report is 59 commits behind head on release-1.10.0.

Files with missing lines Patch % Lines
src/lfx/src/lfx/mcp/server.py 43.61% 46 Missing and 7 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           release-1.10.0   #12528      +/-   ##
==================================================
+ Coverage           55.24%   55.90%   +0.65%     
==================================================
  Files                2173     2186      +13     
  Lines              203469   207824    +4355     
  Branches            30709    32600    +1891     
==================================================
+ Hits               112404   116181    +3777     
- Misses              89781    90289     +508     
- Partials             1284     1354      +70     
Flag Coverage Δ
backend 60.57% <ø> (+0.30%) ⬆️
frontend 55.75% <ø> (+0.67%) ⬆️
lfx 52.06% <43.61%> (+0.98%) ⬆️

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

Files with missing lines Coverage Δ
src/lfx/src/lfx/mcp/server.py 47.74% <43.61%> (+0.34%) ⬆️

... and 530 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 commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 40%
40.47% (51619/127527) 68.52% (7024/10251) 39.18% (1156/2950)

Unit Test Results

Tests Skipped Failures Errors Time
4473 0 💤 0 ❌ 0 🔥 11m 45s ⏱️

@erichare erichare left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@github-actions github-actions Bot added lgtm This PR has been approved by a maintainer bug Something isn't working and removed bug Something isn't working labels Apr 6, 2026
@erichare

erichare commented Apr 7, 2026

Copy link
Copy Markdown
Member

@ogabrielluiz Seeing this in the backend tests:

  FAILED src/backend/tests/unit/api/v1/test_mcp_client_server.py::TestCreateFlowFromSpec::test_create_flow_from_spec_with_tool_mode - RuntimeError: Flow validation failed: Build timed out: 0/4 components completed
  FAILED src/backend/tests/unit/api/v1/test_mcp_client_server.py::TestCreateFlowFromSpec::test_create_flow_from_spec_prompt_multiple_variables - RuntimeError: Flow validation failed: Build timed out: 0/1 components completed

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Apr 7, 2026
@ogabrielluiz
ogabrielluiz force-pushed the fix/mcp-server-bugs branch from fa48d7e to 935b8cd Compare April 8, 2026 13:16
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Apr 8, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Apr 15, 2026
shaun0927 added a commit to shaun0927/langflow that referenced this pull request Apr 17, 2026
validate_flow already tracked how many nodes were expected, but the final
success path only checked whether a failing event had been seen. An early
end event could therefore return valid=true even when only part of the
flow finished. This change treats that condition as invalid and records a
flow-level error, while keeping the existing fast-fail behavior unchanged.

Constraint: Keep the fix narrowly scoped to validate_flow rather than folding it into broader MCP/session work
Rejected: Wait for PR langflow-ai#12528 to land | it does not close this exact success-path gap on current main
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: If validate_flow semantics change again, preserve the invariant that success means every expected component completed
Tested: cd src/lfx && uv sync && uv run pytest tests/unit/mcp/test_validate_flow.py -q
Not-tested: End-to-end MCP validation against a live Langflow server
Related: langflow-ai#12757
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 18, 2026
@ogabrielluiz
ogabrielluiz disabled auto-merge May 19, 2026 11:45
@ogabrielluiz
ogabrielluiz force-pushed the fix/mcp-server-bugs branch from 33fddc5 to 33b298a Compare May 19, 2026 11:46
@ogabrielluiz
ogabrielluiz changed the base branch from main to release-1.10.0 May 19, 2026 11:46
@ogabrielluiz
ogabrielluiz enabled auto-merge May 19, 2026 11:46
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 19, 2026
@ogabrielluiz ogabrielluiz added lgtm This PR has been approved by a maintainer and removed lgtm This PR has been approved by a maintainer labels May 19, 2026
@erichare
erichare deleted the branch release-1.10.0 May 19, 2026 22:39
@erichare erichare closed this May 19, 2026
auto-merge was automatically disabled May 19, 2026 22:39

Pull request was closed

@erichare erichare reopened this May 19, 2026
@github-actions

github-actions Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

✅ Test Coverage Advisor

No source changes detected without accompanying tests. Thanks for keeping coverage up! 🎉

Advisory check only — never blocks merge.

@ogabrielluiz
ogabrielluiz enabled auto-merge May 25, 2026 13:41
create_flow_from_spec parses YAML config blocks, so numeric / boolean
inputs naturally land as int / float / bool primitives. The flat
configure_component path wrote those into the template as-is and the
downstream build then choked: e.g. ChatInput.input_value is a str-typed
MultilineInput, but YAML 'A.input_value: 42' delivered int 42 and the
Message constructor refused ("The message does not have the required
fields (text, sender, sender_name).") -> RuntimeError 'Flow validation
failed: Build error' rolled the whole spec back.

Adds _coerce_param_value that reads each field's declared 'type' from
the template and coerces str/int/float/bool primitives accordingly.
Containers, code, and unknown shapes pass through unchanged so existing
non-primitive call sites are unaffected. None passes through too --
clearing a field is a valid intent.

bool->str converts to lowercase 'true'/'false' to match the YAML spec
convention (str(True) would give 'True'/'False' capitalized).

Test test_create_flow_from_spec_coerces_numeric_config now passes; the
assertion was tightened to compare against the coerced string form
"42" since the coercion target for input_value is str.

Pre-existing test_create_flow_from_spec_with_tool_mode failure (the
Agent component requires a model + API key to build) is unrelated to
this change -- it fails the same way against the parent commit and is
left for a separate fix.
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 25, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 25, 2026
Agent requires a model + API key to build, but this test only verifies
that URLComponent.component_as_tool -> Agent.tools wiring round-trips
through the spec parser. Pass validate=False so the test no longer
depends on a buildable graph.
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 26, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 26, 2026
@ogabrielluiz
ogabrielluiz added this pull request to the merge queue May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix-index lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants