Raxol.MCP.ToolSynchronizer (Raxol MCP v2.6.0)

Copy Markdown View Source

Per-session GenServer that bridges the render pipeline to the MCP Registry.

Listens for [:raxol, :runtime, :view_tree_updated] telemetry events, derives tools from the view tree via TreeWalker, diffs against the previously registered set, and updates the Registry. Debounces rapid renders (50ms) to avoid thrashing.

Also manages model-projected resources when the app implements Raxol.MCP.ResourceProvider, and registers context tree + widget tree resources for the session.

Started by Raxol.Headless when creating a session. Linked to the session lifecycle -- dies when the session dies, cleaning up its tools.

Usage

{:ok, pid} = ToolSynchronizer.start_link(
  registry: Raxol.MCP.Registry,
  dispatcher_pid: dispatcher_pid,
  session_id: :my_session,
  app_module: MyApp
)

Summary

Functions

Returns a specification to start this module under a supervisor.

Start a ToolSynchronizer linked to the calling process.

Force an immediate tool sync from the current view tree.

Update the focused widget ID for FocusLens filtering.

Update the hovered widget ID for anticipatory tool exposure.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

handle_manager_call(request, from, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_call/3.

start_link(init_opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start a ToolSynchronizer linked to the calling process.

sync(synchronizer, view_tree)

@spec sync(GenServer.server(), map()) :: :ok

Force an immediate tool sync from the current view tree.

update_focus(synchronizer, widget_id)

@spec update_focus(GenServer.server(), String.t() | nil) :: :ok

Update the focused widget ID for FocusLens filtering.

When a widget gains focus (keyboard or mouse click), call this to adjust which tools are exposed via FocusLens.

update_hover(synchronizer, widget_id)

@spec update_hover(GenServer.server(), String.t() | nil) :: :ok

Update the hovered widget ID for anticipatory tool exposure.

When the mouse hovers over a widget, call this so FocusLens can pre-expose that widget's tools alongside the focused widget's.