use crate::client::McpClient;
use async_trait::async_trait;
use klieo_core::error::ToolError;
use klieo_core::tool::{Tool, ToolCtx};
use std::sync::Arc;
pub(crate) struct McpTool {
pub(crate) namespaced_name: String,
pub(crate) original_name: String,
pub(crate) description: String,
pub(crate) schema: serde_json::Value,
pub(crate) client: Arc<McpClient>,
pub(crate) pii_bearing: bool,
}
#[async_trait]
impl Tool for McpTool {
fn name(&self) -> &str {
&self.namespaced_name
}
fn description(&self) -> &str {
&self.description
}
fn json_schema(&self) -> &serde_json::Value {
&self.schema
}
fn redacts_audit(&self) -> bool {
self.pii_bearing
}
async fn invoke(
&self,
args: serde_json::Value,
ctx: ToolCtx,
) -> Result<serde_json::Value, ToolError> {
tokio::select! {
_ = ctx.cancel.cancelled() => Err(ToolError::Cancelled),
r = self.client.call_tool(&self.original_name, args) => r,
}
}
}