Skip to main content

Crate egui_inspection

Crate egui_inspection 

Source
Expand description

§egui_inspection

Latest version Documentation

Inspection for egui apps.

egui_inspection defines a wire protocol and an egui::Plugin (InspectionPlugin) that serves it. An external inspector — such as the egui_mcp MCP server — connects and can:

  • read the app’s AccessKit tree (GetTree),
  • inject input events (HandleEvents — clicks, typing, scrolling, …),
  • capture a screenshot on request (Screenshot),
  • resize the window (Resize).

The protocol is strictly request → response, which maps cleanly onto both a TCP socket and a unary RPC (so the same machinery can be tunnelled over another transport).

Screenshots need a visible window. Reading the tree and injecting input work even while the app is in the background, but capturing a screenshot requires a rendered frame — which the OS won’t produce for a fully-occluded or minimized window (notably on macOS, where the GPU surface isn’t available). Bring the window to the foreground to capture it; the Screenshot request times out otherwise.

§What it’s for

egui_inspection is the shared foundation for tools that observe or drive an egui app from the outside. Anything that speaks the protocol (over TCP, or another transport) can be a consumer:

  • egui_mcp — an MCP server that exposes the app to AI agents and other tooling: query the widget tree, click / type / scroll, take screenshots.
  • An egui inspector GUI (planned) — a visual debugger that connects to a running app to browse its widget tree and drive it interactively.
  • Test inspection & frame streaming (planned) — attach to egui_kittest tests, and stream frames for live mirroring of an app’s window.

§Enabling it in an eframe app

Enable eframe’s inspection feature, then set the EGUI_INSPECTION env var at runtime. It’s either truthy, falsy, or a bind address:

EGUI_INSPECTION=1 cargo run --features inspection            # binds 127.0.0.1:5719
EGUI_INSPECTION=0.0.0.0:5719 cargo run --features inspection # reachable across devices

When the variable is unset or falsy (0 / false), inspection is completely off (production-safe).

⚠️ Binding a non-loopback address exposes full control of the app — and its screenshots — to anyone who can reach the port, with no authentication. A warning is logged when you do so. Prefer loopback + an SSH tunnel for remote debugging.

§Using the plugin directly

ctx.add_plugin(egui_inspection::InspectionPlugin::new(Some("my app".to_owned())));
egui_inspection::serve(&ctx, "127.0.0.1:5719").unwrap();

§Feature flags

  • png — Screenshot PNG encoding — the EncodedPng::from_color_image / from_rgba constructors. egui/bytemuck is required for ColorImage::as_raw in from_color_image.
  • pluginInspectionPlugin — an egui::Plugin that serves the request/response inspection protocol over TCP. Apps usually enable inspection by setting the EGUI_INSPECTION env var (handled by eframe’s inspection feature).

Re-exports§

pub use protocol::EncodedPng;
pub use protocol::MAX_MESSAGE_BYTES;
pub use protocol::PROTOCOL_MAGIC;
pub use protocol::PROTOCOL_VERSION;
pub use protocol::Request;
pub use protocol::Response;
pub use protocol::read_message;
pub use protocol::write_message;

Modules§

protocol
Request/response wire protocol for inspecting a running egui app.

Structs§

InspectionPlugin
An egui::Plugin that serves the inspection protocol. See the module docs.

Constants§

DEFAULT_INSPECTION_ADDR
Default bind address used when INSPECTION_ENV_VAR is just truthy.
INSPECTION_ENV_VAR
The single environment variable that controls inspection.

Functions§

attach_from_env
Attach inspection if enabled via the environment (see crate::bind_addr_from_env).
bind_addr_from_env
Resolve the bind address from INSPECTION_ENV_VAR, returning None when inspection is disabled. Used by attach_from_env and eframe’s auto-attach.
serve
Bind a TCP listener at addr (e.g. 127.0.0.1:5719) and accept inspector connections.