16namespace mcp::protocol {
22inline core::Result<core::Unit> validate_finite_double(
const double& value) {
23 if (!std::isfinite(value)) {
25 core::Error{
static_cast<int>(ErrorCode::InvalidRequest),
26 "number must be finite",
32inline core::Result<core::Unit> validate_optional_finite_double(
33 const std::optional<double>& value) {
34 if (value.has_value() && !std::isfinite(*value)) {
36 core::Error{
static_cast<int>(ErrorCode::InvalidRequest),
37 "number must be finite",
49 static constexpr bool defined =
true;
50 static auto fields() {
51 return std::make_tuple(
55 static std::vector<std::string> known_keys() {
56 return {
"src",
"mimeType",
"sizes",
"theme"};
68 static constexpr bool defined =
true;
69 static auto fields() {
70 return std::make_tuple(
74 static std::vector<std::string> known_keys() {
75 return {
"requestId",
"reason"};
87 static constexpr bool defined =
true;
88 static auto fields() {
89 return std::make_tuple(
92 validate_finite_double),
94 validate_optional_finite_double),
97 static std::vector<std::string> known_keys() {
98 return {
"progressToken",
"progress",
"total",
"message"};
115 auto result = reflect_from_json<Icon>(json);
119 return std::move(*result);
129inline std::optional<CancelledNotificationParams>
131 auto result = reflect_from_json<CancelledNotificationParams>(json);
135 return std::move(*result);
145inline std::optional<ProgressNotificationParams>
147 auto result = reflect_from_json<ProgressNotificationParams>(json);
151 return std::move(*result);
Shared JSON, JSON-RPC, error, cancellation, and progress model types.
nlohmann::json Json
JSON value type used by all protocol DTOs.
Definition types.hpp:28
C++17 tuple-reflection infrastructure for zero-boilerplate DTO serialization.
#define CXXMCP_REFLECT_CHECK(Struct, expected_count)
Validates that a Reflect<> specialization covers the expected number of fields.
Definition reflect.hpp:1008
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
constexpr FieldDescriptor< Struct, Field > defaulted_field(const char *wire_name, Field Struct::*pointer)
Creates a FieldDescriptor whose missing wire value keeps the C++ default value.
Definition reflect.hpp:145
Json reflect_to_json(const T &obj)
Serializes a DTO to JSON using its Reflect<T> trait.
Definition reflect.hpp:701
constexpr FieldDescriptor< Struct, Field > validated_field(const char *wire_name, Field Struct::*pointer, core::Result< core::Unit >(*validator)(const Field &))
Creates a FieldDescriptor with a post-deserialization validator.
Definition reflect.hpp:82
constexpr auto unexpected(E &&value)
Creates an unexpected result value for the active expected backend.
Definition result.hpp:24
Parameters for notifications/cancelled.
Definition types.hpp:218
RequestId request_id
Id of the JSON-RPC request being cancelled.
Definition types.hpp:220
std::optional< std::string > reason
Optional human-readable cancellation reason.
Definition types.hpp:222
Icon descriptor used by tools, resources, resource templates, and prompts.
Definition types.hpp:160
std::string src
Required icon source URI or data URI.
Definition types.hpp:162
std::string mime_type
Optional MIME type such as image/png or image/svg+xml.
Definition types.hpp:164
std::vector< std::string > sizes
Optional size hints such as 16x16, 32x32, or any.
Definition types.hpp:166
std::optional< IconTheme > theme
Optional theme specialization.
Definition types.hpp:168
Parameters for notifications/progress.
Definition types.hpp:226
double progress
Current progress value.
Definition types.hpp:230
std::optional< std::string > message
Optional human-readable status text.
Definition types.hpp:234
ProgressToken progress_token
Token supplied by the original request metadata.
Definition types.hpp:228
std::optional< double > total
Optional total value using the same unit as progress.
Definition types.hpp:232
Primary template.
Definition reflect.hpp:199
Json cancelled_notification_params_to_json(const CancelledNotificationParams ¶ms)
Serializes cancellation notification parameters.
Definition types_reflect.hpp:123
Json progress_notification_params_to_json(const ProgressNotificationParams ¶ms)
Serializes progress notification parameters.
Definition types_reflect.hpp:139
Json icon_to_json(const Icon &icon)
Serializes a shared icon descriptor.
Definition types_reflect.hpp:109
std::optional< Icon > icon_from_json(const Json &json)
Parses a shared icon descriptor.
Definition types_reflect.hpp:114
std::optional< CancelledNotificationParams > cancelled_notification_params_from_json(const Json &json)
Parses cancellation notification parameters.
Definition types_reflect.hpp:130
std::optional< ProgressNotificationParams > progress_notification_params_from_json(const Json &json)
Parses progress notification parameters.
Definition types_reflect.hpp:146