adk_tool/lib.rs
1//! # adk-tool
2//!
3//! Tool system for ADK agents (FunctionTool, MCP, Google Search, AgentTool).
4//!
5//! ## Overview
6//!
7//! This crate provides the tool infrastructure for ADK agents:
8//!
9//! - [`FunctionTool`] - Create tools from async Rust functions
10//! - [`AgentTool`] - Use agents as callable tools for composition
11//! - [`GoogleSearchTool`] - Web search via Gemini's grounding
12//! - [`McpToolset`] - Model Context Protocol integration
13//! - [`BasicToolset`] - Group multiple tools together
14//! - [`ExitLoopTool`] - Control flow for loop agents
15//! - [`LoadArtifactsTool`] - Inject binary artifacts into context
16//!
17//! ## Quick Start
18//!
19//! ```rust,no_run
20//! use adk_tool::FunctionTool;
21//! use adk_core::{ToolContext, Result};
22//! use serde_json::{json, Value};
23//! use std::sync::Arc;
24//!
25//! async fn get_weather(ctx: Arc<dyn ToolContext>, args: Value) -> Result<Value> {
26//! let city = args["city"].as_str().unwrap_or("Unknown");
27//! Ok(json!({
28//! "city": city,
29//! "temperature": 72,
30//! "condition": "sunny"
31//! }))
32//! }
33//!
34//! let tool = FunctionTool::new(
35//! "get_weather",
36//! "Get current weather for a city",
37//! get_weather,
38//! );
39//! ```
40//!
41//! ## MCP Integration
42//!
43//! Connect to MCP servers for external tools:
44//!
45//! ```rust,ignore
46//! use adk_tool::McpToolset;
47//! use rmcp::{ServiceExt, transport::TokioChildProcess};
48//!
49//! let client = ().serve(TokioChildProcess::new(
50//! Command::new("npx")
51//! .arg("-y")
52//! .arg("@modelcontextprotocol/server-filesystem")
53//! .arg("/path/to/files")
54//! )?).await?;
55//!
56//! let toolset = McpToolset::new(client);
57//! ```
58
59mod agent_tool;
60pub mod builtin;
61mod function_tool;
62pub mod mcp;
63mod simple_context;
64mod stateful_tool;
65pub mod toolset;
66
67#[cfg(feature = "code")]
68pub mod code_execution;
69
70pub use adk_core::{AdkError, Result, Tool, ToolContext, Toolset};
71pub use adk_rust_macros::tool;
72
73// Re-export async_trait so the #[tool] macro's generated code can reference it
74// without requiring users to add async-trait as a direct dependency.
75pub use agent_tool::{AgentTool, AgentToolConfig};
76pub use async_trait::async_trait;
77pub use builtin::{
78 AnthropicBashTool20241022, AnthropicBashTool20250124, AnthropicTextEditorTool20250124,
79 AnthropicTextEditorTool20250429, AnthropicTextEditorTool20250728, ExitLoopTool,
80 GeminiCodeExecutionTool, GeminiComputerEnvironment, GeminiComputerUseTool,
81 GeminiFileSearchTool, GoogleMapsContext, GoogleMapsTool, GoogleSearchTool, LoadArtifactsTool,
82 OpenAIApplyPatchTool, OpenAIApproximateLocation, OpenAICodeInterpreterTool,
83 OpenAIComputerEnvironment, OpenAIComputerUseTool, OpenAIFileSearchTool,
84 OpenAIImageGenerationTool, OpenAILocalShellTool, OpenAIMcpTool, OpenAIShellTool,
85 OpenAIWebSearchTool, UrlContextTool, WebSearchTool, WebSearchUserLocation,
86};
87pub use function_tool::FunctionTool;
88pub use mcp::{
89 AutoDeclineElicitationHandler, ElicitationHandler, McpAuth, McpHttpClientBuilder,
90 McpTaskConfig, McpToolset, OAuth2Config, Resource, ResourceContents, ResourceTemplate,
91};
92pub use simple_context::SimpleToolContext;
93pub use stateful_tool::StatefulTool;
94pub use toolset::{
95 BasicToolset, FilteredToolset, MergedToolset, PrefixedToolset, string_predicate,
96};
97
98#[cfg(feature = "code")]
99#[allow(deprecated)]
100pub use code_execution::RustCodeTool;
101
102#[cfg(feature = "code")]
103pub use code_execution::CodeTool;
104
105#[cfg(feature = "code")]
106pub use code_execution::FrontendCodeTool;
107
108#[cfg(feature = "code")]
109pub use code_execution::JavaScriptCodeTool;
110
111#[cfg(feature = "code")]
112pub use code_execution::PythonCodeTool;