| 959 | /* ── VS Code MCP (servers key with type:stdio) ────────────────── */ |
| 960 | |
| 961 | int cbm_install_vscode_mcp(const char *binary_path, const char *config_path) { |
| 962 | if (!binary_path || !config_path) { |
| 963 | return CLI_ERR; |
| 964 | } |
| 965 | |
| 966 | yyjson_mut_doc *mdoc = yyjson_mut_doc_new(NULL); |
| 967 | if (!mdoc) { |
| 968 | return CLI_ERR; |
| 969 | } |
| 970 | |
| 971 | yyjson_doc *doc = read_json_file(config_path); |
| 972 | yyjson_mut_val *root; |
| 973 | if (doc) { |
| 974 | root = yyjson_val_mut_copy(mdoc, yyjson_doc_get_root(doc)); |
| 975 | yyjson_doc_free(doc); |
| 976 | } else { |
| 977 | root = yyjson_mut_obj(mdoc); |
| 978 | } |
| 979 | if (!root) { |
| 980 | yyjson_mut_doc_free(mdoc); |
| 981 | return CLI_ERR; |
| 982 | } |
| 983 | yyjson_mut_doc_set_root(mdoc, root); |
| 984 | |
| 985 | yyjson_mut_val *servers = yyjson_mut_obj_get(root, "servers"); |
| 986 | if (!servers || !yyjson_mut_is_obj(servers)) { |
| 987 | servers = yyjson_mut_obj(mdoc); |
| 988 | yyjson_mut_obj_add_val(mdoc, root, "servers", servers); |
| 989 | } |
| 990 | |
| 991 | yyjson_mut_obj_remove_key(servers, "codebase-memory-mcp"); |
| 992 | |
| 993 | yyjson_mut_val *entry = yyjson_mut_obj(mdoc); |
| 994 | yyjson_mut_obj_add_str(mdoc, entry, "type", "stdio"); |
| 995 | yyjson_mut_obj_add_str(mdoc, entry, "command", binary_path); |
| 996 | yyjson_mut_obj_add_val(mdoc, servers, "codebase-memory-mcp", entry); |
| 997 | |
| 998 | int rc = write_json_file(config_path, mdoc); |
| 999 | yyjson_mut_doc_free(mdoc); |
| 1000 | return rc; |
| 1001 | } |
| 1002 | |
| 1003 | int cbm_remove_vscode_mcp(const char *config_path) { |
| 1004 | if (!config_path) { |
no test coverage detected