flipped-aurora/gin-vue-admin · error

构建 MCP 独立服务失败: %w

Error message

构建 MCP 独立服务失败: %w

What it means

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.

Source

Thrown at server/mcp/standalone_manager.go:341

	}

	binaryPath := filepath.Join(runtimeDir, managedBinaryName())
	sourceDir := filepath.Join(serverRoot, "cmd", "mcp")

	goBin, lookErr := exec.LookPath("go")
	if lookErr == nil && isDir(sourceDir) {
		buildCtx, cancel := context.WithTimeout(context.Background(), mcpBuildTimeout)
		defer cancel()

		cmd := exec.CommandContext(buildCtx, goBin, "build", "-o", binaryPath, "./cmd/mcp")
		cmd.Dir = serverRoot
		output, err := cmd.CombinedOutput()
		if err != nil {
			message := strings.TrimSpace(string(output))
			if message != "" {
				return "", fmt.Errorf("构建 MCP 独立服务失败: %w, 输出: %s", err, message)
			}
			return "", fmt.Errorf("构建 MCP 独立服务失败: %w", err)
		}
		return binaryPath, nil
	}

	if fileExists(binaryPath) {
		return binaryPath, nil
	}

	return "", errors.New("未检测到可用的 Go 环境,且本地没有可复用的 MCP 独立二进制")
}

func resolveMCPServerRoot() string {
	root := strings.TrimSpace(global.GVA_CONFIG.AutoCode.Root)
	serverDir := strings.TrimSpace(global.GVA_CONFIG.AutoCode.Server)
	if serverDir == "" {
		serverDir = "server"
	}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Check the wrapped cause: 'exec: "go": executable file not found' means goBin resolution failed — fix PATH or install Go for the process user.
  2. Run the build manually: cd server && go build -o bin/mcp ./cmd/mcp to see any suppressed output.
  3. Clear stale cache if builds hang/crash: go clean -cache.
  4. If context timeouts cancel the build, increase the build timeout budget in ensureManagedBinary.
  5. Check dmesg for OOM kills and memory limits.

Example fix

// before
PATH=/usr/local/bin systemd service -> exec: "go": executable file not found in $PATH
// after (systemd unit)
[Service]
Environment=PATH=/usr/local/go/bin:/usr/local/bin:/usr/bin:/bin
ExecStartPre=/usr/local/go/bin/go build -o /opt/gva/mcp ./cmd/mcp
Defensive patterns

Strategy: validation

Validate before calling

// verify the toolchain is available and budget enough build time
if _, err := exec.LookPath("go"); err != nil {
    return fmt.Errorf("go not on PATH for this process: %w", err)
}
buildCtx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

Try / catch

if _, err := ensureManagedBinary(serverRoot); err != nil {
    // empty-output failure: usually toolchain/env, retry verbosely
    out, err2 := exec.Command("go", "build", "-o", "/tmp/mcp-dbg", "./cmd/mcp").CombinedOutput()
    log.Printf("manual build rc=%v out=%s", err2, out)
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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