//! Tool module aggregating built‑in tool implementations. //! //! The crate originally declared `pub mod tools;` in `lib.rs` but the source //! directory only contained individual tool files without a `mod.rs`, causing the //! compiler to look for `tools.rs` and fail. Adding this module file makes the //! directory a proper Rust module and re‑exports the concrete tool types. pub mod code_exec; pub mod fs_tools; pub mod registry; pub mod web_scrape; pub mod web_search; pub mod web_search_detailed; use async_trait::async_trait; use serde_json::{Value, json}; use std::collections::HashMap; use std::time::Duration; use crate::Result; /// Trait representing a tool that can be called via the MCP interface. #[async_trait] pub trait Tool: Send + Sync { /// Unique name of the tool (used in the MCP protocol). fn name(&self) -> &'static str; /// Human‑readable description for documentation. fn description(&self) -> &'static str; /// JSON‑Schema describing the expected arguments. fn schema(&self) -> Value; /// Execute the tool with the provided arguments. fn requires_network(&self) -> bool { false } fn requires_filesystem(&self) -> Vec { Vec::new() } async fn execute(&self, args: Value) -> Result; } /// Result returned by a tool execution. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ToolResult { /// Indicates whether the tool completed successfully. pub success: bool, /// Human‑readable status string – retained for compatibility. pub status: String, /// Arbitrary JSON payload describing the tool output. pub output: Value, /// Execution duration. #[serde(skip_serializing_if = "Duration::is_zero", default)] pub duration: Duration, /// Optional key/value metadata for the tool invocation. #[serde(default)] pub metadata: HashMap, } impl ToolResult { pub fn success(output: Value) -> Self { Self { success: true, status: "success".into(), output, duration: Duration::default(), metadata: HashMap::new(), } } pub fn error(msg: &str) -> Self { Self { success: false, status: "error".into(), output: json!({ "error": msg }), duration: Duration::default(), metadata: HashMap::new(), } } pub fn cancelled(msg: &str) -> Self { Self { success: false, status: "cancelled".into(), output: json!({ "error": msg }), duration: Duration::default(), metadata: HashMap::new(), } } } // Re‑export the most commonly used types so they can be accessed as // `owlen_core::tools::CodeExecTool`, etc. pub use code_exec::CodeExecTool; pub use fs_tools::{ResourcesDeleteTool, ResourcesGetTool, ResourcesListTool, ResourcesWriteTool}; pub use registry::ToolRegistry; pub use web_scrape::WebScrapeTool; pub use web_search::WebSearchTool; pub use web_search_detailed::WebSearchDetailedTool;