flipped-aurora/gin-vue-admin · critical

解析 MCP 配置失败: %w

Error message

解析 MCP 配置失败: %w

What it means

After successfully reading the MCP config file, it is unmarshaled into standaloneConfig with yaml.Unmarshal. This error wraps a YAML parse/decode failure — the file exists but its content is not valid YAML or does not match the expected structure.

Source

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

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 {
		return "", err
	}
	if explicit != "" {
		return filepath.Abs(explicit)
	}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Validate the YAML with a linter (yamllint or an editor plugin) to find the syntax error reported by the wrapped error
  2. Replace tab characters with spaces for indentation
  3. Check field names/types against the standaloneConfig struct for the server version in use
  4. Restore from a known-good example config and reapply changes incrementally

Example fix

// before (invalid)
mcp:
	api-key: xxx
// after
mcp:
  api-key: xxx
Defensive patterns

Strategy: validation

Validate before calling

if err := yaml.Unmarshal(content, &standaloneConfig{}); err != nil {
    return fmt.Errorf("invalid YAML in %s: %w", configPath, err)
}

Try / catch

if err := yaml.Unmarshal(content, &cfg); err != nil {
    var typeErr *yaml.TypeError
    if errors.As(err, &typeErr) { /* print field-level mismatches */ }
    return err
}

Prevention

When it happens

Trigger: The config file contains invalid YAML syntax (bad indentation, tabs, unclosed quotes) or fields whose types don't match standaloneConfig (e.g. string where int expected).

Common situations: Hand-editing YAML and introducing tab indentation; merging configs and leaving duplicate keys; type mismatch after a config schema change in a newer server version.

Related errors


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