universal_tool_core/
lib.rs

1// Re-export the error types
2pub mod error;
3
4// Re-export schemars types for use in generated code
5pub use schemars::{self, JsonSchema};
6
7// CLI utilities module (only available with cli feature)
8// NOTE: We use #[cfg(feature = "cli")] to ensure CLI utilities are only available
9// when the CLI feature is enabled. This keeps the API clean and follows idiomatic
10// Rust practices. Testing confirms this approach works correctly with our examples.
11#[cfg(feature = "cli")]
12pub mod cli;
13
14// REST utilities module (only available with rest feature)
15#[cfg(feature = "rest")]
16pub mod rest;
17
18// MCP utilities module (only available with mcp feature)
19#[cfg(feature = "mcp")]
20pub mod mcp;
21
22// Re-export the macros at the crate root for easy access
23// IMPORTANT: Users should NOT depend on universal-tool-macros directly!
24// These re-exports ensure that features propagate correctly. When you enable
25// a feature on universal-tool-core, it automatically enables the corresponding
26// feature on universal-tool-macros, ensuring only the requested code is generated.
27pub use universal_tool_macros::{universal_tool, universal_tool_router};
28
29/// The `prelude` module provides a single, convenient import for all essential
30/// library items. This is just a convenience - users control their own application structure.
31pub mod prelude {
32    // Re-export the procedural macros from the other crate.
33    // This allows the user to have a single `use` statement.
34    pub use universal_tool_macros::{universal_tool, universal_tool_router};
35
36    // Re-export the error types.
37    pub use crate::error::{ErrorCode, ToolError};
38
39    // Re-export JsonSchema for generated code
40    pub use schemars::JsonSchema;
41
42    // Re-export CLI utilities when the CLI feature is enabled
43    #[cfg(feature = "cli")]
44    pub use crate::cli::{CliFormatter, OutputFormat, ProgressReporter};
45
46    // Re-export REST utilities when the REST feature is enabled
47    #[cfg(feature = "rest")]
48    pub use crate::rest::{
49        IntoResponse,
50        Json,
51        Path,
52        Query,
53        Response,
54        State,
55        StatusCode,
56        // Core axum types for handlers
57        axum,
58        // Tower utilities
59        tower,
60        tower_http,
61    };
62
63    // Re-export OpenAPI utilities when enabled
64    #[cfg(feature = "openapi")]
65    pub use crate::rest::{utoipa, utoipa_swagger_ui};
66
67    // Re-export MCP utilities when the MCP feature is enabled
68    #[cfg(feature = "mcp")]
69    pub use crate::mcp::{
70        CancellationToken,
71        IntoCallToolResult,
72        // Re-export commonly used values
73        JsonValue,
74        // MCP-specific types
75        McpError,
76        McpErrorData,
77        McpProgressReporter,
78        NumberOrString,
79        ProgressNotification,
80        ProgressToken,
81        ServerHandler,
82        ToolAnnotations,
83        ToolMetadata,
84        convert_tool_definitions,
85        // Error codes
86        error_codes,
87        extract_parameter_schema,
88        // Helper functions
89        generate_schema,
90        json,
91        // Core rmcp types and functions
92        rmcp,
93        stdio,
94    };
95
96    // Re-export the MCP server macro (exported at crate root due to macro_export)
97    #[cfg(feature = "mcp")]
98    pub use crate::implement_mcp_server;
99}