Skip to content

Commit 205e707

Browse files
authored
Merge pull request modelcontextprotocol#191 from nathanArseneau/show-all-notifications
Refactor notification handling to include all notifications
2 parents 4d4bb91 + 9244ecf commit 205e707

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

client/src/lib/hooks/useConnection.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import {
1919
McpError,
2020
CompleteResultSchema,
2121
ErrorCode,
22+
CancelledNotificationSchema,
23+
ResourceListChangedNotificationSchema,
24+
ToolListChangedNotificationSchema,
25+
PromptListChangedNotificationSchema,
2226
} from "@modelcontextprotocol/sdk/types.js";
2327
import { useState } from "react";
2428
import { toast } from "react-toastify";
@@ -250,20 +254,24 @@ export function useConnection({
250254
});
251255

252256
if (onNotification) {
253-
client.setNotificationHandler(
257+
[
258+
CancelledNotificationSchema,
254259
ProgressNotificationSchema,
255-
onNotification,
256-
);
257-
258-
client.setNotificationHandler(
260+
LoggingMessageNotificationSchema,
259261
ResourceUpdatedNotificationSchema,
260-
onNotification,
261-
);
262+
ResourceListChangedNotificationSchema,
263+
ToolListChangedNotificationSchema,
264+
PromptListChangedNotificationSchema,
265+
].forEach((notificationSchema) => {
266+
client.setNotificationHandler(notificationSchema, onNotification);
267+
});
262268

263-
client.setNotificationHandler(
264-
LoggingMessageNotificationSchema,
265-
onNotification,
266-
);
269+
client.fallbackNotificationHandler = (
270+
notification: Notification,
271+
): Promise<void> => {
272+
onNotification(notification);
273+
return Promise.resolve();
274+
};
267275
}
268276

269277
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)