@@ -132,7 +132,7 @@ async def send_request(
132
132
self ._response_streams [request_id ] = response_stream
133
133
134
134
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 )
136
136
)
137
137
138
138
# TODO: Support progress callbacks
@@ -150,7 +150,7 @@ async def send_notification(self, notification: SendNotificationT) -> None:
150
150
Emits a notification, which is a one-way message that does not expect a response.
151
151
"""
152
152
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 )
154
154
)
155
155
156
156
await self ._write_stream .send (JSONRPCMessage (jsonrpc_notification ))
@@ -165,7 +165,7 @@ async def _send_response(
165
165
jsonrpc_response = JSONRPCResponse (
166
166
jsonrpc = "2.0" ,
167
167
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 ),
169
169
)
170
170
await self ._write_stream .send (JSONRPCMessage (jsonrpc_response ))
171
171
@@ -180,7 +180,7 @@ async def _receive_loop(self) -> None:
180
180
await self ._incoming_message_stream_writer .send (message )
181
181
elif isinstance (message .root , JSONRPCRequest ):
182
182
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 )
184
184
)
185
185
responder = RequestResponder (
186
186
request_id = message .root .id ,
@@ -196,7 +196,7 @@ async def _receive_loop(self) -> None:
196
196
await self ._incoming_message_stream_writer .send (responder )
197
197
elif isinstance (message .root , JSONRPCNotification ):
198
198
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 )
200
200
)
201
201
202
202
await self ._received_notification (notification )
0 commit comments