@@ -28,6 +28,7 @@ import {
28
28
ToolListChangedNotificationSchema ,
29
29
PromptListChangedNotificationSchema ,
30
30
Progress ,
31
+ ElicitRequestSchema ,
31
32
} from "@modelcontextprotocol/sdk/types.js" ;
32
33
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js" ;
33
34
import { useState } from "react" ;
@@ -62,6 +63,8 @@ interface UseConnectionOptions {
62
63
// eslint-disable-next-line @typescript-eslint/no-explicit-any
63
64
onPendingRequest ?: ( request : any , resolve : any , reject : any ) => void ;
64
65
// 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
65
68
getRoots ?: ( ) => any [ ] ;
66
69
}
67
70
@@ -77,6 +80,7 @@ export function useConnection({
77
80
onNotification,
78
81
onStdErrNotification,
79
82
onPendingRequest,
83
+ onElicitationRequest,
80
84
getRoots,
81
85
} : UseConnectionOptions ) {
82
86
const [ connectionStatus , setConnectionStatus ] =
@@ -295,6 +299,7 @@ export function useConnection({
295
299
{
296
300
capabilities : {
297
301
sampling : { } ,
302
+ elicitation : { } ,
298
303
roots : {
299
304
listChanged : true ,
300
305
} ,
@@ -521,6 +526,14 @@ export function useConnection({
521
526
} ) ;
522
527
}
523
528
529
+ if ( onElicitationRequest ) {
530
+ client . setRequestHandler ( ElicitRequestSchema , async ( request ) => {
531
+ return new Promise ( ( resolve ) => {
532
+ onElicitationRequest ( request , resolve ) ;
533
+ } ) ;
534
+ } ) ;
535
+ }
536
+
524
537
setMcpClient ( client ) ;
525
538
setConnectionStatus ( "connected" ) ;
526
539
} catch ( e ) {
0 commit comments