cloud_clear
Delete cloud repositories and local sync state to switch projects, reset after major restructuring, or clean up unused repositories. This irreversible action permanently removes remote data.
Instructions
Delete the cloud repository and local sync state.
Use when: switching to a different project, resetting after major codebase restructuring, or cleaning up unused cloud repositories.
WARNING: This action is IRREVERSIBLE. It permanently deletes the remote repository and removes the local sync state file.
Args: confirm: Must be True to proceed. Acts as a safety guard.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| confirm | No |
Implementation Reference
- src/relace_mcp/tools/__init__.py:149-166 (handler)The MCP tool handler for 'cloud_clear', decorated with @mcp.tool. It resolves the base directory using resolve_base_dir and calls the cloud_clear_logic helper with the repo_client and confirm flag. This function defines the input schema via its parameters and docstring.@mcp.tool async def cloud_clear(confirm: bool = False, ctx: Context | None = None) -> dict[str, Any]: """Delete the cloud repository and local sync state. Use when: switching to a different project, resetting after major codebase restructuring, or cleaning up unused cloud repositories. WARNING: This action is IRREVERSIBLE. It permanently deletes the remote repository and removes the local sync state file. Args: confirm: Must be True to proceed. Acts as a safety guard. """ from .repo.clear import cloud_clear_logic base_dir, _ = await resolve_base_dir(config.base_dir, ctx) return cloud_clear_logic(repo_client, base_dir, confirm=confirm)
- The core implementation logic for clearing the cloud repository. It checks confirmation, attempts to find the repo_id from local state or API search, deletes the repo via client.delete_repo, clears local sync state, and returns status details.def cloud_clear_logic( client: RelaceRepoClient, base_dir: str, confirm: bool = False, ) -> dict[str, Any]: """Clear (delete) the cloud repository and local sync state. Args: client: RelaceRepoClient instance. base_dir: Base directory of the repository. confirm: Confirmation flag to proceed with deletion. Returns: Dict containing operation result. """ trace_id = str(uuid.uuid4())[:8] logger.info("[%s] Starting cloud clear from %s", trace_id, base_dir) if not confirm: return { "status": "cancelled", "message": "Operation cancelled. Access to this tool requires 'confirm=True' to proceed with irreversible deletion.", "repo_id": None, } try: repo_name = client.get_repo_name_from_base_dir(base_dir) # 1. Try to get repo_id from local sync state (safest) repo_id = None sync_state = load_sync_state(repo_name) if sync_state: repo_id = sync_state.repo_id logger.info("[%s] Found repo_id %s from local sync state", trace_id, repo_id) # 2. Fallback: Search by name (riskier, but needed if local state is missing) if not repo_id: logger.warning( "[%s] No local sync state found for '%s', searching API...", trace_id, repo_name ) repos = client.list_repos(trace_id=trace_id) matching_repos = [] for r in repos: # Handle different API response structures if necessary metadata = r.get("metadata") or {} r_name = metadata.get("name") or r.get("name") if r_name == repo_name: matching_repos.append(r) if len(matching_repos) > 1: logger.error( "[%s] Multiple repos found with name '%s', aborting unsafe delete", trace_id, repo_name, ) return { "status": "error", "message": f"Multiple repositories found with name '{repo_name}'. Cannot safely delete unambiguously.", "repo_name": repo_name, } if matching_repos: r = matching_repos[0] repo_id = r.get("repo_id") or r.get("id") if not repo_id: logger.info("[%s] No repository found for '%s'", trace_id, repo_name) # Even if repo not found remotely, ensure local state is clean clear_sync_state(repo_name) return { "status": "not_found", "message": f"Repository '{repo_name}' not found on cloud.", "repo_name": repo_name, } # 3. specific deletion logger.info("[%s] Deleting repo '%s' (%s)...", trace_id, repo_name, repo_id) if client.delete_repo(repo_id, trace_id=trace_id): # 4. Clear local state only after successful remote deletion clear_sync_state(repo_name) return { "status": "deleted", "message": f"Repository '{repo_name}' ({repo_id}) and local sync state deleted successfully.", "repo_name": repo_name, "repo_id": repo_id, } else: return { "status": "error", "message": f"Failed to delete repository '{repo_name}' ({repo_id}).", "repo_name": repo_name, "repo_id": repo_id, } except Exception as exc: logger.error("[%s] Cloud clear failed: %s", trace_id, exc) return { "status": "error", "message": f"Operation failed: {str(exc)}", "error": str(exc), }
- src/relace_mcp/tools/__init__.py:225-229 (registration)Explicit listing of the 'cloud_clear' tool in the relace://tool_list MCP resource, confirming its ID and metadata."id": "cloud_clear", "name": "Cloud Clear", "description": "Delete cloud repository and sync state", "enabled": True, },