BorgVR Guide

Agent control

Model Context Protocol

Trusted AI agents can inspect datasets, control the visualization, and evaluate rendered images without driving the user interface remotely.

Mandelbulb volume controlled through BorgVR
Edit states and filesThe Data and Edit States guide explains storage, automatic edit persistence, variants, shared SharePlay state, and export. MCP uses the same restrictions as the UI; in particular, states cannot be switched during a running session.

What BorgVR MCP provides

All three native renderers contain the same optional MCP server. It is independent of the dataset and WebGPU servers and uses the same central command layer as the macOS scripting language. An agent can therefore act reproducibly instead of operating buttons through mouse or gaze control.

  • Read the dataset catalog with complete metadata and known origins, then open or close datasets
  • Read and change rendering mode, isovalue, transform, clipping, and lighting
  • Manage objects, sphere and stroke markers, mesh instances, and length, area, and volume measurements
  • Hide objects or the complete measurement visualization without deleting data
  • Wait for a completed rendered frame, retrieve the current view as a PNG image, and export isosurfaces as OBJ on macOS

Enabling MCP

  1. Open BorgVR Settings and select the MCP section.
  2. Enable Enable MCP server and choose another port if required. The default is 8765.
  3. Add one of the displayed endpoints to the configuration of your MCP client.
This device onlyWithout network access enabled, BorgVR listens only at http://127.0.0.1:8765/mcp. Local connections require neither TLS nor an access token.

Access from the network

When Allow connections from the network is enabled, BorgVR binds the MCP server to all available network interfaces and displays an HTTPS endpoint for every reachable address. Depending on router, firewall, and port forwarding, the service may also be reachable from outside the local network.

  • Generate an access token or enter your own. The client sends it as Authorization: Bearer ….
  • The generation button copies the new token directly to the clipboard.
  • Network connections use HTTPS. Without an imported PKCS#12 identity, BorgVR creates a temporary self-signed certificate whenever the server starts.
Trust boundaryA connected MCP client can open datasets, change the visualization, edit annotations and measurements, erase and restore local volume data, discard all local edits, export files, and read screenshots. Share the endpoint and token only with trusted systems.

Typical agent workflow

  1. The agent uses list_datasets to inspect metadata and origins, then opens the selected dataset with open_dataset.
  2. It inspects get_application_state, changes the view and rendering parameters, and hides objects or measurements when required.
  3. After each change it uses wait_until_rendered to wait for a new completed frame, then calls capture_screenshot.
  4. On macOS it can use export_isosurface to save the current dataset as an OBJ file at the current or an explicitly supplied normalized isovalue.
  5. By comparing multiple views, rendering modes, isovalues, or clipping ranges, the agent can inspect visible structures systematically.

The JSON schemas returned by tools/list are the authoritative reference for argument names and value ranges.

Brick diagnostics and optimizations

set_brick_visualization accepts optional boolean fields enabled, resident, empty, and missing. Type filters are local and also apply to subblocks: red = resident, green = skipped as empty, blue = missing or coarser substitute. Hiding a type changes neither traversal nor brick requests.

set_render_optimizations accepts boolean subbrick_skipping and opacity_adaptive_sampling, plus alpha_epsilon from 0 through 1. These settings persist locally. Alpha epsilon affects only TF empty-space classification, not the transfer function itself or iso rendering.

For both tools, omitted fields remain unchanged; at least one field is required. get_application_state reports all current values in renderingOptions. While GSC recording is active, UI and MCP changes are recorded, including the initial values of these options.

{"name":"set_brick_visualization","arguments":{"enabled":true,"resident":false,"empty":true,"missing":true}}
{"name":"set_render_optimizations","arguments":{"subbrick_skipping":true,"opacity_adaptive_sampling":true,"alpha_epsilon":0}}

Volume editing and export

configure_volume_brush also accepts channels: "all" or an array of one-based channel numbers, e.g. [1,3]. At least one valid channel is required. get_volume_edit_state reports componentCount and channels as a list of selected, one-based channel numbers. Opening selects all channels. Selection is local; SharePlay carries it with each operation. discard_volume_edits always resets every channel.

Dataset and isosurface exports are disabled during SharePlay. Edits and edit-state changes are rejected while an export is running. Starting SharePlay cancels a running export.

The following tools are available on macOS, iOS, and visionOS. Edits affect the active edit state and are shared during SharePlay. The original file is never modified.

  • get_volume_edit_state returns availability, dataset ID, brush settings, edit status, pending brick count, and the latest export job with UUID, status, progress, and any error. The same state is included in get_application_state.volumeEditing.
  • get_volume_edit_state includes savedStates, activeStateID, and SharePlay status. select_edit_state selects a UUID or original; create_edit_state creates an empty state or a copy with duplicate=true. rename_edit_state changes its name. delete_edit_state removes an inactive state with confirm=true. State management is locked during SharePlay.
  • configure_volume_brush accepts optional mode (erase/restore), radius_fraction (0.002–0.15 of the largest extent), project_onto_volume, and activate. The latter activates hand/mouse/touch editing and defaults to false; Muse/PSVR modes stay independent.
  • edit_volume requires mode and samples, an array of objects with center_meters: [x,y,z] and positive radius_meters. Coordinates are physical meters from the volume minimum corner, not screen, hand, or world coordinates. Interactive radius and projection do not affect these explicit samples; the channel selection from configure_volume_brush applies here too. At most 65536 samples per call within the HTTP request limit; no interpolation. Erase sets selected channels to 0; restore recovers only their original values.
  • edit_volume returns after journaling. Use wait_volume_edits with optional timeout_seconds (default 30, maximum 86400) to wait for background jobs. Unreachable remote bricks may cause a timeout.
  • prepare_volume_edits rebuilds pending edited bricks with foreground priority and waits for persistence. Uses Metal when available; cancellation preserves recorded edits.
  • discard_volume_edits requires explicit confirm: true and clears only the active edit state. During SharePlay, it clears the shared state; other states are preserved.
  • export_edited_dataset starts an export job with absolute output_path (.data), plus optional name and description. Paths refer to the app device and must be accessible to its sandbox. Existing destinations are refused. The consistent export includes all previously recorded edits and preserves source compression; waiting for brick jobs first is unnecessary.
  • Poll get_volume_edit_state until export.status is completed, cancelled, or failed; progress ranges from 0 to 1. cancel_volume_export with the job UUID in id cancels only that job. Incomplete export files are removed; recorded edits remain.
{"name":"edit_volume","arguments":{"mode":"erase","samples":[{"center_meters":[0.5,0.5,0.5],"radius_meters":0.05}]}}
{"name":"export_edited_dataset","arguments":{"output_path":"/path/on/app-device/edited.data","name":"Edited volume"}}

Troubleshooting

Empty response or no connection
Verify that scheme and endpoint match: local access uses http, network access uses https.
Unauthorized
For network access, the Authorization header must contain exactly the currently displayed bearer token. Local access on the same device does not check a token.
Certificate error
Explicitly trust the self-signed certificate or import your own PKCS#12 identity. Some externally hosted agents cannot reach private or local IP addresses at all.