Skip to content

Quick start

Start here even if you have a GUI: a headless bridge needs no toolkit and no main-thread hop, so you can exercise the projection from a test or a main.

toml
[dependencies]
purview = "0.1"
tokio = { version = "1", features = ["full"] }
rust
use purview::{ActionError, GuiBridge, Outcome, on_ui};

#[tokio::main]
async fn main() -> Result<(), purview::ServeError> {
    // 1. Build the bridge. `headless()` fixes Cx = () and runs posted work inline.
    let (bridge, app) = GuiBridge::headless()
        .instructions_append("An order-management app.")
        .build();

    // 2. Describe a window and its initial content.
    let win = app.open("Order");
    win.set_summary("Editing order #12345");
    let form = win.blocks().fields([("Recipient", ""), ("Amount", "$0")]);

    // 3. Register an action. It becomes the MCP tool `{winId}__submit`.
    win.actions()
        .add("submit", "Submit order")
        .destructive()
        .on(on_ui(move || {
            form.set("Recipient", "Alice"); // read side: projection follows
            Ok::<_, ActionError>(Outcome::message("submitted"))
        }));

    // 4. Serve until the client disconnects.
    bridge.serve_stdio().await
}

That is the whole shape of every integration: build → describe → register → serve. Everything else in this guide fills in those four steps.

What the agent sees

The projection is served as a single resource, app://windows, plus one tool per window action named {winId}__{action}. Nothing else is exposed, and you never assemble either by hand.