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