Skip to content

fix: optionize initialized notification tolerance#2765

Merged
seratch merged 4 commits intomainfrom
dev/elainegan/sevbot-initnotif-tolerance
Mar 25, 2026
Merged

fix: optionize initialized notification tolerance#2765
seratch merged 4 commits intomainfrom
dev/elainegan/sevbot-initnotif-tolerance

Conversation

@elainegan-openai
Copy link
Contributor

@elainegan-openai elainegan-openai commented Mar 24, 2026

Summary

  • add an explicit MCP streamable-HTTP option for tolerating failed initialized notifications
  • keep the default strict and only ignore the failure when callers opt in
  • implement the option by wrapping the configured httpx_client_factory, rather than forking MCP's stream client orchestration
  • add focused transport and wiring coverage for the new option

Why

Best-effort notifications/initialized POST could fail and poison the transport, even though subsequent real requests could still succeed. This change keeps the behavior opt-in at the SDK layer so apps can choose the more tolerant transport policy explicitly.

Validation

  • ruff check src/agents/mcp/server.py tests/mcp/test_streamable_http_client_factory.py
  • PYTHONPATH=src pytest -q tests/mcp/test_streamable_http_client_factory.py

Add an explicit MCP streamable-HTTP option for tolerating failed initialized notifications, and opt into that behavior only when callers request it.

Co-authored-by: Codex <noreply@openai.com>
@github-actions github-actions bot added enhancement New feature or request feature:mcp labels Mar 24, 2026
@elainegan-openai elainegan-openai changed the title [SEVBot] Optionize initialized notification tolerance Optionize initialized notification tolerance Mar 25, 2026
Co-authored-by: Codex <noreply@openai.com>
@elainegan-openai elainegan-openai marked this pull request as ready for review March 25, 2026 00:20
@seratch seratch changed the title Optionize initialized notification tolerance fix: optionize initialized notification tolerance Mar 25, 2026
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall direction makes sense. Making only the notifications/initialized request best-effort, behind an explicit opt-in flag, is a reasonable approach, and it correctly avoids hiding failures for other requests.

My main concern is the implementation layer. Right now, this change depends on create_mcp_http_client from mcp.client.streamable_http, which is not part of that module’s exported public surface and already breaks mypy. It also replaces httpx.AsyncClient._transport, which is a private attribute and therefore somewhat brittle.

A cleaner solution would be to handle this directly in the MCP Streamable HTTP transport, where the code already knows when it is sending the initialized notification. That would avoid re-parsing raw HTTP request bodies, avoid private httpx internals, and keep the behavior closer to the protocol logic.

So my recommendation would be:

  1. For a quick fix, keep the current behavior but remove the non-exported import issue and make sure the full typecheck/test gate passes.
  2. For the better long-term solution, move this tolerance into the upstream transport layer and let the SDK only pass through the opt-in flag.

It would also be good to add a test covering the combination of ignore_initialized_notification_failure=True with a custom httpx_client_factory, to ensure headers, timeout, and auth are still preserved correctly.

@seratch seratch added this to the 0.13.x milestone Mar 25, 2026
Co-authored-by: Codex <noreply@openai.com>
@github-actions github-actions bot added bug Something isn't working and removed enhancement New feature or request labels Mar 25, 2026
Co-authored-by: Codex <noreply@openai.com>
@elainegan-openai
Copy link
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@seratch seratch merged commit 9088496 into main Mar 25, 2026
9 checks passed
@seratch seratch deleted the dev/elainegan/sevbot-initnotif-tolerance branch March 25, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:mcp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants