bevy_brp_mcp 0.22.2

MCP server for Bevy Remote Protocol (BRP) integration
//! `world.trigger_event` tool - Trigger events in the Bevy world

use std::collections::HashMap;

use bevy_brp_mcp_macros::ParamStruct;
use bevy_brp_mcp_macros::ResultStruct;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use serde_json::Value;

use crate::brp_tools::Port;

/// Parameters for the `world.trigger_event` tool
#[derive(Clone, Deserialize, Serialize, JsonSchema, ParamStruct)]
pub struct TriggerEventParams {
    /// The full type path of the event to trigger (e.g., "`my_game::events::SpawnEnemy`")
    pub event: String,

    /// The event payload as JSON. Omit for unit events (events with no data).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub value: Option<HashMap<String, Value>>,

    /// The BRP port (default: 15702)
    #[serde(default)]
    pub port: Port,
}

/// Result for the `world.trigger_event` tool
///
/// Note: This follows the `DespawnEntityResult` pattern - the `{event}` placeholder
/// in the message template is resolved from `TriggerEventParams.event` at response-building
/// time, so we don't need an `event` field in this struct.
#[derive(Serialize, ResultStruct)]
#[brp_result]
pub struct TriggerEventResult {
    /// The raw BRP response (null on success)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[to_result(skip_if_none)]
    pub result: Option<Value>,

    /// Message template for formatting responses
    #[to_message(message_template = "Triggered event {event}")]
    pub message_template: String,
}