# Tools Reference Victauri exposes 35 MCP tools organized into standalone tools (one action per call) and compound tools (multiple actions via an `action` parameter). All tools are accessible via MCP at `/mcp` or REST at `POST /api/tools/{tool_name}`. ## Backend Tools These tools access the Rust backend directly — no webview proxy, no JavaScript evaluation. ### app_info Get application configuration, directory paths, environment, discovered databases, and process info. **Parameters:** None required. **Returns:** `{config, paths, databases, process, environment}` --- ### list_app_dir Browse files in app backend directories (data, config, log, local_data). **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `directory` | string | no | One of: `data`, `config`, `log`, `local_data` (default: `data`) | | `path` | string | no | Subdirectory to list within the chosen directory | | `pattern` | string | no | Glob to filter entries (e.g. `*.db`) | | `max_depth` | number | no | Recursion depth (default: 1) | **Returns:** `{root, entries: [{name, path, is_dir, size, modified}]}` --- ### read_app_file Read a file from one of the app's backend directories. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `path` | string | yes | File path relative to the directory root | | `directory` | string | no | One of: `data`, `config`, `log`, `local_data` (default: `data`) | | `max_bytes` | number | no | Max bytes to read (default: 1 MB) | | `binary` | boolean | no | Return base64 instead of UTF-8 text | **Returns:** UTF-8 text, or base64-encoded bytes when `binary` is true. Path-traversal-guarded. --- ### query_db Execute a read-only SQL query against a SQLite database in the app's data directory. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `query` | string | yes | SQL query — `SELECT`/`PRAGMA`(read)/`EXPLAIN`/`WITH` only | | `path` | string | no | Path to the database file (auto-discovers if omitted) | | `params` | array | no | Positional bind parameters | | `max_rows` | number | no | Max rows to return (default 100) | **Examples:** ```json {"query": "SELECT * FROM users WHERE active = ?", "params": [true]} {"query": "SELECT count(*) FROM items", "path": "app.db"} ``` **Returns:** `{columns, rows, row_count, truncated, max_rows}` Read-only and path-traversal-guarded: writes (`INSERT`/`UPDATE`/…), stacked queries, `ATTACH`, and the write form of `PRAGMA` (`PRAGMA x = y`) are rejected. By default only the OS app-data directories are searched; if your app stores its DB elsewhere (a project/working dir or custom path), register the directory via `VictauriBuilder::db_search_paths(["../data", "/abs/path"])` — then relative names and absolute paths within those roots become reachable. --- ## Webview & IPC Tools ### eval_js Evaluate JavaScript in the webview and return the result. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `code` | string | yes | JavaScript code to evaluate (expressions, statements, or async/await) | | `webview_label` | string | no | Target webview (defaults to "main" or first visible) | **Examples:** ```json {"code": "document.title"} {"code": "document.querySelectorAll('button').length"} {"code": "await fetch('/api/data').then(r => r.json())"} ``` **Auto-`return`:** a single bare expression is auto-wrapped with `return` (`document.title` → `return document.title`). **Multi-statement code must include an explicit `return`** — e.g. `localStorage.setItem('k','v'); return localStorage.getItem('k')` — or be wrapped in an IIFE; otherwise only the first statement runs. async/await is supported. JavaScript errors (thrown exceptions) return an MCP error with `isError: true`. `undefined` returns `"undefined"`, `null` returns `null`. A **syntax error** surfaces only as the eval timeout (the webview cannot report parse errors to the host). Targeting a hidden or unresponsive window fails fast (~2s); and if a prior eval timed out, the next call re-probes and fails fast if the webview reloaded or the app stopped responding. --- ### dom_snapshot Capture a full accessible DOM tree with ref handles for every element. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `webview_label` | string | no | Target webview | **Returns:** Tree of elements with `ref`, `role`, `name`, `children`, and bounding box data. Descends into open shadow DOM and **same-origin iframes** (cross-origin frames are marked and skipped). --- ### find_elements Search for elements by CSS selector or text content. Returns an MCP error for invalid CSS selectors. Searches into open shadow roots and **same-origin iframes** — frame elements get ref handles and are fully interactable. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `selector` | string | no | CSS selector (alias: `css`). Invalid selectors return an error. | | `text` | string | no | Text content to search for | | `role` | string | no | ARIA role to filter by | | `webview_label` | string | no | Target webview | **Examples:** ```json {"selector": "button.primary"} {"text": "Submit"} {"role": "heading"} ``` --- ### invoke_command Invoke a Tauri command from the backend. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `command` | string | yes | Command name | | `args` | object | no | Arguments to pass | **Example:** ```json {"command": "get_settings", "args": {}} {"command": "search_context", "args": {"query": "hello"}} ``` --- ### screenshot Capture a PNG screenshot of the application window. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `window_label` | string | no | Target window (defaults to main) | **Returns:** Base64-encoded PNG image data. > **Linux:** capture requires X11 or XWayland (the common case, including CI under `xvfb`). A > pure-Wayland session exposes no safe per-window capture path, so `screenshot` returns a clear > error there rather than a wrong or blank image. Windows and macOS capture natively. --- ### verify_state Compare frontend and backend state to detect drift. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `frontend_expr` | string | no | JS expression for frontend state | | `backend_state` | object | no | Expected backend state to compare | **Example:** ```json { "frontend_expr": "document.title", "backend_state": {"title": "My App"} } ``` --- ### detect_ghost_commands Find commands invoked by the frontend that are not registered in the backend registry. **Parameters:** None required. **Returns:** List of ghost commands with invocation counts. --- ### check_ipc_integrity Verify the health of IPC communication. **Parameters:** None required. **Returns:** `{healthy, total_calls, pending_count, stale_count, error_count, stale_calls, errored_calls, warning}` --- ### wait_for Wait for a condition to become true, polling until timeout. Use the `expression` and `event` conditions to await async backend work to **true** completion instead of guessing with a fixed sleep. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `condition` | string | yes | One of: `selector`, `selector_gone`, `text`, `text_gone`, `url`, `ipc_idle`, `network_idle`, `expression`, `event` | | `value` | string | no | Selector/text/URL to match; the JS expression (`expression`); or the Tauri event name (`event`). Not needed for `ipc_idle`/`network_idle` | | `expected` | any | no | For `expression`: the JSON value the expression must equal. Omit to wait for the expression to become truthy | | `since_ms` | number | no | For `event`: how far back (ms) to accept an already-fired event when the wait begins (default: 2000) | | `timeout_ms` | number | no | Max wait time in ms (default: 10000) | | `poll_ms` | number | no | Poll interval in ms (default: 200) | **Conditions for async completion:** - **`expression`** — polls a JS expression until truthy (or `== expected`). It may `await`, so you can await a fire-and-forget command's status directly. Level-triggered and race-free; needs no app changes. Returns `{ ok, value, elapsed_ms }`. - **`event`** — blocks until a named Tauri event fires (evaluated against the captured event bus, with a `since_ms` look-back). The app must emit the event and Victauri must capture it via `VictauriBuilder::listen_events`. Returns `{ ok, event, elapsed_ms }`. **Example:** ```json {"condition": "selector", "value": ".modal.open", "timeout_ms": 3000} {"condition": "url", "value": "/dashboard"} {"condition": "expression", "value": "(await window.__TAURI_INTERNALS__.invoke('get_status')).running === false", "timeout_ms": 30000} {"condition": "event", "value": "analysis-complete", "timeout_ms": 30000} ``` The robust async pattern is `invoke_command(...)` then `wait_for(expression|event, ...)`. --- ### app_state Read application-defined backend state through a registered probe. Probes give an agent first-class, discoverable access to domain state (a scoring pipeline's version and stale-item count, a queue's depth, cache stats) that would otherwise require `query_db` + log-grepping. A probe runs in the Rust process with **no IPC round-trip and no frontend involvement** — direct-backend introspection a browser-external tool cannot do. Apps register probes via `VictauriBuilder::probe("name", || serde_json::json!({ … }))` (build your shared state as an `Arc` once, clone it into both `.manage()` and the probe). **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `probe` | string | no | Name of the probe to run. Omit to list all available probe names | **Example:** ```json {} // → { "probes": ["scoring", "queue"] } {"probe": "scoring"} // → { "pipeline_version": 5, "stale_items": 0 } ``` --- ### assert_semantic Assert a condition about the application state using JS expressions. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `expression` | string | yes | JS expression to evaluate | | `condition` | string | yes | One of: `equals`, `not_equals`, `contains`, `greater_than`, `less_than`, `truthy`, `falsy` | | `expected` | any | no | Expected value (not needed for truthy/falsy) | **Example:** ```json { "expression": "document.title", "condition": "equals", "expected": "My App" } ``` --- ### resolve_command Resolve a natural language description to registered commands. **Parameters:** | Name | Type | Required | Description | |------|------|----------|-------------| | `query` | string | yes | Natural language description | **Example:** ```json {"query": "show settings"} ``` --- ### get_registry List all registered commands with their metadata. **Parameters:** None. --- ### get_memory_stats Get real OS process memory usage. **Parameters:** None. **Returns:** `{working_set_bytes, peak_working_set_bytes, page_fault_count, page_file_bytes}` --- ### get_plugin_info Get plugin version, uptime, configuration, and capabilities. **Parameters:** None. --- ### get_diagnostics Get detailed diagnostic information about the plugin state. **Parameters:** None. --- ## Compound Tools Compound tools use an `action` parameter to select the specific operation. ### interact Element interactions with Playwright-grade actionability checks. Works on elements inside same-origin iframes too (refs from a snapshot/find resolve across frame boundaries). | Action | Parameters | Description | |--------|-----------|-------------| | `click` | `ref_id` | Click an element | | `double_click` | `ref_id` | Double-click an element | | `hover` | `ref_id` | Hover over an element | | `focus` | `ref_id` | Focus an element | | `scroll_into_view` | `ref_id` | Scroll element into viewport | | `select_option` | `ref_id`, `value` or `values` | Select option(s) in a `