Raxol.MCP.ContextTree (Raxol MCP v2.6.0)

Copy Markdown View Source

Assembles a structured context tree from multiple sources.

The context tree provides a unified view of session state for AI agents. Different sources contribute subtrees (model projections, widget tree, tools, agents, notifications). Built on demand -- no cached state.

Sources

  • :model -- TEA model projections from registered resources
  • :widgets -- current widget tree (types, IDs, bounds)
  • :tools -- list of available MCP tools
  • :session -- session metadata (id, uptime)

Roles

filter_for_role/2 restricts the tree based on a role atom:

  • :full -- everything (default)
  • :observer -- model + widgets + session (no tools)
  • :operator -- model + widgets + tools + session

Summary

Functions

Build a context tree from the given sources.

Build a full context tree with all sources.

Filter a context tree for a given role.

Types

context()

@type context() :: %{
  registry: GenServer.server(),
  session_id: term(),
  view_tree: map() | list() | nil,
  model: map() | nil
}

role()

@type role() :: :full | :observer | :operator

source()

@type source() :: :model | :widgets | :tools | :session

Functions

build(sources, context)

@spec build([source()], context()) :: map()

Build a context tree from the given sources.

The context map must include :registry and :session_id. Optional keys: :view_tree, :model.

build_all(context)

@spec build_all(context()) :: map()

Build a full context tree with all sources.

filter_for_role(tree, atom)

@spec filter_for_role(map(), role()) :: map()

Filter a context tree for a given role.