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:

  • tool - Turn an async function into a Tool whose arguments are checked against the derived schema before it runs
  • FunctionTool - Create tools from async Rust functions
  • StatefulTool - Share Arc<S> state with a tool handler
  • AgentTool - Use agents as callable tools for composition
  • AdvisorTool - Let an agent consult a stronger or different model for advice mid-task, under the run’s budget, spend ledger and kill switch
  • GoogleSearchTool and the other builtin wrappers - Provider-hosted tools, each declaring its ToolEffect
  • 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, FilteredToolset, MergedToolset, PrefixedToolset - Group, filter, combine, and namespace toolsets
  • ToolArgumentValidator - Check hand-written tools’ arguments against a JSON Schema
  • ExitLoopTool - Control flow for loop agents
  • LoadArtifactsTool - Inject binary artifacts into context

§Quick Start

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

#[derive(Serialize, JsonSchema)]
struct WeatherParams {
    /// The city to get weather for
    city: String,
}

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": 22,
        "condition": "sunny"
    }))
}

let tool = FunctionTool::new("get_weather", "Get current weather for a city", get_weather)
    .with_parameters_schema::<WeatherParams>();

§MCP Integration

Connect to MCP servers for external tools (requires the mcp feature):

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

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

let toolset = McpToolset::new(client);

§Features

No feature is on by default; function tools, agent tools and toolsets need none. MCP (mcp, http-transport, mcp-server, mcp-sampling, mcp-apps), memory tools (memory-tools, graph-memory-tools), code execution (code, code-embedded-js, code-embedded-python, code-docker), slack, bigquery, spanner, example-store and vertex-agent-registry each have a feature; the README says what each enables.

Re-exports§

pub use memory::GraphMemoryToolset;
pub use memory::RelateTool;
pub use memory::RememberTool;
pub use advisor::AdvisorTool;
pub use advisor::AdvisorToolBuilder;
pub use builtin::AnthropicAdvisorTool;
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::DeepSeekWebSearchTool;
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 example_store::ExampleStoreClient;
pub use example_store::ExampleStoreConfig;
pub use example_store::ExampleStoreProvider;
pub use mcp::AutoDeclineElicitationHandler;
pub use mcp::ElicitationHandler;
pub use mcp::McpAuth;
pub use mcp::McpDiscoveryLimits;
pub use mcp::McpHttpClientBuilder;
pub use mcp::McpSchemaLimits;
pub use mcp::McpServerManager;
pub use mcp::McpTaskConfig;
pub use mcp::McpToolset;
pub use mcp::OAuth2Config;
pub use mcp::ResourceNotificationHandler;
pub use toolset::BasicToolset;
pub use toolset::FilteredToolset;
pub use toolset::MergedToolset;
pub use toolset::PrefixedToolset;
pub use toolset::string_predicate;
pub use vertex::agent_registry::AgentRegistryClient;
pub use vertex::agent_registry::AgentRegistryConfig;
pub use vertex::agent_registry::AgentSearchTool;
pub use code_execution::FrontendCodeTool;
pub use code_execution::JavaScriptCodeTool;
pub use code_execution::PythonCodeTool;
pub use code_execution::MontyPythonCodeTool;
pub use code_execution::MontyPythonCodeToolBuilder;

Modules§

advisor
Advisor consultation: a tool an agent calls to ask a stronger or different model for advice mid-task.
bigquery
Native BigQuery toolset for ADK agents.
builtin
Built-in tool wrappers for Gemini, OpenAI, and Anthropic hosted tools.
code_execution
Code execution tools for ADK agents.
example_store
Vertex AI Example Store client and few-shot retrieval provider.
mcp
Model Context Protocol (MCP) clients, server SDK re-export, catalog APIs, elicitation, tasks, HTTP transport, and dynamic local-server management.
memory
Memory tools for ADK agents.
sampling
MCP sampling callback support for ADK agents.
slack
Native Slack toolset for ADK agents.
spanner
Native Spanner toolset for ADK agents.
toolset
Toolset combinators: basic, filtered, merged, and prefixed toolsets.
vertex
Hosted Google Cloud registry integrations for agent tooling.

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.
CodeTool
Re-export adk_code::CodeTool as the recommended code execution tool. A tool that executes code through language-specific pipelines.
FunctionTool
A tool created from an async Rust function.
Resource
A known resource that the server is capable of reading (spec Resource).
ResourceTemplate
A template description for resources available on the server (spec ResourceTemplate).
SimpleToolContext
A lightweight ToolContext with sensible defaults for non-agent callers.
StatefulTool
A generic tool wrapper that manages shared state for stateful closures.
ToolArgumentValidator
Validates tool-call arguments against a JSON Schema.

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.
ErrorCategory
The kind of failure independent of subsystem.
ErrorComponent
The subsystem that produced the error — the origin, not the boundary it surfaces through.
ResourceContents
The contents of a specific resource or sub-resource.
ToolEffect
The side-effect class of a tool, reported by Tool::effect.

Constants§

TOOL_INVALID_ARGUMENTS_CODE
The error code for a call whose arguments do not fit the tool.
TOOL_INVALID_PARAMETERS_SCHEMA_CODE
The error code for a tool whose parameters schema does not compile.

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.

Functions§

close_object_schemas
Sets additionalProperties: false on each object schema in schema that declares all of its fields, so a validator rejects keys the schema does not name.
coerce_integral_floats
Rewrites each integral float in args at a position schema types as an integer, so 3.0 becomes 3.
model_facing_schema
Reduces a schema generated for a #[tool] argument type to the form sent to the model.

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.