Remove only an entry that is still recognisably ours (an annotated entry is * left in place and reported, same rule as insertion above); a missing file, * path, or entry is a successful no-op. */
| 2583 | * left in place and reported, same rule as insertion above); a missing file, |
| 2584 | * path, or entry is a successful no-op. */ |
| 2585 | static int cbm_remove_openhands_settings_mcp(const char *settings_path) { |
| 2586 | if (!settings_path) { |
| 2587 | return CLI_ERR; |
| 2588 | } |
| 2589 | static const char *const path[] = {"mcp_config"}; |
| 2590 | char *document = NULL; |
| 2591 | size_t document_length = 0U; |
| 2592 | int read_result = cbm_json_like_read_document(settings_path, &document, &document_length); |
| 2593 | if (read_result == 1) { |
| 2594 | free(document); |
| 2595 | return CLI_OK; |
| 2596 | } |
| 2597 | if (read_result < 0) { |
| 2598 | free(document); |
| 2599 | return CLI_ERR; |
| 2600 | } |
| 2601 | cbm_json_like_object_field_t fields[3]; |
| 2602 | size_t field_count = cbm_openhands_ownership_fields(fields); |
| 2603 | char *command = NULL; |
| 2604 | int ownership = cbm_json_like_match_object_entry(document, document_length, path, 1U, |
| 2605 | CBM_DEFAULT_MCP_SERVER_NAME, fields, |
| 2606 | field_count, &command); |
| 2607 | free(command); |
| 2608 | if (ownership == CBM_JSON_LIKE_OBJECT_MISSING || ownership == CBM_JSON_LIKE_OBJECT_MISMATCH) { |
| 2609 | free(document); |
| 2610 | return CLI_OK; |
| 2611 | } |
| 2612 | if (ownership != CBM_JSON_LIKE_OBJECT_MATCH) { |
| 2613 | free(document); |
| 2614 | return CLI_ERR; |
| 2615 | } |
| 2616 | int edit_result = cbm_json_like_remove_entry_if_unchanged( |
| 2617 | settings_path, path, 1U, CBM_DEFAULT_MCP_SERVER_NAME, document, document_length); |
| 2618 | free(document); |
| 2619 | return edit_result == 0 ? CLI_OK : CLI_ERR; |
| 2620 | } |
| 2621 | |
| 2622 | /* ── VS Code MCP (servers key with type:stdio) ────────────────── */ |
| 2623 |
no test coverage detected