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 ¶
- Variables
- func CancelledResult(message string) *mcp.CallToolResult
- func ConfirmAction(ctx context.Context, req *mcp.CallToolRequest, message string) *mcp.CallToolResult
- type Client
- func (c Client) Confirm(ctx context.Context, message string) (bool, error)
- func (c Client) ElicitURL(ctx context.Context, gitlabBaseURL, targetURL, message string) error
- func (c Client) GatherData(ctx context.Context, message string, schema map[string]any) (map[string]any, error)
- func (c Client) IsSupported() bool
- func (c Client) IsURLSupported() bool
- func (c Client) PromptNumber(ctx context.Context, message, fieldName string, minVal, maxVal float64) (float64, error)
- func (c Client) PromptText(ctx context.Context, message, fieldName string) (string, error)
- func (c Client) SelectMulti(ctx context.Context, message string, options []string, minItems, maxItems int) ([]string, error)
- func (c Client) SelectOne(ctx context.Context, message string, options []string) (string, error)
- func (c Client) SelectOneInt(ctx context.Context, message string, options []int) (int, error)
Constants ¶
This section is empty.
Variables ¶
var ErrCancelled = errors.New("elicitation: user canceled")
ErrCancelled is returned when the user dismisses an elicitation without making an explicit choice.
var ErrDeclined = errors.New("elicitation: user declined")
ErrDeclined is returned when the user explicitly declines an elicitation.
var ErrElicitationNotSupported = errors.New("elicitation: client does not support elicitation capability")
ErrElicitationNotSupported is returned when the MCP client does not advertise the elicitation capability.
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 ¶
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 ¶
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 ¶
IsSupported returns true if the MCP client supports elicitation.
func (Client) IsURLSupported ¶
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 ¶
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).