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
@@ -550,9 +550,14 @@ from mcp.shared._context import SessionT
550
550
from mcp.shared._context import SessionT_co
551
551
```
552
552
553
-
#### `AbstractBaseSession`simplified
553
+
#### New `AbstractBaseSession`structural interface
554
554
555
-
`AbstractBaseSession` is now a pure abstract interface with no `__init__` method and no `WireMessageT` type parameter. If you were subclassing it directly, you now need to manage all state in your subclass.
555
+
The session hierarchy now uses a new **runtime-checkable Protocol** called `AbstractBaseSession` to define the shared contract for all MCP sessions. This protocol enables structural subtyping, allowing different transport implementations to be used interchangeably without requiring rigid inheritance.
556
+
557
+
Key characteristics of `AbstractBaseSession`:
558
+
1.**Pure Interface**: It is a structural protocol with no implementation state or `__init__` method.
559
+
2.**Simplified Type Parameters**: It takes two parameters: `AbstractBaseSession[SendRequestT, SendNotificationT]`. Contravariant variance is used for these parameters to ensure that sessions can be used safely in generic contexts (like `RequestContext`).
560
+
3.**BaseSession Implementation**: The concrete implementation logic (state management, response routing) is provided by the `BaseSession` class, which satisfies the protocol.
556
561
557
562
**Before:**
558
563
@@ -575,6 +580,56 @@ class MySession(AbstractBaseSession[...]):
575
580
self._my_state = {}
576
581
```
577
582
583
+
#### `SendRequestT` changed to contravariant
584
+
585
+
The `SendRequestT` TypeVar is now defined as **contravariant** to support its use in the `AbstractBaseSession` Protocol.
`BaseClientSession` is now a `typing.Protocol` (structural subtyping) instead of an abstract base class. It no longer inherits from `AbstractBaseSession` and requires no inheritance to satisfy.
0 commit comments