Add support for additional notification schemas in useConnection hook
This commit is contained in:
parent
dd460bd877
commit
27b54104c1
1 changed files with 19 additions and 0 deletions
|
|
@ -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> => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue