Refactor notification handling to include all notifications

This commit is contained in:
Nathan Arseneau
2025-03-17 02:44:59 -04:00
parent cedf02d152
commit dd460bd877
2 changed files with 9 additions and 18 deletions

View File

@@ -8,9 +8,6 @@ import {
ClientRequest,
CreateMessageRequestSchema,
ListRootsRequestSchema,
ProgressNotificationSchema,
ResourceUpdatedNotificationSchema,
LoggingMessageNotificationSchema,
Request,
Result,
ServerCapabilities,
@@ -250,20 +247,12 @@ export function useConnection({
});
if (onNotification) {
client.setNotificationHandler(
ProgressNotificationSchema,
onNotification,
);
client.setNotificationHandler(
ResourceUpdatedNotificationSchema,
onNotification,
);
client.setNotificationHandler(
LoggingMessageNotificationSchema,
onNotification,
);
client.fallbackNotificationHandler = (
notification: Notification,
): Promise<void> => {
onNotification(notification);
return Promise.resolve();
};
}
if (onStdErrNotification) {

View File

@@ -14,7 +14,9 @@ export const StdErrNotificationSchema = BaseNotificationSchema.extend({
export const NotificationSchema = ClientNotificationSchema.or(
StdErrNotificationSchema,
).or(ServerNotificationSchema);
)
.or(ServerNotificationSchema)
.or(BaseNotificationSchema);
export type StdErrNotification = z.infer<typeof StdErrNotificationSchema>;
export type Notification = z.infer<typeof NotificationSchema>;