fix(mcp): boot when cwd is outside a git repo (#105)#106
Merged
Conversation
Before this change `devkit mcp` ran the root command's git-repo check at startup and exited with `Error: not inside a git repo — run devkit from a project directory` whenever Claude Code's working directory wasn't inside a git checkout. That message went to the engine's stderr, which CC doesn't surface to the user, so the only visible signal was the opaque JSON-RPC server error `-32000`. The MCP server doesn't structurally need git state to complete the initialize handshake — only individual tool calls do (and they own that check). So: - Add an `allow_no_git` cobra annotation that subcommands can set to opt out of the persistent git check. `mcpCmd` sets it. - When the annotation is set and there's no git repo, leave `repoRoot` empty rather than aborting. - Pick the MCP data dir in priority order: `CLAUDE_PLUGIN_DATA` env → `<repoRoot>/.devkit` → `<user cache dir>/devkit`. The last branch is the new one — it handles the non-git case so the DB still has a home. - Relax `mcp.NewServer` to require only `dataDir`; empty `repoRoot` and empty `workflowDir` are tolerated so the handshake can complete. Tools that need git or workflow definitions return structured errors at call time instead of exiting at boot. - Add a regression test that runs `devkit mcp` from a non-git tempdir and asserts the JSON-RPC initialize response lands on stdout. Closes #105.
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.
Summary
Fixes #105 — devkit MCP server failed with opaque
-32000whenever Claude Code's working directory wasn't inside a git repo.Root cause:
rootCmd.PersistentPreRunE(src/cmd/root.go) ran a git-repo check before every subcommand, includingmcp. The error went to stderr, which CC doesn't surface — the user only sawFailed to reconnect to plugin:devkit:devkit-engine: -32000.Fix (issue's Option 1 — defer the git check):
allow_no_gitcobra annotation. Subcommands set it to opt out of the persistent git check.mcpCmdopts out — the MCP server doesn't structurally need git state to complete the JSON-RPC initialize handshake.CLAUDE_PLUGIN_DATA→<repoRoot>/.devkit→<user cache dir>/devkit. The last branch is new and handles the non-git case.mcp.NewServerrelaxed: onlydataDiris required. EmptyrepoRoot/workflowDirare tolerated so the handshake completes; individual tool calls that need git or workflow defs return structured errors at call time instead of exiting at boot.In production CC always sets
CLAUDE_PLUGIN_ROOT, so workflows still resolve regardless of cwd — the user just needs the boot path not to fatal on a missing.git.Test plan
TestMCPInitializeOutsideGitRepo(src/cmd/mcp_test.go) — builds the real binary, runsdevkit mcpfrom a tempdir with no.git, sends a realinitializeJSON-RPC request, asserts the response lands on stdout and the boot doesn't error withnot inside a git repo.TestMCPStdoutIsCleanJSONRPCstill passes (no stdout pollution introduced).go test ./...→ 441 passed in 6 packages./mcpconnects from a non-git cwd.Out of scope
mcpb/manifest.jsonversion drift vs..claude-plugin/plugin.json— separate follow-up to teachrelease.ymlto bump both. The Makefile'ssync-versionstep touched it on local build; reverted before committing so this PR stays scoped.