elicit

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package elicit provides the MCP elicitation gate and write-tool sentinels.

Gate runs the elicitation handshake that fronts a write tool. It first requires the client to advertise the elicitation capability (else ErrNoElicitation), then issues the request and maps the returned action to a result:

accept  -> nil (the caller proceeds with the mutating call)
decline -> ErrUserDeclined
cancel  -> ErrUserCanceled
other   -> ErrUnexpectedElicitAction

A transport/protocol failure is wrapped with ErrElicitationFailed. Only the action gates the call; returned field values are not inspected.

ErrNoElicitation has a second, easily-missed cause: a stateless HTTP handler. It uses a temporary session with default init params, so the client's elicitation capability is never retained and server->client requests are rejected — Gate then fails even when the client did advertise the capability. Serve write tools over stdio or a stateful HTTP handler (see package server).

The sentinels live in errors.go; toolkit re-exports them so callers need not import elicit directly.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserDeclined  = errors.New("declined by user")
	ErrUserCanceled  = errors.New("canceled by user")
	ErrNoElicitation = errors.New(
		"client must support MCP elicitation for write tools " +
			"(a stateless HTTP server handler also drops this capability)",
	)
	ErrUnexpectedElicitAction = errors.New("unexpected elicit action")
	ErrElicitationFailed      = errors.New("elicitation failed")
)

Sentinels for write-tool elicitation outcomes, wrapped with detail.

Functions

func Gate

func Gate(
	ctx context.Context,
	session *mcp.ServerSession,
	params *mcp.ElicitParams,
) error

Gate runs write-tool elicitation: accept->nil, else 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 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 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