MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / adr_parse_section_updates

Function adr_parse_section_updates

src/mcp/mcp.c:19909–19942  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19907}
19908
19909static adr_section_updates_t adr_parse_section_updates(const char *args) {
19910 adr_section_updates_t u;
19911 memset(&u, 0, sizeof(u));
19912
19913 yyjson_doc *doc = yyjson_read(args, strlen(args), 0);
19914 yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL;
19915 yyjson_val *updates =
19916 (root && yyjson_is_obj(root)) ? yyjson_obj_get(root, "section_updates") : NULL;
19917
19918 if (!updates) {
19919 /* Never fall through to 'get': a caller that meant to write must not
19920 * receive a success-shaped read. */
19921 u.status = "missing_section_updates";
19922 u.error = "mode='set_sections' requires 'section_updates', an object mapping section "
19923 "name to its new body. No ADR write was performed.";
19924 } else if (!yyjson_is_obj(updates) || yyjson_obj_size(updates) == 0) {
19925 u.status = "invalid_section_updates";
19926 u.error = "'section_updates' must be a non-empty object mapping section name to its new "
19927 "body. No ADR write was performed.";
19928 } else {
19929 size_t idx = 0;
19930 size_t max = 0;
19931 yyjson_val *key = NULL;
19932 yyjson_val *val = NULL;
19933 yyjson_obj_foreach(updates, idx, max, key, val) {
19934 if (!adr_collect_section_update(&u, key, val)) {
19935 adr_section_updates_free(&u);
19936 break;
19937 }
19938 }
19939 }
19940 yyjson_doc_free(doc);
19941 return u;
19942}
19943
19944/* Build the rejection payload for a set_sections request that never reached a
19945 * store. Caller frees. */

Callers 1

handle_manage_adrFunction · 0.85

Calls 2

adr_section_updates_freeFunction · 0.85

Tested by

no test coverage detected