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
105pub use adk_core::{AdkError, Result, Tool, ToolContext, Toolset};
106pub use adk_rust_macros::tool;
107
108// Re-export async_trait so the #[tool] macro's generated code can reference it
109// without requiring users to add async-trait as a direct dependency.
110pub use agent_tool::{
111    AgentTool, AgentToolConfig, AgentToolFailureMode, AgentToolSessionSnapshot,
112    AgentToolStateMergePolicy,
113};
114pub use async_trait::async_trait;
115pub use builtin::{
116    AnthropicBashTool20241022, AnthropicBashTool20250124, AnthropicTextEditorTool20250124,
117    AnthropicTextEditorTool20250429, AnthropicTextEditorTool20250728, BypassBuiltinTool,
118    BypassMultiToolsLimit, ExitLoopTool, GeminiCodeExecutionTool, GeminiComputerEnvironment,
119    GeminiComputerUseTool, GeminiFileSearchTool, GoogleMapsContext, GoogleMapsTool,
120    GoogleSearchTool, LoadArtifactsTool, OpenAIApplyPatchTool, OpenAIApproximateLocation,
121    OpenAICodeInterpreterTool, OpenAIComputerEnvironment, OpenAIComputerUseTool,
122    OpenAIFileSearchTool, OpenAIImageGenerationTool, OpenAILocalShellTool, OpenAIMcpTool,
123    OpenAIShellTool, OpenAIWebSearchTool, UrlContextTool, WebSearchTool, WebSearchUserLocation,
124};
125#[cfg(feature = "example-store")]
126pub use example_store::{ExampleStoreClient, ExampleStoreConfig, ExampleStoreProvider};
127pub use function_tool::FunctionTool;
128#[cfg(feature = "mcp")]
129pub use mcp::{
130    AutoDeclineElicitationHandler, ElicitationHandler, McpAuth, McpHttpClientBuilder,
131    McpServerManager, McpTaskConfig, McpToolset, OAuth2Config, Resource, ResourceContents,
132    ResourceNotificationHandler, ResourceTemplate,
133};
134pub use simple_context::SimpleToolContext;
135pub use stateful_tool::StatefulTool;
136pub use toolset::{
137    BasicToolset, FilteredToolset, MergedToolset, PrefixedToolset, string_predicate,
138};
139
140#[cfg(feature = "code")]
141pub use code_execution::CodeTool;
142
143#[cfg(feature = "code")]
144pub use code_execution::FrontendCodeTool;
145
146#[cfg(feature = "code")]
147pub use code_execution::JavaScriptCodeTool;
148
149#[cfg(feature = "code")]
150pub use code_execution::PythonCodeTool;
151
152#[cfg(feature = "code")]
153pub use code_execution::MontyPythonCodeTool;
154
155#[cfg(feature = "code-embedded-python")]
156pub use code_execution::MontyPythonCodeToolBuilder;