Skip to content

fix: reject duplicate initialize on existing sessions#2945

Open
fengjikui wants to merge 1 commit into
modelcontextprotocol:mainfrom
fengjikui:codex/reject-duplicate-initialize
Open

fix: reject duplicate initialize on existing sessions#2945
fengjikui wants to merge 1 commit into
modelcontextprotocol:mainfrom
fengjikui:codex/reject-duplicate-initialize

Conversation

@fengjikui

@fengjikui fengjikui commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Reject a second initialize request once a session connection already has negotiated client params.
  • Preserve stateless HTTP first-initialize behavior by keying the guard on client_params, not the initialized event.
  • Update the hosting session reinitialize requirement/test to assert the duplicate request returns INVALID_REQUEST and does not overwrite the original client params.

Fixes #2605

Validation

  • uv run --frozen pytest tests/interaction/transports/test_hosting_session.py::test_second_initialize_on_an_existing_session_is_rejected -q
  • uv run --frozen pytest tests/interaction/transports/test_hosting_session.py::test_second_initialize_on_an_existing_session_is_rejected tests/interaction/transports/test_hosting_session.py::test_stateless_mode_never_issues_a_session_id tests/interaction/transports/test_hosting_session.py::test_stateless_mode_serves_concurrent_clients_independently -q
  • uv run --frozen pytest tests/interaction/transports/test_hosting_session.py -q
  • uv run --frozen pyright src/mcp/server/runner.py tests/interaction/_connect.py tests/interaction/transports/test_hosting_session.py tests/interaction/_requirements.py
  • uv run --frozen ruff format --check src/mcp/server/runner.py tests/interaction/_connect.py tests/interaction/transports/test_hosting_session.py tests/interaction/_requirements.py
  • uv run --frozen ruff check src/mcp/server/runner.py tests/interaction/_connect.py tests/interaction/transports/test_hosting_session.py tests/interaction/_requirements.py
  • uv run --frozen python scripts/update_readme_snippets.py --check
  • uv lock --check
  • git diff --check

@fengjikui fengjikui force-pushed the codex/reject-duplicate-initialize branch from dbd9632 to a79648a Compare June 22, 2026 12:51
@fengjikui fengjikui marked this pull request as ready for review June 22, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate initialize with changed parameters can overwrite ServerSession.client_params

1 participant