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

Source from the content-addressed store, hash-verified

14185#endif
14186
14187char *cbm_cli_build_args_json(const char *tool_name, int argc, char **argv, char **err_out) {
14188 if (err_out) {
14189 *err_out = NULL;
14190 }
14191
14192 /* The tool's input_schema (may be NULL for an unknown tool — then every
14193 * value is treated as a string). Static lifetime; do not free. */
14194 const char *schema_str = cbm_mcp_tool_input_schema(tool_name);
14195 yyjson_doc *schema_doc = NULL;
14196 yyjson_val *props = NULL;
14197 if (schema_str) {
14198 schema_doc = yyjson_read(schema_str, strlen(schema_str), 0);
14199 if (schema_doc) {
14200 props = yyjson_obj_get(yyjson_doc_get_root(schema_doc), "properties");
14201 }
14202 }
14203
14204 yyjson_mut_doc *out = yyjson_mut_doc_new(NULL);
14205 if (!out) {
14206 if (schema_doc) {
14207 yyjson_doc_free(schema_doc);
14208 }
14209 return NULL;
14210 }
14211 yyjson_mut_val *obj = yyjson_mut_obj(out);
14212 yyjson_mut_doc_set_root(out, obj);
14213
14214 bool ok = true;
14215 for (int i = 0; i < argc && ok; i++) {
14216 const char *arg = argv[i];
14217 if (strcmp(arg, "--") == 0) {
14218 break; /* end of flag parsing */
14219 }
14220 if (strncmp(arg, "--", CLI_PAIR_LEN) != 0) {
14221 if (err_out) {
14222 *err_out = cli_heap_msgf("unexpected argument '%s' (expected --flag value)", arg);
14223 }
14224 ok = false;
14225 break;
14226 }
14227
14228 const char *body = arg + CLI_PAIR_LEN; /* skip leading "--" */
14229 const char *eq = strchr(body, '=');
14230 char key[CLI_BUF_256];
14231 const char *value = NULL;
14232 bool have_value = false;
14233
14234 if (eq) {
14235 /* --key=value : split on the FIRST '='; value may contain '='/spaces. */
14236 size_t klen = (size_t)(eq - body);
14237 if (klen >= sizeof(key)) {
14238 klen = sizeof(key) - CLI_SKIP_ONE;
14239 }
14240 memcpy(key, body, klen);
14241 key[klen] = '\0';
14242 value = eq + CLI_SKIP_ONE;
14243 have_value = true;
14244 } 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