ContentType Class Referenceabstract

#include <Pt/Mcp/ContentType.h>

Formats a tool result as MCP content. More...

Inherited by ImageContent, and TextContent.

Public Member Functions

virtual ContentFormattergetFormatter () const =0
 Creates a new ContentFormatter for a result. More...
 
virtual void releaseFormatter (ContentFormatter *formatter) const =0
 Releases a ContentFormatter previously obtained from getFormatter(). More...
 

Detailed Description

ContentType determines how a Decomposer result is serialized into an MCP content block (text, image, etc.). getFormatter() creates the ContentFormatter used to write the block; the caller drives it directly (beginFormat(), the Decomposer begin/advance protocol, finishFormat()) and releases it via releaseFormatter().

Thread-safety
Implementations are shared, process-wide singletons (see textContent(), imageContent()) that may be used by many Responders concurrently. getFormatter() must therefore be stateless: it may only read immutable members of the ContentType (set once at construction) and must never cache a Formatter, stream or scratch buffer as a mutable member of the ContentType itself. All per-request state must live exclusively in the ContentFormatter instance returned by getFormatter().

Member Function Documentation

◆ getFormatter()

virtual ContentFormatter* getFormatter ( ) const
pure virtual

The caller owns the returned ContentFormatter and must release it via releaseFormatter() once done with it, whether the format completed normally or was abandoned. The output stream is not known yet; it is passed to ContentFormatter::beginFormat().

Implemented in ImageContent, and TextContent.

◆ releaseFormatter()

virtual void releaseFormatter ( ContentFormatter formatter) const
pure virtual

Deletes formatter; the caller must not use it afterward. Does not write anything - call formatter->finishFormat() first to complete the content block normally.

Implemented in ImageContent, and TextContent.