mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
Exclude Nones
This commit is contained in:
@@ -132,7 +132,7 @@ class BaseSession(
|
||||
self._response_streams[request_id] = response_stream
|
||||
|
||||
jsonrpc_request = JSONRPCRequest(
|
||||
jsonrpc="2.0", id=request_id, **request.model_dump(by_alias=True, mode="json")
|
||||
jsonrpc="2.0", id=request_id, **request.model_dump(by_alias=True, mode="json", exclude_none=True)
|
||||
)
|
||||
|
||||
# TODO: Support progress callbacks
|
||||
@@ -150,7 +150,7 @@ class BaseSession(
|
||||
Emits a notification, which is a one-way message that does not expect a response.
|
||||
"""
|
||||
jsonrpc_notification = JSONRPCNotification(
|
||||
jsonrpc="2.0", **notification.model_dump(by_alias=True, mode="json")
|
||||
jsonrpc="2.0", **notification.model_dump(by_alias=True, mode="json", exclude_none=True)
|
||||
)
|
||||
|
||||
await self._write_stream.send(JSONRPCMessage(jsonrpc_notification))
|
||||
@@ -165,7 +165,7 @@ class BaseSession(
|
||||
jsonrpc_response = JSONRPCResponse(
|
||||
jsonrpc="2.0",
|
||||
id=request_id,
|
||||
result=response.model_dump(by_alias=True, mode="json"),
|
||||
result=response.model_dump(by_alias=True, mode="json", exclude_none=True),
|
||||
)
|
||||
await self._write_stream.send(JSONRPCMessage(jsonrpc_response))
|
||||
|
||||
@@ -180,7 +180,7 @@ class BaseSession(
|
||||
await self._incoming_message_stream_writer.send(message)
|
||||
elif isinstance(message.root, JSONRPCRequest):
|
||||
validated_request = self._receive_request_type.model_validate(
|
||||
message.root.model_dump(by_alias=True, mode="json")
|
||||
message.root.model_dump(by_alias=True, mode="json", exclude_none=True)
|
||||
)
|
||||
responder = RequestResponder(
|
||||
request_id=message.root.id,
|
||||
@@ -196,7 +196,7 @@ class BaseSession(
|
||||
await self._incoming_message_stream_writer.send(responder)
|
||||
elif isinstance(message.root, JSONRPCNotification):
|
||||
notification = self._receive_notification_type.model_validate(
|
||||
message.root.model_dump(by_alias=True, mode="json")
|
||||
message.root.model_dump(by_alias=True, mode="json", exclude_none=True)
|
||||
)
|
||||
|
||||
await self._received_notification(notification)
|
||||
|
||||
Reference in New Issue
Block a user