Skip to content

fix: serialize streamable-http MCP requests per session#2682

Merged
seratch merged 2 commits intomainfrom
dev/elainegan/mcp-streamable-http-request-isolation
Mar 16, 2026
Merged

fix: serialize streamable-http MCP requests per session#2682
seratch merged 2 commits intomainfrom
dev/elainegan/mcp-streamable-http-request-isolation

Conversation

@elainegan-openai
Copy link
Copy Markdown
Contributor

Summary

Serialize request RPCs per MCPServerStreamableHttp session so one failed request cannot cancel sibling in-flight requests that share the same underlying streamable-HTTP transport task group.

This is a narrow SDK-side workaround for the shared transport behavior in the mcp client dependency. It keeps the public API unchanged and only affects how MCPServerStreamableHttp schedules requests on a single connected session.

Test plan

  • make sync
  • make format
  • make lint
  • make typecheck
  • make tests
  • uv run python -m pytest tests/mcp/test_client_session_retries.py -k 'serialized_session_requests_prevent_sibling_cancellation or test_call_tool_retries_until_success' -q

Issue number

N/A

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

@github-actions github-actions bot added bug Something isn't working feature:mcp labels Mar 16, 2026
@elainegan-openai
Copy link
Copy Markdown
Contributor Author

@codex please review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

return await self.session.list_prompts()
async def get_prompt(
self, name: str, arguments: dict[str, Any] | None = None
) -> GetPromptResult:
"""Get a specific prompt from the server."""
if not self.session:
raise UserError("Server not initialized. Make sure you call `connect()` first.")
return await self.session.get_prompt(name, arguments)

P2 Badge Serialize prompt RPCs with the session lock

MCPServerStreamableHttp enables _serialize_session_requests, but list_prompts/get_prompt bypass _maybe_serialize_request and call ClientSession directly. That leaves prompt RPCs able to run concurrently with tool RPCs, so one failed request can still cancel an in-flight sibling on the shared streamable-HTTP transport.

ℹ️ 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".

Route prompt RPCs through the existing request lock and add regression coverage for list_prompts/get_prompt so prompt calls cannot cancel in-flight tool calls on streamable HTTP.\n\nCo-authored-by: Codex <[email protected]>
@elainegan-openai
Copy link
Copy Markdown
Contributor Author

@codex please review

@chatgpt-codex-connector
Copy link
Copy Markdown

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 changed the title Serialize streamable-http MCP requests per session fix: serialize streamable-http MCP requests per session Mar 16, 2026
@seratch seratch merged commit a5cd815 into main Mar 16, 2026
9 checks passed
@seratch seratch deleted the dev/elainegan/mcp-streamable-http-request-isolation branch March 16, 2026 02:54
@seratch seratch added this to the 0.12.x milestone Mar 16, 2026
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