cancel_run
Stop an in-progress Terraform Cloud run during planning or applying phases. Gracefully interrupts the process, cleans up resources, and logs the cancellation with an optional comment for audit purposes.
Instructions
Cancel a run that is currently planning or applying
Gracefully stops an in-progress run during planning or applying phases. Use this when you need to stop a run that's taking too long, consuming too many resources, or needs to be stopped for any reason. The operation attempts to cleanly terminate the run by sending an interrupt signal.
API endpoint: POST /runs/{run_id}/actions/cancel
Args: run_id: The ID of the run to cancel (format: "run-xxxxxxxx") comment: An optional explanation for why the run was canceled
Returns: Run status update with canceled state, timestamp of cancellation, and any provided comment in the response metadata
See: docs/tools/run.md for reference documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| comment | No | ||
| run_id | Yes |
Implementation Reference
- The main handler function for the 'cancel_run' tool. It constructs a payload with an optional comment and sends a POST request to the Terraform Cloud API endpoint /runs/{run_id}/actions/cancel to gracefully cancel an in-progress run.async def cancel_run(run_id: str, comment: str = "") -> APIResponse: """Cancel a run that is currently planning or applying Gracefully stops an in-progress run during planning or applying phases. Use this when you need to stop a run that's taking too long, consuming too many resources, or needs to be stopped for any reason. The operation attempts to cleanly terminate the run by sending an interrupt signal. API endpoint: POST /runs/{run_id}/actions/cancel Args: run_id: The ID of the run to cancel (format: "run-xxxxxxxx") comment: An optional explanation for why the run was canceled Returns: Run status update with canceled state, timestamp of cancellation, and any provided comment in the response metadata See: docs/tools/run.md for reference documentation """ request = RunActionRequest(run_id=run_id, comment=comment) # Create payload if comment is provided payload = {} if request.comment: payload = {"comment": request.comment} # Make API request return await api_request( f"runs/{run_id}/actions/cancel", method="POST", data=payload )
- terraform_cloud_mcp/server.py:70-70 (registration)Registration of the 'cancel_run' tool using the mcp.tool decorator, referencing the handler from the runs module. The write_tool_config enables the tool and sets annotations indicating it's not read-only.mcp.tool(**write_tool_config)(runs.cancel_run)
- terraform_cloud_mcp/server.py:39-42 (registration)Configuration used in the tool registration that enables write tools and sets appropriate annotations for non-read-only operations.write_tool_config = { "enabled": not read_only_mode, "annotations": {"readOnlyHint": False} }
- terraform_cloud_mcp/server.py:15-15 (registration)Import of the runs module containing the cancel_run handler function.from terraform_cloud_mcp.tools import runs