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 = "slack")]
73pub mod slack;
74
75#[cfg(feature = "bigquery")]
76pub mod bigquery;
77
78#[cfg(feature = "spanner")]
79pub mod spanner;
80
81#[cfg(feature = "mcp-sampling")]
82pub mod sampling;
83
84pub use adk_core::{AdkError, Result, Tool, ToolContext, Toolset};
85pub use adk_rust_macros::tool;
86
87// Re-export async_trait so the #[tool] macro's generated code can reference it
88// without requiring users to add async-trait as a direct dependency.
89pub use agent_tool::{AgentTool, AgentToolConfig};
90pub use async_trait::async_trait;
91pub use builtin::{
92    AnthropicBashTool20241022, AnthropicBashTool20250124, AnthropicTextEditorTool20250124,
93    AnthropicTextEditorTool20250429, AnthropicTextEditorTool20250728, ExitLoopTool,
94    GeminiCodeExecutionTool, GeminiComputerEnvironment, GeminiComputerUseTool,
95    GeminiFileSearchTool, GoogleMapsContext, GoogleMapsTool, GoogleSearchTool, LoadArtifactsTool,
96    OpenAIApplyPatchTool, OpenAIApproximateLocation, OpenAICodeInterpreterTool,
97    OpenAIComputerEnvironment, OpenAIComputerUseTool, OpenAIFileSearchTool,
98    OpenAIImageGenerationTool, OpenAILocalShellTool, OpenAIMcpTool, OpenAIShellTool,
99    OpenAIWebSearchTool, UrlContextTool, WebSearchTool, WebSearchUserLocation,
100};
101pub use function_tool::FunctionTool;
102#[cfg(feature = "mcp")]
103pub use mcp::{
104    AutoDeclineElicitationHandler, ElicitationHandler, McpAuth, McpHttpClientBuilder,
105    McpServerManager, McpTaskConfig, McpToolset, OAuth2Config, Resource, ResourceContents,
106    ResourceTemplate,
107};
108pub use simple_context::SimpleToolContext;
109pub use stateful_tool::StatefulTool;
110pub use toolset::{
111    BasicToolset, FilteredToolset, MergedToolset, PrefixedToolset, string_predicate,
112};
113
114#[cfg(feature = "code")]
115#[allow(deprecated)]
116pub use code_execution::RustCodeTool;
117
118#[cfg(feature = "code")]
119pub use code_execution::CodeTool;
120
121#[cfg(feature = "code")]
122pub use code_execution::FrontendCodeTool;
123
124#[cfg(feature = "code")]
125pub use code_execution::JavaScriptCodeTool;
126
127#[cfg(feature = "code")]
128pub use code_execution::PythonCodeTool;