fix: local_preview MCP tool now works when server CWD is a repo subdirectory#390
Merged
tomasmik merged 1 commit intospacelift-io:mainfrom Mar 16, 2026
Merged
Conversation
… workspaces When the MCP server is started from a subdirectory of a git repository, createLocalPreviewRun archives from that subdirectory rather than the repo root, causing Spacelift to fail with "project root ... does not exist". Save the original CWD before calling createLocalPreviewRun with FindRepositoryRoot=true (same as the CLI), then defer a restore so the long-running MCP server process has its working directory restored after each call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #389
Problem
The
local_previewMCP tool failed when the MCP server was started from a subdirectory of the git repository.createLocalPreviewRunarchives from"."(the process CWD), but the MCP handler passedFindRepositoryRoot: false, so it never walked up to the git root before archiving. Spacelift then couldn't find the stack's configuredproject_rootpath inside the archive.This is a common scenario: editors like VS Code and Claude Code typically open a project at a specific stack subdirectory, so the MCP server inherits a subdirectory as its CWD.
Fix
Save the original CWD before calling
createLocalPreviewRunwithFindRepositoryRoot: true, then defer a restore. This makes the MCP tool walk up to the git root (identical to CLI behavior) while ensuring the long-running MCP server process has its CWD restored after each call.The
defer os.Chdir(origDir)runs whencreateLocalPreviewRunreturns — which is after the archive is built and uploaded — so the upload is unaffected.