Skip to main content

ToolProtocol

Trait ToolProtocol 

Source
pub trait ToolProtocol: Send + Sync {
    // Required methods
    fn execute<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tool_name: &'life1 str,
        parameters: Value,
    ) -> Pin<Box<dyn Future<Output = Result<ToolResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list_tools<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ToolMetadata>, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_tool_metadata<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tool_name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<ToolMetadata, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn protocol_name(&self) -> &str;

    // Provided methods
    fn initialize<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn shutdown<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn list_resources<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceMetadata>, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn read_resource<'life0, 'life1, 'async_trait>(
        &'life0 self,
        uri: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn supports_resources(&self) -> bool { ... }
}
Expand description

Trait for implementing tool execution protocols

Required Methods§

Source

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, tool_name: &'life1 str, parameters: Value, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a tool with the given parameters

Source

fn list_tools<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ToolMetadata>, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get metadata about available tools

Source

fn get_tool_metadata<'life0, 'life1, 'async_trait>( &'life0 self, tool_name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<ToolMetadata, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get metadata about a specific tool

Source

fn protocol_name(&self) -> &str

Protocol identifier (e.g., “mcp”, “custom”, “openai-functions”)

Provided Methods§

Source

fn initialize<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Initialize/connect to the tool protocol

Source

fn shutdown<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Cleanup/disconnect from the tool protocol

Source

fn list_resources<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceMetadata>, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List available resources (MCP Resource support)

Resources are application-provided contextual data that agents can read. This method is optional and defaults to returning an empty list.

Source

fn read_resource<'life0, 'life1, 'async_trait>( &'life0 self, uri: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read the content of a resource by URI (MCP Resource support)

This method is optional and defaults to returning NotFound.

Source

fn supports_resources(&self) -> bool

Check if this protocol supports resources

Implementors§