Sonde

CI Latest release Docs License: MIT Qt 6.8+ C++17

A cartoon sailor on a small ship lowers a sounding line into the sea; far below, a grinning mass of glowing eyes and tentacles waits for the weight.

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:

See it in action

Each walkthrough is a real session against an example app in this repository, with real tool output:

And two to build on:

examples/ lists every example, including the smallest Widgets and Qt Quick apps with Sonde in them.

A bar chart the agent drew inside the running app, showing how old each network packet was when the app handled it

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/:

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

Security

This is a remote-control port into your process: object_set and object_invoke can do anything your app can do. By default:

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

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.

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.