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

Source from the content-addressed store, hash-verified

11944}
11945
11946int cbm_cli_print_tool_help(const char *tool_name) {
11947 const char *schema_str = cbm_mcp_tool_input_schema(tool_name);
11948 if (!schema_str) {
11949 return CLI_ERR;
11950 }
11951
11952 yyjson_doc *doc = yyjson_read(schema_str, strlen(schema_str), 0);
11953 yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL;
11954 yyjson_val *props = root ? yyjson_obj_get(root, "properties") : NULL;
11955 yyjson_val *required = root ? yyjson_obj_get(root, "required") : NULL;
11956
11957 printf("Usage:\n");
11958 printf(" codebase-memory-mcp cli %s --flag value [--flag2 value2 ...]\n", tool_name);
11959 printf(" codebase-memory-mcp cli %s --args-file <path-to-json>\n", tool_name);
11960 printf(" echo '<json>' | codebase-memory-mcp cli %s\n", tool_name);
11961 printf(" codebase-memory-mcp cli %s '<raw-json-args>'\n", tool_name);
11962
11963 printf("\nFlags:\n");
11964 if (props && yyjson_is_obj(props)) {
11965 yyjson_obj_iter iter;
11966 yyjson_obj_iter_init(props, &iter);
11967 yyjson_val *pkey;
11968 while ((pkey = yyjson_obj_iter_next(&iter)) != NULL) {
11969 yyjson_val *pval = yyjson_obj_iter_get_val(pkey);
11970 const char *name = yyjson_get_str(pkey);
11971 if (!name) {
11972 continue;
11973 }
11974 const char *type = "string";
11975 const char *desc = "";
11976 if (yyjson_is_obj(pval)) {
11977 yyjson_val *t = yyjson_obj_get(pval, "type");
11978 if (t && yyjson_is_str(t)) {
11979 type = yyjson_get_str(t);
11980 }
11981 yyjson_val *d = yyjson_obj_get(pval, "description");
11982 if (d && yyjson_is_str(d)) {
11983 desc = yyjson_get_str(d);
11984 }
11985 }
11986 char flag[CLI_BUF_256];
11987 snprintf(flag, sizeof(flag), "%s", name);
11988 cli_snake_to_kebab(flag);
11989 bool req = cli_schema_required_has(required, name);
11990 printf(" --%s <%s>%s", flag, type, req ? " [required]" : "");
11991 if (desc[0]) {
11992 printf(" %s", desc);
11993 }
11994 printf("\n");
11995 }
11996 }
11997
11998 if (doc) {
11999 yyjson_doc_free(doc);
12000 }
12001 return CLI_OK;
12002}

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