From 16f63dc2bf0d555e17814b614a81103283461373 Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Fri, 16 Jan 2026 15:36:04 +0100 Subject: [PATCH] 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 --- src/mcp/shared/session.py | 2 +- src/mcp/types.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mcp/shared/session.py b/src/mcp/shared/session.py index 51d1f64e02..94b340372f 100644 --- a/src/mcp/shared/session.py +++ b/src/mcp/shared/session.py @@ -320,8 +320,8 @@ async def send_notification( """ # Some transport implementations may need to set the related_request_id # to attribute to the notifications to the request that triggered them. + # Note: notification already has jsonrpc="2.0" from base Notification class jsonrpc_notification = JSONRPCNotification( - jsonrpc="2.0", **notification.model_dump(by_alias=True, mode="json", exclude_none=True), ) session_message = SessionMessage( # pragma: no cover diff --git a/src/mcp/types.py b/src/mcp/types.py index 6fc551035b..b91b8f3f31 100644 --- a/src/mcp/types.py +++ b/src/mcp/types.py @@ -108,6 +108,7 @@ class PaginatedRequest(Request[PaginatedRequestParams | None, MethodT], Generic[ class Notification(MCPModel, Generic[NotificationParamsT, MethodT]): """Base class for JSON-RPC notifications.""" + jsonrpc: Literal["2.0"] = "2.0" method: MethodT params: NotificationParamsT @@ -142,7 +143,6 @@ class JSONRPCRequest(Request[dict[str, Any] | None, str]): class JSONRPCNotification(Notification[dict[str, Any] | None, str]): """A notification which does not expect a response.""" - jsonrpc: Literal["2.0"] params: dict[str, Any] | None = None