Documentation
¶
Overview ¶
Package elicit implements confirmation gates for MCP write tools.
Ask returns an input-required result. The client supplies an action and retries the call. Decide accepts the action or returns a matchable sentinel. The handler therefore runs once to ask and once to act. Work before the gate must not have side effects.
A response supplied with the initial call bypasses Ask. RequestState is not signed, so the retry is not bound to the original request. The gate records reported user intent; it does not authenticate the client or authorize the operation. Use authentication and idempotency controls where required.
Ask does not inspect client capabilities. The SDK rejects clients that cannot answer with a call error that has no matchable sentinel.
Clients must check CallToolResult.NeedsInput. Ignoring InputRequests returns an empty successful result without running the write.
Stateless HTTP supports gated writes for protocol 2026-07-28 and later. Earlier clients need stdio or a stateful HTTP handler.
BoundedConfirmation checks the message before returning an input request. It panics with ErrInvalidLimits when either limit is below 1; oversized messages return ErrPromptOverflow and prevent the write. CheckPrompt returns ErrInvalidLimits instead of panicking.
DefaultLimits allows 4 lines and 100 runes per line. This targets Claude Code 2.1.312, whose collapsed display hides excess lines and clips terminal width. Width counts runes, not display columns: CJK, emoji, and tabs can be wider. Put the action, object, and irreversible consequences first.
Index ¶
Constants ¶
const GateID = "io.github.acidsailor.mcpkit/confirm"
GateID is the default key naming the write-tool confirmation request.
Variables ¶
var ( ErrUserDeclined = errors.New("declined by user") ErrUserCanceled = errors.New("canceled by user") ErrUnexpectedElicitAction = errors.New("unexpected elicit action") ErrElicitationFailed = errors.New("elicitation failed") ErrPromptOverflow = errors.New("prompt exceeds limits") ErrInvalidLimits = errors.New("prompt limits must be at least 1") )
Sentinels for write-tool elicitation outcomes, wrapped with detail.
Functions ¶
func Ask ¶ added in v0.8.0
func Ask(gateID string, params *mcp.ElicitParams) *mcp.CallToolResult
Ask returns an input-required confirmation result keyed by gateID.
func CheckPrompt ¶ added in v0.12.0
CheckPrompt validates message size and limits.
func Decide ¶ added in v0.8.0
func Decide(resp mcp.InputResponse) error
Decide maps a fulfilled confirmation to nil (accept) or a sentinel error.
Types ¶
type DescribeFunc ¶
DescribeFunc renders a confirmation message from a decoded In request.
type Limits ¶ added in v0.12.0
type Limits struct {
// Lines is the most message lines the client shows.
Lines int
// Width caps line length in runes, not terminal columns.
Width int
}
Limits bound a confirmation message to what the user can see.
func DefaultLimits ¶ added in v0.12.0
func DefaultLimits() Limits
DefaultLimits returns the default prompt line and width limits.
type ParamsFunc ¶
ParamsFunc builds an elicitation prompt from a decoded request of type In.
func BoundedConfirmation ¶ added in v0.12.0
func BoundedConfirmation[In any]( limits Limits, describe DescribeFunc[In], ) ParamsFunc[In]
BoundedConfirmation rejects prompts exceeding the supplied limits.
func DynamicConfirmation ¶
func DynamicConfirmation[In any](describe DescribeFunc[In]) ParamsFunc[In]
DynamicConfirmation returns a ParamsFunc building the prompt via describe.
func SimpleConfirmation ¶
func SimpleConfirmation[In any](message string) ParamsFunc[In]
SimpleConfirmation returns a ParamsFunc that prompts with message, no fields.