21namespace mcp::protocol {
28 std::optional<std::string>
name;
37 static constexpr bool defined =
true;
38 static auto fields() {
39 return std::make_tuple(
44 static std::vector<std::string> known_keys() {
45 return {
"uri",
"name",
"_meta"};
62 static_cast<int>(ErrorCode::InvalidRequest), std::move(message), {}};
71 return reflect_from_json<Root>(json);
76 Json json = Json::object();
77 json[
"roots"] = Json::array();
78 for (
const auto& root : result.
roots) {
81 if (result.
meta.has_value()) {
82 json[
"_meta"] = *result.
meta;
92 if (!json.is_object()) {
93 return mcp::core::unexpected(
96 if (!json.contains(
"roots") || !json.at(
"roots").is_array()) {
97 return mcp::core::unexpected(
102 for (
const auto& item : json.at(
"roots")) {
105 return mcp::core::unexpected(root.error());
107 result.
roots.push_back(*root);
109 if (json.contains(
"_meta")) {
110 if (!json.at(
"_meta").is_object()) {
111 return mcp::core::unexpected(
114 result.
meta = json.at(
"_meta");
Shared JSON, JSON-RPC, error, cancellation, and progress model types.
void append_json_extensions(Json &json, const Json &extensions)
Flattens extension members into a JSON object without overwriting typed fields.
Definition types.hpp:358
nlohmann::json Json
JSON value type used by all protocol DTOs.
Definition types.hpp:28
Json collect_json_extensions(const Json &json, std::initializer_list< std::string_view > known_keys)
Collects unknown object members so typed DTOs can preserve future protocol fields and vendor extensio...
Definition types.hpp:320
C++17 tuple-reflection infrastructure for zero-boilerplate DTO serialization.
constexpr FieldDescriptor< Struct, Field > field(const char *wire_name, Field Struct::*pointer)
Creates a FieldDescriptor with wire name and pointer-to-member.
Definition reflect.hpp:75
ExtensionsField< Struct > extensions_field(Json Struct::*pointer, std::vector< std::string > own_keys)
Creates an ExtensionsField descriptor.
Definition reflect.hpp:90
Json reflect_to_json(const T &obj)
Serializes a DTO to JSON using its Reflect<T> trait.
Definition reflect.hpp:701
Shared result and error primitives used by the public cxxmcp SDK.
tl::expected< T, Error > Result
Alias for the SDK result type.
Definition result.hpp:64
core::Result< RootsListResult > roots_list_result_from_json(const Json &json)
Parses a roots/list result.
Definition roots.hpp:90
Json root_to_json(const Root &root)
Serializes a root entry.
Definition roots.hpp:66
Json roots_list_result_to_json(const RootsListResult &result)
Serializes a roots/list result.
Definition roots.hpp:75
core::Error roots_json_error(std::string message)
Builds an InvalidRequest error for roots JSON validation failures.
Definition roots.hpp:60
core::Result< Root > root_from_json(const Json &json)
Parses a root entry.
Definition roots.hpp:70
Structured error returned by fallible SDK operations.
Definition result.hpp:35
Primary template.
Definition reflect.hpp:199
One client root entry.
Definition roots.hpp:24
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition roots.hpp:30
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition roots.hpp:32
std::optional< std::string > name
Optional human-readable name for display.
Definition roots.hpp:28
std::string uri
Root URI. The interpretation is transport/client specific.
Definition roots.hpp:26
Result object for roots/list.
Definition roots.hpp:50
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition roots.hpp:54
std::vector< Root > roots
Roots currently available to the server.
Definition roots.hpp:52
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition roots.hpp:56