use descry_tool_core::{call_tool, tool_exists, tool_names, Tool, ToolContext, ToolError};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Deserialize, JsonSchema)]
struct AddParams {
a: i32,
b: i32,
}
#[derive(Serialize, JsonSchema)]
struct AddOutput {
result: i32,
}
struct AddTool;
impl Tool for AddTool {
type Params = AddParams;
type Output = AddOutput;
const NAME: &'static str = "add";
const DESCRIPTION: &'static str = "Add two numbers";
async fn call(_ctx: Arc<ToolContext>, params: Self::Params) -> Result<Self::Output, ToolError> {
Ok(AddOutput {
result: params.a + params.b,
})
}
}
inventory::submit! {
descry_tool_core::ToolMeta {
name: AddTool::NAME,
description: AddTool::DESCRIPTION,
call: |ctx, params| {
Box::pin(async move {
let params: AddParams = serde_json::from_value(params)?;
let result = <AddTool as Tool>::call(ctx, params).await?;
Ok(serde_json::to_value(result)?)
})
},
schema: || <AddTool as Tool>::schema(),
examples: || <AddTool as Tool>::EXAMPLES,
}
}
#[tokio::main]
async fn main() {
println!("=== Descry Basic Example ===\n");
let names = tool_names();
println!("Registered tools: {:?}", names);
println!("Tool count: {}\n", names.len());
println!("Tool 'add' exists: {}", tool_exists("add"));
println!("Tool 'nonexistent' exists: {}\n", tool_exists("nonexistent"));
let ctx = Arc::new(ToolContext::new());
let params = serde_json::json!({"a": 5, "b": 3});
println!("Calling add({a}, {b})...", a = 5, b = 3);
match call_tool("add", params, ctx).await {
Ok(result) => {
println!("Result: {}", serde_json::to_string_pretty(&result).unwrap());
}
Err(e) => {
eprintln!("Error: {}", e);
}
}
if let Some(schema) = descry_tool_core::get_tool_schema("add") {
println!("\nTool schema:");
println!("{}", serde_json::to_string_pretty(schema).unwrap());
}
}