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
windowargument is a case-sensitive substring of the window title, andqupath_describecovers every match. A popup often has the same title as its dialog, soqupath_screenshottakes anindex(0 is the first match) numbered asqupath_describenumbers them; the other tools use the first match. With nowindow, they target an open context menu, else the focused non-main window, else the most recently opened one, else the main window.qupath_screenshotdefaults to the main window. - Keys.
qupath_keytakes JavaFX key names, for exampleEnter,Escape(orEsc),Tab,Ctrl+A,Shortcut+S(Shortcutis Cmd on macOS). Enter presses a dialog's default button and Escape its cancel button. - Windows opened while waiting.
qupath_waitnotes the open windows when it starts. Its result, on success and on timeout, ends withOpened 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" — 420x180for each window that opened since, followed by its outline if that is at most ten lines (elsequpath_describe window="…"), andClosed 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 asqupath_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_describegives with nowindowends withcommand runningwhile any of it runs, and the action result that started it says what is running, soqupath_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_describeshows one asProgressBar 40%, orProgressBar [running]when it has no percentage, and one that is running, or part-way and not at 0%, counts ascommand running. The action result saysProgress 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, andqupath_waitkeeps polling until the UI thread is free ortimeout_sruns out. - A
qupath_run_groovyscript 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'stimeoutin.mcp.jsonis raised, and so does Codex CLI by default. So no qupath-mcp call waits longer than 50 s. Aqupath_waitwith a longertimeout_sreturnsNot 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. Aqupath_run_groovyscript with atimeout_sabove 50 that is still running after 50 s returnsThe script is still running after 50 s, …and goes on running until itstimeout_s; meanwhilecommand runningis in the summary, and its output and result are added to the end of that MCP session's first result after it ends, underA script from an earlier call has ended.- Dialogs waiting for an answer. When aqupath_run_groovyscript is blocked on a modal dialog that opened during the call, or a modal dialog opens during aqupath_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 onIt 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, forqupath_wait, a dialog whose title contains itswindow. - 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 withAdded to history: Cell detectionfor steps added during the call, and starts withAdded to history since your last call: …for steps added between calls, including the person's own. More than five are reported as7 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 inqupath_describeprintlimitrows fromoffsetand end withrows X–Y of N; the next page isoffset=Y. Controls are not paged: every one is listed. - Waiting on long tables.qupath_waitsearches every row of every table, list and tree, not only the pagequpath_describeprints, so it can wait for a row far down a table, and it matches a text field's whole text, not only the 200 charactersqupath_describeshows. A line longer than 200 characters comes back as the 80 characters either side oftext. On a timeout it says so, and prints the first page. - Sorting. Click a column header withqupath_clickto sort a table by it, and again to reverse.qupath_describemarks the sort column with ↑ or ↓, asArea µm^2 ↓. Selecting a row of QuPath's measurement tables also selects that object in the viewer. - Controls.qupath_describetags buttons, checkboxes and the controls thatqupath_selectandqupath_setcan 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"thenLabel "µ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, asButton [Install extension], else its accessible text or graphic, else justButton. Theircontrolargument is that tag (#3or3) or the text of the label next to the control (Size:);qupath_selectwithoutcontroltries every list-like control in turn. - Click targets.qupath_clicktakestextas a#nfromqupath_describe, else finds the first labeled node whose text is exactlytext, passing over a plain label when a control has the same text (so inSearch [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 namequpath_describeshows 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 buttonsqupath_describetags 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_describeshows a collapsed one asTitledPane "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 controlsorcollapsed 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. Whenqupath_click,qupath_setorqupath_describefinds 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=Truecrops 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 atmax_sizeand a smaller image is never enlarged. Useformat="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 saysstill openingand the action result shows the prompt. -qupath_describewith 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 linecommand runningwhile 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 aqupath_run_groovyscript 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_openopens an image by path or URI,File>Open URI...is a normal dialog, and aqupath_run_groovyscript 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_groovyscripts getqupath(theQuPathGUI) and these helpers:fx { }runs a closure on the FX thread;window(titleSubstring)picks a window as thewindowargument does (nullfor the default);waitFor(titleSubstring, seconds)waits for a window to show and returns it;lookup(window, text)finds a control asqupath_clickdoes;click(node)andfire(findMenuItem("Help>License"))return at once, so a modal dialog they open doesn't block;typeInto(window, text[, field])sets thefield-th text field;describe(window)andview(x, y, downsample[, z, t])matchqupath_describeandqupath_view.snap(name)writes a PNG of every window, andsnapMain(name)of the main window, to thequpath.driver.outfolder (default: the JVM temp dir);quit()quits QuPath; no tool does, since quitting is the person's call. - 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