{"record":{"id":"1e6f97a6a0c4ee7b","repo":"flipped-aurora/gin-vue-admin","slug":"mcp-autocode-root","errorCode":null,"errorMessage":"未能自动识别项目根目录，请在 MCP 配置中设置 autocode.root","messagePattern":"未能自动识别项目根目录，请在 MCP 配置中设置 autocode\\.root","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/mcp/config.go","lineNumber":164,"sourceCode":"}\n\nfunc detectProjectRoot(startDir string) (string, error) {\n\tdir := startDir\n\tfor {\n\t\tserverDir := filepath.Join(dir, \"server\")\n\t\twebDir := filepath.Join(dir, \"web\")\n\t\tif isDir(serverDir) && isDir(webDir) {\n\t\t\treturn dir, nil\n\t\t}\n\n\t\tparent := filepath.Dir(dir)\n\t\tif parent == dir {\n\t\t\tbreak\n\t\t}\n\t\tdir = parent\n\t}\n\n\treturn \"\", errors.New(\"未能自动识别项目根目录，请在 MCP 配置中设置 autocode.root\")\n}\n\nfunc detectGoModule(goModPath string) (string, error) {\n\tfile, err := os.Open(goModPath)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdefer file.Close()\n\n\tscanner := bufio.NewScanner(file)\n\tfor scanner.Scan() {\n\t\tline := strings.TrimSpace(scanner.Text())\n\t\tif strings.HasPrefix(line, \"module \") {\n\t\t\treturn strings.TrimSpace(strings.TrimPrefix(line, \"module \")), nil\n\t\t}\n\t}\n\n\tif err := scanner.Err(); err != nil {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/cmd/mcp/config.go#L146-L182","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Set autocode.root: /absolute/path/to/project in the MCP config.yaml","Run the mcp server from within the project directory so detection finds the marker","Ensure go.mod (or the marker it looks for) exists at the project root"],"exampleFix":"# mcp config.yaml\n# before\nautocode:\n  # root not set\n# after\nautocode:\n  root: /home/user/projects/gin-vue-admin/server","handlingStrategy":"validation","validationCode":"# before launch, verify autocode.root resolves to a dir containing go.mod\nROOT=$(yq '.autocode.root' config.yaml)\n[ -f \"$ROOT/go.mod\" ] || { echo \"autocode.root ($ROOT) missing go.mod\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"root, err := detectProjectRoot(startDir)\nif err != nil {\n  return fmt.Errorf(\"resolve project root: %w (set autocode.root to skip detection)\", err)\n}","preventionTips":["Explicitly set autocode.root in config.yaml for all non-dev deployments","Keep go.mod at the repo root so upward detection works","Log the directories walked during detection to speed up diagnosis","Avoid launching the binary from /, /tmp, or other marker-less dirs"],"tags":["config","mcp","go","startup"],"backgroundTag":"missing-config-file","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}