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