feat: migrate_workspace_provider + get_workspace_migration_status MCP tools #65
Reference in New Issue
Block a user
Delete Branch "feat/migrate-workspace-provider"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Adds two CP-tier management tools that wrap the control-plane cross-cloud provider-migration endpoint, closing the capability gap (#64) where the canvas can migrate a workspace's compute box across clouds (AWS ↔ Hetzner ↔ GCP) but the management MCP could not.
update_workspaceexposes tier but has no provider field, so there was no path to change a workspace's compute provider through the MCP.Tools
migrate_workspace_provider—POST /api/v1/admin/workspaces/:id/migrate-provider{from,to,confirm:true,…}→202 {status:"migration_started"}. Data-safe + async (~15-20 min): CP snapshots the source's/workspaceto R2, provisions the target (restores on boot), verifies health, then retires the source (verify-before-destroy + rollback live in CP).get_workspace_migration_status—GETsame path →{migration:{state,from_provider,to_provider,detail,…}, terminal};404mapped to a cleanNOT_FOUND.Contract guards (client-side, fail-fast)
Mirrors the CP handler so a bad call surfaces a clear message instead of round-tripping a CP 400/503:
torequired, provider enumaws|hetzner|gcp.fromrequired by CP; auto-resolved from the workspace's current provider when omitted; must differ fromto.confirm:trueis mandatory — a real migration mutates two clouds. confirm defaults to false; the tool refuses without it (never auto-confirms a destructive op).from_instance_idrequired for non-AWS (Hetzner/GCP) sources (no workspace→instance resolver); optional for AWS (CP resolves from EC2 tags, cp#711).Both tools are gated on
CP_ADMIN_API_TOKEN(the Org API Key cannot reach the control plane), living incp_admin.tsalongside the existingrecreate_workspacetool and following its exact pattern.Tests
New Jest coverage (full suite green: 314 passed, 1 skipped): URL/method/body/auth-bearer, CP-tier gating, confirm-gating,
fromauto-resolution +FROM_UNRESOLVED, non-AWSfrom_instance_idrequirement,from===torejection, 404→NOT_FOUND, and CP error mapping. Registration assertion updated for the two new tool names.Closes #64
🤖 Generated with Claude Code
Add two CP-tier management tools that wrap the control-plane cross-cloud provider-migration endpoint, closing the capability gap where the canvas can migrate a workspace's compute box across clouds (AWS <-> Hetzner <-> GCP) but the management MCP could not. - migrate_workspace_provider: POST /api/v1/admin/workspaces/:id/migrate-provider {from,to,confirm:true,...} -> 202 {status:migration_started}. Resolves `from` from the workspace when omitted, enforces the CP contract guards client-side (provider enum, from!=to, confirm required, from_instance_id required for non-AWS sources), and never auto-confirms a destructive two-cloud op (confirm defaults to false). - get_workspace_migration_status: GET same path -> {migration:{state,...}, terminal}; maps 404 to a clean NOT_FOUND. Both gated on CP_ADMIN_API_TOKEN (the Org API Key cannot reach the CP), mirroring the existing recreate_workspace cp_admin tool. Jest tests cover the URL/method/body/auth, confirm-gating, from auto-resolution, non-AWS from_instance_id requirement, and CP error mapping. Closes #64 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>APPROVED
8d44bee0. 5-axis clean: correctness adds the two CP-tier migration tools against the documented admin migrate-provider endpoint with status polling; robustness covers confirm gating, provider/from validation, non-AWS from_instance_id, 404 mapping, URL encoding, and CP error paths; security keeps the tools behind CP_ADMIN_API_TOKEN and never auto-confirms the destructive migration; performance adds only async CP calls/no blocking local work; readability and tests are clear. Note: Gitea PR diff/files endpoints returned 500, so review used local git diff against origin/main.5-axis review on head
8d44bee0: correctness/robustness/security/performance/readability checked via local diff against origin/main because Gitea diff/files returned 500. The new handlers themselves are CP_ADMIN_API_TOKEN-gated, use the CP admin bearer for POST/GET, encode workspace_id, require confirm:true for migration, enforce provider enum/from!=to/non-AWS from_instance_id, and tests exercise the real exported handlers plus registry composition. CI is green.Request changes: contract/documentation drift. The PR adds two public CP-tier management tools, migrate_workspace_provider and get_workspace_migration_status, but README.md still documents the CP-tier surface as only list_orgs/get_org (README.md:126, README.md:158-164) and says CP_ADMIN_API_TOKEN is required only for list_orgs/get_org (README.md:178). src/index.ts:270-272 also has the same stale comment. This makes the public management contract/auth guidance wrong for the new tools. Please update the CP-tier tool list and CP_ADMIN_API_TOKEN wording before merge.
5-axis review: APPROVED. Correctness: migrate_workspace_provider and get_workspace_migration_status are registered CP-tier tools using CP_ADMIN_API_TOKEN, encode workspace ids, enforce confirm:true, validate provider enums, require from_instance_id for non-AWS sources, and surface structured start/status errors. Security: no tenant-org-key escalation; operations are gated on CP admin bearer and status remains CP-admin scoped. Tests: management tests cover token absence, request body/auth/path, confirmation/provider guards, non-AWS source id, auto-resolved from provider, CP errors, 404 status, and registration. Robustness/performance: fail-fast validation avoids destructive bad calls; migration remains async. Readability/scope: contained to cp_admin and tests. Note: Gitea PR files/diff endpoints still 500, so I reviewed local git diff against main.