You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/migration.md
+57-2Lines changed: 57 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,6 +169,30 @@ result = await session.list_resources(params=PaginatedRequestParams(cursor="next
169
169
result =await session.list_tools(params=PaginatedRequestParams(cursor="next_page_token"))
170
170
```
171
171
172
+
### `ClientSession.get_server_capabilities()` replaced by `initialize_result` property
173
+
174
+
`ClientSession` now stores the full `InitializeResult` via an `initialize_result` property. This provides access to `server_info`, `capabilities`, `instructions`, and the negotiated `protocol_version` through a single property. The `get_server_capabilities()` method has been removed.
175
+
176
+
**Before (v1):**
177
+
178
+
```python
179
+
capabilities = session.get_server_capabilities()
180
+
# server_info, instructions, protocol_version were not stored — had to capture initialize() return value
181
+
```
182
+
183
+
**After (v2):**
184
+
185
+
```python
186
+
result = session.initialize_result
187
+
if result isnotNone:
188
+
capabilities = result.capabilities
189
+
server_info = result.server_info
190
+
instructions = result.instructions
191
+
version = result.protocol_version
192
+
```
193
+
194
+
The high-level `Client.initialize_result` returns the same `InitializeResult` but is non-nullable — initialization is guaranteed inside the context manager, so no `None` check is needed. This replaces v1's `Client.server_capabilities`; use `client.initialize_result.capabilities` instead.
195
+
172
196
### `McpError` renamed to `MCPError`
173
197
174
198
The `McpError` exception class has been renamed to `MCPError` for consistent naming with the MCP acronym style used throughout the SDK.
**Note:** DNS rebinding protection is automatically enabled when `host` is `127.0.0.1`, `localhost`, or `::1`. This now happens in `sse_app()` and `streamable_http_app()` instead of the constructor.
290
314
315
+
### `MCPServer.get_context()` removed
316
+
317
+
`MCPServer.get_context()` has been removed. Context is now injected by the framework and passed explicitly — there is no ambient ContextVar to read from.
318
+
319
+
**If you were calling `get_context()` from inside a tool/resource/prompt:** use the `ctx: Context` parameter injection instead.
320
+
321
+
**Before (v1):**
322
+
323
+
```python
324
+
@mcp.tool()
325
+
asyncdefmy_tool(x: int) -> str:
326
+
ctx = mcp.get_context()
327
+
await ctx.info("Processing...")
328
+
returnstr(x)
329
+
```
330
+
331
+
**After (v2):**
332
+
333
+
```python
334
+
@mcp.tool()
335
+
asyncdefmy_tool(x: int, ctx: Context) -> str:
336
+
await ctx.info("Processing...")
337
+
returnstr(x)
338
+
```
339
+
340
+
### `MCPServer.call_tool()`, `read_resource()`, `get_prompt()` now accept a `context` parameter
341
+
342
+
`MCPServer.call_tool()`, `MCPServer.read_resource()`, and `MCPServer.get_prompt()` now accept an optional `context: Context | None = None` parameter. The framework passes this automatically during normal request handling. If you call these methods directly and omit `context`, a Context with no active request is constructed for you — tools that don't use `ctx` work normally, but any attempt to use `ctx.session`, `ctx.request_id`, etc. will raise.
343
+
344
+
The internal layers (`ToolManager.call_tool`, `Tool.run`, `Prompt.render`, `ResourceTemplate.create_resource`, etc.) now require `context` as a positional argument.
345
+
291
346
### Replace `RootModel` by union types with `TypeAdapter` validation
292
347
293
348
The following union types are no longer `RootModel` subclasses:
@@ -694,7 +749,7 @@ If you prefer the convenience of automatic wrapping, use `MCPServer` which still
The `server.request_context` property has been removed. Request context is now passed directly to handlers as the first argument (`ctx`). The `request_ctx` module-level contextvar is now an internal implementation detail and should not be relied upon.
752
+
The `server.request_context` property has been removed. Request context is now passed directly to handlers as the first argument (`ctx`). The `request_ctx` module-level contextvar has been removed entirely.
698
753
699
754
**Before (v1):**
700
755
@@ -828,6 +883,6 @@ The lowlevel `Server` also now exposes a `session_manager` property to access th
828
883
829
884
If you encounter issues during migration:
830
885
831
-
1. Check the [API Reference](api.md) for updated method signatures
886
+
1. Check the [API Reference](api/mcp/index.md) for updated method signatures
832
887
2. Review the [examples](https://github.com/modelcontextprotocol/python-sdk/tree/main/examples) for updated usage patterns
833
888
3. Open an issue on [GitHub](https://github.com/modelcontextprotocol/python-sdk/issues) if you find a bug or need further assistance
0 commit comments