Python: preserve MCP request ownership on low-level sends - #8246
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation consistently extends existing request-scoping behavior and includes appropriate regression coverage.
Pull request overview
Ensures MCP low-level HTTP sends retain request ownership so scoped header hooks apply correctly.
Changes:
- Wraps
AsyncClient.send()to attach the MCP ownership marker. - Adds regression coverage for low-level sends.
File summaries
| File | Description |
|---|---|
python/packages/core/agent_framework/_mcp.py |
Tags requests before delegating low-level sends. |
python/packages/core/tests/core/test_mcp.py |
Verifies ownership tagging through send(). |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): 0ad4dfe38bbd
Model: gpt-5.6-sol-fast
Overview
The PR extends the private MCP HTTP client wrapper so prebuilt requests sent through AsyncClient.send() receive the same per-tool ownership marker as stream and delete requests. Identity checks, origin checks, redirect cleanup, lifecycle cleanup, and the focused regression test constrain the change without altering the public API or client ownership model. No publishable Critical, High, or Medium defect was established.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Motivation & Context
Supported MCP dependencies can issue streamable HTTP requests through
AsyncClient.send(). That path bypassed the transport wrapper's request ownership marker, soheader_providerhooks ignored those requests.Description & Review Guide
send()wrapper that applies the same private request marker as the existing stream and delete paths, plus a regression test for that invariant.Related Issue
Related to #7841.
Follow-up to #8225, which supplies run kwargs during connection setup; this change preserves request ownership when the MCP dependency sends through
AsyncClient.send().Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.