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

Handle for an in-flight tools/call, used by asynchronous tools. More...

#include <types.h>

Public Member Functions

 ToolCall ()=default
 An invalid handle; every operation on it is a no-op.
bool isValid () const
 Whether the handle refers to a call.
QString toolName () const
 Name of the tool being called.
QJsonObject arguments () const
 The call's arguments (already checked against the input schema).
QString sessionId () const
 Id of the MCP session that made the call.
bool isFinished () const
 Whether the call has been answered or cancelled (true for invalid handles).
bool isCancelled () const
 Whether the client cancelled the call or went away.
void finish (const ToolResult &result) const
 Answers the call. Later calls are ignored.
void fail (const QString &message) const
 Answers the call with ToolResult::error(message).
void reportProgress (double progress, double total=-1, const QString &message={ }) const
 Sends notifications/progress if the client asked for progress.
void onCancelled (std::function< void()> callback) const
 Registers callback to run when the client cancels the request or disconnects.
QObject * context () const
 A QObject that lives exactly as long as the call is in flight.

Private Member Functions

 ToolCall (std::shared_ptr< ToolCallPrivate > state)
 Wraps the shared call state (created by the server).

Private Attributes

std::shared_ptr< ToolCallPrivate > d
 Shared call state.

Friends

class ServerPrivate

Detailed Description

Handle for an in-flight tools/call, used by asynchronous tools.

The handle is cheap to copy; all copies refer to the same call. The call is answered once finish() (or fail()) is called on any copy. If every copy is destroyed without finishing, the client receives an error result, so a forgotten call never hangs the client.

Thread safety: every function may be called from any thread, and copies may be used and destroyed on different threads. The reply and progress notifications are always sent from the server's thread (posted there when you call from another one), and onCancelled() callbacks run on the server's thread. context() lives on the server's thread too, so only use it as a parent or connection context there. If the server is destroyed first, finish() and reportProgress() do nothing.

Member Function Documentation

◆ context()

QObject * Sonde::ToolCall::context ( ) const

A QObject that lives exactly as long as the call is in flight.

Use it as the parent of timers or as the context object of connections so they are cleaned up automatically when the call ends.

◆ onCancelled()

void Sonde::ToolCall::onCancelled ( std::function< void()> callback) const

Registers callback to run when the client cancels the request or disconnects.

Ignored once the call has finished.

◆ reportProgress()

void Sonde::ToolCall::reportProgress ( double progress,
double total = -1,
const QString & message = { } ) const

Sends notifications/progress if the client asked for progress.

Parameters
progressProgress so far.
totalTotal amount of work, or a negative value if unknown.
messageOptional human-readable status.

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