Isolate MCP connections per task and surface connection status in the UIs - #1181
Merged
Conversation
Contributor
Greptile SummaryThe PR isolates MCP connections behind per-connection supervisor tasks and exposes persisted connection health in the terminal and web interfaces.
Confidence Score: 5/5The PR appears safe to merge because both previously reported MCP teardown failures are addressed and no blocking failure remains. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "Bound MCP session teardown and handle a ..." | Re-trigger Greptile |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two related changes to how the engine handles connected MCP servers:
failure in one connection can no longer cancel the whole scan. On failure a
connection reconnects once and retries once; if it still fails it is marked
unavailable and the run continues without it.
connections and their live status (healthy, in use, offline).
Why
An MCP connection's live session used to be opened on the run's main task, and the
streamable-HTTP transport keeps an internal task group open on that task for the
session's lifetime. A background error from a provider (for example an HTTP 403 on
a background request) cancelled that task group's scope, which cancelled the entire
scan and surfaced as a bare
CancelledError. There was also no way to see whichMCP servers a run had connected or whether they were still alive.
What changed
SupervisedMcpSession) thatconnects, holds, and cleans up the session on one task. Callers reach it over a
queue and get a value back, so a session failure surfaces as a failed tool result
rather than a cancellation. On a failure the supervisor reconnects once and
retries once (reusing the existing connect path); a connection that dies while
idle also gets one reconnect. If reconnect fails, the connection is marked dead
for the run and later calls return a clean "unavailable" result. This also fixes
the teardown "exit cancel scope in a different task" errors, since connect and
cleanup now run on the same task.
(name, provider, tool count, dead) and persists it to the run record, so both
live and finished views can render it. Only these non-secret fields are exposed.
connection status;
list_mcpsalso reflects offline connections."in use" derived from tool-call events.
Testing
New unit tests cover containment, reconnect-then-retry, give-up-and-mark-dead, the
idle-death self-heal, roster persistence, and that connection config and tokens
never reach logs, reprs, or disk. The full Python suite, Go build/vet/test, ruff,
mypy, and the viewer frontend typecheck and build all pass.