elicit

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const GateID = "io.github.acidsailor.mcpkit/confirm"

GateID is the default key naming the write-tool confirmation request.

Variables

View Source
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

func CheckPrompt(message string, limits Limits) error

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

type DescribeFunc[In any] func(ctx context.Context, in In) (string, error)

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

type ParamsFunc[In any] func(
	ctx context.Context, in In,
) (*mcp.ElicitParams, error)

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.

Jump to

Keyboard shortcuts

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