Snodo.Component.Wrap behaviour (snodo v0.4.1)

Copy Markdown View Source

Opt-in middleware for one tool, resource, or prompt callback.

A component declares wrap: [MyWrapper, {AnotherWrapper, option: value}]. Each wrapper implements call/4. The first declared wrapper runs first and receives a continuation that calls the next wrapper with a context and arguments. A wrapper may call that continuation, replace the context or arguments, or return a result without invoking the handler.

The options passed to call/4 include the declaration's options plus :component, :kind, :operation, and :slot. Those keys identify the component and wrapper occurrence. Resource and prompt wrappers also run on an explicitly defined complete/2 callback. Middleware runs inside the component callback, after router lookup, authorization, and input validation.

Summary

Callbacks

Runs one middleware layer and may call the continuation or return a result.

Types

continuation()

@type continuation() :: (Snodo.Context.t(), term() -> term())

kind()

@type kind() :: :tool | :resource | :prompt

Callbacks

call(t, term, continuation, keyword)

@callback call(Snodo.Context.t(), term(), continuation(), keyword()) :: term()

Runs one middleware layer and may call the continuation or return a result.