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

View File

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