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

Function sg_parse_fields

src/mcp/mcp.c:4610–4650  ·  view source on GitHub ↗

Parse the `fields` argument (array of property names) into out[] as * pointers owned by the returned doc (caller frees the doc after emission). * Blocked internal fields are silently dropped; core-column requests are * dropped too and reported via *core_requested so the emitter can hint. */

Source from the content-addressed store, hash-verified

4608 * Blocked internal fields are silently dropped; core-column requests are
4609 * dropped too and reported via *core_requested so the emitter can hint. */
4610static int sg_parse_fields(const char *args, const char *out[], int max_out, yyjson_doc **out_owner,
4611 bool *core_requested) {
4612 *out_owner = NULL;
4613 if (core_requested) {
4614 *core_requested = false;
4615 }
4616 yyjson_doc *args_doc = yyjson_read(args, strlen(args), 0);
4617 yyjson_val *args_root = args_doc ? yyjson_doc_get_root(args_doc) : NULL;
4618 yyjson_val *fv = args_root ? yyjson_obj_get(args_root, "fields") : NULL;
4619 if (!fv || !yyjson_is_arr(fv)) {
4620 if (args_doc) {
4621 yyjson_doc_free(args_doc);
4622 }
4623 return 0;
4624 }
4625 int n = 0;
4626 size_t idx = 0;
4627 size_t max = 0;
4628 yyjson_val *item;
4629 yyjson_arr_foreach(fv, idx, max, item) {
4630 const char *s = yyjson_get_str(item);
4631 if (!s || !s[0] || sg_field_blocked(s)) {
4632 continue;
4633 }
4634 if (sg_field_is_core(s)) {
4635 if (core_requested) {
4636 *core_requested = true;
4637 }
4638 continue;
4639 }
4640 if (n < max_out) {
4641 out[n++] = s;
4642 }
4643 }
4644 if (n == 0) {
4645 yyjson_doc_free(args_doc);
4646 return 0;
4647 }
4648 *out_owner = args_doc;
4649 return n;
4650}
4651
4652/* Append a property as one compact-output cell. Compound values stay one
4653 * column by using their compact JSON representation; the cell emitter quotes

Callers 1

handle_search_graphFunction · 0.85

Calls 2

sg_field_blockedFunction · 0.85
sg_field_is_coreFunction · 0.85

Tested by

no test coverage detected