|
12 | 12 | from typing_extensions import Self |
13 | 13 |
|
14 | 14 | from mcp.shared.exceptions import McpError |
15 | | -from mcp.shared.message import SessionMessage |
| 15 | +from mcp.shared.message import ServerMessageMetadata, SessionMessage |
16 | 16 | from mcp.types import ( |
17 | 17 | CancelledNotification, |
18 | 18 | ClientNotification, |
|
24 | 24 | JSONRPCNotification, |
25 | 25 | JSONRPCRequest, |
26 | 26 | JSONRPCResponse, |
27 | | - NotificationParams, |
28 | 27 | RequestParams, |
29 | 28 | ServerNotification, |
30 | 29 | ServerRequest, |
@@ -280,22 +279,14 @@ async def send_notification( |
280 | 279 | """ |
281 | 280 | # Some transport implementations may need to set the related_request_id |
282 | 281 | # to attribute to the notifications to the request that triggered them. |
283 | | - if related_request_id is not None and notification.root.params is not None: |
284 | | - # Create meta if it doesn't exist |
285 | | - if notification.root.params.meta is None: |
286 | | - meta_dict = {"related_request_id": related_request_id} |
287 | | - |
288 | | - else: |
289 | | - meta_dict = notification.root.params.meta.model_dump( |
290 | | - by_alias=True, mode="json", exclude_none=True |
291 | | - ) |
292 | | - meta_dict["related_request_id"] = related_request_id |
293 | | - notification.root.params.meta = NotificationParams.Meta(**meta_dict) |
294 | 282 | jsonrpc_notification = JSONRPCNotification( |
295 | 283 | jsonrpc="2.0", |
296 | 284 | **notification.model_dump(by_alias=True, mode="json", exclude_none=True), |
297 | 285 | ) |
298 | | - session_message = SessionMessage(message=JSONRPCMessage(jsonrpc_notification)) |
| 286 | + session_message = SessionMessage( |
| 287 | + message=JSONRPCMessage(jsonrpc_notification), |
| 288 | + metadata=ServerMessageMetadata(related_request_id=related_request_id), |
| 289 | + ) |
299 | 290 | await self._write_stream.send(session_message) |
300 | 291 |
|
301 | 292 | async def _send_response( |
|
0 commit comments