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

An MCP client of the server at a URL, whose session is remembered between runs in a per-user directory, so consecutive commands share it (sequence numbers, log levels). More...

#include <client.h>

Classes

struct  Answer
 An answer to a POST: its status, session and body (JSON, text or nothing). More...

Public Member Functions

 Client (QString url, QString token, std::optional< QString > expectedExecutable)
 A client of url, sending token if it isn't empty.
QString url () const
 The server's URL.
void setTimeoutMs (int ms)
 Gives up on an answer after ms (default: a little over five minutes, for tool calls that wait); shell completion uses a second (design 0036).
QString sessionFile () const
 The file the session's id is kept in (its directory created).
QJsonObject request (const QString &method, const QJsonObject &params)
 Sends JSON-RPC method with params in the remembered session, or a new one; fails on an error.

Private Member Functions

Answer post (const QJsonObject &message, const QByteArray &session={ })
 POSTs message in session (if any); fails if there was no answer, or the server wants a token.
QByteArray newSession ()
 Starts a session, and remembers it.
void checkExecutable (const QByteArray &session)
 Fails if the server is another build's copy than the expected one.

Private Attributes

QString m_url
 See url().
QString m_token
 The bearer token, or empty.
int m_timeoutMs = 330'000
 See setTimeoutMs().
std::optional< QString > m_expectedExecutable
 The executable the server must be.
Http m_http
 Makes the requests.

Detailed Description

An MCP client of the server at a URL, whose session is remembered between runs in a per-user directory, so consecutive commands share it (sequence numbers, log levels).

Constructor & Destructor Documentation

◆ Client()

Sonde::Cli::Client::Client ( QString url,
QString token,
std::optional< QString > expectedExecutable )

A client of url, sending token if it isn't empty.

With expectedExecutable, a new session first checks that the server is that executable's.

Member Function Documentation

◆ request()

QJsonObject Sonde::Cli::Client::request ( const QString & method,
const QJsonObject & params )

Sends JSON-RPC method with params in the remembered session, or a new one; fails on an error.

Returns
The result.

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