flipped-aurora/gin-vue-admin · critical

读取 MCP 配置失败: %w

Error message

读取 MCP 配置失败: %w

What it means

The standalone MCP server loads its YAML config before starting. This error wraps os.ReadFile failure when the config file path cannot be read (missing file, permission denied, path is a directory).

Source

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

	"github.com/flipped-aurora/gin-vue-admin/server/config"
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"gopkg.in/yaml.v3"
)

type standaloneConfig struct {
	MCP      config.MCP      `yaml:"mcp"`
	AutoCode config.Autocode `yaml:"autocode"`
}

func loadStandaloneConfig() (string, error) {
	configPath, err := resolveConfigPath()
	if err != nil {
		return "", err
	}

	content, err := os.ReadFile(configPath)
	if err != nil {
		return "", fmt.Errorf("读取 MCP 配置失败: %w", err)
	}

	var cfg standaloneConfig
	if err := yaml.Unmarshal(content, &cfg); err != nil {
		return "", fmt.Errorf("解析 MCP 配置失败: %w", err)
	}

	applyStandaloneDefaults(configPath, &cfg)

	global.GVA_CONFIG.MCP = cfg.MCP
	global.GVA_CONFIG.AutoCode = cfg.AutoCode

	return configPath, nil
}

func resolveConfigPath() (string, error) {
	explicit, err := parseConfigFlag(os.Args[1:])
	if err != nil {

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Check the resolved path exists: ls -l <configPath> (the error includes the wrapped os error)
  2. Run the server from the directory where the config lives, or pass the absolute path via the config flag
  3. Fix file permissions so the process user can read the file
  4. Create the config file from the project's example config if missing

Example fix

// before
./mcp-server   # expects config.yaml in cwd
// after
./mcp-server --config /absolute/path/to/config.yaml
Defensive patterns

Strategy: validation

Validate before calling

info, err := os.Stat(configPath)
if err != nil { log.Fatalf("config missing: %v", err) }
if info.IsDir() { log.Fatalf("config path is a directory: %s", configPath) }

Try / catch

cfg, err := loadStandaloneConfig(path)
if err != nil {
    var pe *fs.PathError
    if errors.As(err, &pe) { fmt.Printf("cannot read %s: %v\n", pe.Path, pe.Err) }
    os.Exit(1)
}

Prevention

When it happens

Trigger: Running the MCP server when the config file doesn't exist at the resolved path, the process lacks read permission, or the path points to a directory.

Common situations: Wrong working directory so a relative config path resolves incorrectly; config never created; file permissions changed; typo'd --config flag value.

Related errors


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