Skip to content

Tools

A failing tool returns an error result (isError) with the message. Groovy failures come back as the exception, its causes and the script lines they came from. qupath_screenshot fails when no window matches the title and index.

Tools that act on the GUI (qupath_menu, qupath_click, qupath_select, qupath_set, qupath_key, qupath_close, qupath_open) return without waiting for the handler, so a modal dialog never blocks the call. They wait about a second, then return what they did, the open windows one per line (title — WxH (focused)), and the outline of each window the action opened, or No new window opened., which tells the agent to check with qupath_describe or qupath_wait. If work the action started is still running at that point, as Cell detection is after Run, the result ends with a line such as A QuPath command or script is still running; qupath_wait text="command running" gone=true returns when it ends. A parameter dialog stays open after it. Call that the action result. An opened window's outline is whole when it has at most five controls, as an error popup does (its text fields cut only after 20,000 characters), or is at most 1,500 characters long. Otherwise it stops at the last whole control within 1,500 characters, and after 25 controls at most, with a line such as +82 more controls; qupath_describe window="Preferences" (or + more lines; … when only text is left). The first control always shows, so a wide table that alone passes 1,500 characters shows its column names, the rows that fit and how many rows it has (rows 1–6 of 31).

Tool Use it to… Returns
qupath_run_groovy(code, timeout_s=60) do anything the dedicated tools don't cover Captured println output, then result: …; a script still running after 50 s, or held up by a dialog, returns a note instead and keeps running (see Calls longer than a minute and Dialogs waiting for an answer)
qupath_menu(path) fire a menu item such as File>Open URI... (the trailing ... is optional); a check item such as Extensions>MCP server>Enabled is toggled The action result; a level that doesn't match lists the items it has
qupath_click(text, window=None, button="left", double=False) press a button, tick a checkbox, expand or collapse a titled pane, or click a label or cell; button="right" opens a context menu and returns its items, to click next The action result
qupath_select(text, window=None, control=None, check=None) pick an item in a combo box, choice box, list, tree, tab pane or table row; with check=True or False, tick or clear the checkbox of every matching table row The control's qupath_describe line, as #7 ComboBox "Detection" = Cell, then the action result; with check, checked 3 rows of TableView
qupath_set(value, control, window=None) set a spinner, slider, checkbox (true/false), text field, or the text of an editable combo box The control's qupath_describe line with the value it holds after the change, as #3 NumericField "Number of parallel threads" = "8", then the action result
qupath_key(keys, window=None) press keys, space-separated for several sent Enter to <node>, then the action result
qupath_close(window=None) close a window, such as a measurement table, as its close button would; a window that prompts first shows its prompt closed <title>, then the action result
qupath_open(path_or_uri) open an image without a file chooser opened <path>, then the action result
qupath_describe(window=None, control=None, offset=0, limit=20) read a dialog or the viewer state as text; control reads one control, as qupath_set finds it The controls of every window matching window, each headed by its index; with control, the lines of each control it matches, in the window window picks as qupath_set does
qupath_wait(text, window=None, timeout_s=30, gone=False) wait for an image to load, a dialog to fill or a command to finish, instead of polling in Groovy Once text appears in the qupath_describe output, up to 20 lines that contain it (then +N more lines; found 'X' if it spans lines; with gone=True, 'X' is gone), then the open windows; on timeout an error with the last output. A call returns after at most 50 s, with Not yet: … if timeout_s is longer, and sooner if a dialog opens that may be waiting for an answer
qupath_view(x, y, downsample, z=None, t=None) move the viewer to a pixel, zoom, plane z and timepoint t ok
qupath_screenshot(window=None, index=0, max_size=1024, format="png", viewer=False, region=None) see what a window shows The window as an image, plus a text item with its size
qupath_show_actions(mode=None, delay_ms=None) change what the person watching sees: off, mark or paced, and the delay before each paced action mode: mark, delay_ms: 1000

The action log

qupath-mcp writes every action the agent takes to a log file; see Action log.

Watching the agent

qupath-mcp shows the person at the screen what the agent does, in one of three modes:

