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