Skip to content

Commit dd460bd

Browse files
Refactor notification handling to include all notifications
1 parent cedf02d commit dd460bd

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

client/src/lib/hooks/useConnection.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import {
88
ClientRequest,
99
CreateMessageRequestSchema,
1010
ListRootsRequestSchema,
11-
ProgressNotificationSchema,
12-
ResourceUpdatedNotificationSchema,
13-
LoggingMessageNotificationSchema,
1411
Request,
1512
Result,
1613
ServerCapabilities,
@@ -250,20 +247,12 @@ export function useConnection({
250247
});
251248

252249
if (onNotification) {
253-
client.setNotificationHandler(
254-
ProgressNotificationSchema,
255-
onNotification,
256-
);
257-
258-
client.setNotificationHandler(
259-
ResourceUpdatedNotificationSchema,
260-
onNotification,
261-
);
262-
263-
client.setNotificationHandler(
264-
LoggingMessageNotificationSchema,
265-
onNotification,
266-
);
250+
client.fallbackNotificationHandler = (
251+
notification: Notification,
252+
): Promise<void> => {
253+
onNotification(notification);
254+
return Promise.resolve();
255+
};
267256
}
268257

269258
if (onStdErrNotification) {

client/src/lib/notificationTypes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export const StdErrNotificationSchema = BaseNotificationSchema.extend({
1414

1515
export const NotificationSchema = ClientNotificationSchema.or(
1616
StdErrNotificationSchema,
17-
).or(ServerNotificationSchema);
17+
)
18+
.or(ServerNotificationSchema)
19+
.or(BaseNotificationSchema);
1820

1921
export type StdErrNotification = z.infer<typeof StdErrNotificationSchema>;
2022
export type Notification = z.infer<typeof NotificationSchema>;

0 commit comments

Comments
 (0)