bevy_brp_mcp 0.22.0

MCP server for Bevy Remote Protocol (BRP) integration
//! Traits for field placement system
//!
//! These traits work with the `FieldPlacement` derive macro to provide:
//! - Field placement information
//! - Direct field access without JSON serialization
//! - Automatic `CallInfo` generation

/// Specifies where a response field should be placed in the output JSON
#[derive(Clone, Debug)]
pub enum FieldPlacement {
    /// Place field in the metadata object
    Metadata,
    /// Place field in the result object
    Result,
    /// Place field in the `error_info` object
    ErrorInfo,
}

/// Whether to omit a `None`-valued field from the serialized output.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SkipIfNone {
    Omit,
    Keep,
}

impl From<bool> for SkipIfNone {
    fn from(value: bool) -> Self { if value { Self::Omit } else { Self::Keep } }
}

/// Information about where a field should be placed in the response
///
/// Note: The `ParamStruct` and `ResultStruct` derive macros generate implementations that use
/// `crate::tool::FieldPlacementInfo` and `crate::tool::HasFieldPlacement`
/// but no code within `mcp/src` calls this so we use the allow
#[derive(Debug, Clone)]
#[allow(dead_code, reason = "used by ParamStruct/ResultStruct derive macros")]
pub struct FieldPlacementInfo {
    /// The name of the field
    pub field_name:   &'static str,
    /// Where to place this field (metadata or result)
    pub placement:    FieldPlacement,
    /// Optional source path for response fields (e.g., "result.entities")
    pub source_path:  Option<&'static str>,
    /// Whether to skip this field if it's None
    pub skip_if_none: SkipIfNone,
}

/// Trait for types that have field placement information
///
/// Note: see note on `FieldPlacementInfo`
#[allow(dead_code, reason = "used by ParamStruct/ResultStruct derive macros")]
pub trait HasFieldPlacement {
    /// Get the field placement information for this type
    fn field_placements() -> Vec<FieldPlacementInfo>;
}