Add support for additional notification schemas in useConnection hook

This commit is contained in:
Nathan Arseneau
2025-03-19 19:51:01 -04:00
parent dd460bd877
commit 27b54104c1

View File

@@ -8,6 +8,9 @@ import {
ClientRequest, ClientRequest,
CreateMessageRequestSchema, CreateMessageRequestSchema,
ListRootsRequestSchema, ListRootsRequestSchema,
ProgressNotificationSchema,
ResourceUpdatedNotificationSchema,
LoggingMessageNotificationSchema,
Request, Request,
Result, Result,
ServerCapabilities, ServerCapabilities,
@@ -16,6 +19,10 @@ import {
McpError, McpError,
CompleteResultSchema, CompleteResultSchema,
ErrorCode, ErrorCode,
CancelledNotificationSchema,
ResourceListChangedNotificationSchema,
ToolListChangedNotificationSchema,
PromptListChangedNotificationSchema,
} from "@modelcontextprotocol/sdk/types.js"; } from "@modelcontextprotocol/sdk/types.js";
import { useState } from "react"; import { useState } from "react";
import { toast } from "react-toastify"; import { toast } from "react-toastify";
@@ -247,6 +254,18 @@ export function useConnection({
}); });
if (onNotification) { if (onNotification) {
[
CancelledNotificationSchema,
ProgressNotificationSchema,
LoggingMessageNotificationSchema,
ResourceUpdatedNotificationSchema,
ResourceListChangedNotificationSchema,
ToolListChangedNotificationSchema,
PromptListChangedNotificationSchema,
].forEach((notificationSchema) => {
client.setNotificationHandler(notificationSchema, onNotification);
});
client.fallbackNotificationHandler = ( client.fallbackNotificationHandler = (
notification: Notification, notification: Notification,
): Promise<void> => { ): Promise<void> => {