universal_tool_macros/lib.rs
1//! Universal Tool Framework (UTF) Procedural Macros
2//!
3//! This crate provides the procedural macros that power UTF's code generation.
4//! Users should depend on `universal-tool-core`, not this crate directly.
5//!
6//! See `parser.rs` for detailed documentation on the feature propagation system.
7
8use proc_macro::TokenStream;
9
10mod codegen;
11mod model;
12mod parser;
13
14/// The main attribute macro for defining universal tools.
15///
16/// This macro will generate interface-specific methods (CLI, REST, MCP)
17/// from your tool implementation.
18///
19/// # Example
20///
21/// ```ignore
22/// #[universal_tool_router]
23/// impl MyTools {
24/// #[universal_tool(description = "Analyze code for quality metrics")]
25/// async fn analyze_code(
26/// &self,
27/// path: String,
28/// detailed: Option<bool>
29/// ) -> Result<AnalysisResult, ToolError> {
30/// // Your business logic here
31/// }
32/// }
33/// ```
34#[proc_macro_attribute]
35pub fn universal_tool_router(attr: TokenStream, item: TokenStream) -> TokenStream {
36 parser::parse_router(attr.into(), item.into())
37 .unwrap_or_else(|err| err.to_compile_error())
38 .into()
39}
40
41/// Attribute macro for individual tool methods within a universal_tool_router impl block.
42#[proc_macro_attribute]
43pub fn universal_tool(_attr: TokenStream, item: TokenStream) -> TokenStream {
44 // This is a marker macro - the actual parsing happens in universal_tool_router
45 // We just pass through the original item unchanged
46 item
47}
48
49// Note: universal_tool_param is not a proc macro attribute!
50// It's an inert helper attribute that gets parsed by universal_tool_router.
51// This allows it to be used on function parameters, which Rust doesn't allow
52// for arbitrary proc macro attributes.