11from collections .abc import Callable
2- from typing import Annotated , Any , Generic , Literal , TypeAlias , TypeVar
2+ from typing import Annotated , Any , Final , Generic , Literal , TypeAlias , TypeVar
33
44from pydantic import BaseModel , ConfigDict , Field , FileUrl , RootModel
55from pydantic .networks import AnyUrl , UrlConstraints
3333"""
3434DEFAULT_NEGOTIATED_VERSION = "2025-03-26"
3535
36+ """
37+ The JSON-RPC version (fixed at "2.0") to use for MCP messages.
38+ """
39+ JSON_RPC_VERSION : Final [str ] = "2.0"
40+ JSONRPCVersionType : TypeAlias = Literal ["2.0" ]
41+
3642ProgressToken = str | int
3743Cursor = str
3844Role = Literal ["user" , "assistant" ]
@@ -124,7 +130,7 @@ class PaginatedResult(Result):
124130class JSONRPCRequest (Request [dict [str , Any ] | None , str ]):
125131 """A request that expects a response."""
126132
127- jsonrpc : Literal [ "2.0" ]
133+ jsonrpc : JSONRPCVersionType = JSON_RPC_VERSION
128134 id : RequestId
129135 method : str
130136 params : dict [str , Any ] | None = None
@@ -133,14 +139,14 @@ class JSONRPCRequest(Request[dict[str, Any] | None, str]):
133139class JSONRPCNotification (Notification [dict [str , Any ] | None , str ]):
134140 """A notification which does not expect a response."""
135141
136- jsonrpc : Literal [ "2.0" ]
142+ jsonrpc : JSONRPCVersionType = JSON_RPC_VERSION
137143 params : dict [str , Any ] | None = None
138144
139145
140146class JSONRPCResponse (BaseModel ):
141147 """A successful (non-error) response to a request."""
142148
143- jsonrpc : Literal [ "2.0" ]
149+ jsonrpc : JSONRPCVersionType = JSON_RPC_VERSION
144150 id : RequestId
145151 result : dict [str , Any ]
146152 model_config = ConfigDict (extra = "allow" )
@@ -182,7 +188,7 @@ class ErrorData(BaseModel):
182188class JSONRPCError (BaseModel ):
183189 """A response to a request that indicates an error occurred."""
184190
185- jsonrpc : Literal [ "2.0" ]
191+ jsonrpc : JSONRPCVersionType = JSON_RPC_VERSION
186192 id : str | int
187193 error : ErrorData
188194 model_config = ConfigDict (extra = "allow" )
0 commit comments