Skip to content

fix: reject changed duplicate initialize#2606

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/reject-changed-reinitialize
Open

fix: reject changed duplicate initialize#2606
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/reject-changed-reinitialize

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • reject a second initialize request if it tries to change the session's client parameters
  • keep the first client_params intact so later capability checks cannot be spoofed by a duplicate handshake
  • add a regression test covering the changed-params path

To verify

  • uv run pytest tests/server/test_session.py -q -k "duplicate_initialize or server_session_initialize"
  • 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
  • uv run python -m py_compile src/mcp/server/session.py tests/server/test_session.py
  • git diff --check

Closes #2605

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