Documentation
¶
Overview ¶
Package toolkit provides a generic fluent builder for registering JSON MCP tools on a server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserDeclined = elicit.ErrUserDeclined ErrUserCanceled = elicit.ErrUserCanceled ErrNoElicitation = elicit.ErrNoElicitation ErrUnexpectedElicitAction = elicit.ErrUnexpectedElicitAction ErrElicitationFailed = elicit.ErrElicitationFailed )
Re-exported so callers can match elicitation sentinels without importing elicit.
Functions ¶
func AddRead ¶
AddRead registers a read-only MCP tool (ReadOnlyHint=true, IdempotentHint=true, DestructiveHint=false). Panics if an elicitation prompt was set via WithElicitParamsFunc, which is meaningless for a read tool.
func AddWrite ¶
AddWrite registers a state-mutating MCP tool guarded by elicitation (ReadOnlyHint=false, IdempotentHint=false, DestructiveHint=true). Clients lacking elicitation capability get ErrNoElicitation. The prompt is set via WithElicitParamsFunc; when unset the elicitation message is empty.
func InputSchema ¶
func InputSchema[In any]() *jsonschema.Schema
InputSchema reflects a JSON Schema from the Go input type In, for tools whose input is a plain struct with json tags. Panics on reflection failure, like mcp.AddTool: an unbuildable schema is a registration-time programming error.
Types ¶
type ElicitParamsFunc ¶
type ElicitParamsFunc[In any] = elicit.ParamsFunc[In]
ElicitParamsFunc builds the elicitation prompt for a write tool.
type Items ¶
type Items[T any] struct { Items []T `json:"items"` }
Items wraps a slice result under the "items" key.
func WrapItems ¶
WrapItems adapts a (slice, error) pair — e.g. WrapItems(client.List(ctx)) — into an Items envelope. Items.MarshalJSON handles nil-slice normalization, so the result always marshals to a JSON array.
func (Items[T]) MarshalJSON ¶
MarshalJSON normalizes a nil slice to "items":[] rather than null (which an array-typed schema rejects), for every construction path including the zero value, not only WrapItems.
type Tool ¶
type Tool[In, Out any] struct { // contains filtered or unexported fields }
Tool is a fluent registration builder. New infers In/Out from call, so the type name is rarely written at call sites. Distinct from the SDK's mcp.Tool, which it produces internally.
func New ¶
func New[In, Out any]( server *mcp.Server, name, description string, inputSchema *jsonschema.Schema, call CallFunc[In, Out], ) Tool[In, Out]
New starts a tool registration, inferring In/Out from call. The input schema is required (the SDK panics on nil); the output schema is optional, set via WithOutputSchema.
func (Tool[In, Out]) WithElicitParamsFunc ¶
WithElicitParamsFunc sets the function that builds a write tool's elicitation prompt. Optional for AddWrite; AddRead panics if it is set.
func (Tool[In, Out]) WithOutputSchema ¶
func (t Tool[In, Out]) WithOutputSchema( schema *jsonschema.Schema, ) Tool[In, Out]
WithOutputSchema sets the optional output schema. When set, the SDK validates the structured result against it; when unset, the tool declares none.
func (Tool[In, Out]) WithValidateFunc ¶
WithValidateFunc sets an optional validator run on decoded input before the call (and, for writes, before elicitation).
type ValidateFunc ¶
ValidateFunc validates decoded input before the call.