Skip to main content

Crate adk_tool

Crate adk_tool 

Source
Expand description

§adk-tool

Tool system for ADK agents: typed Rust tools, toolset composition, hosted provider tools, and Model Context Protocol clients and servers.

§Overview

This crate provides the tool infrastructure for ADK agents:

  • FunctionTool - Create tools from async Rust functions
  • AgentTool - Use agents as callable tools for composition
  • GoogleSearchTool - Web search via Gemini’s grounding
  • McpToolset - MCP tools, resources, prompts, completion, elicitation, subscriptions, and negotiated tasks with the mcp feature
  • McpServerManager - Dynamic local MCP server registry, process lifecycle, persistence, health monitoring, and bounded restart with the mcp feature
  • BasicToolset - Group multiple tools together
  • ExitLoopTool - Control flow for loop agents
  • LoadArtifactsTool - Inject binary artifacts into context

§Quick Start

use adk_tool::FunctionTool;
use adk_core::{ToolContext, Result};
use serde_json::{json, Value};
use std::sync::Arc;

async fn get_weather(ctx: Arc<dyn ToolContext>, args: Value) -> Result<Value> {
    let city = args["city"].as_str().unwrap_or("Unknown");
    Ok(json!({
        "city": city,
        "temperature": 72,
        "condition": "sunny"
    }))
}

let tool = FunctionTool::new(
    "get_weather",
    "Get current weather for a city",
    get_weather,
);

§MCP Integration

Connect to MCP servers for external tools:

use adk_tool::{
    McpToolset,
    mcp::rmcp::{ServiceExt, transport::TokioChildProcess},
};
use tokio::process::Command;

let client = ().serve(TokioChildProcess::new(
    Command::new("/opt/company/bin/workspace-mcp")
        .arg("--stdio")
        .arg("--root")
        .arg("/srv/workspace")
)?).await?;

let toolset = McpToolset::new(client);

Re-exports§

pub use builtin::AnthropicBashTool20241022;
pub use builtin::AnthropicBashTool20250124;
pub use builtin::AnthropicTextEditorTool20250124;
pub use builtin::AnthropicTextEditorTool20250429;
pub use builtin::AnthropicTextEditorTool20250728;
pub use builtin::BypassBuiltinTool;
pub use builtin::BypassMultiToolsLimit;
pub use builtin::ExitLoopTool;
pub use builtin::GeminiCodeExecutionTool;
pub use builtin::GeminiComputerEnvironment;
pub use builtin::GeminiComputerUseTool;
pub use builtin::GeminiFileSearchTool;
pub use builtin::GoogleMapsContext;
pub use builtin::GoogleMapsTool;
pub use builtin::GoogleSearchTool;
pub use builtin::LoadArtifactsTool;
pub use builtin::OpenAIApplyPatchTool;
pub use builtin::OpenAIApproximateLocation;
pub use builtin::OpenAICodeInterpreterTool;
pub use builtin::OpenAIComputerEnvironment;
pub use builtin::OpenAIComputerUseTool;
pub use builtin::OpenAIFileSearchTool;
pub use builtin::OpenAIImageGenerationTool;
pub use builtin::OpenAILocalShellTool;
pub use builtin::OpenAIMcpTool;
pub use builtin::OpenAIShellTool;
pub use builtin::OpenAIWebSearchTool;
pub use builtin::UrlContextTool;
pub use builtin::WebSearchTool;
pub use builtin::WebSearchUserLocation;
pub use toolset::BasicToolset;
pub use toolset::FilteredToolset;
pub use toolset::MergedToolset;
pub use toolset::PrefixedToolset;
pub use toolset::string_predicate;

Modules§

builtin
Built-in tool wrappers for Gemini, OpenAI, and Anthropic hosted tools.
toolset
Toolset combinators: basic, filtered, merged, and prefixed toolsets.

Structs§

AdkError
Unified structured error type for all ADK-Rust operations.
AgentTool
AgentTool wraps an Agent to make it callable as a Tool.
AgentToolConfig
Configuration options for AgentTool behavior.
FunctionTool
A tool created from an async Rust function.
SimpleToolContext
A lightweight ToolContext with sensible defaults for non-agent callers.
StatefulTool
A generic tool wrapper that manages shared state for stateful closures.

Enums§

AgentToolFailureMode
Controls how an AgentTool reports delegated execution failures.
AgentToolSessionSnapshot
Controls which parent session data is copied into an agent-tool invocation.
AgentToolStateMergePolicy
Merge behavior for state produced by an agent-as-tool invocation.

Traits§

Tool
The core trait for all tools that agents can invoke.
ToolContext
Context available to tools during execution.
Toolset
A collection of tools that can be resolved dynamically from context.

Type Aliases§

Result
Convenience alias used throughout ADK crates.

Attribute Macros§

async_trait
tool
Attribute macro that generates a Tool implementation from an async function.