Skip to main content

mcp_authorization/
metadata.rs

1/// Compile-time metadata about which fields or variants require capabilities.
2///
3/// This trait is generated by `#[derive(AuthSchema)]` from the
4/// `mcp-authorization-macros` crate. Each `#[requires("capability")]`
5/// annotation on a struct field or enum variant produces an entry in the
6/// returned static slice.
7///
8/// You can also implement this manually:
9///
10/// ```
11/// use mcp_authorization::AuthSchemaMetadata;
12///
13/// struct MyInput {
14///     pub name: String,
15///     pub secret_field: Option<String>,
16/// }
17///
18/// impl AuthSchemaMetadata for MyInput {
19///     fn requirements() -> &'static [(&'static str, &'static str)] {
20///         &[("secret_field", "admin")]
21///     }
22/// }
23/// ```
24pub trait AuthSchemaMetadata {
25    /// Returns `(field_or_variant_name, capability_name)` pairs.
26    ///
27    /// For structs, the first element is the field name (matching the JSON property name).
28    /// For enums, the first element is the variant name.
29    fn requirements() -> &'static [(&'static str, &'static str)];
30}