adk-tool
Tool system for Rust Agent Development Kit (ADK-Rust) agents (FunctionTool, MCP, Google Search).
Overview
adk-tool provides the tool infrastructure for the Rust Agent Development Kit (ADK-Rust):
- FunctionTool - Create tools from async Rust functions
- AgentTool - Use agents as callable tools for composition
- GoogleSearchTool - Web search via Gemini's grounding
- McpToolset - Model Context Protocol integration (local & remote servers)
- BasicToolset - Group multiple tools together
- FilteredToolset - Filter tools from any toolset by predicate
- MergedToolset - Combine multiple toolsets into one
- PrefixedToolset - Namespace tool names with a prefix
- ExitLoopTool - Control flow for loop agents
- LoadArtifactsTool - Inject binary artifacts into context
Installation
[]
= "0.4"
# For remote MCP servers via HTTP:
= { = "0.4", = ["http-transport"] }
Or use the meta-crate:
[]
= { = "0.4", = ["tools"] }
Quick Start
Function Tool
use FunctionTool;
use ;
use ;
use Arc;
async
let tool = new;
With Parameter Schema (Recommended)
Always add a schema so the LLM knows what parameters to pass:
use JsonSchema;
use ;
let tool = new
.;
MCP Tools (Local Server via stdio)
Connect to local MCP servers running as child processes:
use McpToolset;
use ;
use Command;
// Connect to a local MCP server
let cmd = new
.arg
.arg
.arg;
let client = .serve.await?;
let toolset = new
.with_name
.with_filter;
// Get cancellation token for graceful shutdown
let cancel_token = toolset.cancellation_token.await;
// ... use toolset with agent ...
// Cleanup before exit
cancel_token.cancel;
MCP Tools (Remote Server via HTTP)
Connect to remote MCP servers using HTTP transport (requires http-transport feature):
use McpHttpClientBuilder;
use Duration;
// Connect to a public remote MCP server
let toolset = new
.timeout
.connect
.await?;
MCP Authentication
Connect to authenticated MCP servers:
use ;
use Duration;
// Bearer token (e.g., GitHub Copilot MCP)
let toolset = new
.with_auth
.timeout
.connect
.await?;
// API key in custom header
let toolset = new
.with_auth
.connect
.await?;
// OAuth2 client credentials flow
let oauth_config = new
.with_secret
.with_scopes;
let toolset = new
.with_auth
.connect
.await?;
MCP Task Support (Long-Running Operations)
Enable async task lifecycle for long-running MCP operations (SEP-1686):
use ;
use Duration;
let toolset = new
.with_task_support;
MCP Auto-Reconnect (Connection Resilience)
For long-running agents, use ConnectionRefresher to automatically reconnect when connections fail:
use ;
use ;
use Arc;
use Command;
// Define a factory that can create new connections
// Create initial connection
let cmd = new
.arg
.arg
.arg;
let client = .serve.await?;
// Wrap with auto-reconnect
let factory = new;
let refresher = new
.with_config;
// Operations automatically retry on connection failure
let tools = refresher.list_tools.await?;
if tools.reconnected
The refresher handles these error conditions automatically:
- Connection closed / EOF
- Broken pipe / transport errors
- Session not found (server restart)
- Connection reset
Google Search
use GoogleSearchTool;
let search = new;
// Add to agent - enables grounded web search
Features
| Feature | Description |
|---|---|
| (default) | Local MCP servers via stdio transport |
http-transport |
Remote MCP servers via streamable HTTP |
MCP Server Examples
Available Public MCP Servers
https://remote.mcpservers.org/fetch/mcp- Web content fetchinghttps://remote.mcpservers.org/sequentialthinking/mcp- Step-by-step reasoning
GitHub Copilot MCP (40+ tools)
// Requires GITHUB_TOKEN with Copilot access
let toolset = new
.with_auth
.connect
.await?;
// Discovered tools include:
// - search_repositories, search_code, search_issues
// - create_pull_request, merge_pull_request
// - get_file_contents, create_or_update_file
// - issue_read, issue_write, add_issue_comment
// - and 30+ more GitHub operations
Toolset Composition
Compose, filter, and namespace toolsets for complex agent configurations:
use ;
use Arc;
// Group tools into named toolsets
let weather = new;
let utils = new;
// Filter: expose only specific tools from a toolset
let filtered = new;
// Or use a custom predicate
let custom = with_name;
// Merge: combine multiple toolsets (first-wins deduplication)
let merged = new;
// Prefix: namespace tool names to avoid collisions
let prefixed = new; // wx_get_weather, wx_get_forecast
// Chain them: prefix → filter → merge
let composed = new;
// Register with an agent
let agent = new
.model
.toolset
.build?;
All composition utilities implement Toolset and work with any Toolset implementation including McpToolset and BrowserToolset.
Migration from rmcp 0.9
No changes required! The rmcp 0.14 breaking changes were handled internally:
| What Changed | Impact |
|---|---|
CallToolRequestParam → CallToolRequestParams |
Internal only |
Added meta: None field |
Internal only |
| HTTP transport API | Internal only |
Your existing code using McpToolset::new(client) continues to work unchanged.
Related Crates
- adk-rust - Meta-crate with all components
- adk-core - Core
Tooltrait - adk-agent - Agents that use tools
License
Apache-2.0
Part of ADK-Rust
This crate is part of the ADK-Rust framework for building AI agents in Rust.