Skip to content

Add force_unlock_workspace tool#371

Open
sebin wants to merge 3 commits into
hashicorp:mainfrom
sebin:feat/force-unlock-workspace
Open

Add force_unlock_workspace tool#371
sebin wants to merge 3 commits into
hashicorp:mainfrom
sebin:feat/force-unlock-workspace

Conversation

@sebin

@sebin sebin commented May 25, 2026

Copy link
Copy Markdown

Closes #372.

Summary

  • New TFE tool force_unlock_workspace that force-unlocks a Terraform workspace by ID via go-tfe Workspaces.ForceUnlock.
  • Intended as a recovery action for stuck workspace locks (e.g. after an interrupted run).
  • Annotated as destructive (ReadOnlyHint=false, DestructiveHint=true, OpenWorldHint=true) and gated behind ENABLE_TF_OPERATIONS, matching delete_workspace_safely and action_run.

Why

The force-unlock workspace action is a recovery path operators need but it isn't exposed by the MCP server today. Engineers hitting a stuck workspace lock have to leave their AI assistant context and call the TFE API by hand. Adding it here closes that gap while keeping the operation gated behind the same opt-in flag as the other destructive workspace tools. See #372 for the full feature-request rationale and open questions.

Changes

  • pkg/tools/tfe/force_unlock_workspace.go — tool definition + handler, follows the delete_workspace_safely pattern.
  • pkg/tools/tfe/force_unlock_workspace_test.go — unit tests for tool creation, annotations, parameter validation, ID format.
  • pkg/tools/dynamic_tool.go — registers the tool when ENABLE_TF_OPERATIONS=true and the toolset is enabled.
  • pkg/toolsets/mapping.go — maps force_unlock_workspace to the Terraform toolset.
  • cmd/terraform-mcp-server/instructions.md — documents the new tool under Workspace Management.
  • CHANGELOG.md — entry under 0.5.3 FEATURES.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • go test ./... — 583 tests pass (10 packages)
  • go test ./pkg/tools/tfe/ -run TestForceUnlock -v — 12 new assertions pass

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.
  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request. (Pure additive: revert this PR to remove the tool. No data/schema migrations.)
  • If applicable, I've documented the impact of any changes to security controls. (No change to existing controls. The new tool is destructive and is therefore gated behind ENABLE_TF_OPERATIONS, the same opt-in flag already used by delete_workspace_safely and action_run. It additionally requires a valid TFE_TOKEN whose principal must have can-force-unlock permission on the target workspace; the underlying TFE API enforces that.)

Adds a new TFE tool that force-unlocks a Terraform workspace by ID via
the go-tfe Workspaces.ForceUnlock API. This is intended as a recovery
action when a workspace lock is stuck (for example after an interrupted
run); using it while a run is still active can leave workspace state
inconsistent, so the tool is annotated destructive and gated behind
ENABLE_TF_OPERATIONS, matching delete_workspace_safely and action_run.

- pkg/tools/tfe/force_unlock_workspace.go: tool + handler
- pkg/tools/tfe/force_unlock_workspace_test.go: unit tests
- pkg/tools/dynamic_tool.go: ENABLE_TF_OPERATIONS-gated registration
- pkg/toolsets/mapping.go: maps tool to the Terraform toolset
- cmd/terraform-mcp-server/instructions.md: documents the new tool
@sebin sebin requested a review from a team as a code owner May 25, 2026 14:42
@hashicorp-cla-app

hashicorp-cla-app Bot commented May 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add force_unlock_workspace MCP tool

1 participant