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

Source from the content-addressed store, hash-verified

11816}
11817
11818char *cbm_cli_build_args_json(const char *tool_name, int argc, char **argv, char **err_out) {
11819 if (err_out) {
11820 *err_out = NULL;
11821 }
11822
11823 /* The tool's input_schema (may be NULL for an unknown tool — then every
11824 * value is treated as a string). Static lifetime; do not free. */
11825 const char *schema_str = cbm_mcp_tool_input_schema(tool_name);
11826 yyjson_doc *schema_doc = NULL;
11827 yyjson_val *props = NULL;
11828 if (schema_str) {
11829 schema_doc = yyjson_read(schema_str, strlen(schema_str), 0);
11830 if (schema_doc) {
11831 props = yyjson_obj_get(yyjson_doc_get_root(schema_doc), "properties");
11832 }
11833 }
11834
11835 yyjson_mut_doc *out = yyjson_mut_doc_new(NULL);
11836 if (!out) {
11837 if (schema_doc) {
11838 yyjson_doc_free(schema_doc);
11839 }
11840 return NULL;
11841 }
11842 yyjson_mut_val *obj = yyjson_mut_obj(out);
11843 yyjson_mut_doc_set_root(out, obj);
11844
11845 bool ok = true;
11846 for (int i = 0; i < argc && ok; i++) {
11847 const char *arg = argv[i];
11848 if (strcmp(arg, "--") == 0) {
11849 break; /* end of flag parsing */
11850 }
11851 if (strncmp(arg, "--", CLI_PAIR_LEN) != 0) {
11852 if (err_out) {
11853 *err_out = cli_heap_msgf("unexpected argument '%s' (expected --flag value)", arg);
11854 }
11855 ok = false;
11856 break;
11857 }
11858
11859 const char *body = arg + CLI_PAIR_LEN; /* skip leading "--" */
11860 const char *eq = strchr(body, '=');
11861 char key[CLI_BUF_256];
11862 const char *value = NULL;
11863 bool have_value = false;
11864
11865 if (eq) {
11866 /* --key=value : split on the FIRST '='; value may contain '='/spaces. */
11867 size_t klen = (size_t)(eq - body);
11868 if (klen >= sizeof(key)) {
11869 klen = sizeof(key) - CLI_SKIP_ONE;
11870 }
11871 memcpy(key, body, klen);
11872 key[klen] = '\0';
11873 value = eq + CLI_SKIP_ONE;
11874 have_value = true;
11875 } 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