@@ -132,7 +132,7 @@ async def send_request(
132132 self ._response_streams [request_id ] = response_stream
133133
134134 jsonrpc_request = JSONRPCRequest (
135- jsonrpc = "2.0" , id = request_id , ** request .model_dump (by_alias = True , mode = "json" )
135+ jsonrpc = "2.0" , id = request_id , ** request .model_dump (by_alias = True , mode = "json" , exclude_none = True )
136136 )
137137
138138 # TODO: Support progress callbacks
@@ -150,7 +150,7 @@ async def send_notification(self, notification: SendNotificationT) -> None:
150150 Emits a notification, which is a one-way message that does not expect a response.
151151 """
152152 jsonrpc_notification = JSONRPCNotification (
153- jsonrpc = "2.0" , ** notification .model_dump (by_alias = True , mode = "json" )
153+ jsonrpc = "2.0" , ** notification .model_dump (by_alias = True , mode = "json" , exclude_none = True )
154154 )
155155
156156 await self ._write_stream .send (JSONRPCMessage (jsonrpc_notification ))
@@ -165,7 +165,7 @@ async def _send_response(
165165 jsonrpc_response = JSONRPCResponse (
166166 jsonrpc = "2.0" ,
167167 id = request_id ,
168- result = response .model_dump (by_alias = True , mode = "json" ),
168+ result = response .model_dump (by_alias = True , mode = "json" , exclude_none = True ),
169169 )
170170 await self ._write_stream .send (JSONRPCMessage (jsonrpc_response ))
171171
@@ -180,7 +180,7 @@ async def _receive_loop(self) -> None:
180180 await self ._incoming_message_stream_writer .send (message )
181181 elif isinstance (message .root , JSONRPCRequest ):
182182 validated_request = self ._receive_request_type .model_validate (
183- message .root .model_dump (by_alias = True , mode = "json" )
183+ message .root .model_dump (by_alias = True , mode = "json" , exclude_none = True )
184184 )
185185 responder = RequestResponder (
186186 request_id = message .root .id ,
@@ -196,7 +196,7 @@ async def _receive_loop(self) -> None:
196196 await self ._incoming_message_stream_writer .send (responder )
197197 elif isinstance (message .root , JSONRPCNotification ):
198198 notification = self ._receive_notification_type .model_validate (
199- message .root .model_dump (by_alias = True , mode = "json" )
199+ message .root .model_dump (by_alias = True , mode = "json" , exclude_none = True )
200200 )
201201
202202 await self ._received_notification (notification )
0 commit comments