Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
SondeTest::LocalClient Class Reference

Minimal MCP client speaking newline-delimited JSON over QLocalSocket. More...

#include <testsupport.h>

Public Member Functions

 LocalClient (const QString &name)
 Connects to the local server name; check isConnected().
bool isConnected () const
 Whether the socket connected.
QJsonObject request (const QString &method, const QJsonObject &params={ }, int timeoutMs=5000)
 Sends a request and waits for its response.
int sendRequest (const QString &method, const QJsonObject &params={ })
 Sends a request without waiting; returns the id used.
QJsonObject waitForResponse (int id, int timeoutMs=5000)
 Waits for the response to request id.
void notify (const QString &method, const QJsonObject &params={ })
 Sends a notification (no id).
void sendRaw (const QByteArray &data)
 Writes raw bytes to the socket.
QJsonObject initialize (const QString &protocolVersion=QStringLiteral("2025-06-18"))
 Performs initialize + notifications/initialized.
QJsonObject callTool (const QString &name, const QJsonObject &arguments={ }, int timeoutMs=5000)
 Calls a tool and returns its result object (empty on JSON-RPC error).
QString callToolText (const QString &name, const QJsonObject &arguments={ }, int timeoutMs=5000)
 Calls a tool and returns the concatenated text of its result.
bool waitForNotification (const QString &method, int timeoutMs=3000, qsizetype from=0)
 Waits until a notification with method arrives (counting from from).
const QList< QJsonObject > & notifications () const
 All notifications received so far.
const QList< QJsonArray > & batches () const
 Responses that arrived as JSON arrays (legacy batches).
QLocalSocket & socket ()
 The underlying socket.

Private Member Functions

void onReadyRead ()
 Parses complete lines from the read buffer.

Private Attributes

QLocalSocket m_socket
 Connection to the server.
QByteArray m_buffer
 Received bytes not yet split into lines.
QHash< int, QJsonObject > m_responses
 Responses not yet collected, by id.
QList< QJsonObject > m_notifications
 Messages without an id.
QList< QJsonArray > m_batches
 Array responses.
int m_nextId = 1
 Next request id.

Detailed Description

Minimal MCP client speaking newline-delimited JSON over QLocalSocket.

Responses are matched by id; everything without an id (notifications) is collected in notifications().

Member Function Documentation

◆ request()

QJsonObject SondeTest::LocalClient::request ( const QString & method,
const QJsonObject & params = { },
int timeoutMs = 5000 )

Sends a request and waits for its response.

Returns
The full JSON-RPC response, or an empty object on timeout.

The documentation for this class was generated from the following files: