Skip to content

Commit e163aea

Browse files
committed
feat: add elicitations to useConnection
1 parent 424b449 commit e163aea

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

client/src/lib/hooks/useConnection.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ToolListChangedNotificationSchema,
2929
PromptListChangedNotificationSchema,
3030
Progress,
31+
ElicitRequestSchema,
3132
} from "@modelcontextprotocol/sdk/types.js";
3233
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
3334
import { useState } from "react";
@@ -62,6 +63,8 @@ interface UseConnectionOptions {
6263
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6364
onPendingRequest?: (request: any, resolve: any, reject: any) => void;
6465
// eslint-disable-next-line @typescript-eslint/no-explicit-any
66+
onElicitationRequest?: (request: any, resolve: any) => void;
67+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6568
getRoots?: () => any[];
6669
}
6770

@@ -77,6 +80,7 @@ export function useConnection({
7780
onNotification,
7881
onStdErrNotification,
7982
onPendingRequest,
83+
onElicitationRequest,
8084
getRoots,
8185
}: UseConnectionOptions) {
8286
const [connectionStatus, setConnectionStatus] =
@@ -295,6 +299,7 @@ export function useConnection({
295299
{
296300
capabilities: {
297301
sampling: {},
302+
elicitation: {},
298303
roots: {
299304
listChanged: true,
300305
},
@@ -521,6 +526,14 @@ export function useConnection({
521526
});
522527
}
523528

529+
if (onElicitationRequest) {
530+
client.setRequestHandler(ElicitRequestSchema, async (request) => {
531+
return new Promise((resolve) => {
532+
onElicitationRequest(request, resolve);
533+
});
534+
});
535+
}
536+
524537
setMcpClient(client);
525538
setConnectionStatus("connected");
526539
} catch (e) {

0 commit comments

Comments
 (0)