descry-tool-core
Core traits and types for the descry-tool framework - a modern, async-first Rust framework for building LLM-compatible tools.
Features
- Unified async Tool trait - Single trait for all tools, no SyncTool/AsyncTool separation
- Arc - Thread-safe context that works seamlessly across await points
- Compile-time registration - Zero-cost tool registration using
inventory - Thread-safe extensions - Concurrent extensions using
DashMap - Multi-protocol adapters - Built-in support for MCP, OpenAI, and Anthropic
- Tower Service integration - Optional middleware ecosystem support
- Auto-generated schemas - Type-safe JSON Schema with thread-local caching
- Error chaining - Rich error types with
thiserrorand#[source]support
Quick Start
Define a Tool
use ;
use ;
use JsonSchema;
use Arc;
;
// Register the tool
submit!
Use the Tool
use ;
use Arc;
async
Core API
Tool Trait
Context System
use ToolContext;
use Arc;
let ctx = new;
// Store extensions
;
ctx.insert;
// Retrieve extensions
let db: = ctx.get.unwrap;
Registry Functions
// Get all registered tools
pub async
Multi-Protocol Adapters
MCP (Model Context Protocol)
use ;
let mcp_spec = to_spec;
// {
// "name": "add",
// "description": "Add two numbers",
// "inputSchema": {...}
// }
OpenAI Function Calling
use ;
let openai_spec = to_spec;
// {
// "type": "function",
// "function": {
// "name": "add",
// "description": "Add two numbers",
// "parameters": {...}
// }
// }
Anthropic (Claude)
use ;
let anthropic_spec = to_spec;
// {
// "name": "add",
// "description": "Add two numbers",
// "input_schema": {...}
// }
Tower Service (Optional)
Enable the tower feature for middleware support:
[]
= { = "0.3", = ["tower"] }
= "0.5"
use ;
use ;
use Duration;
let service = new
.timeout
.service;
let response = service.call.await?;
Error Handling
use ToolError;
match call_tool.await
Examples
See the examples directory:
basic.rs- Basic tool definition and usagemacro_example.rs- Using with#[tool]macrocomplete_example.rs- Multiple tools with error handlingmulti_protocol.rs- Multi-protocol adapter usagetower_basic.rs- Tower Service integrationtower_middleware.rs- Tower middleware exampledebug_schema.rs- Schema generation debugging
Related Crates
descry-tool-macros- Procedural macros for simplified tool definition
Requirements
- Rust 1.85.0+ (Edition 2024)
License
MIT