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 with the `mcp` feature
13//! - `McpServerManager` - Multi-server lifecycle management with the `mcp` feature
14//! - [`BasicToolset`] - Group multiple tools together
15//! - [`ExitLoopTool`] - Control flow for loop agents
16//! - [`LoadArtifactsTool`] - Inject binary artifacts into context
17//!
18//! ## Quick Start
19//!
20//! ```rust,no_run
21//! use adk_tool::FunctionTool;
22//! use adk_core::{ToolContext, Result};
23//! use serde_json::{json, Value};
24//! use std::sync::Arc;
25//!
26//! async fn get_weather(ctx: Arc<dyn ToolContext>, args: Value) -> Result<Value> {
27//!     let city = args["city"].as_str().unwrap_or("Unknown");
28//!     Ok(json!({
29//!         "city": city,
30//!         "temperature": 72,
31//!         "condition": "sunny"
32//!     }))
33//! }
34//!
35//! let tool = FunctionTool::new(
36//!     "get_weather",
37//!     "Get current weather for a city",
38//!     get_weather,
39//! );
40//! ```
41//!
42//! ## MCP Integration
43//!
44//! Connect to MCP servers for external tools:
45//!
46//! ```rust,ignore
47//! use adk_tool::McpToolset;
48//! use rmcp::{ServiceExt, transport::TokioChildProcess};
49//!
50//! let client = ().serve(TokioChildProcess::new(
51//!     Command::new("npx")
52//!         .arg("-y")
53//!         .arg("@modelcontextprotocol/server-filesystem")
54//!         .arg("/path/to/files")
55//! )?).await?;
56//!
57//! let toolset = McpToolset::new(client);
58//! ```
59
60mod agent_tool;
61pub mod builtin;
62mod function_tool;
63#[cfg(feature = "mcp")]
64pub mod mcp;
65mod simple_context;
66mod stateful_tool;
67pub mod toolset;
68
69#[cfg(feature = "code")]
70pub mod code_execution;
71
72#[cfg(feature = "memory-tools")]
73pub mod memory;
74
75#[cfg(feature = "slack")]
76pub mod slack;
77
78#[cfg(feature = "bigquery")]
79pub mod bigquery;
80
81#[cfg(feature = "spanner")]
82pub mod spanner;
83
84#[cfg(feature = "mcp-sampling")]
85pub mod sampling;
86
87pub use adk_core::{AdkError, Result, Tool, ToolContext, Toolset};
88pub use adk_rust_macros::tool;
89
90// Re-export async_trait so the #[tool] macro's generated code can reference it
91// without requiring users to add async-trait as a direct dependency.
92pub use agent_tool::{AgentTool, AgentToolConfig};
93pub use async_trait::async_trait;
94pub use builtin::{
95    AnthropicBashTool20241022, AnthropicBashTool20250124, AnthropicTextEditorTool20250124,
96    AnthropicTextEditorTool20250429, AnthropicTextEditorTool20250728, ExitLoopTool,
97    GeminiCodeExecutionTool, GeminiComputerEnvironment, GeminiComputerUseTool,
98    GeminiFileSearchTool, GoogleMapsContext, GoogleMapsTool, GoogleSearchTool, LoadArtifactsTool,
99    OpenAIApplyPatchTool, OpenAIApproximateLocation, OpenAICodeInterpreterTool,
100    OpenAIComputerEnvironment, OpenAIComputerUseTool, OpenAIFileSearchTool,
101    OpenAIImageGenerationTool, OpenAILocalShellTool, OpenAIMcpTool, OpenAIShellTool,
102    OpenAIWebSearchTool, UrlContextTool, WebSearchTool, WebSearchUserLocation,
103};
104pub use function_tool::FunctionTool;
105#[cfg(feature = "mcp")]
106pub use mcp::{
107    AutoDeclineElicitationHandler, ElicitationHandler, McpAuth, McpHttpClientBuilder,
108    McpServerManager, McpTaskConfig, McpToolset, OAuth2Config, Resource, ResourceContents,
109    ResourceTemplate,
110};
111pub use simple_context::SimpleToolContext;
112pub use stateful_tool::StatefulTool;
113pub use toolset::{
114    BasicToolset, FilteredToolset, MergedToolset, PrefixedToolset, string_predicate,
115};
116
117#[cfg(feature = "code")]
118#[allow(deprecated)]
119pub use code_execution::RustCodeTool;
120
121#[cfg(feature = "code")]
122pub use code_execution::CodeTool;
123
124#[cfg(feature = "code")]
125pub use code_execution::FrontendCodeTool;
126
127#[cfg(feature = "code")]
128pub use code_execution::JavaScriptCodeTool;
129
130#[cfg(feature = "code")]
131pub use code_execution::PythonCodeTool;