cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
resource.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 [caomengxuan666]
2
3#pragma once
4
12
13#include <cstdint>
14#include <limits>
15#include <optional>
16#include <string>
17#include <utility>
18#include <vector>
19
24
25namespace mcp::protocol {
26
28struct Resource {
30 std::string title;
32 std::string uri;
34 std::string name;
36 std::string description;
38 std::string mime_type;
40 std::optional<std::int64_t> size;
42 std::vector<Icon> icons;
44 Json annotations = Json::object();
46 std::optional<Json> meta;
48 Json extensions = Json::object();
49};
50
53 public:
54 ResourceBuilder(std::string uri, std::string name) {
55 resource_.uri = std::move(uri);
56 resource_.name = std::move(name);
57 }
58
59 ResourceBuilder& title(std::string value) {
60 resource_.title = std::move(value);
61 return *this;
62 }
63
64 ResourceBuilder& description(std::string value) {
65 resource_.description = std::move(value);
66 return *this;
67 }
68
69 ResourceBuilder& mime_type(std::string value) {
70 resource_.mime_type = std::move(value);
71 return *this;
72 }
73
74 ResourceBuilder& size(std::int64_t value) {
75 resource_.size = value;
76 return *this;
77 }
78
79 ResourceBuilder& icon(Icon value) {
80 resource_.icons.push_back(std::move(value));
81 return *this;
82 }
83
84 ResourceBuilder& annotations(Json value) {
85 resource_.annotations = std::move(value);
86 return *this;
87 }
88
89 ResourceBuilder& meta(Json value) {
90 resource_.meta = std::move(value);
91 return *this;
92 }
93
94 ResourceBuilder& extension(std::string name, Json value) {
95 resource_.extensions[std::move(name)] = std::move(value);
96 return *this;
97 }
98
99 Resource build() { return std::move(resource_); }
100
101 private:
102 Resource resource_;
103};
104
106inline ResourceBuilder resource_definition(std::string uri, std::string name) {
107 return ResourceBuilder(std::move(uri), std::move(name));
108}
109
113 std::vector<Resource> resources;
115 std::optional<std::string> next_cursor;
117 std::optional<Json> meta;
119 Json extensions = Json::object();
121 std::optional<std::int64_t> ttl_ms;
123 std::optional<std::string> cache_scope;
124};
125
129 std::string title;
131 std::string uri_template;
133 std::string name;
135 std::string description;
137 std::string mime_type;
139 std::optional<std::int64_t> size;
141 std::vector<Icon> icons;
143 Json annotations = Json::object();
145 std::optional<Json> meta;
147 Json extensions = Json::object();
148};
149
152 public:
153 ResourceTemplateBuilder(std::string uri_template, std::string name) {
154 resource_template_.uri_template = std::move(uri_template);
155 resource_template_.name = std::move(name);
156 }
157
158 ResourceTemplateBuilder& title(std::string value) {
159 resource_template_.title = std::move(value);
160 return *this;
161 }
162
163 ResourceTemplateBuilder& description(std::string value) {
164 resource_template_.description = std::move(value);
165 return *this;
166 }
167
168 ResourceTemplateBuilder& mime_type(std::string value) {
169 resource_template_.mime_type = std::move(value);
170 return *this;
171 }
172
173 ResourceTemplateBuilder& size(std::int64_t value) {
174 resource_template_.size = value;
175 return *this;
176 }
177
178 ResourceTemplateBuilder& icon(Icon value) {
179 resource_template_.icons.push_back(std::move(value));
180 return *this;
181 }
182
183 ResourceTemplateBuilder& annotations(Json value) {
184 resource_template_.annotations = std::move(value);
185 return *this;
186 }
187
188 ResourceTemplateBuilder& meta(Json value) {
189 resource_template_.meta = std::move(value);
190 return *this;
191 }
192
193 ResourceTemplateBuilder& extension(std::string name, Json value) {
194 resource_template_.extensions[std::move(name)] = std::move(value);
195 return *this;
196 }
197
198 ResourceTemplate build() { return std::move(resource_template_); }
199
200 private:
201 ResourceTemplate resource_template_;
202};
203
206 std::string uri_template, std::string name) {
207 return ResourceTemplateBuilder(std::move(uri_template), std::move(name));
208}
209
213 std::vector<ResourceTemplate> resource_templates;
215 std::optional<std::string> next_cursor;
217 std::optional<Json> meta;
219 Json extensions = Json::object();
221 std::optional<std::int64_t> ttl_ms;
223 std::optional<std::string> cache_scope;
224};
225
229 std::string uri;
231 std::optional<Json> meta;
233 Json extensions = Json::object();
234};
235
239 std::string uri;
241 std::optional<Json> meta;
243 Json extensions = Json::object();
244};
245
248
252 std::string uri;
254 std::string mime_type;
256 std::optional<std::string> text;
258 std::optional<std::string> blob;
260 std::optional<Json> meta;
262 Json extensions = Json::object();
263};
264
265template <>
267 static constexpr bool defined = true;
268 static auto fields() {
269 return std::make_tuple(
274 field("_meta", &ResourceContents::meta),
276 {"uri", "mimeType", "text", "blob", "_meta"}));
277 }
278 static std::vector<std::string> known_keys() {
279 return {"uri", "mimeType", "text", "blob", "_meta"};
280 }
281};
283
287 std::vector<ResourceContents> contents;
289 std::optional<Json> meta;
291 Json extensions = Json::object();
293 std::optional<std::int64_t> ttl_ms;
295 std::optional<std::string> cache_scope;
296};
297
301 std::string uri;
303 Json extensions = Json::object();
304};
305
306template <>
308 static constexpr bool defined = true;
309 static auto fields() {
310 return std::make_tuple(
313 {"uri"}));
314 }
315 static std::vector<std::string> known_keys() { return {"uri"}; }
316};
317
319inline core::Error resource_json_error(std::string message) {
320 return core::Error{
321 static_cast<int>(ErrorCode::InvalidRequest), std::move(message), {}};
322}
323
324inline core::Result<std::int64_t> resource_size_from_json(
325 const Json& json, std::string_view context) {
326 if (!json.is_number_integer()) {
327 return mcp::core::unexpected(
328 resource_json_error(std::string(context) + " size must be an integer"));
329 }
330 const auto size = json.get<std::int64_t>();
331 if (size < 0 || size > static_cast<std::int64_t>(
332 std::numeric_limits<std::uint32_t>::max())) {
333 return mcp::core::unexpected(resource_json_error(
334 std::string(context) + " size must be a uint32 value"));
335 }
336 return size;
337}
338
340inline Json resource_to_json(const Resource& resource) {
341 Json json = Json::object();
342 if (!resource.title.empty()) {
343 json["title"] = resource.title;
344 }
345 json["uri"] = resource.uri;
346 json["name"] = resource.name;
347 if (!resource.description.empty()) {
348 json["description"] = resource.description;
349 }
350 if (!resource.mime_type.empty()) {
351 json["mimeType"] = resource.mime_type;
352 }
353 if (resource.size.has_value()) {
354 json["size"] = *resource.size;
355 }
356 if (!resource.icons.empty()) {
357 json["icons"] = Json::array();
358 for (const auto& icon : resource.icons) {
359 json["icons"].push_back(icon_to_json(icon));
360 }
361 }
362 if (!resource.annotations.empty()) {
363 json["annotations"] = resource.annotations;
364 }
365 if (resource.meta.has_value()) {
366 json["_meta"] = *resource.meta;
367 }
368 append_json_extensions(json, resource.extensions);
369 return json;
370}
371
375 if (!json.is_object()) {
376 return mcp::core::unexpected(
377 resource_json_error("resource must be an object"));
378 }
379 if (json.contains("title")) {
380 if (!json.at("title").is_string()) {
381 return mcp::core::unexpected(
382 resource_json_error("resource title must be a string"));
383 }
384 }
385 if (!json.contains("uri") || !json.at("uri").is_string()) {
386 return mcp::core::unexpected(
387 resource_json_error("resource requires a string uri"));
388 }
389 if (!json.contains("name") || !json.at("name").is_string()) {
390 return mcp::core::unexpected(
391 resource_json_error("resource requires a string name"));
392 }
393
394 Resource resource;
395 if (json.contains("title")) {
396 resource.title = json.at("title").get<std::string>();
397 }
398 resource.uri = json.at("uri").get<std::string>();
399 resource.name = json.at("name").get<std::string>();
400 if (json.contains("description")) {
401 if (!json.at("description").is_string()) {
402 return mcp::core::unexpected(
403 resource_json_error("resource description must be a string"));
404 }
405 resource.description = json.at("description").get<std::string>();
406 }
407 if (json.contains("mimeType")) {
408 if (!json.at("mimeType").is_string()) {
409 return mcp::core::unexpected(
410 resource_json_error("resource mimeType must be a string"));
411 }
412 resource.mime_type = json.at("mimeType").get<std::string>();
413 }
414 if (json.contains("size")) {
415 const auto size = resource_size_from_json(json.at("size"), "resource");
416 if (!size) {
417 return mcp::core::unexpected(size.error());
418 }
419 resource.size = *size;
420 }
421 if (json.contains("icons")) {
422 if (!json.at("icons").is_array()) {
423 return mcp::core::unexpected(
424 resource_json_error("resource icons must be an array"));
425 }
426 for (const auto& item : json.at("icons")) {
427 const auto icon = icon_from_json(item);
428 if (!icon.has_value()) {
429 return mcp::core::unexpected(
430 resource_json_error("resource icon is invalid"));
431 }
432 resource.icons.push_back(*icon);
433 }
434 }
435 if (json.contains("annotations")) {
436 if (!json.at("annotations").is_object()) {
437 return mcp::core::unexpected(
438 resource_json_error("resource annotations must be an object"));
439 }
440 resource.annotations = json.at("annotations");
441 }
442 if (json.contains("_meta")) {
443 if (!json.at("_meta").is_object()) {
444 return mcp::core::unexpected(
445 resource_json_error("resource _meta must be an object"));
446 }
447 resource.meta = json.at("_meta");
448 }
449 resource.extensions = collect_json_extensions(
450 json, {"title", "uri", "name", "description", "mimeType", "size", "icons",
451 "annotations", "_meta"});
452 return resource;
453}
454
457 const ResourceTemplate& resource_template) {
458 Json json = Json::object();
459 if (!resource_template.title.empty()) {
460 json["title"] = resource_template.title;
461 }
462 json["uriTemplate"] = resource_template.uri_template;
463 json["name"] = resource_template.name;
464 if (!resource_template.description.empty()) {
465 json["description"] = resource_template.description;
466 }
467 if (!resource_template.mime_type.empty()) {
468 json["mimeType"] = resource_template.mime_type;
469 }
470 if (resource_template.size.has_value()) {
471 json["size"] = *resource_template.size;
472 }
473 if (!resource_template.icons.empty()) {
474 json["icons"] = Json::array();
475 for (const auto& icon : resource_template.icons) {
476 json["icons"].push_back(icon_to_json(icon));
477 }
478 }
479 if (!resource_template.annotations.empty()) {
480 json["annotations"] = resource_template.annotations;
481 }
482 if (resource_template.meta.has_value()) {
483 json["_meta"] = *resource_template.meta;
484 }
485 append_json_extensions(json, resource_template.extensions);
486 return json;
487}
488
492 const Json& json) {
493 if (!json.is_object()) {
494 return mcp::core::unexpected(
495 resource_json_error("resource template must be an object"));
496 }
497 if (json.contains("title")) {
498 if (!json.at("title").is_string()) {
499 return mcp::core::unexpected(
500 resource_json_error("resource template title must be a string"));
501 }
502 }
503 if (!json.contains("uriTemplate") || !json.at("uriTemplate").is_string()) {
504 return mcp::core::unexpected(
505 resource_json_error("resource template requires a string uriTemplate"));
506 }
507 if (!json.contains("name") || !json.at("name").is_string()) {
508 return mcp::core::unexpected(
509 resource_json_error("resource template requires a string name"));
510 }
511
512 ResourceTemplate resource_template;
513 if (json.contains("title")) {
514 resource_template.title = json.at("title").get<std::string>();
515 }
516 resource_template.uri_template = json.at("uriTemplate").get<std::string>();
517 resource_template.name = json.at("name").get<std::string>();
518 if (json.contains("description")) {
519 if (!json.at("description").is_string()) {
520 return mcp::core::unexpected(resource_json_error(
521 "resource template description must be a string"));
522 }
523 resource_template.description = json.at("description").get<std::string>();
524 }
525 if (json.contains("mimeType")) {
526 if (!json.at("mimeType").is_string()) {
527 return mcp::core::unexpected(
528 resource_json_error("resource template mimeType must be a string"));
529 }
530 resource_template.mime_type = json.at("mimeType").get<std::string>();
531 }
532 if (json.contains("size")) {
533 const auto size =
534 resource_size_from_json(json.at("size"), "resource template");
535 if (!size) {
536 return mcp::core::unexpected(size.error());
537 }
538 resource_template.size = *size;
539 }
540 if (json.contains("icons")) {
541 if (!json.at("icons").is_array()) {
542 return mcp::core::unexpected(
543 resource_json_error("resource template icons must be an array"));
544 }
545 for (const auto& item : json.at("icons")) {
546 const auto icon = icon_from_json(item);
547 if (!icon.has_value()) {
548 return mcp::core::unexpected(
549 resource_json_error("resource template icon is invalid"));
550 }
551 resource_template.icons.push_back(*icon);
552 }
553 }
554 if (json.contains("annotations")) {
555 if (!json.at("annotations").is_object()) {
556 return mcp::core::unexpected(resource_json_error(
557 "resource template annotations must be an object"));
558 }
559 resource_template.annotations = json.at("annotations");
560 }
561 if (json.contains("_meta")) {
562 if (!json.at("_meta").is_object()) {
563 return mcp::core::unexpected(
564 resource_json_error("resource template _meta must be an object"));
565 }
566 resource_template.meta = json.at("_meta");
567 }
568 resource_template.extensions = collect_json_extensions(
569 json, {"title", "uriTemplate", "name", "description", "mimeType", "size",
570 "icons", "annotations", "_meta"});
571 return resource_template;
572}
573
576 Json json = Json::object();
577 json["resources"] = Json::array();
578 for (const auto& resource : result.resources) {
579 json["resources"].push_back(resource_to_json(resource));
580 }
581 if (result.next_cursor.has_value()) {
582 json["nextCursor"] = *result.next_cursor;
583 }
584 if (result.meta.has_value()) {
585 json["_meta"] = *result.meta;
586 }
587 if (result.ttl_ms.has_value()) {
588 json["ttlMs"] = *result.ttl_ms;
589 }
590 if (result.cache_scope.has_value()) {
591 json["cacheScope"] = *result.cache_scope;
592 }
594 return json;
595}
596
600 const Json& json) {
601 if (!json.is_object()) {
602 return mcp::core::unexpected(
603 resource_json_error("resources/list result must be an object"));
604 }
605 if (!json.contains("resources") || !json.at("resources").is_array()) {
606 return mcp::core::unexpected(resource_json_error(
607 "resources/list result requires a resources array"));
608 }
609
610 ResourcesListResult result;
611 for (const auto& item : json.at("resources")) {
612 const auto resource = resource_from_json(item);
613 if (!resource) {
614 return mcp::core::unexpected(resource.error());
615 }
616 result.resources.push_back(*resource);
617 }
618 if (json.contains("nextCursor")) {
619 if (!json.at("nextCursor").is_string()) {
620 return mcp::core::unexpected(
621 resource_json_error("resources/list nextCursor must be a string"));
622 }
623 result.next_cursor = json.at("nextCursor").get<std::string>();
624 }
625 if (json.contains("_meta")) {
626 if (!json.at("_meta").is_object()) {
627 return mcp::core::unexpected(
628 resource_json_error("resources/list result _meta must be an object"));
629 }
630 result.meta = json.at("_meta");
631 }
632 result.extensions =
633 collect_json_extensions(json, {"resources", "nextCursor", "_meta"});
634 return result;
635}
636
639 const ResourceTemplatesListResult& result) {
640 Json json = Json::object();
641 json["resourceTemplates"] = Json::array();
642 for (const auto& resource_template : result.resource_templates) {
643 json["resourceTemplates"].push_back(
644 resource_template_to_json(resource_template));
645 }
646 if (result.next_cursor.has_value()) {
647 json["nextCursor"] = *result.next_cursor;
648 }
649 if (result.meta.has_value()) {
650 json["_meta"] = *result.meta;
651 }
652 if (result.ttl_ms.has_value()) {
653 json["ttlMs"] = *result.ttl_ms;
654 }
655 if (result.cache_scope.has_value()) {
656 json["cacheScope"] = *result.cache_scope;
657 }
659 return json;
660}
661
666 if (!json.is_object()) {
667 return mcp::core::unexpected(resource_json_error(
668 "resources/templates/list result must be an object"));
669 }
670 if (!json.contains("resourceTemplates") ||
671 !json.at("resourceTemplates").is_array()) {
672 return mcp::core::unexpected(resource_json_error(
673 "resources/templates/list result requires a resourceTemplates array"));
674 }
675
677 for (const auto& item : json.at("resourceTemplates")) {
678 const auto resource_template = resource_template_from_json(item);
679 if (!resource_template) {
680 return mcp::core::unexpected(resource_template.error());
681 }
682 result.resource_templates.push_back(*resource_template);
683 }
684 if (json.contains("nextCursor")) {
685 if (!json.at("nextCursor").is_string()) {
686 return mcp::core::unexpected(resource_json_error(
687 "resources/templates/list nextCursor must be a string"));
688 }
689 result.next_cursor = json.at("nextCursor").get<std::string>();
690 }
691 if (json.contains("_meta")) {
692 if (!json.at("_meta").is_object()) {
693 return mcp::core::unexpected(resource_json_error(
694 "resources/templates/list result _meta must be an object"));
695 }
696 result.meta = json.at("_meta");
697 }
699 json, {"resourceTemplates", "nextCursor", "_meta"});
700 return result;
701}
702
705 Json json = Json{{"uri", params.uri}};
706 if (params.meta.has_value()) {
707 json["_meta"] = *params.meta;
708 }
710 return json;
711}
712
716 const Json& json) {
717 if (!json.is_object()) {
718 return mcp::core::unexpected(
719 resource_json_error("resources/read params must be an object"));
720 }
721 if (!json.contains("uri") || !json.at("uri").is_string()) {
722 return mcp::core::unexpected(
723 resource_json_error("resources/read params require a string uri"));
724 }
725 ResourcesReadParams params;
726 params.uri = json.at("uri").get<std::string>();
727 if (json.contains("_meta")) {
728 if (!json.at("_meta").is_object()) {
729 return mcp::core::unexpected(
730 resource_json_error("resources/read _meta must be an object"));
731 }
732 params.meta = json.at("_meta");
733 }
734 params.extensions = collect_json_extensions(json, {"uri", "_meta"});
735 return params;
736}
737
740 const ResourcesSubscribeParams& params) {
741 Json json = Json{{"uri", params.uri}};
742 if (params.meta.has_value()) {
743 json["_meta"] = *params.meta;
744 }
746 return json;
747}
748
753 if (!json.is_object()) {
754 return mcp::core::unexpected(
755 resource_json_error("resources subscribe params must be an object"));
756 }
757 if (!json.contains("uri") || !json.at("uri").is_string()) {
758 return mcp::core::unexpected(
759 resource_json_error("resources subscribe params require a string uri"));
760 }
762 params.uri = json.at("uri").get<std::string>();
763 if (json.contains("_meta")) {
764 if (!json.at("_meta").is_object()) {
765 return mcp::core::unexpected(
766 resource_json_error("resources subscribe _meta must be an object"));
767 }
768 params.meta = json.at("_meta");
769 }
770 params.extensions = collect_json_extensions(json, {"uri", "_meta"});
771 return params;
772}
773
779
786
789 return reflect_to_json(contents);
790}
791
796 const Json& json) {
797 auto result = reflect_from_json<ResourceContents>(json);
798 if (!result) {
799 return result;
800 }
801 if (!result->text.has_value() && !result->blob.has_value()) {
802 return mcp::core::unexpected(
803 resource_json_error("resource contents require text or blob"));
804 }
805 return result;
806}
807
810 Json json = Json::object();
811 json["contents"] = Json::array();
812 for (const auto& contents : result.contents) {
813 json["contents"].push_back(resource_contents_to_json(contents));
814 }
815 if (result.meta.has_value()) {
816 json["_meta"] = *result.meta;
817 }
818 if (result.ttl_ms.has_value()) {
819 json["ttlMs"] = *result.ttl_ms;
820 }
821 if (result.cache_scope.has_value()) {
822 json["cacheScope"] = *result.cache_scope;
823 }
825 return json;
826}
827
831 const Json& json) {
832 if (!json.is_object()) {
833 return mcp::core::unexpected(
834 resource_json_error("resources/read result must be an object"));
835 }
836 if (!json.contains("contents") || !json.at("contents").is_array()) {
837 return mcp::core::unexpected(
838 resource_json_error("resources/read result requires a contents array"));
839 }
840
841 ResourcesReadResult result;
842 for (const auto& item : json.at("contents")) {
843 const auto contents = resource_contents_from_json(item);
844 if (!contents) {
845 return mcp::core::unexpected(contents.error());
846 }
847 result.contents.push_back(*contents);
848 }
849 if (json.contains("_meta")) {
850 if (!json.at("_meta").is_object()) {
851 return mcp::core::unexpected(
852 resource_json_error("resources/read result _meta must be an object"));
853 }
854 result.meta = json.at("_meta");
855 }
856 result.extensions = collect_json_extensions(json, {"contents", "_meta"});
857 return result;
858}
859
865
869 return reflect_from_json<ResourceUpdatedNotificationParams>(json);
870}
871
872} // namespace mcp::protocol
Fluent builder for concrete resource descriptors.
Definition resource.hpp:52
Fluent builder for resource-template descriptors.
Definition resource.hpp:151
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.
#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
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
ResourceBuilder resource_definition(std::string uri, std::string name)
Creates a fluent builder for advertised MCP resource metadata.
Definition resource.hpp:106
Json resource_contents_to_json(const ResourceContents &contents)
Serializes resource contents.
Definition resource.hpp:788
core::Result< ResourcesSubscribeParams > resources_subscribe_params_from_json(const Json &json)
Parses resources/subscribe params.
Definition resource.hpp:752
core::Result< ResourcesReadParams > resources_read_params_from_json(const Json &json)
Parses resources/read params.
Definition resource.hpp:715
core::Result< ResourcesUnsubscribeParams > resources_unsubscribe_params_from_json(const Json &json)
Parses resources/unsubscribe params.
Definition resource.hpp:783
Json resource_template_to_json(const ResourceTemplate &resource_template)
Serializes a resource template descriptor.
Definition resource.hpp:456
core::Result< ResourcesReadResult > resources_read_result_from_json(const Json &json)
Parses a resources/read result.
Definition resource.hpp:830
core::Result< ResourceUpdatedNotificationParams > resource_updated_notification_params_from_json(const Json &json)
Parses notifications/resources/updated params.
Definition resource.hpp:868
core::Result< ResourceContents > resource_contents_from_json(const Json &json)
Parses resource contents.
Definition resource.hpp:795
core::Result< ResourcesListResult > resources_list_result_from_json(const Json &json)
Parses a resources/list result.
Definition resource.hpp:599
core::Result< ResourceTemplatesListResult > resource_templates_list_result_from_json(const Json &json)
Parses a resources/templates/list result.
Definition resource.hpp:665
Json resources_read_params_to_json(const ResourcesReadParams &params)
Serializes resources/read params.
Definition resource.hpp:704
Json resource_updated_notification_params_to_json(const ResourceUpdatedNotificationParams &params)
Serializes notifications/resources/updated params.
Definition resource.hpp:861
core::Result< Resource > resource_from_json(const Json &json)
Parses a resource descriptor.
Definition resource.hpp:374
Json resources_read_result_to_json(const ResourcesReadResult &result)
Serializes a resources/read result.
Definition resource.hpp:809
core::Result< ResourceTemplate > resource_template_from_json(const Json &json)
Parses a resource template descriptor.
Definition resource.hpp:491
core::Error resource_json_error(std::string message)
Builds an InvalidRequest error for resource JSON validation failures.
Definition resource.hpp:319
Json resources_subscribe_params_to_json(const ResourcesSubscribeParams &params)
Serializes resources/subscribe params.
Definition resource.hpp:739
ResourceTemplateBuilder resource_template_definition(std::string uri_template, std::string name)
Creates a fluent builder for advertised resource-template metadata.
Definition resource.hpp:205
Json resource_templates_list_result_to_json(const ResourceTemplatesListResult &result)
Serializes a resources/templates/list result.
Definition resource.hpp:638
Json resources_list_result_to_json(const ResourcesListResult &result)
Serializes a resources/list result.
Definition resource.hpp:575
Json resource_to_json(const Resource &resource)
Serializes a resource descriptor.
Definition resource.hpp:340
Json resources_unsubscribe_params_to_json(const ResourcesUnsubscribeParams &params)
Serializes resources/unsubscribe params.
Definition resource.hpp:775
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
Structured error returned by fallible SDK operations.
Definition result.hpp:35
Icon descriptor used by tools, resources, resource templates, and prompts.
Definition types.hpp:160
Primary template.
Definition reflect.hpp:199
One content part returned by resources/read.
Definition resource.hpp:250
std::optional< std::string > text
Text content when the resource is represented as UTF-8 text.
Definition resource.hpp:256
std::optional< std::string > blob
Base64-encoded binary content when the resource is not text.
Definition resource.hpp:258
std::string uri
URI of the resource content.
Definition resource.hpp:252
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition resource.hpp:262
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition resource.hpp:260
std::string mime_type
Optional MIME type of this content part.
Definition resource.hpp:254
URI template advertised by resources/templates/list.
Definition resource.hpp:127
Json annotations
Optional annotations for model or client presentation.
Definition resource.hpp:143
std::string mime_type
Optional MIME type expected for matching resources.
Definition resource.hpp:137
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition resource.hpp:147
std::string description
Optional human-readable description.
Definition resource.hpp:135
std::vector< Icon > icons
Optional icon descriptors for client presentation.
Definition resource.hpp:141
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition resource.hpp:145
std::optional< std::int64_t > size
Optional size hint in bytes when known.
Definition resource.hpp:139
std::string uri_template
URI template string that can be expanded into concrete resource URIs.
Definition resource.hpp:131
std::string title
Optional human-readable display title.
Definition resource.hpp:129
std::string name
Stable template name.
Definition resource.hpp:133
Result object for resources/templates/list.
Definition resource.hpp:211
std::vector< ResourceTemplate > resource_templates
Resource templates available to the caller.
Definition resource.hpp:213
std::optional< std::string > cache_scope
Cache scope hint: "public" or "private" (SEP-2549).
Definition resource.hpp:223
std::optional< std::string > next_cursor
Optional cursor for retrieving the next page.
Definition resource.hpp:215
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition resource.hpp:219
std::optional< std::int64_t > ttl_ms
Cache time-to-live hint in milliseconds (SEP-2549).
Definition resource.hpp:221
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition resource.hpp:217
Parameters for notifications/resources/updated.
Definition resource.hpp:299
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition resource.hpp:303
std::string uri
URI of the resource that was updated.
Definition resource.hpp:301
Concrete resource advertised by resources/list.
Definition resource.hpp:28
std::string title
Optional human-readable display title.
Definition resource.hpp:30
std::string name
Stable resource name.
Definition resource.hpp:34
std::string uri
Stable URI used by resources/read and subscription methods.
Definition resource.hpp:32
std::string mime_type
Optional MIME type for the resource contents.
Definition resource.hpp:38
std::string description
Optional human-readable description.
Definition resource.hpp:36
Json annotations
Optional annotations for model or client presentation.
Definition resource.hpp:44
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition resource.hpp:46
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition resource.hpp:48
std::optional< std::int64_t > size
Optional size hint in bytes when known.
Definition resource.hpp:40
std::vector< Icon > icons
Optional icon descriptors for client presentation.
Definition resource.hpp:42
Result object for resources/list.
Definition resource.hpp:111
std::optional< std::string > next_cursor
Optional cursor for retrieving the next page.
Definition resource.hpp:115
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition resource.hpp:117
std::vector< Resource > resources
Resources available to the caller.
Definition resource.hpp:113
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition resource.hpp:119
std::optional< std::int64_t > ttl_ms
Cache time-to-live hint in milliseconds (SEP-2549).
Definition resource.hpp:121
std::optional< std::string > cache_scope
Cache scope hint: "public" or "private" (SEP-2549).
Definition resource.hpp:123
Parameters for resources/read.
Definition resource.hpp:227
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition resource.hpp:231
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition resource.hpp:233
std::string uri
URI of the resource to read.
Definition resource.hpp:229
Result object for resources/read.
Definition resource.hpp:285
std::optional< std::string > cache_scope
Cache scope hint: "public" or "private" (SEP-2549).
Definition resource.hpp:295
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition resource.hpp:289
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition resource.hpp:291
std::vector< ResourceContents > contents
One or more content parts for the requested URI.
Definition resource.hpp:287
std::optional< std::int64_t > ttl_ms
Cache time-to-live hint in milliseconds (SEP-2549).
Definition resource.hpp:293
Parameters for resources/subscribe.
Definition resource.hpp:237
std::optional< Json > meta
Optional _meta extension object preserved on the wire.
Definition resource.hpp:241
std::string uri
URI of the resource to subscribe to.
Definition resource.hpp:239
Json extensions
Unknown JSON members preserved for forward-compatible round trips.
Definition resource.hpp:243
Reflection specializations for DTOs defined in types.hpp.
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