use claude_sdk::server_tools::{CodeExecutionTool, WebSearchTool};
use claude_sdk::{CustomTool, Message, MessagesRequest, ToolDefinition};
use serde_json::json;
fn main() {
println!("Claude SDK - Server Tools Example");
println!("=====================================\n");
let web_search = WebSearchTool::new()
.with_allowed_domains(vec!["docs.rs".into(), "crates.io".into()])
.with_max_uses(5);
println!("Web Search Tool:");
println!(" Type: {}", web_search.tool_type);
println!(" Allowed domains: {:?}", web_search.allowed_domains);
println!(" Max uses: {:?}\n", web_search.max_uses);
let code_exec = CodeExecutionTool::new();
println!("Code Execution Tool:");
println!(" Type: {}\n", code_exec.tool_type);
let custom_tool = CustomTool::new(
"format_output",
"Format data into a specific output structure",
json!({
"type": "object",
"properties": {
"title": {"type": "string"},
"data": {"type": "array", "items": {"type": "string"}}
},
"required": ["title", "data"]
}),
)
.programmatic()
.with_strict();
println!("Custom Tool:");
println!(" Name: {}", custom_tool.name);
println!(" Strict: {:?}\n", custom_tool.strict);
let request = MessagesRequest::new(
"claude-sonnet-4-5-20250929",
4096,
vec![Message::user(
"Search for the latest version of the tokio crate, \
then write Python code to calculate how many days \
since its release date, and format the results.",
)],
)
.with_tools(vec![
ToolDefinition::from(web_search),
ToolDefinition::from(code_exec),
ToolDefinition::Custom(custom_tool),
]);
println!("Request JSON (tools section):");
let json = serde_json::to_string_pretty(&request.tools.as_ref().unwrap()).unwrap();
println!("{}\n", json);
println!("To send this request, set ANTHROPIC_API_KEY and use:");
println!(" let response = client.send_message(request).await?;");
}