@@ -184,15 +184,43 @@ class JSONRPCMessage(
184184
185185
186186class MessageFrame (BaseModel , Generic [RawT ]):
187- root : JSONRPCMessage
187+ """
188+ A wrapper around the general message received that contains both the parsed message
189+ and the raw message.
190+
191+ This class serves as an encapsulation for JSON-RPC messages, providing access to
192+ both the parsed structure (root) and the original raw data. This design is
193+ particularly useful for Server-Sent Events (SSE) consumers who may need to access
194+ additional metadata or headers associated with the message.
195+
196+ The 'root' attribute contains the parsed JSONRPCMessage, which could be a request,
197+ notification, response, or error. The 'raw' attribute preserves the original
198+ message as received, allowing access to any additional context or metadata that
199+ might be lost in parsing.
200+
201+ This dual representation allows for flexible handling of messages, where consumers
202+ can work with the structured data for standard operations, but still have the
203+ option to examine or utilize the raw data when needed, such as for debugging,
204+ logging, or accessing transport-specific information.
205+ """
206+
207+ message : JSONRPCMessage
188208 raw : RawT | None = None
189209 model_config = ConfigDict (extra = "allow" )
190210
191211 def model_dump (self , * args , ** kwargs ):
192- return self .root .model_dump (* args , ** kwargs )
212+ """
213+ Dumps the model to a dictionary, delegating to the root JSONRPCMessage.
214+ This method allows for consistent serialization of the parsed message.
215+ """
216+ return self .message .model_dump (* args , ** kwargs )
193217
194218 def model_dump_json (self , * args , ** kwargs ):
195- return self .root .model_dump_json (* args , ** kwargs )
219+ """
220+ Dumps the model to a JSON string, delegating to the root JSONRPCMessage.
221+ This method provides a convenient way to serialize the parsed message to JSON.
222+ """
223+ return self .message .model_dump_json (* args , ** kwargs )
196224
197225
198226class EmptyResult (Result ):
0 commit comments