Repository navigation
Python: Make MCP connection-loss recovery ownership-aware - #9583
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Disconnected-wrapper discovery regresses, and modern caller-owned connection-loss coverage is missing.
2 open issues
What changed in this PR
Makes Python MCP connection-loss recovery respect lifecycle ownership, preventing retries against ended caller-supplied connections.
Changes:
- Adds a shared ownership check across discovery, liveness, tool calls, and prompt calls.
- Adds caller-owned regression tests and explicitly marks framework-owned recovery fixtures.
| File | Description |
|---|---|
python/packages/core/tests/core/test_mcp.py |
Adds ownership-aware recovery tests and updates fixtures. |
python/packages/core/agent_framework/_mcp.py |
Guards automatic recovery and reports caller replacement responsibilities. |
Review effort: Balanced
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 18d099a5113d
Model: gpt-5.6-sol
Overview
The PR centralizes ownership-aware recovery and places the guard before each existing automatic reconnect path, while preserving framework-owned retries and caller-owned object lifecycles. Its ownership initialization, reset/close behavior, and operation-specific regression coverage are strong. One residual issue remains in liveness checks: failures that do not establish connection loss are now reported as requiring replacement of a caller-owned connection.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/core/agent_framework/_mcp.py
|
Thanks for clarifying the scope and addressing the review feedback! I was interested in contributing to this issue, and I’ve been following the implementation. Since this PR now covers the identified gaps, is there any related testing or follow-up work where an additional contributor could help? I’d be happy to take on a focused task to avoid duplicating your work. |
Code coverage overviewLanguages: Python Python / code-coverage/python
View coverage of the 1 most impacted file.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. |


Motivation & Context
Caller-supplied MCP
ClientandClientSessionconnections are preserved by reset and close because Agent Framework does not own their lifecycle. Existing connection-loss paths nevertheless logged that they were reconnecting, calledconnect(reset=True), and retried against the same ended caller-owned object. This contradicted the documented ownership boundary and could issue a second RPC without performing a real reconnection.This change makes connection-loss handling ownership-aware while preserving existing recovery for framework-owned connections.
Description & Review Guide
Related Issue
Fixes #9426
AI Assistance
AI assistance details: Copilot assisted with implementation, regression tests, historical/design analysis, and this PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" in the title prefix, before or after a language prefix) — a workflow keeps the label and the title prefix in sync automatically.Fixes: #9426