Skip to content

fix(mcp): reconnect Streamable HTTP after MCP server restart - #12777

Merged
erichare merged 1 commit into
langflow-ai:release-1.10.0from
schuellerf:release-1.10.0_stable_mcp
Apr 20, 2026
Merged

fix(mcp): reconnect Streamable HTTP after MCP server restart#12777
erichare merged 1 commit into
langflow-ai:release-1.10.0from
schuellerf:release-1.10.0_stable_mcp

Conversation

@schuellerf

@schuellerf schuellerf commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

This is the rebase of #12270 onto 1.10.0 as #12270 never seemed to have landed in 1.9.0


This PR contains the fix to reconnect streamable HTTP after MCP server restart without bogus SSE fallback

When the remote MCP process restarts, Langflow kept a stale ClientSession: tool list updates could fail with "Session terminated", the session health check could re-raise instead of discarding the session, and any Streamable HTTP failure triggered SSE fallback and could lock transport preference to SSE—masking the real issue and producing misleading TaskGroup/dual-transport errors.

This invalidates all sessions for the server URL on list_tools failure, treat any health-check failure as a dead session, retry transient Streamable HTTP errors before considering SSE, only fall back to SSE for clear transport-mismatch signals (e.g. 404/405/406), reset and re-record transport preference accordingly, and bust sessions on run_tool using the same termination/connection signals.

Add unit tests with mocked streamablehttp_client and sse_client.

Please check if this makes sense and if we should do those retries…

…without bogus SSE fallback

When the remote MCP process restarts, Langflow kept a stale ClientSession:
tool list updates could fail with "Session terminated", the session
health check could re-raise instead of discarding the session, and
any Streamable HTTP failure triggered SSE fallback and could lock
transport preference to SSE—masking the real issue and producing
misleading TaskGroup/dual-transport errors.

Invalidate all sessions for the server URL on list_tools failure,
treat any health-check failure as a dead session, retry transient
Streamable HTTP errors before considering SSE, only fall back to
SSE for clear transport-mismatch signals (e.g. 404/405/406),
reset and re-record transport preference accordingly, and bust
sessions on run_tool using the same termination/connection signals.

Add unit tests with mocked streamablehttp_client and sse_client.
@coderabbitai

coderabbitai Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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: 10c2afe0-2548-4998-b2cd-2721b788b7e4

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 bug Something isn't working and removed bug Something isn't working labels Apr 20, 2026
@schuellerf

Copy link
Copy Markdown
Contributor Author

@erichare am I right, that it makes sense to merge this to 1.10.0 as 1.9.0 is already released? (so just close #12270 )
Additionally to the question if this PR is reproducible on your end and makes sense, of couse :-D

@erichare
erichare self-requested a review April 20, 2026 13:30

@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.

Overall LGTM — the transient-vs-transport-mismatch split is the right model, invalidate_server_key cleanly fixes the stale-session bug, and tests cover the key paths. No blockers from my read — merge-worthy.

Two things worth addressing (non-blocking, could be follow-ups):

  1. Substring matching on str(exc) for "404/405/406" in _should_attempt_sse_after_streamable_failure will false-positive on unrelated errors whose message happens to contain those digits, silently flipping to SSE. Prefer typed checks only, or word-boundary match.

  2. _validate_session_connectivity now catches bare Exception. Solves the real bug, but a targeted widening (McpError, ClosedResourceError, BaseExceptionGroup) would avoid masking unrelated errors.

Nits: _iter_exception_leaves can use plain import builtins; invalidate_server_key is public but callers reach into private _get_server_key — consider a public helper.

@erichare erichare added lgtm This PR has been approved by a maintainer fast-track Skip tests and sends PR into the merge queue labels Apr 20, 2026
@erichare
erichare added this pull request to the merge queue Apr 20, 2026
Merged via the queue into langflow-ai:release-1.10.0 with commit 16432b6 Apr 20, 2026
217 of 230 checks passed
erichare pushed a commit that referenced this pull request Apr 24, 2026
…without bogus SSE fallback

When the remote MCP process restarts, Langflow kept a stale ClientSession:
tool list updates could fail with "Session terminated", the session
health check could re-raise instead of discarding the session, and
any Streamable HTTP failure triggered SSE fallback and could lock
transport preference to SSE—masking the real issue and producing
misleading TaskGroup/dual-transport errors.

Invalidate all sessions for the server URL on list_tools failure,
treat any health-check failure as a dead session, retry transient
Streamable HTTP errors before considering SSE, only fall back to
SSE for clear transport-mismatch signals (e.g. 404/405/406),
reset and re-record transport preference accordingly, and bust
sessions on run_tool using the same termination/connection signals.

Add unit tests with mocked streamablehttp_client and sse_client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fast-track Skip tests and sends PR into the merge queue lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants