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
**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
290
291
+
### `MCPServer.get_context()` removed
292
+
293
+
`MCPServer.get_context()` has been removed. Context is now injected by the framework and passed explicitly — there is no ambient ContextVar to read from.
294
+
295
+
**If you were calling `get_context()` from inside a tool/resource/prompt:** use the `ctx: Context` parameter injection instead.
296
+
297
+
**Before (v1):**
298
+
299
+
```python
300
+
@mcp.tool()
301
+
asyncdefmy_tool(x: int) -> str:
302
+
ctx = mcp.get_context()
303
+
await ctx.info("Processing...")
304
+
returnstr(x)
305
+
```
306
+
307
+
**After (v2):**
308
+
309
+
```python
310
+
@mcp.tool()
311
+
asyncdefmy_tool(x: int, ctx: Context) -> str:
312
+
await ctx.info("Processing...")
313
+
returnstr(x)
314
+
```
315
+
316
+
### `MCPServer.call_tool()`, `read_resource()`, `get_prompt()` now accept a `context` parameter
317
+
318
+
`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.
319
+
320
+
The internal layers (`ToolManager.call_tool`, `Tool.run`, `Prompt.render`, `ResourceTemplate.create_resource`, etc.) now require `context` as a positional argument.
321
+
291
322
### Replace `RootModel` by union types with `TypeAdapter` validation
292
323
293
324
The following union types are no longer `RootModel` subclasses:
@@ -694,7 +725,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.
728
+
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.
0 commit comments