use server_less::tool;
pub struct FileTools;
#[tool(namespace = "file")]
impl FileTools {
pub fn read_file(&self, path: String) -> String {
format!("(contents of {})", path)
}
pub fn write_file(&self, path: String, content: String) -> bool {
println!("Writing {} bytes to {}", content.len(), path);
true
}
pub fn list_dir(&self, path: String) -> Vec<String> {
vec![format!("{}/file1.txt", path), format!("{}/file2.txt", path)]
}
}
fn main() {
let tools = FileTools;
println!("MCP tools:");
for tool in FileTools::mcp_tools() {
println!(" {}", serde_json::to_string_pretty(&tool).unwrap());
}
println!("\nJSON Schema:");
println!(
"{}",
serde_json::to_string_pretty(&FileTools::json_schema()).unwrap()
);
let result = tools
.mcp_call("file_read_file", serde_json::json!({"path": "/etc/hosts"}))
.unwrap();
println!("\nfile_read_file result: {}", result);
}