Skip to content

Commit 16f63dc

Browse files
refactor: add jsonrpc field to base Notification class
This aligns with the TypeScript SDK where notification types extend JSONRPCNotification and include the jsonrpc field. All notification types now automatically have jsonrpc='2.0' via the base class. The session.py code no longer needs to explicitly add jsonrpc since it's included in the notification's model_dump(). Github-Issue: #1729
1 parent 7080fcf commit 16f63dc

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/mcp/shared/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ async def send_notification(
320320
"""
321321
# Some transport implementations may need to set the related_request_id
322322
# to attribute to the notifications to the request that triggered them.
323+
# Note: notification already has jsonrpc="2.0" from base Notification class
323324
jsonrpc_notification = JSONRPCNotification(
324-
jsonrpc="2.0",
325325
**notification.model_dump(by_alias=True, mode="json", exclude_none=True),
326326
)
327327
session_message = SessionMessage( # pragma: no cover

src/mcp/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class PaginatedRequest(Request[PaginatedRequestParams | None, MethodT], Generic[
108108
class Notification(MCPModel, Generic[NotificationParamsT, MethodT]):
109109
"""Base class for JSON-RPC notifications."""
110110

111+
jsonrpc: Literal["2.0"] = "2.0"
111112
method: MethodT
112113
params: NotificationParamsT
113114

@@ -142,7 +143,6 @@ class JSONRPCRequest(Request[dict[str, Any] | None, str]):
142143
class JSONRPCNotification(Notification[dict[str, Any] | None, str]):
143144
"""A notification which does not expect a response."""
144145

145-
jsonrpc: Literal["2.0"]
146146
params: dict[str, Any] | None = None
147147

148148

0 commit comments

Comments
 (0)