flipped-aurora/gin-vue-admin · error

未能自动识别项目根目录,请在 MCP 配置中设置 autocode.root

Error message

未能自动识别项目根目录,请在 MCP 配置中设置 autocode.root

What it means

applyStandaloneDefaults auto-detects the project root by walking upward from the config/binary location looking for a marker (go.mod etc.). If the walk reaches the filesystem root without a match, it errors and asks the user to set autocode.root in the MCP config.

Source

Thrown at server/cmd/mcp/config.go:164

}

func detectProjectRoot(startDir string) (string, error) {
	dir := startDir
	for {
		serverDir := filepath.Join(dir, "server")
		webDir := filepath.Join(dir, "web")
		if isDir(serverDir) && isDir(webDir) {
			return dir, nil
		}

		parent := filepath.Dir(dir)
		if parent == dir {
			break
		}
		dir = parent
	}

	return "", errors.New("未能自动识别项目根目录,请在 MCP 配置中设置 autocode.root")
}

func detectGoModule(goModPath string) (string, error) {
	file, err := os.Open(goModPath)
	if err != nil {
		return "", err
	}
	defer file.Close()

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := strings.TrimSpace(scanner.Text())
		if strings.HasPrefix(line, "module ") {
			return strings.TrimSpace(strings.TrimPrefix(line, "module ")), nil
		}
	}

	if err := scanner.Err(); err != nil {

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Set autocode.root: /absolute/path/to/project in the MCP config.yaml
  2. Run the mcp server from within the project directory so detection finds the marker
  3. Ensure go.mod (or the marker it looks for) exists at the project root

Example fix

# mcp config.yaml
# before
autocode:
  # root not set
# after
autocode:
  root: /home/user/projects/gin-vue-admin/server
Defensive patterns

Strategy: validation

Validate before calling

# before launch, verify autocode.root resolves to a dir containing go.mod
ROOT=$(yq '.autocode.root' config.yaml)
[ -f "$ROOT/go.mod" ] || { echo "autocode.root ($ROOT) missing go.mod" >&2; exit 1; }

Try / catch

root, err := detectProjectRoot(startDir)
if err != nil {
  return fmt.Errorf("resolve project root: %w (set autocode.root to skip detection)", err)
}

Prevention

When it happens

Trigger: No autocode.root configured and no ancestor directory of the working directory contains the root marker (e.g. config placed in an isolated dir, or running outside a checkout).

Common situations: Deploying the mcp binary into a bare directory without the repo; project root detection depending on go.mod but repo checked out without it; symlinked/overlay paths confusing the upward walk.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/1e6f97a6a0c4ee7b. Report an issue: GitHub.