Title: Duplicate `initialize` with changed parameters can overwrite `ServerSession.client_params` · Issue #2605 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Duplicate `initialize` with changed parameters can overwrite `ServerSession.client_params` · Issue #2605 · modelcontextprotocol/python-sdk
X Title: Duplicate `initialize` with changed parameters can overwrite `ServerSession.client_params` · Issue #2605 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue Description After a normal MCP ini...
Open Graph Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ...
X Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening t...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/2605
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Duplicate `initialize` with changed parameters can overwrite `ServerSession.client_params`","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the latest version of MCP Python SDK\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Description\n\nAfter a normal MCP initialization flow, a Python SDK server accepts another `initialize` request on the same live connection/session and returns a normal `initialize` result.\n\nI agree that the spec does not explicitly say every repeated `initialize` must be rejected. My concern is narrower: after the session has already moved into normal operation, a later same-session `initialize` with different parameters can update the server's stored client initialization parameters.\n\nThe MCP lifecycle documentation describes initialization as the first client/server interaction and says the operation phase uses the negotiated protocol version and capabilities. In that model, silently changing the stored client identity/capabilities/protocol version after operation has begun seems surprising unless the SDK intentionally supports same-session renegotiation.\n\n- `src/mcp/server/session.py` stores the client initialization request in `ServerSession._client_params`.\n- `ServerSession.client_params` exposes that value.\n- In both the stable release and the `main` snapshot I tested, the `InitializeRequest` handler assigns `self._client_params = params`.\n- `ServerSession.check_client_capability()` later reads `self._client_params.capabilities`, so a duplicate `initialize` with different `capabilities` can affect capability-gated server logic.\n\n### What I observed\n\nReproduced on stable `v1.27.1` (`77431ebe7dda9ed0c61451b22d3e7f8d981bc092`):\n\n- `stdio`: a second `initialize` was accepted after `notifications/initialized`; a later `ping` still succeeded.\n- stateful Streamable HTTP: a second `initialize` was accepted after `notifications/initialized`; a later `ping` still succeeded.\n- stateless Streamable HTTP: a second `initialize` was accepted after `notifications/initialized`; a later `ping` still succeeded.\n\nFor stateful Streamable HTTP on `v1.27.1`, I added a local diagnostic tool that reads `ctx.session.client_params` before and after the duplicate `initialize` on the same session:\n\n| Duplicate `initialize` parameters | Observed result |\n|---|---|\n| Same parameters | No state change |\n| Changed `clientInfo` and `capabilities` | `client_params.clientInfo` and `client_params.capabilities` changed |\n| Older `protocolVersion` (`2024-11-05`) | `client_params.protocolVersion` and `client_params.clientInfo` changed |\n\nOn the frozen `main` snapshot (`161834d4aee2633c42d3976c8f8751b6c4d947d5`), the same duplicate-initialize acceptance still reproduced. My diagnostic snapshot directly observed `client_params.capabilities` changing after a duplicate `initialize` with changed capabilities on both `stdio` and stateful Streamable HTTP.\n\n### Expected behavior\n\nIf same-session duplicate initialization is not intended, I would expect the server to reject the later `initialize` after normal operation has begun, for example with a JSON-RPC `-32600 Invalid Request` error.\n\nIf this tolerant behavior is intentional, I think it should be either:\n\n- a no-op once the session has already initialized, especially for changed parameters, or\n- documented as same-session renegotiation, including whether `ServerSession.client_params`, client capabilities, client identity, and protocol version are allowed to change.\n\n### Example Code\n\n```Python\nimport json\n\ntry:\n # Current main branch naming.\n from mcp.server.mcpserver import Context, MCPServer\nexcept ImportError:\n # Latest stable release naming.\n from mcp.server.fastmcp import Context, FastMCP as MCPServer\n\n\nmcp = MCPServer(\"dup-init-repro\")\n\n\ndef field(obj, *names):\n if obj is None:\n return None\n for name in names:\n if hasattr(obj, name):\n return getattr(obj, name)\n return None\n\n\ndef dump(value):\n if value is None:\n return None\n if hasattr(value, \"model_dump\"):\n return value.model_dump(mode=\"json\", by_alias=True)\n return value\n\n\n@mcp.tool()\nasync def session_snapshot(ctx: Context) -\u003e str:\n params = ctx.session.client_params\n return json.dumps(\n {\n \"protocolVersion\": field(params, \"protocolVersion\", \"protocol_version\"),\n \"clientInfo\": dump(field(params, \"clientInfo\", \"client_info\")),\n \"clientCapabilities\": dump(field(params, \"capabilities\")),\n },\n separators=(\",\", \":\"),\n default=str,\n )\n\n\nif __name__ == \"__main__\":\n mcp.run(transport=\"streamable-http\")\n\n'''\nRequest sequence:\n\n1. Start the server.\n2. Send a normal `initialize`.\n3. Send `notifications/initialized`.\n4. Call the `session_snapshot` tool and record the returned JSON.\n5. Send another `initialize` on the same live session, but change `clientInfo` and/or `capabilities`.\n6. Call `session_snapshot` again on the same session.\n\nOn `v1.27.1`, the second snapshot reflects the changed `clientInfo` / `capabilities`. On the `main` snapshot I tested, the second snapshot still reflects changed `capabilities`.\n'''\n```\n\n### Python \u0026 MCP Python SDK\n\n```Text\n- Python: `3.12.3`\n- MCP Python SDK: `mcp==1.27.1` (`v1.27.1`, `77431ebe7dda9ed0c61451b22d3e7f8d981bc092`)\n- Also reproduced on `main` snapshot `161834d4aee2633c42d3976c8f8751b6c4d947d5` (`v1.25.0-159-g161834d4`, pinned 2026-05-11)\n```","author":{"url":"https://github.com/cclabadmin","@type":"Person","name":"cclabadmin"},"datePublished":"2026-05-15T13:34:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/2605/python-sdk/issues/2605"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9e2c948d-e53a-e332-bb75-01cd55236f99 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E96A:102E0A:176332D:1F90F46:6A5968C0 |
| html-safe-nonce | 53ea25d11728c0b369e354f775a54ee1b29d20395d7e924ff36c6c6f517cbcba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTZBOjEwMkUwQToxNzYzMzJEOjFGOTBGNDY6NkE1OTY4QzAiLCJ2aXNpdG9yX2lkIjoiNzkwNDMwMjA1MDkzNzAxODI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 90715076c79777ee8c8a6a0511e121c092893e89e08b28c85bb23b0ef8b47b43 |
| hovercard-subject-tag | issue:4454307519 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/2605/issue_layout |
| twitter:image | https://opengraph.githubassets.com/19c7d3aba7f857d5a9974626e0c4aa1f5e12851179424d6ecc17b1ed3d1ef869/modelcontextprotocol/python-sdk/issues/2605 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/19c7d3aba7f857d5a9974626e0c4aa1f5e12851179424d6ecc17b1ed3d1ef869/modelcontextprotocol/python-sdk/issues/2605 |
| og:image:alt | Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cclabadmin |
| hostname | github.com |
| expected-hostname | github.com |
| None | a540949572872b935b393b36db38922db390ae71c859537d741b8f3eb7e545b5 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4aa391d605ba491481565840251a4b0fec3f4807 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width