{"record":{"id":"4de289c80e86413d","repo":"flipped-aurora/gin-vue-admin","slug":"mcp-w-4de289","errorCode":null,"errorMessage":"构建 MCP 独立服务失败: %w","messagePattern":"构建 MCP 独立服务失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/standalone_manager.go","lineNumber":341,"sourceCode":"\t}\n\n\tbinaryPath := filepath.Join(runtimeDir, managedBinaryName())\n\tsourceDir := filepath.Join(serverRoot, \"cmd\", \"mcp\")\n\n\tgoBin, lookErr := exec.LookPath(\"go\")\n\tif lookErr == nil && isDir(sourceDir) {\n\t\tbuildCtx, cancel := context.WithTimeout(context.Background(), mcpBuildTimeout)\n\t\tdefer cancel()\n\n\t\tcmd := exec.CommandContext(buildCtx, goBin, \"build\", \"-o\", binaryPath, \"./cmd/mcp\")\n\t\tcmd.Dir = serverRoot\n\t\toutput, err := cmd.CombinedOutput()\n\t\tif err != nil {\n\t\t\tmessage := strings.TrimSpace(string(output))\n\t\t\tif message != \"\" {\n\t\t\t\treturn \"\", fmt.Errorf(\"构建 MCP 独立服务失败: %w, 输出: %s\", err, message)\n\t\t\t}\n\t\t\treturn \"\", fmt.Errorf(\"构建 MCP 独立服务失败: %w\", err)\n\t\t}\n\t\treturn binaryPath, nil\n\t}\n\n\tif fileExists(binaryPath) {\n\t\treturn binaryPath, nil\n\t}\n\n\treturn \"\", errors.New(\"未检测到可用的 Go 环境，且本地没有可复用的 MCP 独立二进制\")\n}\n\nfunc resolveMCPServerRoot() string {\n\troot := strings.TrimSpace(global.GVA_CONFIG.AutoCode.Root)\n\tserverDir := strings.TrimSpace(global.GVA_CONFIG.AutoCode.Server)\n\tif serverDir == \"\" {\n\t\tserverDir = \"server\"\n\t}\n","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/standalone_manager.go#L323-L359","documentation":"The companion case of the build failure: ensureManagedBinary's `go build` errored but CombinedOutput was empty (no compiler diagnostics), so the error is wrapped alone. This typically indicates the build failed without emitting output — toolchain crash, signal, or resource exhaustion.","triggerScenarios":"exec.CommandContext(buildCtx, goBin, \"build\", ...) returns err with empty CombinedOutput: go binary missing from PATH causing exec failure surfaced here, context canceled mid-build, OOM-killed compiler, or build sandbox/disk error producing no stdout/stderr.","commonSituations":"go toolchain not on PATH for the server process (systemd service with minimal PATH); build context canceled by timeout; OOM under memory pressure; corrupted Go cache.","solutions":["Check the wrapped cause: 'exec: \"go\": executable file not found' means goBin resolution failed — fix PATH or install Go for the process user.","Run the build manually: cd server && go build -o bin/mcp ./cmd/mcp to see any suppressed output.","Clear stale cache if builds hang/crash: go clean -cache.","If context timeouts cancel the build, increase the build timeout budget in ensureManagedBinary.","Check dmesg for OOM kills and memory limits."],"exampleFix":"// before\nPATH=/usr/local/bin systemd service -> exec: \"go\": executable file not found in $PATH\n// after (systemd unit)\n[Service]\nEnvironment=PATH=/usr/local/go/bin:/usr/local/bin:/usr/bin:/bin\nExecStartPre=/usr/local/go/bin/go build -o /opt/gva/mcp ./cmd/mcp","handlingStrategy":"validation","validationCode":"// verify the toolchain is available and budget enough build time\nif _, err := exec.LookPath(\"go\"); err != nil {\n    return fmt.Errorf(\"go not on PATH for this process: %w\", err)\n}\nbuildCtx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\ndefer cancel()","typeGuard":null,"tryCatchPattern":"if _, err := ensureManagedBinary(serverRoot); err != nil {\n    // empty-output failure: usually toolchain/env, retry verbosely\n    out, err2 := exec.Command(\"go\", \"build\", \"-o\", \"/tmp/mcp-dbg\", \"./cmd/mcp\").CombinedOutput()\n    log.Printf(\"manual build rc=%v out=%s\", err2, out)\n    return err\n}","preventionTips":["Ensure `go` is on PATH for the service user (systemd/containers often strip PATH).","Give builds a generous context timeout; canceling mid-build yields empty output errors.","Watch memory limits — an OOM-killed compiler returns errors without output.","Run go clean -cache if builds start failing mysteriously with no diagnostics."],"tags":["build","go","mcp","toolchain"],"backgroundTag":"build-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}