Skip to content

fix(server): reject changed duplicate initialize#3078

Open
ychampion wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
ychampion:reject-duplicate-initialize
Open

fix(server): reject changed duplicate initialize#3078
ychampion wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
ychampion:reject-duplicate-initialize

Conversation

@ychampion

@ychampion ychampion commented Jul 8, 2026

Copy link
Copy Markdown

Summary

  • Keep same-parameter duplicate initialize requests idempotent for already initialized stateful sessions.
  • Reject changed duplicate initialize requests so stored client_params are not rewritten.

Why

Fixes #2605. A later initialize on the same session could overwrite ServerSession.client_params after negotiation. Existing connected-session fixtures also send an idempotent duplicate initialize, so the rejection only applies when the duplicate request changes the original parameters.

Validation

  • uv run pytest -n0 tests/server/test_session.py::test_duplicate_initialize_after_initialized_preserves_negotiated_params -q - passed
  • uv run pytest -n0 tests/server/test_session.py tests/server/fastmcp/test_elicitation.py tests/server/fastmcp/test_url_elicitation.py tests/server/fastmcp/test_url_elicitation_error_throw.py tests/server/fastmcp/test_title.py tests/issues/test_141_resource_templates.py -q - passed, 34 tests
  • uv run ruff format --check src/mcp/server/session.py tests/server/test_session.py - passed
  • uv run ruff check src/mcp/server/session.py tests/server/test_session.py - passed
  • uv run pyright src/mcp/server/session.py tests/server/test_session.py - passed
  • git diff --check - passed

AI assistance: Codex.

Copilot AI review requested due to automatic review settings July 8, 2026 19:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread tests/server/test_session.py Outdated
Keep duplicate initialize requests idempotent when the client sends the same parameters, but return INVALID_REQUEST if a stateful server is reinitialized with different parameters after negotiation.
@ychampion ychampion force-pushed the reject-duplicate-initialize branch from fd8d08d to 394ed98 Compare July 8, 2026 19:49
@ychampion ychampion changed the title fix(server): reject duplicate initialize after negotiation fix(server): reject changed duplicate initialize Jul 8, 2026
@ychampion

Copy link
Copy Markdown
Author

Good catch. Updated in 394ed98:

  • same-parameter duplicate initialize requests stay idempotent
  • changed duplicate initialize requests now return INVALID_REQUEST
  • the regression test receive calls are wrapped in anyio.fail_after(5)

Validation:

  • uv run pytest -n0 tests/server/test_session.py::test_duplicate_initialize_after_initialized_preserves_negotiated_params -q
  • uv run pytest -n0 tests/server/test_session.py tests/server/fastmcp/test_elicitation.py tests/server/fastmcp/test_url_elicitation.py tests/server/fastmcp/test_url_elicitation_error_throw.py tests/server/fastmcp/test_title.py tests/issues/test_141_resource_templates.py -q
  • uv run ruff format --check src/mcp/server/session.py tests/server/test_session.py
  • uv run ruff check src/mcp/server/session.py tests/server/test_session.py
  • uv run pyright src/mcp/server/session.py tests/server/test_session.py
  • git diff --check

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.

2 participants