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

Function cbm_cli_print_tool_help

src/cli/cli.c:12400–12456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12398}
12399
12400int cbm_cli_print_tool_help(const char *tool_name) {
12401 const char *schema_str = cbm_mcp_tool_input_schema(tool_name);
12402 if (!schema_str) {
12403 return CLI_ERR;
12404 }
12405
12406 yyjson_doc *doc = yyjson_read(schema_str, strlen(schema_str), 0);
12407 yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL;
12408 yyjson_val *props = root ? yyjson_obj_get(root, "properties") : NULL;
12409 yyjson_val *required = root ? yyjson_obj_get(root, "required") : NULL;
12410
12411 printf("Usage:\n");
12412 printf(" codebase-memory-mcp cli %s --flag value [--flag2 value2 ...]\n", tool_name);
12413 printf(" codebase-memory-mcp cli %s --args-file <path-to-json>\n", tool_name);
12414 printf(" echo '<json>' | codebase-memory-mcp cli %s\n", tool_name);
12415 printf(" codebase-memory-mcp cli %s '<raw-json-args>'\n", tool_name);
12416
12417 printf("\nFlags:\n");
12418 if (props && yyjson_is_obj(props)) {
12419 yyjson_obj_iter iter;
12420 yyjson_obj_iter_init(props, &iter);
12421 yyjson_val *pkey;
12422 while ((pkey = yyjson_obj_iter_next(&iter)) != NULL) {
12423 yyjson_val *pval = yyjson_obj_iter_get_val(pkey);
12424 const char *name = yyjson_get_str(pkey);
12425 if (!name) {
12426 continue;
12427 }
12428 const char *type = "string";
12429 const char *desc = "";
12430 if (yyjson_is_obj(pval)) {
12431 yyjson_val *t = yyjson_obj_get(pval, "type");
12432 if (t && yyjson_is_str(t)) {
12433 type = yyjson_get_str(t);
12434 }
12435 yyjson_val *d = yyjson_obj_get(pval, "description");
12436 if (d && yyjson_is_str(d)) {
12437 desc = yyjson_get_str(d);
12438 }
12439 }
12440 char flag[CLI_BUF_256];
12441 snprintf(flag, sizeof(flag), "%s", name);
12442 cli_snake_to_kebab(flag);
12443 bool req = cli_schema_required_has(required, name);
12444 printf(" --%s <%s>%s", flag, type, req ? " [required]" : "");
12445 if (desc[0]) {
12446 printf(" %s", desc);
12447 }
12448 printf("\n");
12449 }
12450 }
12451
12452 if (doc) {
12453 yyjson_doc_free(doc);
12454 }
12455 return CLI_OK;
12456}

Callers 2

run_cliFunction · 0.85
test_cli.cFile · 0.85

Calls 3

cli_snake_to_kebabFunction · 0.85
cli_schema_required_hasFunction · 0.85

Tested by

no test coverage detected