python-sdk
python-sdk copied to clipboard
fix: reject changed duplicate initialize
## Summary
- reject a second
initializerequest if it tries to change the session's client parameters - keep the first
client_paramsintact 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.pyuv run pyright src/mcp/server/session.py tests/server/test_session.pyuv run python -m py_compile src/mcp/server/session.py tests/server/test_session.pygit diff --check
Closes #2605
Code Review
PR: fix: reject changed duplicate initialize by @he-yufeng
- ✅ Bug fix
Wallet: 0xdaE5d307339074A24F579dB48e7c639359D94904
Code review for MCP Python SDK
Rebased this PR onto the current runner/connection architecture instead of keeping the old ServerSession._received_request patch. The duplicate-initialize guard now lives in ServerRunner._handle_initialize(), so a second initialize with changed params returns INVALID_PARAMS and leaves the original connection.client_params intact.
Validation:
python -m py_compile src\mcp\server\runner.py tests\server\test_runner.pyuv run pytest tests/server/test_runner.py -q -k "initialize" --basetemp .tmp\pytest-2606-20260610 -p no:cacheprovider(16 passed)