elicitation

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package elicitation provides a Client for requesting structured user input via the MCP elicitation protocol.

The Client is a value type — its zero value is safe to use and acts as a no-op when the connected MCP client does not support elicitation. This mirrors the pattern used by sampling.Client and progress.Tracker.

SECURITY: All responses are validated against the expected JSON Schema. User input is never trusted and must be sanitized by the caller before use in API calls.

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.New("elicitation: user canceled")

ErrCancelled is returned when the user dismisses an elicitation without making an explicit choice.

View Source
var ErrDeclined = errors.New("elicitation: user declined")

ErrDeclined is returned when the user explicitly declines an elicitation.

View Source
var ErrElicitationNotSupported = errors.New("elicitation: client does not support elicitation capability")

ErrElicitationNotSupported is returned when the MCP client does not advertise the elicitation capability.

View Source
var ErrURLElicitationNotSupported = errors.New("elicitation: client does not support URL elicitation")

ErrURLElicitationNotSupported is returned when the MCP client supports form elicitation but not URL mode elicitation.

Functions

func CancelledResult

func CancelledResult(message string) *mcp.CallToolResult

CancelledResult returns a non-error tool result indicating the user canceled.

func ConfirmAction

func ConfirmAction(ctx context.Context, req *mcp.CallToolRequest, message string) *mcp.CallToolResult

ConfirmAction asks the user to confirm an action via elicitation. Returns nil if confirmed or elicitation is not supported (backward compatible). Returns a non-nil *mcp.CallToolResult if the user declined or canceled.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client sends elicitation requests to the MCP client for user input. Its zero value is an inactive client where IsSupported returns false.

func FromRequest

func FromRequest(req *mcp.CallToolRequest) Client

FromRequest extracts the server session from a CallToolRequest and returns a Client. If the connected MCP client does not support elicitation, the returned Client is inactive (IsSupported returns false).

func (Client) Confirm

func (c Client) Confirm(ctx context.Context, message string) (bool, error)

Confirm asks the user a yes/no question and returns true if the user accepted with confirmed=true, false otherwise. Returns ErrDeclined or ErrCancelled if the user did not accept.

func (Client) ElicitURL

func (c Client) ElicitURL(ctx context.Context, gitlabBaseURL, targetURL, message string) error

ElicitURL sends a URL-mode elicitation request, directing the user to a GitLab page. The URL must belong to the configured GitLab instance (SSRF prevention). Returns the action ("accept", "decline", "cancel").

func (Client) GatherData

func (c Client) GatherData(ctx context.Context, message string, schema map[string]any) (map[string]any, error)

GatherData sends an arbitrary JSON Schema to the client and returns the user's response as a map. This is the low-level method underlying the convenience methods.

SECURITY: The caller is responsible for validating and sanitizing the returned data before using it in API calls.

func (Client) IsSupported

func (c Client) IsSupported() bool

IsSupported returns true if the MCP client supports elicitation.

func (Client) IsURLSupported

func (c Client) IsURLSupported() bool

IsURLSupported returns true if the MCP client supports URL mode elicitation.

func (Client) PromptNumber

func (c Client) PromptNumber(ctx context.Context, message, fieldName string, minVal, maxVal float64) (float64, error)

PromptNumber asks the user for a numeric input within a range. minVal and maxVal define inclusive bounds; use math.Inf(-1) and math.Inf(1) for no bounds.

func (Client) PromptText

func (c Client) PromptText(ctx context.Context, message, fieldName string) (string, error)

PromptText asks the user for free-form text input and returns the value.

func (Client) SelectMulti

func (c Client) SelectMulti(ctx context.Context, message string, options []string, minItems, maxItems int) ([]string, error)

SelectMulti asks the user to pick one or more options from a list. minItems and maxItems constrain the number of selections (0 means no limit).

func (Client) SelectOne

func (c Client) SelectOne(ctx context.Context, message string, options []string) (string, error)

SelectOne asks the user to pick one option from a list.

func (Client) SelectOneInt

func (c Client) SelectOneInt(ctx context.Context, message string, options []int) (int, error)

SelectOneInt asks the user to pick one integer from a list of allowed values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL