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
Merge upstream/main which included major refactors:
- Context class moved from server.py to mcpserver/context.py (#2203)
- Lowlevel Server decorators replaced with on_* kwargs (#1985)
- Docstring formatting standardized with periods (#2095)
- mcp.shared.progress module removed (#2080)
Resolved conflicts by:
- Taking upstream server.py (Context class removed)
- Adding progress_callback to new context.py
- Keeping progress_callback docstrings with upstream period style
- Restoring RequestContext import for new tests
- Updating tests to use ctx: Context injection pattern
Thank you for helping us keep the SDKs and systems they interact with secure.
3
+
Thank you for helping keep the Model Context Protocol and its ecosystem secure.
4
4
5
5
## Reporting Security Issues
6
6
7
-
This SDK is maintained by [Anthropic](https://www.anthropic.com/) as part of the Model Context Protocol project.
7
+
If you discover a security vulnerability in this repository, please report it through
8
+
the [GitHub Security Advisory process](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability)
9
+
for this repository.
8
10
9
-
The security of our systems and user data is Anthropic’s top priority. We appreciate the work of security researchers acting in good faith in identifying and reporting potential vulnerabilities.
11
+
Please **do not** report security vulnerabilities through public GitHub issues, discussions,
12
+
or pull requests.
10
13
11
-
Our security program is managed on HackerOne and we ask that any validated vulnerability in this functionality be reported through their [submission form](https://hackerone.com/anthropic-vdp/reports/new?type=team&report_type=vulnerability).
14
+
## What to Include
12
15
13
-
## Vulnerability Disclosure Program
16
+
To help us triage and respond quickly, please include:
14
17
15
-
Our Vulnerability Program Guidelines are defined on our [HackerOne program page](https://hackerone.com/anthropic-vdp).
**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:
The `RequestContext` class has been split to separate shared fields from server-specific fields. The shared `RequestContext` now only takes 1 type parameter (the session type) instead of 3.
377
408
@@ -380,40 +411,59 @@ The `RequestContext` class has been split to separate shared fields from server-
380
411
- Type parameters reduced from `RequestContext[SessionT, LifespanContextT, RequestT]` to `RequestContext[SessionT]`
381
412
- Server-specific fields (`lifespan_context`, `experimental`, `request`, `close_sse_stream`, `close_standalone_sse_stream`) moved to new `ServerRequestContext` class in `mcp.server.context`
382
413
383
-
**`ProgressContext` changes:**
384
-
385
-
- Type parameters reduced from `ProgressContext[SendRequestT, SendNotificationT, SendResultT, ReceiveRequestT, ReceiveNotificationT]` to `ProgressContext[SessionT]`
386
-
387
414
**Before (v1):**
388
415
389
416
```python
390
417
from mcp.client.session import ClientSession
391
418
from mcp.shared.context import RequestContext, LifespanContextT, RequestT
### `ProgressContext` and `progress()` context manager removed
438
+
439
+
The `mcp.shared.progress` module (`ProgressContext`, `Progress`, and the `progress()` context manager) has been removed. This module had no real-world adoption — all users send progress notifications via `Context.report_progress()` or `session.send_progress_notification()` directly.
414
440
415
-
# ProgressContext with 1 type parameter
416
-
progress_ctx: ProgressContext[ClientSession]
441
+
**Before:**
442
+
443
+
```python
444
+
from mcp.shared.progress import progress
445
+
446
+
with progress(ctx, total=100) as p:
447
+
await p.progress(25)
448
+
```
449
+
450
+
**After — use `Context.report_progress()` (recommended):**
451
+
452
+
```python
453
+
@server.tool()
454
+
asyncdefmy_tool(x: int, ctx: Context) -> str:
455
+
await ctx.report_progress(25, 100)
456
+
return"done"
457
+
```
458
+
459
+
**After — use `session.send_progress_notification()` (low-level):**
460
+
461
+
```python
462
+
await session.send_progress_notification(
463
+
progress_token=progress_token,
464
+
progress=25,
465
+
total=100,
466
+
)
417
467
```
418
468
419
469
### Resource URI type changed from `AnyUrl` to `str`
@@ -675,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