Skip to main content

ToolServerConnection

Trait ToolServerConnection 

Source
pub trait ToolServerConnection: Send + Sync {
    // Required methods
    fn server_id(&self) -> &str;
    fn tool_names(&self) -> Vec<String>;
    fn invoke(
        &self,
        tool_name: &str,
        arguments: Value,
        nested_flow_bridge: Option<&mut dyn NestedFlowBridge>,
    ) -> Result<Value, KernelError>;

    // Provided methods
    fn invoke_with_cost(
        &self,
        tool_name: &str,
        arguments: Value,
        nested_flow_bridge: Option<&mut dyn NestedFlowBridge>,
    ) -> Result<(Value, Option<ToolInvocationCost>), KernelError> { ... }
    fn invoke_stream(
        &self,
        tool_name: &str,
        arguments: Value,
        nested_flow_bridge: Option<&mut dyn NestedFlowBridge>,
    ) -> Result<Option<ToolServerStreamResult>, KernelError> { ... }
    fn drain_events(&self) -> Result<Vec<ToolServerEvent>, KernelError> { ... }
}
Expand description

Trait representing a connection to a tool server.

The kernel holds one ToolServerConnection per registered server. In production this is an mTLS connection over UDS or TCP. For testing, an in-process implementation can be used.

Required Methods§

Source

fn server_id(&self) -> &str

The server’s unique identifier.

Source

fn tool_names(&self) -> Vec<String>

List the tool names available on this server.

Source

fn invoke( &self, tool_name: &str, arguments: Value, nested_flow_bridge: Option<&mut dyn NestedFlowBridge>, ) -> Result<Value, KernelError>

Invoke a tool on this server. The kernel has already validated the capability and run guards before calling this.

Provided Methods§

Source

fn invoke_with_cost( &self, tool_name: &str, arguments: Value, nested_flow_bridge: Option<&mut dyn NestedFlowBridge>, ) -> Result<(Value, Option<ToolInvocationCost>), KernelError>

Invoke a tool and optionally report the actual cost of the invocation.

Tool servers that track monetary costs should override this method. The default implementation delegates to invoke and returns None cost, meaning the kernel will charge max_cost_per_invocation as the worst-case debit.

Source

fn invoke_stream( &self, tool_name: &str, arguments: Value, nested_flow_bridge: Option<&mut dyn NestedFlowBridge>, ) -> Result<Option<ToolServerStreamResult>, KernelError>

Invoke a tool that can emit multiple streamed chunks before its final terminal state.

Servers that do not support streaming can ignore this and rely on invoke.

Source

fn drain_events(&self) -> Result<Vec<ToolServerEvent>, KernelError>

Drain asynchronous events emitted after a tool invocation has already returned.

Native tool servers can use this to surface late URL-elicitation completions and catalog/resource notifications without depending on a still-live request-local bridge.

Implementors§