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

The result of a tools/call: content blocks, optional structured content, and an error flag. More...

#include <types.h>

Public Member Functions

 ToolResult ()
 An empty, successful result.
 ToolResult (const ToolResult &other)
 Shares other's contents (copied when either changes).
ToolResult & operator= (const ToolResult &other)
 Shares other's contents (copied when either changes).
 ~ToolResult ()
 Destroys the result.
ToolResult & addText (const QString &text)
 Appends a text block.
ToolResult & addImage (const QByteArray &data, const QString &mimeType)
 Appends an image block from raw bytes (encoded to base64 here).
ToolResult & addContent (const QJsonObject &contentBlock)
 Appends an arbitrary MCP content block (e.g. an embedded resource).
ToolResult & setStructuredContent (const QJsonObject &object)
 Sets the structuredContent object.
ToolResult & setError (bool isError=true)
 Marks the result as a tool error (or clears the mark).
bool isError () const
 Whether the result is marked as an error.
QJsonArray content () const
 The content blocks.
QJsonObject toJson () const
 The result as a tools/call result object.

Static Public Member Functions

static ToolResult text (const QString &text)
 A result with a single text block.
static ToolResult error (const QString &message)
 A failed result (isError) with an explanatory text block.
static ToolResult image (const QByteArray &data, const QString &mimeType)
 A result with a single image block.
static ToolResult structured (const QJsonObject &object)
 A result whose structuredContent is object, plus the same object serialized as text for clients that ignore structured content.

Private Attributes

QSharedDataPointer< ToolResultData > d
 Implicitly shared contents.

Detailed Description

The result of a tools/call: content blocks, optional structured content, and an error flag.

Builder methods return a reference so results can be chained:

return ToolResult::text("done").setStructuredContent({{"count", 3}});
static ToolResult text(const QString &text)
A result with a single text block.
Definition types.cpp:85
ToolResult & setStructuredContent(const QJsonObject &object)
Sets the structuredContent object.
Definition types.cpp:128

Constructor & Destructor Documentation

◆ ToolResult()

Sonde::ToolResult::ToolResult ( const ToolResult & other)
default

Shares other's contents (copied when either changes).

There are no move operations on purpose: a move would leave other without contents, and sharing costs only a reference count.

Member Function Documentation

◆ image()

ToolResult Sonde::ToolResult::image ( const QByteArray & data,
const QString & mimeType )
static

A result with a single image block.

Parameters
dataRaw (not base64-encoded) image bytes, e.g. PNG data.
mimeTypeThe image type, e.g. "image/png".

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