Skip to main content

JsonUiPlugin

Trait JsonUiPlugin 

Source
pub trait JsonUiPlugin: Send + Sync {
    // Required methods
    fn component_type(&self) -> &str;
    fn props_schema(&self) -> Value;
    fn render(&self, props: &Value, data: &Value) -> String;
    fn css_assets(&self) -> Vec<Asset>;
    fn js_assets(&self) -> Vec<Asset>;
    fn init_script(&self) -> Option<String>;
}
Expand description

Trait for JSON-UI plugin components.

Plugins provide custom interactive components that require client-side JS/CSS. Each plugin declares a unique component type name, a JSON Schema for its props (enabling MCP/agent discovery), a render function producing HTML, and asset declarations for the page.

Implementations must be Send + Sync for use in the global registry across threads.

Required Methods§

Source

fn component_type(&self) -> &str

Unique component type name (e.g., “Map”).

Used in JSON: {"type": "Map", ...}. Must not collide with built-in component type names.

Source

fn props_schema(&self) -> Value

JSON Schema describing accepted props.

Used by MCP/agents for discovery and validation. Should return a valid JSON Schema object.

Source

fn render(&self, props: &Value, data: &Value) -> String

Render the component to an HTML string.

Receives the raw props and the view data for data_path resolution.

Source

fn css_assets(&self) -> Vec<Asset>

CSS assets to load in <head>.

Called once per page; results are deduplicated by URL across all plugin instances on the page.

Source

fn js_assets(&self) -> Vec<Asset>

JS assets to load before </body>.

Called once per page; results are deduplicated by URL across all plugin instances on the page.

Source

fn init_script(&self) -> Option<String>

Inline initialization JS emitted once per page after assets load.

Returns None if no initialization is needed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§