Skip to content

Commit cffdd06

Browse files
committed
refactor: remove unnecessary try-except in _should_validate_notification
The try-except block was unnecessary since getattr already handles the case where the attribute doesn't exist by returning None.
1 parent 6c9ca12 commit cffdd06

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/mcp/shared/session.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,10 @@ def _should_validate_notification(self, message_root: JSONRPCNotification) -> bo
220220
Determines if a notification should be validated.
221221
Internal notifications (like notifications/cancelled) should be ignored.
222222
"""
223-
try:
224-
return (
225-
getattr(message_root, "method", None) != "notifications/cancelled" and
226-
not self._closed
227-
)
228-
except:
229-
return False
223+
return (
224+
getattr(message_root, "method", None) != "notifications/cancelled" and
225+
not self._closed
226+
)
230227

231228
async def _receive_loop(self) -> None:
232229
async with (

0 commit comments

Comments
 (0)