Skip to main content

ToolBase

Trait ToolBase 

Source
pub trait ToolBase {
    type Parameter: for<'de> Deserialize<'de> + JsonSchema + Send + Default + 'static;
    type Output: Serialize + JsonSchema + Send + 'static;
    type Error: Into<ErrorData> + Send + 'static;

    // Required method
    fn name() -> Cow<'static, str>;

    // Provided methods
    fn title() -> Option<String> { ... }
    fn description() -> Option<Cow<'static, str>> { ... }
    fn input_schema() -> Option<Arc<JsonObject>> { ... }
    fn output_schema() -> Option<Arc<JsonObject>> { ... }
    fn annotations() -> Option<ToolAnnotations> { ... }
    fn execution() -> Option<ToolExecution> { ... }
    fn icons() -> Option<Vec<Icon>> { ... }
    fn meta() -> Option<Meta> { ... }
}
Available on crate feature server only.
Expand description

Base trait to define attributes of a tool.

Tools implementing SyncTool or AsyncTool must implement this trait first.

All methods are consistent with fields of Tool.

Required Associated Types§

Source

type Parameter: for<'de> Deserialize<'de> + JsonSchema + Send + Default + 'static

Parameter type, will used in the invoke parameter of SyncTool or AsyncTool trait

If the tool does not have any parameters, you MUST override input_schema method. See its documentation for more details.

Source

type Output: Serialize + JsonSchema + Send + 'static

Output type, will used in the invoke output of SyncTool or AsyncTool trait

If the tool does not have any output, you MUST override output_schema method. See its documentation for more details.

Source

type Error: Into<ErrorData> + Send + 'static

Error type, will used in the invoke output of SyncTool or AsyncTool trait

Required Methods§

Source

fn name() -> Cow<'static, str>

Provided Methods§

Source

fn title() -> Option<String>

Source

fn description() -> Option<Cow<'static, str>>

Source

fn input_schema() -> Option<Arc<JsonObject>>

Json schema for tool input.

The default implementation generates schema based on Self::Parameter type.

If the tool does not have any parameters, you should override this methods to return None, and when invoked, the parameter will get default values.

Source

fn output_schema() -> Option<Arc<JsonObject>>

Json schema for tool output.

The default implementation generates schema based on Self::Output type.

If the tool does not have any output, you should override this methods to return None.

Source

fn annotations() -> Option<ToolAnnotations>

Source

fn execution() -> Option<ToolExecution>

Source

fn icons() -> Option<Vec<Icon>>

Source

fn meta() -> Option<Meta>

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.

Implementors§