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:11892–12014  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11890}
11891
11892char *cbm_cli_build_args_json(const char *tool_name, int argc, char **argv, char **err_out) {
11893 if (err_out) {
11894 *err_out = NULL;
11895 }
11896
11897 /* The tool's input_schema (may be NULL for an unknown tool — then every
11898 * value is treated as a string). Static lifetime; do not free. */
11899 const char *schema_str = cbm_mcp_tool_input_schema(tool_name);
11900 yyjson_doc *schema_doc = NULL;
11901 yyjson_val *props = NULL;
11902 if (schema_str) {
11903 schema_doc = yyjson_read(schema_str, strlen(schema_str), 0);
11904 if (schema_doc) {
11905 props = yyjson_obj_get(yyjson_doc_get_root(schema_doc), "properties");
11906 }
11907 }
11908
11909 yyjson_mut_doc *out = yyjson_mut_doc_new(NULL);
11910 if (!out) {
11911 if (schema_doc) {
11912 yyjson_doc_free(schema_doc);
11913 }
11914 return NULL;
11915 }
11916 yyjson_mut_val *obj = yyjson_mut_obj(out);
11917 yyjson_mut_doc_set_root(out, obj);
11918
11919 bool ok = true;
11920 for (int i = 0; i < argc && ok; i++) {
11921 const char *arg = argv[i];
11922 if (strcmp(arg, "--") == 0) {
11923 break; /* end of flag parsing */
11924 }
11925 if (strncmp(arg, "--", CLI_PAIR_LEN) != 0) {
11926 if (err_out) {
11927 *err_out = cli_heap_msgf("unexpected argument '%s' (expected --flag value)", arg);
11928 }
11929 ok = false;
11930 break;
11931 }
11932
11933 const char *body = arg + CLI_PAIR_LEN; /* skip leading "--" */
11934 const char *eq = strchr(body, '=');
11935 char key[CLI_BUF_256];
11936 const char *value = NULL;
11937 bool have_value = false;
11938
11939 if (eq) {
11940 /* --key=value : split on the FIRST '='; value may contain '='/spaces. */
11941 size_t klen = (size_t)(eq - body);
11942 if (klen >= sizeof(key)) {
11943 klen = sizeof(key) - CLI_SKIP_ONE;
11944 }
11945 memcpy(key, body, klen);
11946 key[klen] = '\0';
11947 value = eq + CLI_SKIP_ONE;
11948 have_value = true;
11949 } 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