Skip to main content

adk_tool/
lib.rs

1//! # adk-tool
2//!
3//! Tool system for ADK agents: typed Rust tools, toolset composition, hosted
4//! provider tools, and Model Context Protocol clients and servers.
5//!
6//! ## Overview
7//!
8//! This crate provides the tool infrastructure for ADK agents:
9//!
10//! - [`FunctionTool`] - Create tools from async Rust functions
11//! - [`AgentTool`] - Use agents as callable tools for composition
12//! - [`GoogleSearchTool`] - Web search via Gemini's grounding
13//! - `McpToolset` - MCP tools, resources, prompts, completion, elicitation,
14//!   subscriptions, and negotiated tasks with the `mcp` feature
15//! - `McpServerManager` - Dynamic local MCP server registry, process lifecycle,
16//!   persistence, health monitoring, and bounded restart with the `mcp` feature
17//! - [`BasicToolset`] - Group multiple tools together
18//! - [`ExitLoopTool`] - Control flow for loop agents
19//! - [`LoadArtifactsTool`] - Inject binary artifacts into context
20//!
21//! ## Quick Start
22//!
23//! ```rust,no_run
24//! use adk_tool::FunctionTool;
25//! use adk_core::{ToolContext, Result};
26//! use serde_json::{json, Value};
27//! use std::sync::Arc;
28//!
29//! async fn get_weather(ctx: Arc<dyn ToolContext>, args: Value) -> Result<Value> {
30//!     let city = args["city"].as_str().unwrap_or("Unknown");
31//!     Ok(json!({
32//!         "city": city,
33//!         "temperature": 72,
34//!         "condition": "sunny"
35//!     }))
36//! }
37//!
38//! let tool = FunctionTool::new(
39//!     "get_weather",
40//!     "Get current weather for a city",
41//!     get_weather,
42//! );
43//! ```
44//!
45//! ## MCP Integration
46//!
47//! Connect to MCP servers for external tools:
48//!
49//! ```rust,ignore
50//! use adk_tool::{
51//!     McpToolset,
52//!     mcp::rmcp::{ServiceExt, transport::TokioChildProcess},
53//! };
54//! use tokio::process::Command;
55//!
56//! let client = ().serve(TokioChildProcess::new(
57//!     Command::new("/opt/company/bin/workspace-mcp")
58//!         .arg("--stdio")
59//!         .arg("--root")
60//!         .arg("/srv/workspace")
61//! )?).await?;
62//!
63//! let toolset = McpToolset::new(client);
64//! ```
65
66#![deny(missing_docs)]
67
68mod agent_tool;
69/// Built-in tool wrappers for Gemini, OpenAI, and Anthropic hosted tools.
70pub mod builtin;
71mod function_tool;
72#[cfg(feature = "mcp")]
73/// Model Context Protocol (MCP) clients, server SDK re-export, catalog APIs,
74/// elicitation, tasks, HTTP transport, and dynamic local-server management.
75pub mod mcp;
76mod simple_context;
77mod stateful_tool;
78/// Toolset combinators: basic, filtered, merged, and prefixed toolsets.
79pub mod toolset;
80
81#[cfg(feature = "code")]
82pub mod code_execution;
83
84#[cfg(feature = "memory-tools")]
85pub mod memory;
86
87#[cfg(feature = "graph-memory-tools")]
88pub use memory::{GraphMemoryToolset, RelateTool, RememberTool};
89
90#[cfg(feature = "slack")]
91pub mod slack;
92
93#[cfg(feature = "bigquery")]
94pub mod bigquery;
95
96#[cfg(feature = "spanner")]
97pub mod spanner;
98
99#[cfg(feature = "mcp-sampling")]
100pub mod sampling;
101
102#[cfg(feature = "example-store")]
103pub mod example_store;
104
105#[cfg(feature = "vertex-agent-registry")]
106pub mod vertex;
107
108pub use adk_core::{AdkError, Result, Tool, ToolContext, Toolset};
109pub use adk_rust_macros::tool;
110
111// Re-export async_trait so the #[tool] macro's generated code can reference it
112// without requiring users to add async-trait as a direct dependency.
113pub use agent_tool::{
114    AgentTool, AgentToolConfig, AgentToolFailureMode, AgentToolSessionSnapshot,
115    AgentToolStateMergePolicy,
116};
117pub use async_trait::async_trait;
118pub use builtin::{
119    AnthropicBashTool20241022, AnthropicBashTool20250124, AnthropicTextEditorTool20250124,
120    AnthropicTextEditorTool20250429, AnthropicTextEditorTool20250728, BypassBuiltinTool,
121    BypassMultiToolsLimit, ExitLoopTool, GeminiCodeExecutionTool, GeminiComputerEnvironment,
122    GeminiComputerUseTool, GeminiFileSearchTool, GoogleMapsContext, GoogleMapsTool,
123    GoogleSearchTool, LoadArtifactsTool, OpenAIApplyPatchTool, OpenAIApproximateLocation,
124    OpenAICodeInterpreterTool, OpenAIComputerEnvironment, OpenAIComputerUseTool,
125    OpenAIFileSearchTool, OpenAIImageGenerationTool, OpenAILocalShellTool, OpenAIMcpTool,
126    OpenAIShellTool, OpenAIWebSearchTool, UrlContextTool, WebSearchTool, WebSearchUserLocation,
127};
128#[cfg(feature = "example-store")]
129pub use example_store::{ExampleStoreClient, ExampleStoreConfig, ExampleStoreProvider};
130pub use function_tool::FunctionTool;
131#[cfg(feature = "mcp")]
132pub use mcp::{
133    AutoDeclineElicitationHandler, ElicitationHandler, McpAuth, McpHttpClientBuilder,
134    McpServerManager, McpTaskConfig, McpToolset, OAuth2Config, Resource, ResourceContents,
135    ResourceNotificationHandler, ResourceTemplate,
136};
137pub use simple_context::SimpleToolContext;
138pub use stateful_tool::StatefulTool;
139pub use toolset::{
140    BasicToolset, FilteredToolset, MergedToolset, PrefixedToolset, string_predicate,
141};
142#[cfg(feature = "vertex-agent-registry")]
143pub use vertex::agent_registry::{AgentRegistryClient, AgentRegistryConfig, AgentSearchTool};
144
145#[cfg(feature = "code")]
146pub use code_execution::CodeTool;
147
148#[cfg(feature = "code")]
149pub use code_execution::FrontendCodeTool;
150
151#[cfg(feature = "code")]
152pub use code_execution::JavaScriptCodeTool;
153
154#[cfg(feature = "code")]
155pub use code_execution::PythonCodeTool;
156
157#[cfg(feature = "code")]
158pub use code_execution::MontyPythonCodeTool;
159
160#[cfg(feature = "code-embedded-python")]
161pub use code_execution::MontyPythonCodeToolBuilder;