//! IPC protocol between Rust MCP server and Python bpy executor
use serde::{Deserialize, Serialize};
/// Command from MCP server to Python
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Command {
/// Unique request ID
pub id: u64,
/// Method name (e.g., "list_objects", "scene_info")
pub method: String,
/// JSON-encoded parameters
pub params: String,
}
/// Response from Python back to MCP server
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Response {
/// Request ID (must match Command.id)
pub id: u64,
/// JSON-encoded result (if success)
pub result: Option<String>,
/// Error message (if failed)
pub error: Option<String>,
}
impl Response {
pub fn success(id: u64, result: impl Serialize) -> Self {
Self {
id,
result: Some(serde_json::to_string(&result).unwrap_or_default()),
error: None,
}
}
pub fn error(id: u64, message: impl Into<String>) -> Self {
Self {
id,
result: None,
error: Some(message.into()),
}
}
}