| 869 | /* ── OpenClaw MCP (nested mcp.servers with command + args) ────── */ |
| 870 | |
| 871 | int cbm_install_openclaw_mcp(const char *binary_path, const char *config_path) { |
| 872 | if (!binary_path || !config_path) { |
| 873 | return CLI_ERR; |
| 874 | } |
| 875 | |
| 876 | yyjson_mut_doc *mdoc = yyjson_mut_doc_new(NULL); |
| 877 | if (!mdoc) { |
| 878 | return CLI_ERR; |
| 879 | } |
| 880 | |
| 881 | yyjson_doc *doc = read_json_file(config_path); |
| 882 | yyjson_mut_val *root; |
| 883 | if (doc) { |
| 884 | root = yyjson_val_mut_copy(mdoc, yyjson_doc_get_root(doc)); |
| 885 | yyjson_doc_free(doc); |
| 886 | } else { |
| 887 | root = yyjson_mut_obj(mdoc); |
| 888 | } |
| 889 | if (!root) { |
| 890 | yyjson_mut_doc_free(mdoc); |
| 891 | return CLI_ERR; |
| 892 | } |
| 893 | yyjson_mut_doc_set_root(mdoc, root); |
| 894 | |
| 895 | yyjson_mut_val *mcp = yyjson_mut_obj_get(root, "mcp"); |
| 896 | if (!mcp || !yyjson_mut_is_obj(mcp)) { |
| 897 | mcp = yyjson_mut_obj(mdoc); |
| 898 | yyjson_mut_obj_add_val(mdoc, root, "mcp", mcp); |
| 899 | } |
| 900 | |
| 901 | yyjson_mut_val *servers = yyjson_mut_obj_get(mcp, "servers"); |
| 902 | if (!servers || !yyjson_mut_is_obj(servers)) { |
| 903 | servers = yyjson_mut_obj(mdoc); |
| 904 | yyjson_mut_obj_add_val(mdoc, mcp, "servers", servers); |
| 905 | } |
| 906 | |
| 907 | yyjson_mut_obj_remove_key(servers, "codebase-memory-mcp"); |
| 908 | |
| 909 | yyjson_mut_val *entry = yyjson_mut_obj(mdoc); |
| 910 | yyjson_mut_obj_add_bool(mdoc, entry, "enabled", true); |
| 911 | yyjson_mut_obj_add_str(mdoc, entry, "command", binary_path); |
| 912 | yyjson_mut_val *args = yyjson_mut_arr(mdoc); |
| 913 | yyjson_mut_obj_add_val(mdoc, entry, "args", args); |
| 914 | yyjson_mut_obj_add_val(mdoc, servers, "codebase-memory-mcp", entry); |
| 915 | |
| 916 | int rc = write_json_file(config_path, mdoc); |
| 917 | yyjson_mut_doc_free(mdoc); |
| 918 | return rc; |
| 919 | } |
| 920 | |
| 921 | int cbm_remove_openclaw_mcp(const char *config_path) { |
| 922 | if (!config_path) { |
no test coverage detected