Skip to content

fix(server): reject changed duplicate initialize - #3078

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

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

@maxisbey

maxisbey commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR, and sorry it sat here without a proper review.

We're closing most of the open PR backlog. v2 is out and changed a lot of the SDK, so many older PRs no longer apply as written, and we're a small team that realistically doesn't have the capacity to work through the rest.

If this still matters to you on v2, the most useful thing you can do is open an issue (or comment on the existing one) with your use case and a repro. Hearing why it matters to you is what we use to decide what to prioritise.

AI Disclaimer

@maxisbey maxisbey closed this Oct 5, 2026
@maxisbey maxisbey added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants