fix: skip MCP preflight content-type probe on reconnect when already ready (#40604)

Closes #40366.

Salvaged from #40548; re-verified on main, tightened, tested.

Co-authored-by: mohamedorigami-jpg <mohamedorigami-jpg@users.noreply.github.com>
This commit is contained in:
Teknium
2026-06-07 09:51:11 -07:00
committed by GitHub
co-authored by mohamedorigami-jpg
parent 76f01780f0
commit af08c43f3e
2 changed files with 80 additions and 1 deletions
+6 -1
View File
@@ -1800,7 +1800,12 @@ class MCPServerTask:
# before surfacing an opaque CancelledError. Probing here — once,
# outside the SDK task group — fails fast and non-retryably with
# an actionable message, mirroring the URL-validation path above.
if config.get("transport") != "sse":
# Skip the probe when _ready is already set: that only happens
# after a prior successful connect, so this run() invocation is a
# reconnect (OAuth recovery / manual refresh). The endpoint was
# already validated once; re-probing burns a redundant network
# round-trip against a known-good server on every reconnect.
if config.get("transport") != "sse" and not self._ready.is_set():
try:
_probe_headers = dict(config.get("headers") or {})
await self._preflight_content_type(