Mode What it shows Effect on the agent
Mark (default) A ring on each control the agent clicks, types into, selects or sets, or on the row a selection picks in a list, tree or table; a crosshair where the viewer moves to; a keycap for key presses. A panel in the window's lower right lists the last six actions, including menu items, opened images and Groovy runs, and fades after 4 s without activity. A badge names the client, as Claude Code is driving, while a tool call runs. None. The marks are drawn after the action is dispatched.
Paced The same, and before each action a pointer moves to the control, or the menu path, key or viewer position shows at the top of the window. For a row in a list, tree or table, the pointer moves once the selection has scrolled the row into view. qupath_view pans and zooms to the new view over the delay instead of jumping. Waits the paced delay (default 1000 ms) before each action.
Off Nothing. None.

Paced suits screen recordings and anyone following along. The person sets the mode under Extensions ▸ MCP server ▸ Show agent actions and the delay with the Paced delay (ms) preference; the agent sets both with qupath_show_actions. Both persist across restarts.

The marks are drawn only in QuPath's windows: a menu in the macOS menu bar can't be opened from code, so paced mode shows its path instead. qupath_screenshot, qupath_describe and click lookups leave the marks out, so the agent sees QuPath as it is.

Notes

  • Window matching. A window argument is a case-sensitive substring of the window title, and qupath_describe covers every match. A popup often has the same title as its dialog, so qupath_screenshot takes an index (0 is the first match) numbered as qupath_describe numbers them; the other tools use the first match. With no window, they target an open context menu, else the focused non-main window, else the most recently opened one, else the main window. qupath_screenshot defaults to the main window.
  • Keys. qupath_key takes JavaFX key names, for example Enter, Escape (or Esc), Tab, Ctrl+A, Shortcut+S (Shortcut is Cmd on macOS). Enter presses a dialog's default button and Escape its cancel button.
  • Windows opened while waiting. qupath_wait notes the open windows when it starts. Its result, on success and on timeout, ends with Opened while waiting: and the outline of each window that opened since, cut short as in an action result, so a warning dialog is not missed.
  • Windows that changed between calls. A dialog that QuPath opens a few seconds after an action, from a background task, misses that action's result. So qupath-mcp keeps, per MCP session, the windows the agent has been shown, and starts each result with Opened since your last call: "Confirm" — 420x180 for each window that opened since, followed by its outline if that is at most ten lines (else qupath_describe window="…"), and Closed since your last call: "…" for windows that closed. A window the result outlines anyway is not repeated, and when nothing changed nothing is added. A window that closes during a call whose result lists the open windows, as an action result does, is not reported again; after other calls, such as qupath_run_groovy, the next result reports it. The check waits at most 300 ms for QuPath's UI; when the UI is busy it is skipped and a later call reports the change.
  • Work that keeps running. Much of QuPath's work goes on after the action that started it returns. The summary that qupath_describe gives with no window ends with command running while any of it runs, and the action result that started it says what is running, so qupath_wait(text="command running", gone=True) returns when it ends:

    • A command or script. A command with a parameter dialog, such as Cell detection, runs in the background after Run, and its dialog stays open; its Run button reads Please wait... until it ends. QuPath marks such a command, and a script run from the Script Editor, as blocking its UI, and the action result says A QuPath command or script is still running. A short command, such as Add intensity features on 20,000 cells, usually ends within the action's second, and the action result reports its history step instead.
    • A task with QuPath's Progress window. QuPath shows its Progress window, with a bar and Cancel, for some tasks that extensions run on their own threads, such as InstanSeg's inference, from 0% until the task ends. While it is open the action result says A task with a "Progress" window is still running.
    • A progress bar in an open window. An extension that runs work on its own threads, outside QuPath's command runner, may show a progress bar or spinner in its own window. qupath_describe shows one as ProgressBar 40%, or ProgressBar [running] when it has no percentage, and one that is running, or part-way and not at 0%, counts as command running. The action result says Progress in "<window>" is still running.
    • A task on QuPath's UI thread. A few commands, such as the pixel classifier's Create objects, run on the UI thread itself, so no window can be read until they end. Tools then fail within about 3 s with QuPath's UI thread is busy in PixelClassifierUI.promptToCreateObjects, …, naming the code it is running, and qupath_wait keeps polling until the UI thread is free or timeout_s runs out.
    • A qupath_run_groovy script that outlasted its call (see Calls longer than a minute).

    Some work shows none of these signs at first. InstanSeg, for example, loads its model for a few seconds before QuPath's Progress window opens, and only its Run button, which stays disabled until it ends, shows that it started. So when a button the agent clicked is still disabled after the action's second and nothing above is running, the action result starts with Button "Run" stayed disabled after the click, so its work may still be running; qupath_wait(text='Button "Run" [disabled]', window="InstanSeg", gone=true) returns when it is enabled again. Work that shows no sign at all is not seen while it runs; its history step, if it adds one, is reported when it ends. - Calls longer than a minute. Most MCP clients end a tool call that takes longer than 60 s with an error: Claude Code does for servers it reaches over HTTP, as it reaches qupath-mcp, unless the server's timeout in .mcp.json is raised, and so does Codex CLI by default. So no qupath-mcp call waits longer than 50 s. A qupath_wait with a longer timeout_s returns Not yet: after 50 s, 'command running' is still there. … call qupath_wait again to keep waiting., not an error; repeating it waits as long as the work runs. A qupath_run_groovy script with a timeout_s above 50 that is still running after 50 s returns The script is still running after 50 s, … and goes on running until its timeout_s; meanwhile command running is in the summary, and its output and result are added to the end of that MCP session's first result after it ends, under A script from an earlier call has ended. - Dialogs waiting for an answer. When a qupath_run_groovy script is blocked on a modal dialog that opened during the call, or a modal dialog opens during a qupath_wait, and the dialog stays open for half a second, the call ends early, since the script or command may be waiting for someone to answer it. The result names the dialog and outlines it: The script is still running. "Confirm" opened and may be waiting for an answer; qupath_click answers it., or for a wait, Not yet: 'command running' is still there. "Confirm" opened …. A script's result goes on It stops at timeout_s, in 115 s.; if nobody answers by then, its error says the dialog is still open and that an answer no longer reaches the script. A native file chooser a script is blocked on ends the call the same way, saying that the person has to close it. These don't count: a dialog the script opened and goes on working with, such as one it fills in and closes itself; QuPath's Progress window; a dialog with a running progress bar; a dialog that closes within half a second; and, for qupath_wait, a dialog whose title contains its window. - History steps. QuPath records a command that completes as a step in the image's history (the Workflow tab). qupath-mcp keeps, per MCP session, the last step the agent has been told about, and reports newer ones by name: a result ends with Added to history: Cell detection for steps added during the call, and starts with Added to history since your last call: … for steps added between calls, including the person's own. More than five are reported as 7 steps, the last five: …. A command that fails adds no step; its error window is reported instead. In QuPath 0.7.0, a command cancelled from its Progress window while its last task runs still adds a step, though its results are discarded. After the image changes, steps are counted from the new image's history, and nothing is reported for the switch itself. Like the window check, this waits at most 300 ms for QuPath's UI and is skipped when the UI is busy. - Paging. Tables, lists and trees in qupath_describe print limit rows from offset and end with rows X–Y of N; the next page is offset=Y. Controls are not paged: every one is listed. - Waiting on long tables. qupath_wait searches every row of every table, list and tree, not only the page qupath_describe prints, so it can wait for a row far down a table, and it matches a text field's whole text, not only the 200 characters qupath_describe shows. A line longer than 200 characters comes back as the 80 characters either side of text. On a timeout it says so, and prints the first page. - Sorting. Click a column header with qupath_click to sort a table by it, and again to reverse. qupath_describe marks the sort column with ↑ or ↓, as Area µm^2 ↓. Selecting a row of QuPath's measurement tables also selects that object in the viewer. - Controls. qupath_describe tags buttons, checkboxes and the controls that qupath_select and qupath_set can address with #n. A line reads #n Type "label" = value: a label just before the control it names is shown on the control's line instead of its own, as #3 NumericField "Number of parallel threads" = "8", also when the form wraps the control in a pane with its units, as #5 TextField "Sigma" = "1.5" then Label "µm" in Cell detection. A checkbox shows [x], [ ], or [-] when indeterminate, a text field's text is quoted and cut after 200 characters (… (512 chars)), and a password field's text is ••••••. An icon-only button shows its tooltip's first line, as Button [Install extension], else its accessible text or graphic, else just Button. Their control argument is that tag (#3 or 3) or the text of the label next to the control (Size:); qupath_select without control tries every list-like control in turn. - Click targets. qupath_click takes text as a #n from qupath_describe, else finds the first labeled node whose text is exactly text, passing over a plain label when a control has the same text (so in Search [field] [Search] the text means the button), else the one whose tooltip (whole, then first line) or accessible text is, else the one whose bracketed name qupath_describe shows is ([Install extension]): a button, checkbox, hyperlink, label, titled pane, or a visible table or tree cell. If several controls match, whether by text (a Search button on each of two rows) or by a later rule (one "Install extension" button per row), the error lists them as #n [near "label"]; click one by its #n. Table and tree cells have no #n, so text repeated in several rows clicks the first. A label that names a checkbox with no text of its own, as in Preferences, clicks the checkbox. A button is fired; anything else, and any right or double click, gets synthetic mouse events. A missing target lists the buttons qupath_describe tags in the window it searched. - Titled panes. Some dialogs, such as Edit ▸ Preferences in its By Category view, group their controls in collapsible titled panes. qupath_describe shows a collapsed one as TitledPane "Viewer" [collapsed] with nothing under it, because its controls are hidden. qupath_click("Viewer") expands it, or collapses it if it is open, and replies with the state the pane is then in: expanded TitledPane “Viewer”; qupath_describe lists its controls or collapsed TitledPane “Viewer”. In an accordion, such as that Preferences view, expanding one pane collapses the one that was open. A disabled pane is left as it is and the click fails. When an open pane holds a control with the same text as its title, the text clicks the control. Panes have no #n, so of two panes with the same title only the first can be clicked. A pane that cannot collapse, and any right or double click on a pane, gets mouse events as a label does. When qupath_click, qupath_set or qupath_describe finds no control and the window has collapsed panes, the error names them, as …, or it may be in a collapsed pane: Appearance, Bio-Formats. - Screenshot crops. viewer=True crops to the active viewer of the main window, region=[x, y, w, h] to window coordinates. The macOS menu bar is not included. - Screenshot size. Image cost grows with pixel size, so the longest side is capped at max_size and a smaller image is never enlarged. Use format="jpeg" for slides and viewer content, where PNG is large and sharp text does not matter; PNG suits dialogs. - qupath_open. It waits up to 5 s for QuPath to open the image. If a prompt (for example about unsaved changes) is holding it, the reply says still opening and the action result shows the prompt. - qupath_describe with no window. It describes every open window except the main one, then gives the main window's title, the viewer's image path, downsample, centre, z/t and annotation count, and a last line command running while work runs (see Work that keeps running). The downsample is image pixels per screen pixel; 1 is full resolution. - File choosers are native. QuPath's open and save dialogs are macOS dialogs that the scene graph does not contain, so no tool can read or drive them. When QuPath's UI thread is showing one, every tool says a native dialog is probably open, within about 3 s, and a qupath_run_groovy script blocked on one returns within about a second saying the same; close it in QuPath. A UI thread that is busy with a long task instead is reported as busy (see Work that keeps running). Avoid them: qupath_open opens an image by path or URI, File>Open URI... is a normal dialog, and a qupath_run_groovy script can use a path instead of prompting for one. - Turning the server off. qupath_menu("Extensions>MCP server>Enabled") toggles the preference like a click, so an agent can switch the server off. The call replies first and the server then stops within a few seconds, ending the session; it has to be turned back on from QuPath's Extensions menu. - Groovy helpers. qupath_run_groovy scripts get qupath (the QuPathGUI) and these helpers: fx { } runs a closure on the FX thread; window(titleSubstring) picks a window as the window argument does (null for the default); waitFor(titleSubstring, seconds) waits for a window to show and returns it; lookup(window, text) finds a control as qupath_click does; click(node) and fire(findMenuItem("Help>License")) return at once, so a modal dialog they open doesn't block; typeInto(window, text[, field]) sets the field-th text field; describe(window) and view(x, y, downsample[, z, t]) match qupath_describe and qupath_view. snap(name) writes a PNG of every window, and snapMain(name) of the main window, to the qupath.driver.out folder (default: the JVM temp dir); quit() quits QuPath; no tool does, since quitting is the person's call.