mcp_authorization_macros/lib.rs
1mod auth_schema;
2
3use proc_macro::TokenStream;
4use syn::{parse_macro_input, DeriveInput};
5
6/// Derive macro that generates `AuthSchemaMetadata` implementations.
7///
8/// Reads `#[requires("capability_name")]` attributes from struct fields
9/// or enum variants and produces a static requirements table used by
10/// the schema shaper to filter fields/variants per-request.
11///
12/// # On structs (input schema shaping)
13///
14/// ```ignore
15/// #[derive(AuthSchema)]
16/// struct AdvanceStepInput {
17/// pub applicant_id: String,
18/// #[requires("backward_routing")]
19/// pub stage_id: Option<String>,
20/// }
21/// ```
22///
23/// # On enums (output variant shaping)
24///
25/// ```ignore
26/// #[derive(AuthSchema)]
27/// enum AdvanceStepOutput {
28/// Success { applicant_id: String },
29/// #[requires("backward_routing")]
30/// ReroutedSuccess { applicant_id: String, previous_stage: String },
31/// }
32/// ```
33#[proc_macro_derive(AuthSchema, attributes(requires))]
34pub fn derive_auth_schema(input: TokenStream) -> TokenStream {
35 let input = parse_macro_input!(input as DeriveInput);
36 auth_schema::derive_auth_schema(input).into()
37}