|
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, |
@@ -288,22 +287,16 @@ async def send_notification( |
288 | 287 | """ |
289 | 288 | # Some transport implementations may need to set the related_request_id |
290 | 289 | # to attribute to the notifications to the request that triggered them. |
291 | | - if related_request_id is not None and notification.root.params is not None: |
292 | | - # Create meta if it doesn't exist |
293 | | - if notification.root.params.meta is None: |
294 | | - meta_dict = {"related_request_id": related_request_id} |
295 | | - |
296 | | - else: |
297 | | - meta_dict = notification.root.params.meta.model_dump( |
298 | | - by_alias=True, mode="json", exclude_none=True |
299 | | - ) |
300 | | - meta_dict["related_request_id"] = related_request_id |
301 | | - notification.root.params.meta = NotificationParams.Meta(**meta_dict) |
302 | 290 | jsonrpc_notification = JSONRPCNotification( |
303 | 291 | jsonrpc="2.0", |
304 | 292 | **notification.model_dump(by_alias=True, mode="json", exclude_none=True), |
305 | 293 | ) |
306 | | - session_message = SessionMessage(message=JSONRPCMessage(jsonrpc_notification)) |
| 294 | + session_message = SessionMessage( |
| 295 | + message=JSONRPCMessage(jsonrpc_notification), |
| 296 | + metadata=ServerMessageMetadata(related_request_id=related_request_id) |
| 297 | + if related_request_id |
| 298 | + else None, |
| 299 | + ) |
307 | 300 | await self._write_stream.send(session_message) |
308 | 301 |
|
309 | 302 | async def _send_response( |
|
0 commit comments