跳转至

MCP Terminal Control

Status (2026-11-13): MCP is enabled by default but read-only by default. The live socket is created automatically at $XDG_RUNTIME_DIR/xtervo/mcp.sock (0600); the state token lives at $XDG_STATE_HOME/xtervo/mcp.token (0600). Grants are grouped and hot-applied in Settings → Privacy. The live socket is embedded in xtervo core; it is not a plugin and plugins do not host MCP.

Implemented live tools:

read:  live_capabilities, live_snapshot, live_list, live_output
input: live_send_text, live_send_key, live_run
tabs:  live_new_tab, live_split, live_focus, live_scroll
L2:    live_close_pane, live_close_tab, live_kill

live_close_pane/live_close_tab require tabs + destructive; live_kill requires input + destructive. live_paste, live_resize, live_metrics, live_rename are not implemented/exposed.

1. Architecture

MCP is not embedded in the PTY. xtervo exposes a local live control socket, and the MCP stdio bridge translates JSON-RPC tools into socket commands:

external harness
  -> MCP stdio (xtervo diag serve)
     -> local Unix socket (0600, token)
        -> xtervo UI/event loop
           -> AppState: tabs/panes/PTY

The socket is the only control boundary. MCP never gets direct filesystem, Vault, environment-variable, or host-process access.

xtervo diag serve uses the app as the authority for tools/list:

tools/list
  -> capability probe ({"cmd":"capabilities","probe":true}, token)
     -> app returns commands filtered by mcp_enabled + read/input/tabs/destructive
        -> bridge lists only those live tools

The server no longer decides tool visibility from its own XTERVO_DIAG_ALLOW_WRITE/XTERVO_DIAG_ALLOW_DESTRUCTIVE. The app also validates every tools/call, so a stale tool list cannot bypass a tightened grant.

2. Permission groups

Config is flat TOML (~/.config/xtervo/config.toml); defaults keep older config files compatible (additive fields, no schema bump):

mcp_enabled = true       # master; false = no socket, no live tools
mcp_read = true          # capabilities/snapshot/list/output
mcp_input = false        # send_text/send_key/run
mcp_tabs = false         # new_tab/new_window/split/focus/scroll
mcp_destructive = false  # close_pane/close_tab/close_window/kill (additional gate)
Group Commands Notes
read capabilities, snapshot, list, output default on
input send_text, send_key, run default off
tabs new_tab, new_window, split, focus, scroll default off
destructive close_pane, close_tab, close_window, kill default off; needs base group

Safe default for destructive:

close_pane / close_tab / close_window = tabs && destructive
kill                   = input && destructive

Turning on mcp_destructive alone grants nothing.

Multi-window additive fields: list returns windows[] + active_window_id; every live tool accepts window_id (default active) and validates it against the WindowRegistry (unknown window_id instead of silently falling back). new_window opens the in-process second window; close_window refuses to close the last window. The [mcp] audit line records the resolved window (action=... window=window-N pane=...), never command text/token. WindowId/ PaneId are explicit routes, not inferred from the active UI.

Old env overrides remain for tests/CI:

XTERVO_DIAG_ALLOW_WRITE=1         -> input + tabs
XTERVO_DIAG_ALLOW_DESTRUCTIVE=1   -> destructive

They cannot bypass mcp_enabled=false. Do not export them in a normal desktop session unless you intend to widen every MCP client.

Settings UI

Settings → Privacy → MCP live control exposes:

  • master switch;
  • read/input/tabs/destructive switches;
  • live socket path and state token path;
  • enabled/readiness/error status.

Changes are saved to config and applied immediately (socket supervisor and per-request app checks); no xtervo restart.

3. Default socket and state token

socket: $XDG_RUNTIME_DIR/xtervo/mcp.sock              (0600)
        fallback without XDG_RUNTIME_DIR:
        $XDG_STATE_HOME/xtervo/mcp.sock
        (or ~/.local/state/xtervo/mcp.sock / temp fallback)
        paths longer than ~100 bytes also fall back to the
        state/temp path (Unix socket length limit)
token:  $XDG_STATE_HOME/xtervo/mcp.token              (0600)
        or ~/.local/state/xtervo/mcp.token
  • xtervo creates the socket automatically when mcp_enabled=true.
  • The token is generated with 32 random bytes (hex) and reused across runs.
  • The token value is never written to config, logs, or feedback bundles.
  • XTERVO_DIAG_SOCKET / XTERVO_DIAG_TOKEN are explicit overrides for tests/CI; they do not override mcp_enabled=false.
  • xtervo diag serve with no arguments reads config/state and discovers both.
  • A stale socket is replaced only after a connection probe fails; an active socket owned by another xtervo instance is left alone.
  • Wrong/missing token -> unauthorized; connection failures name the socket path. tools/list hides live tools when the probe fails.

4. Operation tiers

L0: read-only (default)

