Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
anonymous_namespace{main.cpp}::HttpClient Class Reference

A client over Streamable HTTP: a session, requests as POSTs, an optional SSE stream. More...

Inheritance diagram for anonymous_namespace{main.cpp}::HttpClient:
anonymous_namespace{main.cpp}::Client

Public Member Functions

 HttpClient (quint16 port, Verdict *verdict, QElapsedTimer *clock)
 Starts a session with the server on 127.0.0.1:port.
bool connected () const override
 Whether it can still send.
QString kind () const override
 The transport's name, for the log.
QByteArray session () const
 The session id, so the run can end a session it abandoned.
void disconnectNow () override
 Abandons every request in flight (as a client that goes away does); the session stays, until ended.
void endSession ()
 Ends the session with DELETE, as a polite client does.
bool ended () const
 Whether endSession() was called.
bool closed () const
 Whether the server answered the DELETE with 200.
void toggleStream ()
 Opens the SSE notification stream, or closes it if open.
Public Member Functions inherited from anonymous_namespace{main.cpp}::Client
 Client (Verdict *verdict, QElapsedTimer *clock)
 Reports violations to verdict, timing requests with clock.
int send (const QString &method, const QJsonObject &params={ }, const QString &tool={ })
 Sends a request; returns its id.
void notify (const QString &method, const QJsonObject &params={ })
 Sends a notification.
void cancel (int id)
 Cancels request id, if it is still pending.
QList< int > pendingIds () const
 Ids still waiting for an answer.
void checkTimeouts () const
 Fails the verdict for requests unanswered past the timeout (cancelled ones aside).
bool settled () const
 Whether everything not cancelled has been answered.
QStringList takeTexts ()
 The texts of the last results, for harvesting ids and window titles.

Protected Member Functions

void transmit (const QJsonObject &message, int id) override
 Sends message; id is its request id, or -1 for a notification.
Protected Member Functions inherited from anonymous_namespace{main.cpp}::Client
void fail (const QString &what) const
 Records a violation.
void forget (int id)
 Forgets request id: its answer will never come, and none is owed.
void handle (const QByteArray &bytes)
 Checks one message from the server.

Private Member Functions

QNetworkRequest baseRequest () const
 A request with the session's headers.
QNetworkReply * post (const QJsonObject &message)
 POSTs message.
void finished (QNetworkReply *reply, int id)
 Checks the answer to request id (-1: a notification).
void readStream ()
 Checks every event on the stream: each must be a JSON-RPC notification.
void closeStream ()
 Closes the SSE stream, if open.

Private Attributes

QNetworkAccessManager m_network
 HTTP.
QString m_url
 The endpoint.
QByteArray m_session
 Mcp-Session-Id.
QList< QPointer< QNetworkReply > > m_inFlight
 Requests awaiting their reply.
QPointer< QNetworkReply > m_stream
 The SSE stream, while open.
QByteArray m_streamBuffer
 Unread stream input.
bool m_dropped = false
 Whether disconnectNow() was called.
bool m_ended = false
 Whether endSession() was called.
std::shared_ptr< bool > m_closed = std::make_shared<bool>(false)
 See closed().

Additional Inherited Members

Public Attributes inherited from anonymous_namespace{main.cpp}::Client
QJsonArray tools
 The last tools/list result.
int results = 0
 tools/call results received.
int toolErrors = 0
 Of those, the ones with isError.
Static Protected Member Functions inherited from anonymous_namespace{main.cpp}::Client
static QJsonObject initializeParams ()
 The initialize request's parameters.

Detailed Description

A client over Streamable HTTP: a session, requests as POSTs, an optional SSE stream.

Member Function Documentation

◆ closed()

bool anonymous_namespace{main.cpp}::HttpClient::closed ( ) const
inline

Whether the server answered the DELETE with 200.

Until then the session may still be open: a DELETE still in flight goes when this client and its network manager go.

◆ connected()

bool anonymous_namespace{main.cpp}::HttpClient::connected ( ) const
inlineoverridevirtual

Whether it can still send.

Implements anonymous_namespace{main.cpp}::Client.

◆ disconnectNow()

void anonymous_namespace{main.cpp}::HttpClient::disconnectNow ( )
inlineoverridevirtual

Abandons every request in flight (as a client that goes away does); the session stays, until ended.

Reimplemented from anonymous_namespace{main.cpp}::Client.

◆ kind()

QString anonymous_namespace{main.cpp}::HttpClient::kind ( ) const
inlineoverridevirtual

The transport's name, for the log.

Implements anonymous_namespace{main.cpp}::Client.

◆ transmit()

void anonymous_namespace{main.cpp}::HttpClient::transmit ( const QJsonObject & message,
int id )
inlineoverrideprotectedvirtual

Sends message; id is its request id, or -1 for a notification.

Implements anonymous_namespace{main.cpp}::Client.


The documentation for this class was generated from the following file:
  • tests/chaos/main.cpp