Sonde
Sonde for Qt is an embeddable Model Context Protocol server for Qt 6.8+ applications. Link it into your app, and an AI agent (or any MCP client) can work with the running program the way you would in a debugger: look at what is really there, poke at it, and check what happened. (A sonde is a probe sent into an environment to measure it. This project was called QtMcp until 0.5; see design 0026.)
Why
Without it, an agent working on a Qt app can read the source and look at screenshots, and has to guess the rest. With Sonde, it can ask the app:
- It sees objects, not pixels. The QObject, widget and Quick item trees, property values, QML bindings, layouts and the data in item models, all read from the live process. A widget that is invisible on screen but catches every click shows up as what it is.
- It finds out what really happened. Clicks and key presses report which
object received them, and say so when the target didn’t.
state_diffshows what an action changed,signal_trace_startwhich signals fired, andevent_waitwaits for the app’s own log line. The agent checks its work instead of assuming it. - It can try a fix before editing code. Setting properties and calling slots in the running app tests a theory in seconds.
- It can build its own tools inside your app.
ui_openopens a QML window bound to live objects (a plot, a probe, a draft of a new screen), and hot-reloads it as the agent edits. - It takes a few lines to add. It stays switched off unless a
SONDE_*environment variable is set, and the core needs only QtCore and QtNetwork.
See it in action
Each walkthrough is a real session against an example app in this repository, with real tool output:
- The button that stopped working: diagnosing a UI bug that is hard to find by reading code or looking at the screen, step by step.
- The alarm that wouldn’t clear: the agent draws its own chart inside the app to find a network timing bug.
- From widgets to QML: the agent ports a Qt Widgets window to Qt Quick while the app runs, hot-reloading as it goes.
And two to build on:
- An agent that triages bug tickets: a loop that claims tickets over MCP, reproduces each in the running app, cuts the steps down to the ones that matter, records them with screenshots, and spends a set time trying a fix. In a disposable container, since tickets come from outsiders (the code).
- An MCP interface in a shipped app: a note-taking app that lets the user’s own AI assistant use it, without the debug tools. It has a few narrow tools of its own, is off until the user turns it on, asks before each client gets in, and confirms before deleting anything (release.md says why).
examples/ lists every example, including the smallest Widgets and Qt Quick apps with Sonde in them.

