@@ -56,6 +56,9 @@ type ClientOptions struct {
5656 // Handler for sampling.
5757 // Called when a server calls CreateMessage.
5858 CreateMessageHandler func (context.Context , * ClientSession , * CreateMessageParams ) (* CreateMessageResult , error )
59+ // Handler for elicitation.
60+ // Called when a server requests user input via Elicit.
61+ ElicitationHandler func (context.Context , * ClientSession , * ElicitParams ) (* ElicitResult , error )
5962 // Handlers for notifications from the server.
6063 ToolListChangedHandler func (context.Context , * ClientSession , * ToolListChangedParams )
6164 PromptListChangedHandler func (context.Context , * ClientSession , * PromptListChangedParams )
@@ -119,6 +122,9 @@ func (c *Client) Connect(ctx context.Context, t Transport) (cs *ClientSession, e
119122 if c .opts .CreateMessageHandler != nil {
120123 caps .Sampling = & SamplingCapabilities {}
121124 }
125+ if c .opts .ElicitationHandler != nil {
126+ caps .Elicitation = & ElicitationCapabilities {}
127+ }
122128
123129 params := & InitializeParams {
124130 ProtocolVersion : latestProtocolVersion ,
@@ -255,6 +261,14 @@ func (c *Client) createMessage(ctx context.Context, cs *ClientSession, params *C
255261 return c .opts .CreateMessageHandler (ctx , cs , params )
256262}
257263
264+ func (c * Client ) elicit (ctx context.Context , cs * ClientSession , params * ElicitParams ) (* ElicitResult , error ) {
265+ if c .opts .ElicitationHandler == nil {
266+ // TODO: wrap or annotate this error? Pick a standard code?
267+ return nil , & jsonrpc2.WireError {Code : CodeUnsupportedMethod , Message : "client does not support elicitation" }
268+ }
269+ return c .opts .ElicitationHandler (ctx , cs , params )
270+ }
271+
258272// AddSendingMiddleware wraps the current sending method handler using the provided
259273// middleware. Middleware is applied from right to left, so that the first one is
260274// executed first.
@@ -291,6 +305,7 @@ var clientMethodInfos = map[string]methodInfo{
291305 methodPing : newMethodInfo (sessionMethod ((* ClientSession ).ping )),
292306 methodListRoots : newMethodInfo (clientMethod ((* Client ).listRoots )),
293307 methodCreateMessage : newMethodInfo (clientMethod ((* Client ).createMessage )),
308+ methodElicit : newMethodInfo (clientMethod ((* Client ).elicit )),
294309 notificationToolListChanged : newMethodInfo (clientMethod ((* Client ).callToolChangedHandler )),
295310 notificationPromptListChanged : newMethodInfo (clientMethod ((* Client ).callPromptChangedHandler )),
296311 notificationResourceListChanged : newMethodInfo (clientMethod ((* Client ).callResourceChangedHandler )),
0 commit comments