Skip to main content

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;
63pub mod toolset;
64
65#[cfg(feature = "code")]
66pub mod code_execution;
67
68pub use adk_core::{AdkError, Result, Tool, ToolContext, Toolset};
69pub use adk_rust_macros::tool;
70
71// Re-export async_trait so the #[tool] macro's generated code can reference it
72// without requiring users to add async-trait as a direct dependency.
73pub use agent_tool::{AgentTool, AgentToolConfig};
74pub use async_trait::async_trait;
75pub use builtin::{
76    AnthropicBashTool20241022, AnthropicBashTool20250124, AnthropicTextEditorTool20250124,
77    AnthropicTextEditorTool20250429, AnthropicTextEditorTool20250728, ExitLoopTool,
78    GeminiCodeExecutionTool, GeminiComputerEnvironment, GeminiComputerUseTool,
79    GeminiFileSearchTool, GoogleMapsContext, GoogleMapsTool, GoogleSearchTool, LoadArtifactsTool,
80    OpenAIApplyPatchTool, OpenAIApproximateLocation, OpenAICodeInterpreterTool,
81    OpenAIComputerEnvironment, OpenAIComputerUseTool, OpenAIFileSearchTool,
82    OpenAIImageGenerationTool, OpenAILocalShellTool, OpenAIMcpTool, OpenAIShellTool,
83    OpenAIWebSearchTool, UrlContextTool, WebSearchTool, WebSearchUserLocation,
84};
85pub use function_tool::FunctionTool;
86pub use mcp::{
87    AutoDeclineElicitationHandler, ElicitationHandler, McpAuth, McpHttpClientBuilder,
88    McpTaskConfig, McpToolset, OAuth2Config, Resource, ResourceContents, ResourceTemplate,
89};
90pub use toolset::{
91    BasicToolset, FilteredToolset, MergedToolset, PrefixedToolset, string_predicate,
92};
93
94#[cfg(feature = "code")]
95#[allow(deprecated)]
96pub use code_execution::RustCodeTool;
97
98#[cfg(feature = "code")]
99pub use code_execution::CodeTool;
100
101#[cfg(feature = "code")]
102pub use code_execution::FrontendCodeTool;
103
104#[cfg(feature = "code")]
105pub use code_execution::JavaScriptCodeTool;
106
107#[cfg(feature = "code")]
108pub use code_execution::PythonCodeTool;