Skip to main content

ToolCodec

Trait ToolCodec 

Source
pub trait ToolCodec<T: Tool>:
    Send
    + Sync
    + 'static {
    type WireIn: DeserializeOwned + JsonSchema + Send + 'static;
    type WireOut: Serialize + JsonSchema + Send + 'static;

    // Required methods
    fn decode(wire: Self::WireIn) -> Result<T::Input, ToolError>;
    fn encode(native: T::Output) -> Result<Self::WireOut, ToolError>;
}
Expand description

Codec for serializing tool inputs/outputs at protocol boundaries.

Serde and schemars bounds reside here, NOT on the Tool trait. This keeps native Rust calls zero-serialization while supporting MCP, napi, and provider schema generation.

§Identity Codec

When T::Input and T::Output already implement the required serde/schemars traits, use () as the codec (blanket implementation provided).

Required Associated Types§

Source

type WireIn: DeserializeOwned + JsonSchema + Send + 'static

Wire format for input (must be deserializable and have JSON schema).

Source

type WireOut: Serialize + JsonSchema + Send + 'static

Wire format for output (must be serializable and have JSON schema).

Required Methods§

Source

fn decode(wire: Self::WireIn) -> Result<T::Input, ToolError>

Decode wire input to native input.

Source

fn encode(native: T::Output) -> Result<Self::WireOut, ToolError>

Encode native output to wire output.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> ToolCodec<T> for ()

Identity codec: when Input/Output already have serde/schemars, use () as codec.

Source§

type WireIn = <T as Tool>::Input

Source§

type WireOut = <T as Tool>::Output

Source§

fn decode(wire: Self::WireIn) -> Result<T::Input, ToolError>

Source§

fn encode(native: T::Output) -> Result<Self::WireOut, ToolError>

Implementors§