MCPcopy
hub / github.com/docker/docker-agent / elicitationHandler

Method elicitationHandler

pkg/runtime/elicitation.go:141–179  ·  view source on GitHub ↗

elicitationHandler is the MCP-toolset-side hook that turns an inbound elicitation request from a server into an ElicitationRequest event on the active stream's events channel and waits for the embedder's response on elicitationRequestCh.

(ctx context.Context, req *mcp.ElicitParams)

Source from the content-addressed store, hash-verified

139// active stream's events channel and waits for the embedder's response on
140// elicitationRequestCh.
141func (r *LocalRuntime) elicitationHandler(ctx context.Context, req *mcp.ElicitParams) (tools.ElicitationResult, error) {
142 slog.DebugContext(ctx, "Elicitation request received from MCP server", "message", req.Message)
143
144 // In non-interactive mode (e.g., MCP serve), there is no user to respond
145 // to elicitation requests. Decline immediately instead of blocking forever.
146 if r.nonInteractive {
147 slog.DebugContext(ctx, "Declining elicitation in non-interactive mode", "message", req.Message)
148 return tools.ElicitationResult{
149 Action: tools.ElicitationActionDecline,
150 }, nil
151 }
152
153 r.executeOnUserInputHooks(ctx, "", "elicitation")
154
155 slog.DebugContext(ctx, "Sending elicitation request event to client",
156 "message", req.Message,
157 "mode", req.Mode,
158 "requested_schema", req.RequestedSchema,
159 "url", req.URL)
160 slog.DebugContext(ctx, "Elicitation request meta", "meta", req.Meta)
161
162 if err := r.elicitation.send(
163 ElicitationRequest(req.Message, req.Mode, req.RequestedSchema, req.URL, req.ElicitationID, req.Meta, r.currentAgentName()),
164 ); err != nil {
165 return tools.ElicitationResult{}, err
166 }
167
168 // Wait for response from the client.
169 select {
170 case result := <-r.elicitationRequestCh:
171 return tools.ElicitationResult{
172 Action: result.Action,
173 Content: result.Content,
174 }, nil
175 case <-ctx.Done():
176 slog.DebugContext(ctx, "Context cancelled while waiting for elicitation response")
177 return tools.ElicitationResult{}, ctx.Err()
178 }
179}

Calls 5

currentAgentNameMethod · 0.95
ElicitationRequestFunction · 0.85
ErrMethod · 0.65
sendMethod · 0.45