Skip to main content

descry_tool_core/
lib.rs

1//! Descry Tool Core - Modern async-first tool framework
2//!
3//! Provides zero-cost, compile-time tool registration with modern Rust best practices.
4//!
5//! # Features
6//!
7//! - **Single async Tool trait** - No SyncTool/AsyncTool separation
8//! - **Arc<ToolContext>** - No borrow checker hell, works across await points
9//! - **Compile-time registration** - Using `inventory` for zero startup cost
10//! - **Thread-local schema cache** - Generated once per type
11//! - **Thread-safe** - `DashMap` for concurrent extensions
12//! - **Error chaining** - `thiserror` with `#[source]` support
13//! - **Multi-protocol adapters** - MCP, OpenAI, Anthropic built-in
14//! - **Tower Service integration** - Middleware ecosystem support (optional)
15//!
16//! # Quick Start
17//!
18//! ```ignore
19//! use descry_tool_core::{Tool, ToolContext, ToolError};
20//! use serde::{Deserialize, Serialize};
21//! use schemars::JsonSchema;
22//! use std::sync::Arc;
23//!
24//! #[derive(Deserialize, JsonSchema)]
25//! struct AddParams {
26//!     a: i32,
27//!     b: i32,
28//! }
29//!
30//! #[derive(Serialize, JsonSchema)]
31//! struct AddOutput {
32//!     result: i32,
33//! }
34//!
35//! struct AddTool;
36//!
37//! impl Tool for AddTool {
38//!     type Params = AddParams;
39//!     type Output = AddOutput;
40//!
41//!     const NAME: &'static str = "add";
42//!     const DESCRIPTION: &'static str = "Add two numbers";
43//!
44//!     async fn call(
45//!         ctx: Arc<ToolContext>,
46//!         params: Self::Params,
47//!     ) -> Result<Self::Output, ToolError> {
48//!         Ok(AddOutput {
49//!             result: params.a + params.b,
50//!         })
51//!     }
52//! }
53//! ```
54
55pub mod adapters;
56pub mod context;
57pub mod error;
58pub mod registry;
59pub mod tool;
60pub mod types;
61
62#[cfg(feature = "tower")]
63pub mod tower;
64
65// Re-exports
66pub use context::{Meta, ToolContext};
67pub use error::ToolError;
68pub use registry::{
69    all_tools, call_tool, find_tool, get_tool_examples, get_tool_schema, tool_count, tool_exists,
70    tool_names, ToolMeta,
71};
72pub use tool::{HasAnnotations, Tool};
73pub use types::JsonObject;
74
75// Re-export adapters
76pub use adapters::{AnthropicAdapter, McpAdapter, OpenAiAdapter, ToolAdapter};
77
78// Re-export Tower types (optional)
79#[cfg(feature = "tower")]
80pub use tower::{tool_service, tool_service_for, ToolRequest, ToolResponse, ToolService};
81
82// Re-export schemars for convenience
83pub use schemars::JsonSchema;