klieo-tools-mcp 3.4.0

MCP (Model Context Protocol) adapter for klieo-core's Tool trait.
Documentation
//! `McpTool` — wraps one server-advertised tool as a `klieo_core::Tool`.

use crate::client::McpClient;
use async_trait::async_trait;
use klieo_core::error::ToolError;
use klieo_core::tool::{Tool, ToolCtx};
use std::sync::Arc;

/// One MCP tool exposed as `klieo_core::Tool`. Names are namespaced
/// `mcp:<server_id>.<original_name>`.
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>,
    /// Whether the operator flagged this tool as PII-bearing at connect
    /// time. When `true`, [`Tool::redacts_audit`] returns `true`, so
    /// dispatch records a redacted projection of the tool's args/result
    /// to the audit trail instead of the raw values.
    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,
        }
    }
}