A window the agent wrote in QML during the packet-lag walkthrough: how old each packet was when the app handled it. Packets that should take a millisecond take 8 to 14 seconds, and the delay grows after each pressure spike (red).
Drop it in
add_subdirectory(sonde) # or FetchContent, or an installed Sonde:
# find_package(Sonde 1.1 REQUIRED COMPONENTS Widgets)
target_link_libraries(myapp PRIVATE Sonde::Widgets) # or Sonde::Quick / Sonde::Gui / Sonde::Core
#include <sonde/server.h>
#include <sonde/guitools.h>
#include <sonde/widgetsintegration.h> // or quickintegration.h
Sonde::Server mcp;
Sonde::installWidgetsIntegration(); // or installQuickIntegration()
Sonde::installStandardTools(mcp); // log events + introspection + window + input tools
mcp.listenFromEnvironment(); // does nothing unless SONDE_* variables are set
listenFromEnvironment() keeps the server switched off in normal runs:
| Variable | Meaning |
|---|---|
SONDE_HTTP |
8765 or 127.0.0.1:8765: Streamable HTTP endpoint at /mcp |
SONDE_LOCAL |
local socket name, e.g. myapp-mcp |
SONDE_TOKEN |
if set, HTTP requests need Authorization: Bearer <token> |
The guide lists every variable Sonde reads.
You can also call listenHttp() / listenLocal() directly.
Connect a client
Claude Code, over HTTP:
SONDE_HTTP=8765 ./myapp &
claude mcp add --transport http myapp http://127.0.0.1:8765/mcp
Any stdio client, over the local socket (--wait lets the client start before the app;
--wait-timeout <seconds> gives up after a while; --reconnect also keeps the
connection working when the app restarts):
SONDE_LOCAL=myapp-mcp ./myapp &
claude mcp add myapp -- /path/to/sonde-bridge --reconnect myapp-mcp
To let an agent build, restart and check the app on its own, use sonde,
a small program built with Sonde at the top of your build directory
(build/sonde restart, build/sonde bridge): see
agent-loop.md.
Libraries
The core speaks JSON-RPC through QJsonDocument over QTcpServer (MCP
Streamable HTTP) and QLocalServer (newline-delimited JSON). The GUI tools
sit in separate libraries, so you link only what your app already uses.
| Target | Depends on | Provides |
|---|---|---|
Sonde::Core |
Core, Network | Server, transports, tool/resource API, event sources, LogEventSource, QObject introspection tools |
Sonde::Gui |
+ Gui | window listing, screenshots, mouse/keyboard injection |
Sonde::Widgets |
+ Widgets | QWidget::grab() screenshots, widget geometry and hit-testing |
Sonde::Quick |
+ Quick | QQuickWindow::grabWindow(), item geometry, the visual item tree |
sonde-bridge |
Core, Network | stdio ⇄ QLocalSocket, for stdio-only MCP clients |
sonde |
Core, Network | the command for agents and you: build, restart and stop the app, connect to it, call tools, trust QML templates. Built at <build>/sonde |
Documentation
This README is a quick overview. What changed in each release is in CHANGELOG.md; upgrading from 0.4 (QtMcp) is covered there (go through 0.5). From 1.0, code that builds with one 1.x release builds with every later one: Stability says what stays the same. The full guides live in notes/:
- Using the library
- How it works
- Letting an agent build, restart and check your app (with VS Code and CLion templates)
- Applications in Docker containers
- An agent that triages bug tickets
- An MCP interface in release builds
- Developing and testing and reviewing changes, for working on Sonde itself
Built-in tools
Tool names are <group>_<verb>. Each group comes from one install function, so
an application can leave out what it doesn’t use (see
design 0027).
| Group | Tools | What they do |
|---|---|---|
app |
app_info, app_status, app_stall_arm |
name, version, pid, Qt version, platform, screens, focus, which build this is; whether the main thread is responding (answers during a freeze in WorkerThread mode), and where it is stuck (stack samples); sampling an expected freeze closely |
window |
window_list, window_resize, window_screenshot |
top-level windows; resize one and wait for its layouts; a PNG/JPEG of a window or one widget/item, at logical resolution so image pixels are window coordinates |
object |
object_tree, object_at, object_inspect, object_set, object_invoke |
the QObject / widget / Quick item tree (naming the hidden subtrees it skips); hit-testing; properties, signals, slots and invokables; writing a property (enums by name, geometry as {x,y,width,height}, gadgets as an object of their properties); calling a slot or Q_INVOKABLE |
layout |
layout_explain, layout_overflow |
why a widget or item has its size and place (hints, policies, layouts, anchors, clipping, what covers it); what sticks out of a panel or window, and why |
model |
model_read, model_locate |
the data in tables, lists, trees and combo boxes (item models), and where a cell is on screen |
action |
action_list |
every QAction (and Quick Controls Action) with menu path, shortcut and state, closed menus included |
input |
input_click, input_move, input_drag, input_scroll, input_keys, input_text |
pointer and keyboard input at coordinates or on an object (QKeySequence syntax, shortcuts fire); each reports which objects actually received the event |
state |
state_wait, state_snapshot, state_diff |
wait for a property value or an object to appear or go; what an action changed |
signal |
signal_watch, signal_unwatch, signal_trace_start, signal_trace_stop |
record each emission of one signal as an event; record every signal a subtree emits while you act, and summarize what fired |
event |
event_read, event_wait |
read the event buffer (log, stalls, signals, your own sources), or wait for a matching event |
qml |
qml_eval, qml_binding |
evaluate JavaScript in a QML object’s context; which properties are bound now, to find a binding an assignment broke (Sonde::Quick) |
ui |
ui_open, ui_close, ui_template_list, ui_template_save, ui_template_delete |
a window of the agent’s own, written in QML and bound to live objects; saved as templates in the project or user library, opened by name once the user trusts them (Sonde::Quick, installQmlTools()) |
The ideas the tools share (object specs, windows and coordinates, input targeting) are explained once, in the server’s MCP instructions, rather than in every tool. All of it together costs an agent about 7,800 tokens per session.
Objects are addressed by specs: an @0x… id from object_tree, an
objectName or class name, Class#name, Class[prop=value] (for example
QPushButton[text=Save]; mnemonic & is ignored), or a /-separated path of
these.
Events from each EventSource also go out as MCP log notifications (filtered
by logging/setLevel) and as a subscribable resource, events://<source>.
LogEventSource installs a Qt message handler, chains to the previous one, and
follows your QLoggingCategory rules.
Extending
// Synchronous tool
Sonde::ToolDefinition def;
def.name = "document_stats";
def.description = "Word and page count of the open document";
def.inputSchema = Sonde::Schema::object({}); // <sonde/schema.h>; no arguments
mcp.addTool(def, [&](const QJsonObject &args) {
return Sonde::ToolResult::structured({{"words", doc.wordCount()}, {"pages", doc.pageCount()}});
});
// Asynchronous tool: answer whenever you like; call.context() lives until then.
mcp.addAsyncTool(renderDef, [&](const Sonde::ToolCall &call) {
connect(&renderer, &Renderer::finished, call.context(), [call](const QImage &img) {
call.finish(Sonde::ToolResult::image(toPng(img), "image/png"));
});
call.reportProgress(0, 100);
renderer.start(call.arguments());
});
// Your own event stream (emitEvent is thread-safe)
auto *net = new Sonde::EventSource("network", "requests to the API server");
mcp.addEventSource(net);
net->emitEvent(Sonde::LogLevel::Warning, "Request timed out", "api", {{"url", url}});
// Resources
mcp.addResource({"app://config", "config", {}, "Current settings", "application/json"},
[&](const QString &) { return Sonde::ResourceContents::fromText(configJson(), "application/json"); });
To support another UI toolkit built on QtGui (for example a custom scene
graph), implement Sonde::GuiIntegration and pass it to
Gui::registerIntegration(). To show non-QObject children in the object
tree, use ObjectTree::addChildrenProvider().
Protocol notes
- Negotiates MCP
2025-11-25,2025-06-18,2025-03-26and2024-11-05. The HTTP transport follows the 2025-03-26+ Streamable HTTP spec; older clients can use the local socket. - HTTP:
POST /mcpreturnsapplication/json.GET /mcpwithAccept: text/event-streamopens the notification stream.DELETE /mcpends the session. Sessions useMcp-Session-Idand expire after 30 minutes idle without a stream. - Supports tool
listChanged, resourcesubscribe/listChanged,logging/setLevel, progress notifications and cancellation. Input that fails the tool’s schema check (unknown arguments, required fields, types, enums) comes back as a tool error, so the model can correct itself. Unlike plain JSON Schema, an argument a schema’spropertiesdoesn’t list is refused unlessadditionalPropertiesistrueor a schema, so a misspelt argument isn’t silently dropped.
Security
This is a remote-control port into your process: object_set and
object_invoke can do anything your app can do. By default:
- HTTP binds to
127.0.0.1. Requests whoseOriginis not localhost are rejected, which guards against DNS rebinding from web pages. - The local socket only accepts the current user (
QLocalServer::UserAccessOption). SONDE_TOKENadds bearer-token auth, checked in constant time.ServerLimits(setLimits()) caps sessions, connections, request size, request time and concurrent tool calls.- The HTTP parser and JSON-RPC dispatch are fuzzed (
tests/fuzz/run.py).
Don’t ship the built-in tools in release builds: gate them behind a build
option. If you want an MCP interface in a release, register only your own
narrow tools on Sonde::Core, off by default. See
notes/guide/release.md for what to do and what not
to do.
Caveats
- Input goes through
qt_handleMouseEvent/qt_handleKeyEvent, the QtGui entry points QtTest uses. That gives real QGuiApplication processing: double-clicks, enter/leave, popups, modality, shortcuts. These functions are exported but not documented API. Wheel events use a plainQWheelEvent. - Native drag-and-drop (
QDrag::exec) blocks in a platform loop and can’t be driven by synthetic events. - Hit-testing in Qt Quick returns the topmost visible item, which can be a decoration such as a focus frame. Target by object spec when that matters.
- The screenshot fallback for windows no integration handles is
QScreen::grabWindow(), which may need screen-recording permission on macOS.
Development
mise install && mise run setup # pinned tools, configure build/, install the git hooks
mise run test # build, GoogleTest unit tests, end-to-end smoke test
mise run check # + formatting, clang-tidy, Doxygen, link check (= pre-push hook)
mise run format # Qt-style formatting (.clang-format)
Without mise: cmake -S . -B build -G Ninja, cmake --build build,
ctest --test-dir build, python3 tests/smoke_test.py build, and
python3 tools/check.py pre-push. The git hooks (.githooks/, installed by
mise run setup or python3 tools/check.py hooks) check formatting and run
the tests before each commit, and run everything before each push.
- Libraries are static by default so the server drops into an
application without extra files to ship. Set
BUILD_SHARED_LIBS=ONfor shared libraries. - Unit tests live in
tests/:sonde_core_tests(QtCore/QtNetwork only),sonde_gui_tests(Widgets and Quick, on theoffscreenplatform) andsonde_cli_tests(thesondecommand). They use GoogleTest, which is taken from an installed package if one is found and otherwise fetched (v1.17.0) with FetchContent, plus QtTest helpers. The tests drive the real transports in-process. - Coverage: configure with
-DSONDE_COVERAGE=ON(Clang) and runcmake --build <dir> --target coverage. It prints a per-file report for the libraries and writes an HTML report to<dir>/coverage/html. - clang-tidy uses
.clang-tidy: the bugprone, cert, clang-analyzer, concurrency, cppcoreguidelines, misc, modernize, performance, portability and readability groups. The few exclusions are documented there; most are checks that conflict with Qt idioms. - Doxygen uses
Doxyfile. Private and internal declarations are checked too. GoogleTest case bodies are exempt; test fixtures and helpers are not.
License
Sonde is released under the MIT License. Qt itself is licensed separately (LGPL, GPL or commercial); check that your use of Qt fits its license.