Tool Operation
xtervo.live_capabilities Group switches, allowed commands, limits/version
xtervo.live_snapshot Frame summary: cursor, modes, damage, image rectangles
xtervo.live_list Pane ids, titles, grids, rectangles, focus (no tab list)
xtervo.live_output Bounded visible output tail (not full scrollback)

Read limits:

max output bytes per call (capped)
no environment-variable values
no API keys/tokens/passwords
no unbounded scrollback dump

L1: terminal control (mcp_input / mcp_tabs)

Tool Operation
xtervo.live_send_text Write text to a pane (no automatic Enter)
xtervo.live_send_key Enter/Escape/Ctrl+C/Ctrl+D/arrows/F-keys subset
xtervo.live_run Write one command line + Enter; no shell wrapper added
xtervo.live_focus Focus a pane
xtervo.live_scroll Scroll a pane's scrollback
xtervo.live_new_tab Create a tab
xtervo.live_new_window Open a second in-process window (flag required)
xtervo.live_split Split a pane right/down

This is effectively shell execution through the terminal when input is granted. Required controls:

state token + 0600 socket
explicit per-group grants
app-side validation of every tools/call
argument-length caps
unknown pane/tab -> explicit error, never guess

There is no per-harness token scope or built-in rate limit yet; the app log records action/pane/argument bytes (never argument text or secrets).

L2: destructive (mcp_destructive + base group)

Tool Operation
xtervo.live_close_pane Close a pane
xtervo.live_close_tab Close a tab
xtervo.live_close_window Close a window by window_id (never the last)
xtervo.live_kill Send Ctrl+C to a PTY

All live tools accept an optional window_id; live_list returns windows[] and active_window_id, and each pane carries its window_id. Explicit window ids are validated; responses echo the routed window_id, and [mcp] audit lines include it.

L2 is disabled by default. close_* also needs mcp_tabs; kill also needs mcp_input. There is no per-call confirmation prompt in this version.

5. Example harness flow

(default read-only)
xtervo.live_list
xtervo.live_output

After granting input+tabs+destructive:

xtervo.live_list
  -> find a shell pane
xtervo.live_send_text { pane, text: "cargo test" }
xtervo.live_send_key  { pane, key: "Enter" }
xtervo.live_output    { pane, max_bytes: 65536 }
xtervo.live_split     { pane, direction: "vertical" }
xtervo.live_focus     { pane: original }
xtervo.live_close_pane{ pane: created }

MCP request shape:

{"jsonrpc":"2.0","id":1,"method":"tools/call",
 "params":{"name":"xtervo.live_list","arguments":{}}}

6. Security model

socket mode 0600, Unix local only
state token 0600, required for every request
mcp_enabled master switch (false removes the socket)
read/input/tabs/destructive groups, hot-applied
destructive cannot be granted without its base group
app-side tools/call validation (server tools/list is only a cache)
no host filesystem / Vault / env values / host process execution
no automatic issue creation or git push
token never written to config/logs/feedback; never echoed in errors

Defaults:

mcp_enabled = true
read = enabled
input/tabs/destructive = disabled

7. Explicitly not allowed

read arbitrary host files
read Vault/credentials/environment values
execute host commands outside the terminal PTY
modify user config/plugins/repository
automatically submit issues or push code
unbounded scrollback reads
connect without a token
write/close/kill while the matching group is off

8. Current vs planned

Current mainline (implemented and covered by tests/e2e):

offline:
  xtervo.diag_env
  xtervo.diag_snapshot
  xtervo.diag_replay
  xtervo.doctor_check
  xtervo.issue_draft
  xtervo.metrics_read
live read:
  xtervo.live_capabilities
  xtervo.live_snapshot
  xtervo.live_list
  xtervo.live_output
live input:
  xtervo.live_send_text
  xtervo.live_send_key
  xtervo.live_run
live tabs:
  xtervo.live_new_tab
  xtervo.live_split
  xtervo.live_focus
  xtervo.live_scroll
live destructive:
  xtervo.live_close_pane
  xtervo.live_close_tab
  xtervo.live_kill

Not exposed yet: live_paste, live_resize, live_metrics, live_rename. Per-harness token scopes and rate limits are still follow-up work.

Evidence (2026-11-13):

./scripts/e2e_mcp_settings.sh      # default read-only, hot grants, master off/on, token
./scripts/e2e_mcp_live_control.sh  # env-override write path
./scripts/e2e_diag_live.sh         # read-only raw socket + bridge

9. Acceptance gates

default startup creates 0600 socket + 0600 state token without env
read-only list/snapshot/output work through no-arg `xtervo diag serve`
input/destructive tools absent and their calls rejected by default
config edit grants input/tabs/destructive; tools appear and work without restart
tightening config immediately hides/rejects the corresponding calls
mcp_enabled=false removes the socket and all live tools
mcp_enabled=false at startup creates no socket, even with XTERVO_DIAG_SOCKET
wrong token -> unauthorized; wrong-token bridge hides live tools
missing socket/connection failure -> explicit error
no token value in app log/config