Skip to main content

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