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

Function cbm_cli_build_args_json

src/cli/cli.c:12607–12729  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12605}
12606
12607char *cbm_cli_build_args_json(const char *tool_name, int argc, char **argv, char **err_out) {
12608 if (err_out) {
12609 *err_out = NULL;
12610 }
12611
12612 /* The tool's input_schema (may be NULL for an unknown tool — then every
12613 * value is treated as a string). Static lifetime; do not free. */
12614 const char *schema_str = cbm_mcp_tool_input_schema(tool_name);
12615 yyjson_doc *schema_doc = NULL;
12616 yyjson_val *props = NULL;
12617 if (schema_str) {
12618 schema_doc = yyjson_read(schema_str, strlen(schema_str), 0);
12619 if (schema_doc) {
12620 props = yyjson_obj_get(yyjson_doc_get_root(schema_doc), "properties");
12621 }
12622 }
12623
12624 yyjson_mut_doc *out = yyjson_mut_doc_new(NULL);
12625 if (!out) {
12626 if (schema_doc) {
12627 yyjson_doc_free(schema_doc);
12628 }
12629 return NULL;
12630 }
12631 yyjson_mut_val *obj = yyjson_mut_obj(out);
12632 yyjson_mut_doc_set_root(out, obj);
12633
12634 bool ok = true;
12635 for (int i = 0; i < argc && ok; i++) {
12636 const char *arg = argv[i];
12637 if (strcmp(arg, "--") == 0) {
12638 break; /* end of flag parsing */
12639 }
12640 if (strncmp(arg, "--", CLI_PAIR_LEN) != 0) {
12641 if (err_out) {
12642 *err_out = cli_heap_msgf("unexpected argument '%s' (expected --flag value)", arg);
12643 }
12644 ok = false;
12645 break;
12646 }
12647
12648 const char *body = arg + CLI_PAIR_LEN; /* skip leading "--" */
12649 const char *eq = strchr(body, '=');
12650 char key[CLI_BUF_256];
12651 const char *value = NULL;
12652 bool have_value = false;
12653
12654 if (eq) {
12655 /* --key=value : split on the FIRST '='; value may contain '='/spaces. */
12656 size_t klen = (size_t)(eq - body);
12657 if (klen >= sizeof(key)) {
12658 klen = sizeof(key) - CLI_SKIP_ONE;
12659 }
12660 memcpy(key, body, klen);
12661 key[klen] = '\0';
12662 value = eq + CLI_SKIP_ONE;
12663 have_value = true;
12664 } else {

Callers 2

run_cliFunction · 0.85
test_cli.cFile · 0.85

Calls 7

cli_heap_msgfFunction · 0.85
cli_kebab_to_snakeFunction · 0.85
cli_schema_typeFunction · 0.85
cli_snake_to_kebabFunction · 0.85
cli_closest_propFunction · 0.85
cli_add_typedFunction · 0.85

Tested by

no test coverage detected