|
Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
|
Embeddable Model Context Protocol server for Qt applications. More...
Namespaces | |
| namespace | Gui |
| Window lookup, grabbing and geometry, dispatched to the registered GuiIntegration objects. | |
| namespace | JsonRpc |
| JSON-RPC 2.0 message helpers. | |
| namespace | ObjectTree |
| Process-wide view of the application's object tree, used by the introspection tools and by tools that target objects (clicks, screenshots). | |
| namespace | Schema |
| Builders for tool argument schemas (JSON Schema subsets that the server's argument check understands: type, enum, required). | |
| namespace | SignalCapture |
| Capturing the arguments of a signal emission. | |
Classes | |
| struct | Catalog |
| What dispatch needs to know about the registries, as an immutable snapshot. More... | |
| struct | Error |
| Why something failed. More... | |
| struct | Event |
| One entry of an event stream (see EventSource). More... | |
| class | EventBuffer |
| The event buffer and the event_wait waiters. More... | |
| struct | EventFilter |
| Filter shared by event_read and event_wait. More... | |
| class | EventSource |
| Base class for anything that produces a stream of events for MCP clients. More... | |
| class | EventSourcePrivate |
| EventSource's private part. More... | |
| class | Expected |
A value of type T, or an error of type E, as std::expected. More... | |
| class | Expected< void, E > |
Success, or an error of type E, as std::expected<void, E>. More... | |
| class | GuiIntegration |
| Hooks that let a UI toolkit built on QtGui (Qt Widgets, Qt Quick or your own) tell the GUI tools how to grab, hit-test and locate its objects. More... | |
| class | HomeLink |
| Shared state behind ToolCall handles. More... | |
| class | HttpTransport |
| MCP Streamable HTTP transport on a QTcpServer (httptransport.cpp). More... | |
| class | LocalTransport |
| Newline-delimited JSON-RPC over a QLocalServer (localtransport.cpp). More... | |
| class | LogEventSource |
| Captures Qt log output (qDebug, qInfo, qWarning, qCritical, qCDebug, ...) as events named "log". More... | |
| class | LogEventSourcePrivate |
| LogEventSource's private part. More... | |
| struct | OpenPopup |
| An open popup (menu, drop-down, tooltip) that belongs to an object, for layout_overflow. More... | |
| struct | OverflowFacts |
| What an integration knows about how one object may overflow, for layout_overflow. More... | |
| class | PrivatePtr |
| Owns a class's private part, like std::unique_ptr, but a const owner only gets a const pointer, like std::experimental::propagate_const (which MSVC lacks). More... | |
| class | QmlTemplateTrust |
| Lets the application ask its own user to trust a QML template. More... | |
| struct | ResourceContents |
| Contents returned by a ResourceReader: text or binary data. More... | |
| struct | ResourceDefinition |
| Describes a resource as advertised in resources/list. More... | |
| struct | ScreenRect |
| Where something is on screen: the window that shows it, and its rectangle there. More... | |
| class | Server |
| An embeddable Model Context Protocol server. More... | |
| struct | ServerLimits |
| Limits that protect the server against clients that misbehave or try to exhaust its resources. More... | |
| class | ServerPrivate |
| Implementation of Server: registries, sessions, dispatch and events. More... | |
| struct | Session |
| State of one MCP session (one local connection, or one HTTP Mcp-Session-Id). More... | |
| struct | SessionInfo |
| A connected client, as Server::sessions() lists it. More... | |
| struct | SessionPeer |
| What the operating system says about a client, as far as Sonde can learn it. More... | |
| class | SessionRequest |
| A client asking to start a session, for the application to approve or refuse (see Server::setSessionApproval()). More... | |
| class | SessionRequestPrivate |
| Shared state behind SessionRequest handles (design 0033). More... | |
| class | StallEventSource |
| Reports when the event loop of its thread was blocked, as events from source "stalls". More... | |
| class | StallEventSourcePrivate |
| StallEventSource's private part. More... | |
| class | ToolCall |
| Handle for an in-flight tools/call, used by asynchronous tools. More... | |
| class | ToolCallPrivate |
| The shared state of one tool call. More... | |
| struct | ToolDefinition |
| Describes a tool as advertised in tools/list. More... | |
| class | ToolResult |
| The result of a tools/call: content blocks, optional structured content, and an error flag. More... | |
| class | ToolResultData |
| ToolResult's implicitly shared contents. More... | |
| struct | TrustFile |
| One file that needs the user's trust before a template can open, and why. More... | |
| class | TrustRequest |
| A pending request for trust, from ui_open. More... | |
| class | TrustRequestPrivate |
| A request's shared state; TrustRequest is a handle to it. More... | |
| class | Unexpected |
| An error, to construct an Expected from, as std::unexpected. More... | |
Typedefs | |
| using | ReplyFunction = std::function<void(const QJsonObject &response)> |
| Delivers the response to one request. | |
| using | NotifyFunction = std::function<void(const QJsonObject &message)> |
| Delivers a server-to-client message on a session's stream. | |
| using | SessionPtr = std::shared_ptr<Session> |
| Sessions are shared between the registry and in-flight calls. | |
| using | SessionApproval = std::function<void(const SessionRequest &request)> |
Decides about a client asking to start a session: calls approve() or deny() on request, at once or later (after asking the user, say). | |
| using | ToolHandler = std::function<ToolResult(const QJsonObject &arguments)> |
| Handler of a synchronous tool: arguments in, result out. | |
| using | AsyncToolHandler = std::function<void(const ToolCall &call)> |
| Handler of an asynchronous tool; answer via ToolCall::finish(). | |
| using | ResourceReader = std::function<ResourceContents(const QString &uri)> |
| Produces a resource's contents when a client reads it. | |
| using | TrustApproval = std::function<void(const TrustRequest &request)> |
Decides about a request for trust: calls grant() or deny() on request, at once or later (after asking the user, say). | |
Enumerations | |
| enum class | ErrorKind { Failed , NotHandled } |
| What kind of error an Error is. More... | |
| enum class | JsonType { String , Integer , Number , Boolean , Array , Object } |
| The JSON Schema types a property may have. More... | |
| enum class | ServerThreading { ServerThread = 0 , WorkerThread = 1 } |
| Which threads the server uses (see Server's constructors). More... | |
| enum class | StackSampling { Off = 0 , DuringStalls = 1 } |
| Whether stall events carry samples of the blocked thread's stack (see Server::setStackSampling(), design 0016). More... | |
| enum class | LogLevel { Debug , Info , Notice , Warning , Error , Critical , Alert , Emergency } |
| MCP (RFC 5424) log levels, from lowest to highest severity. More... | |
| enum class | ScrollToCell { No , Yes } |
| Whether cellGeometry() may scroll the view to show the cell. More... | |
| enum class | TrustScope { Everywhere , ThisCheckout } |
| Where a grant of trust applies. More... | |
Functions | |
| static const QStringList & | supportedProtocolVersions () |
| Protocol versions this server speaks, newest first. | |
| static QString | requestKey (const QJsonValue &id) |
| A JSON-RPC id serialized for use as a hash key. | |
| static bool | isWholeNumber (double d) |
Whether d is a whole number. | |
| static bool | hasSchemaType (const QJsonValue &v, const QString &type) |
Whether v is a JSON value of JSON Schema type type. | |
| static QString | unknownArgument (const QJsonObject &schema, const QJsonObject &args) |
| The first argument the schema doesn't list, as an error message, or an empty string. | |
| static QString | checkArgument (const QString &name, const QJsonValue &v, const QJsonObject &prop) |
| Checks one argument against its property schema (type and enum). | |
| static QString | validateArguments (const QJsonObject &schema, const QJsonObject &args) |
| Minimal JSON Schema check: unknown arguments, required properties, and the type and enum of each argument. | |
| static QString | resourceUriFor (const QString &sourceName) |
| The events:// resource URI of a source. | |
| const char * | version () |
| The version of the Sonde library linked, e.g. | |
| QString | instanceKeyFor (const QString &path) |
The instance key of the executable at path. | |
| QString | instanceKey () |
| This build's instance key: three words, such as amber-falcon-tide. | |
| void | installIntrospectionTools (Server &server) |
Registers the QObject introspection tools on server. | |
| QString | jsonText (const QJsonValue &value) |
value as compact JSON text, e.g. "abc", 42 or {"x":1}. | |
| void | installSignalTraceTools (Server &server, EventSource *events) |
Registers signal_trace_start and signal_trace_stop, which report to events. | |
| void | installSignalTools (Server &server) |
Registers signal_watch and signal_unwatch on server, and adds the "signals" event source they report to. | |
| bool | operator== (const Error &a, const Error &b) |
Whether a and b are the same error: the same kind and message. | |
| bool | operator!= (const Error &a, const Error &b) |
Whether a and b are different errors. | |
| template<typename E> | |
| Unexpected (E) -> Unexpected< E > | |
| Deduces the error type: Unexpected(Error{ ... }). | |
| Unexpected< Error > | failure (QString message) |
A failure with message, to return as an Expected<T>. | |
| Unexpected< Error > | notHandled () |
| "Not handled, ask the next integration", for GuiIntegration hooks to return. | |
| template<typename T, typename E, typename T2, typename E2> | |
| bool | operator== (const Expected< T, E > &a, const Expected< T2, E2 > &b) |
Whether a and b hold equal values, or equal errors. | |
| template<typename T, typename E, typename T2, typename E2> | |
| bool | operator!= (const Expected< T, E > &a, const Expected< T2, E2 > &b) |
Whether a and b differ. | |
| template<typename T, typename E, typename G> | |
| bool | operator== (const Expected< T, E > &e, const Unexpected< G > &u) |
Whether e holds an error equal to u's. | |
| template<typename T, typename E, typename G> | |
| bool | operator== (const Unexpected< G > &u, const Expected< T, E > &e) |
Whether e holds an error equal to u's. | |
| template<typename T, typename E, typename G> | |
| bool | operator!= (const Expected< T, E > &e, const Unexpected< G > &u) |
Whether e doesn't hold an error equal to u's. | |
| template<typename T, typename E, typename G> | |
| bool | operator!= (const Unexpected< G > &u, const Expected< T, E > &e) |
Whether e doesn't hold an error equal to u's. | |
| template<typename T, typename E, typename U, std::enable_if_t< Detail::isPlainValue< U > &&!std::is_void_v< T >, int > = 0> | |
| bool | operator== (const Expected< T, E > &e, const U &value) |
Whether e holds a value equal to value. | |
| template<typename T, typename E, typename U, std::enable_if_t< Detail::isPlainValue< U > &&!std::is_void_v< T >, int > = 0> | |
| bool | operator== (const U &value, const Expected< T, E > &e) |
Whether e holds a value equal to value. | |
| template<typename T, typename E, typename U, std::enable_if_t< Detail::isPlainValue< U > &&!std::is_void_v< T >, int > = 0> | |
| bool | operator!= (const Expected< T, E > &e, const U &value) |
Whether e doesn't hold a value equal to value. | |
| template<typename T, typename E, typename U, std::enable_if_t< Detail::isPlainValue< U > &&!std::is_void_v< T >, int > = 0> | |
| bool | operator!= (const U &value, const Expected< T, E > &e) |
Whether e doesn't hold a value equal to value. | |
| void | installStateTools (Server &server) |
Registers state_wait, state_snapshot and state_diff on server. | |
| QString | jsonTypeName (JsonType type) |
The JSON Schema name of type, such as "string". | |
| QString | logLevelName (LogLevel level) |
The MCP wire name of level, e.g. "warning". | |
| std::optional< LogLevel > | logLevelFromName (QStringView name) |
| Parses an MCP level name (case-insensitive). | |
| QStringList | logLevelNames () |
| All level names, lowest severity first. | |
| void | installActionTools (Server &server) |
| Registers action_list: the application's QActions (and Qt Quick Controls Actions) with their menu paths, shortcuts and state. | |
| void | installInputTools (Server &server) |
| Registers input_click, input_move, input_drag, input_scroll, input_keys and input_text. | |
| void | installModelTools (Server &server) |
| Registers model_read and model_locate: the data in item models (through their views), and where a cell is on screen. | |
| void | installLayoutOverflow (Server &server) |
| Registers layout_overflow. | |
| void | installWindowTools (Server &server) |
| Registers app_info, window_list, window_resize, screenshot, object_at, layout_explain and layout_overflow. | |
| void | installStandardTools (Server &server) |
| Registers everything above, the QObject introspection tools, a LogEventSource that feeds Qt log output to the events tools, and a StallEventSource that reports when the main thread was blocked. | |
| void | installQmlBindingTool (Server &server) |
Registers qml_binding on server. | |
| void | installQmlEvalTool (Server &server) |
Registers qml_eval on server. | |
| QmlTemplateTrust * | installQmlTools (Server &server) |
| Registers qml_eval, qml_binding and the QML window tools (installQmlWindowTools()). | |
| Expected< void > | addTemplateLibrary (const QString &name, const QString &resourcePath) |
Registers a library of templates compiled into the application, under name, from the Qt resource directory resourcePath (such as ":/myapp/instruments"). | |
| QmlTemplateTrust * | installQmlWindowTools (Server &server) |
Registers ui_open, ui_close and the template library tools (ui_template_list, ui_template_save, ui_template_delete) on server. | |
| void | installQuickGuiIntegration () |
| Registers the GUI integration for QQuickWindow and QQuickItem (screenshots, item geometry, hit-testing, the visual item tree), without QML debugging. | |
| bool | qmlEngineExists () |
| Whether a QML engine exists that installQuickIntegration() can find: a child of the application object, or the engine of a Qt Quick window's QML items. | |
| void | installQuickIntegration () |
| Teaches the GUI tools about Qt Quick. | |
| void | installWidgetsIntegration () |
| Teaches the GUI tools about Qt Widgets. | |
Variables | |
| static constexpr int | kDefaultReadLimit = 100 |
| Default number of events returned by event_read. | |
| static constexpr int | kMaxReadLimit = 2000 |
| Upper bound for the limit argument. | |
| static constexpr int | kDefaultWaitMs = 10000 |
| Default event_wait timeout. | |
| static constexpr int | kMaxWaitMs = 300000 |
| Upper bound for the event_wait timeout. | |
| static constexpr int | kRefusedLingerMs = 200 |
| How long a refused connection stays open after its 503, so the client can read it. | |
| constexpr qint64 | kHeartbeatMs = 100 |
| Interval of the heartbeat on the server's thread (WorkerThread mode). | |
| constexpr qint64 | kRespondingMs = 250 |
| app_status calls the main thread responding while its heartbeat is at most this late (the default threshold of the stalls source too). | |
| constexpr int | kRecentStalls = 3 |
| How many recent stall events app_status shows. | |
| constexpr std::array< const char *, 8 > | kLevelNames |
| Wire names of the log levels, indexed by LogLevel. | |
Embeddable Model Context Protocol server for Qt applications.
|
strong |
What kind of error an Error is.
| Enumerator | |
|---|---|
| Failed | It failed; Error::message says why. |
| NotHandled | A GuiIntegration hook doesn't handle this object: ask the next integration. Only hooks return it; the Sonde::Gui functions that ask them never do. |
|
strong |
The JSON Schema types a property may have.
| Enumerator | |
|---|---|
| String | "string" |
| Integer | "integer" |
| Number | "number" |
| Boolean | "boolean" |
| Array | "array" |
| Object | "object" |
|
strong |
MCP (RFC 5424) log levels, from lowest to highest severity.
| Enumerator | |
|---|---|
| Debug | Detailed debugging information. |
| Info | General informational messages. |
| Notice | Normal but significant events. |
| Warning | Warning conditions. |
| Error | Error conditions. |
| Critical | Critical conditions. |
| Alert | Action must be taken immediately. |
| Emergency | The system is unusable. |
|
strong |
|
strong |
Which threads the server uses (see Server's constructors).
|
strong |
Whether stall events carry samples of the blocked thread's stack (see Server::setStackSampling(), design 0016).
| Enumerator | |
|---|---|
| Off | No stack samples. |
| DuringStalls | While the server listens, a thread of Sonde's samples the stack of a thread that a StallEventSource watches, while it is blocked: the default. |
|
strong |
| Expected< void > Sonde::addTemplateLibrary | ( | const QString & | name, |
| const QString & | resourcePath ) |
Registers a library of templates compiled into the application, under name, from the Qt resource directory resourcePath (such as ":/myapp/instruments").
Templates in it are opened by name with ui_open and listed by ui_template_list, like the project and user libraries' (design 0034). Being part of the application, they need no trust, and they can't be changed or deleted through the tools. Its components/ folder is what its templates import with import "components", and components/values/<Type>.qml draws values of that type in the instruments.
Libraries are searched in this order: the project library, the user library, the application's libraries in the order they were added, then Sonde's own (sonde, the instruments). A template hides one of the same name further down.
Call it on the GUI thread. A resourcePath that isn't a resource directory (a directory on disk would skip trust), or a name that is taken, reserved ("project", "user", "sonde") or not lower-case letters, digits and '-', is refused, with qCritical().
|
static |
Checks one argument against its property schema (type and enum).
| void Sonde::installInputTools | ( | Server & | server | ) |
Registers input_click, input_move, input_drag, input_scroll, input_keys and input_text.
Input goes through the QPA entry points QtTest uses, so it gets normal QGuiApplication processing (double clicks, enter/leave, popups, modality, shortcuts).
| void Sonde::installIntrospectionTools | ( | Server & | server | ) |
Registers the QObject introspection tools on server.
Objects are addressed with ObjectTree specs.
| void Sonde::installQmlBindingTool | ( | Server & | server | ) |
Registers qml_binding on server.
qml_binding says which properties of an object are bound now, so an agent can find a binding that an assignment broke. Properties declared in QML are covered through the QML engine debug service, which installQuickIntegration() turns on (design 0022); C++ properties declared BINDABLE through QBindable. It only reads.
| void Sonde::installQmlEvalTool | ( | Server & | server | ) |
Registers qml_eval on server.
qml_eval evaluates a JavaScript expression in the QML context of an object declared in QML, as a binding on it would: its ids, properties, context properties and imports are in scope. A watchdog interrupts expressions that run longer than the time limit (QJSEngine::setInterrupted()), so a runaway loop doesn't freeze the application. Like object_invoke, it runs client code: install it in debug builds only.
| QmlTemplateTrust * Sonde::installQmlTools | ( | Server & | server | ) |
Registers qml_eval, qml_binding and the QML window tools (installQmlWindowTools()).
| QmlTemplateTrust * Sonde::installQmlWindowTools | ( | Server & | server | ) |
Registers ui_open, ui_close and the template library tools (ui_template_list, ui_template_save, ui_template_delete) on server.
ui_open lets a client (typically an AI agent) open a window of its own inside the application, written in QML, to visualize what is happening: application objects named by object spec are passed in as context properties, so the QML binds to their live properties and signals, and a sonde object re-emits Sonde's events as a QML signal. ui_close closes such a window. The windows are ordinary top-level windows, so the other tools (screenshot, object_tree, ...) work on them too.
The QML runs in an engine of its own, so the windows' lifetime doesn't depend on the application's engines. Works in Qt Widgets applications as well, as long as they link Sonde::Quick: it registers the Qt Quick part of installQuickIntegration() (item geometry, hit-testing, the item tree) so the other tools work on the windows' items, but not QML debugging.
Windows can also be saved as named templates, in the project library (.sonde/qml/ in the checkout) or the user library (~/.config/sonde/qml/), and opened again by name. A template opens only if the user trusts its files' content: see QmlTemplateTrust and design 0023.
This executes client-supplied code with the application's privileges, like object_invoke: install it in debug builds only.
server). Calling it again returns the same one. | void Sonde::installQuickGuiIntegration | ( | ) |
Registers the GUI integration for QQuickWindow and QQuickItem (screenshots, item geometry, hit-testing, the visual item tree), without QML debugging.
installQmlWindowTools() calls it, so the agent's QML windows work with the input and window tools in a Qt Widgets application too. Safe to call more than once.
| void Sonde::installQuickIntegration | ( | ) |
Teaches the GUI tools about Qt Quick.
Adds QQuickWindow::grabWindow() screenshots, item geometry for object targeting, item hit-testing, and the visual item tree (QQuickItem::childItems()) in the object tree. Safe to call more than once.
It also turns on QML debugging, with only the engine debug service, connected to a local socket Sonde opens itself: that is how qml_binding sees which properties declared in QML are bound. Call it after creating the application object and before creating the first QML engine. It is off when SONDE_QML_DEBUG is 0, and when the application was started with -qmljsdebugger (Qt Creator's QML debugger); app_info's "qmlBindingInspection" says whether it is on, and why not. It also has Sonde's log source capture "qt.qml.binding.removal" (bindings broken by assignments) without changing the application's own log output (see LogEventSource::captureCategory()).
| void Sonde::installSignalTools | ( | Server & | server | ) |
Registers signal_watch and signal_unwatch on server, and adds the "signals" event source they report to.
Called by installIntrospectionTools().
signal_watch connects to a signal of an object and turns every emission into an event, with the arguments converted to JSON, so a client can check that an action emitted the signals it should (with event_wait). Watches last until signal_unwatch or until the object is destroyed; at most 64 are active at once. Only objects in the server's thread can be watched.
| void Sonde::installSignalTraceTools | ( | Server & | server, |
| EventSource * | events ) |
Registers signal_trace_start and signal_trace_stop, which report to events.
Called by installSignalTools().
| void Sonde::installStandardTools | ( | Server & | server | ) |
Registers everything above, the QObject introspection tools, a LogEventSource that feeds Qt log output to the events tools, and a StallEventSource that reports when the main thread was blocked.
With the environment variable SONDE_NON_NATIVE_DIALOGS=1, it also sets Qt::AA_DontUseNativeDialogs, so file and colour dialogs are Qt's own, which the tools can see and drive, instead of the platform's.
Also call installWidgetsIntegration() and/or installQuickIntegration() if the application uses those modules. Safe to call more than once.
| void Sonde::installStateTools | ( | Server & | server | ) |
Registers state_wait, state_snapshot and state_diff on server.
Called by installIntrospectionTools().
state_wait waits (asynchronously, checking every 50 ms) for a property value, or for an object to appear or go. state_snapshot records the readable properties of every object in the tree, and state_diff lists what changed since: new and destroyed objects, and changed values.
| void Sonde::installWidgetsIntegration | ( | ) |
Teaches the GUI tools about Qt Widgets.
Adds QWidget::grab() screenshots (which work for occluded windows), widget geometry for object targeting, QWidget::childAt() hit-testing, and top-level widgets as object-tree roots. Safe to call more than once.
| QString Sonde::instanceKey | ( | ) |
This build's instance key: three words, such as amber-falcon-tide.
The key is the instanceKeyFor() of the application's executable, so each checkout, which builds its own executable, gets its own key, and a copy started from an IDE gets the same key as one started by sonde. Server::listenFromEnvironment() puts it in place of {instance} in SONDE_LOCAL and SONDE_HTTP. For development builds only: a release build shouldn't read Sonde settings from the environment at all.
| QString Sonde::instanceKeyFor | ( | const QString & | path | ) |
The instance key of the executable at path.
The first 33 bits of the SHA-1 of path, in UTF-8, most significant first, as three 11-bit indexes into the BIP39 English word list, joined by hyphens. The sonde command uses the same code. path is used as given: instanceKey() passes the canonical path.
|
static |
Whether d is a whole number.
Checked without converting to an integer type, which would be undefined behaviour for values out of its range.
| std::optional< LogLevel > Sonde::logLevelFromName | ( | QStringView | name | ) |
Parses an MCP level name (case-insensitive).
| bool Sonde::qmlEngineExists | ( | ) |
Whether a QML engine exists that installQuickIntegration() can find: a child of the application object, or the engine of a Qt Quick window's QML items.
(An engine with no parent and no window yet can't be found.)
|
static |
The first argument the schema doesn't list, as an error message, or an empty string.
Unlike JSON Schema, an argument the schema's "properties" doesn't list is an error unless "additionalProperties" allows it (true or a schema): a misspelt argument would otherwise be dropped without a word. A schema with no "properties" accepts anything.
|
static |
Minimal JSON Schema check: unknown arguments, required properties, and the type and enum of each argument.
Enough to give the model a useful error before a handler sees bad input.
| const char * Sonde::version | ( | ) |
The version of the Sonde library linked, e.g.
"0.9.0"; SONDE_VERSION_STR is the version of the headers compiled against.
|
constexpr |
Wire names of the log levels, indexed by LogLevel.