11#include <Poco/Dynamic/Var.h>
12#include <Poco/JSON/Array.h>
13#include <Poco/JSON/Object.h>
14#include <Poco/JSON/Stringifier.h>
24 std::ostringstream out;
25 Poco::JSON::Stringifier::stringify(
value, out, 0, 0);
32 out.reserve(
value.size() + 8);
35 case '"': out +=
"\\\"";
break;
36 case '\\': out +=
"\\\\";
break;
37 case '\n': out +=
"\\n";
break;
38 case '\r': out +=
"\\r";
break;
39 case '\t': out +=
"\\t";
break;
41 if (
static_cast<unsigned char>(
c) < 0x20) {
43 std::snprintf(buf,
sizeof(buf),
"\\u%04x",
static_cast<unsigned>(
c));
60 Poco::JSON::Object::Ptr result = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
61 Poco::JSON::Array::Ptr content = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
62 Poco::JSON::Object::Ptr item = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
63 item->set(
"type",
"text");
64 item->set(
"text",
text);
66 result->set(
"content", content);
67 if (isError) result->set(
"isError",
true);
78 const std::string& caption) {
79 Poco::JSON::Object::Ptr result = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
80 Poco::JSON::Array::Ptr content = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
81 Poco::JSON::Object::Ptr
image = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
82 image->set(
"type",
"image");
83 image->set(
"data", base64Png);
84 image->set(
"mimeType", mimeType);
86 if (!caption.empty()) {
87 Poco::JSON::Object::Ptr item = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
88 item->set(
"type",
"text");
89 item->set(
"text", caption);
92 result->set(
"content", content);
std::string mcpJsonEscape(const std::string &value)
Escape a raw string for embedding inside a JSON string literal.
std::string mcpStringify(const Poco::Dynamic::Var &value)
Compact single-line JSON text for a newline-framed MCP payload.
std::string textContentResult(const std::string &text, bool isError=false)
MCP tools/call result object carrying one text content item.
std::string imageContentResult(const std::string &base64Png, const std::string &mimeType, const std::string &caption)
MCP tools/call result object carrying one image content item.