Register or unregister our server against every existing OpenHands agent * profile's mcp_server_refs array (#1826). A missing agent-profiles/ * directory is a silent no-op in both directions — install must never invent * it, and uninstall has nothing to undo there. Only *.json entries are * touched; a profile directory may hold arbitrary notes alongside profiles. */
| 9965 | * it, and uninstall has nothing to undo there. Only *.json entries are |
| 9966 | * touched; a profile directory may hold arbitrary notes alongside profiles. */ |
| 9967 | static void openhands_update_profile_refs(const char *profiles_dir, bool installing, bool dry_run) { |
| 9968 | cbm_dir_t *d = cbm_opendir(profiles_dir); |
| 9969 | if (!d) { |
| 9970 | return; |
| 9971 | } |
| 9972 | cbm_dirent_t *ent; |
| 9973 | while ((ent = cbm_readdir(d)) != NULL) { |
| 9974 | if (strcmp(ent->name, ".") == 0 || strcmp(ent->name, "..") == 0 || |
| 9975 | !cbm_filename_has_suffix(ent->name, ".json")) { |
| 9976 | continue; |
| 9977 | } |
| 9978 | char profile_path[CLI_BUF_1K]; |
| 9979 | snprintf(profile_path, sizeof(profile_path), "%s/%s", profiles_dir, ent->name); |
| 9980 | struct stat state; |
| 9981 | if (stat(profile_path, &state) != 0 || !S_ISREG(state.st_mode) || dry_run) { |
| 9982 | continue; |
| 9983 | } |
| 9984 | int result = installing ? cbm_json_like_add_unique_string(profile_path, "mcp_server_refs", |
| 9985 | CBM_DEFAULT_MCP_SERVER_NAME) |
| 9986 | : cbm_json_like_remove_string(profile_path, "mcp_server_refs", |
| 9987 | CBM_DEFAULT_MCP_SERVER_NAME); |
| 9988 | if (result != CLI_OK) { |
| 9989 | record_agent_config_error( |
| 9990 | !installing, "OpenHands", |
| 9991 | installing ? "profile_refs_install" : "profile_refs_uninstall", profile_path); |
| 9992 | } |
| 9993 | } |
| 9994 | cbm_closedir(d); |
| 9995 | } |
| 9996 | |
| 9997 | /* Install MCP configs for editor-based agents (Zed, KiloCode, VS Code, OpenClaw). */ |
| 9998 | static void install_editor_agent_configs(const cbm_detected_agents_t *agents, const char *home, |
no test coverage detected