googleapis/mcp-toolbox · error

authService %q declared more than once

Error message

authService %q declared more than once

What it means

Thrown by UnmarshalPrimitiveConfig when two documents declare an authService with the same 'name'. AuthServiceConfigs is keyed by name, so duplicates would overwrite; the parser rejects the config instead, mirroring the duplicate-source check.

Source

Thrown at internal/server/config.go:259

				sourceConfigs = make(SourceConfigs)
			}
			if _, exists := sourceConfigs[name]; exists {
				return nil, nil, nil, nil, nil, nil, fmt.Errorf("source %q declared more than once", name)
			}
			sourceConfigs[name] = c
		case "authService":
			c, err := UnmarshalYAMLAuthServiceConfig(ctx, name, resource)
			if err != nil {
				if len(file.Docs) > 1 {
					return nil, nil, nil, nil, nil, nil, fmt.Errorf("document %d: error unmarshaling %s %q: %w", docIndex, kind, name, err)
				}
				return nil, nil, nil, nil, nil, nil, fmt.Errorf("error unmarshaling %s: %w", kind, err)
			}
			if authServiceConfigs == nil {
				authServiceConfigs = make(AuthServiceConfigs)
			}
			if _, exists := authServiceConfigs[name]; exists {
				return nil, nil, nil, nil, nil, nil, fmt.Errorf("authService %q declared more than once", name)
			}
			authServiceConfigs[name] = c
		case "tool":
			c, err := UnmarshalYAMLToolConfig(ctx, name, resource)
			if err != nil {
				if len(file.Docs) > 1 {
					return nil, nil, nil, nil, nil, nil, fmt.Errorf("document %d: error unmarshaling %s %q: %w", docIndex, kind, name, err)
				}
				return nil, nil, nil, nil, nil, nil, fmt.Errorf("error unmarshaling %s: %w", kind, err)
			}
			if c == nil {
				continue
			}
			if toolConfigs == nil {
				toolConfigs = make(ToolConfigs)
			}
			if _, exists := toolConfigs[name]; exists {
				return nil, nil, nil, nil, nil, nil, fmt.Errorf("tool %q declared more than once", name)

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Rename one authService so names are unique.
  2. Delete the redundant duplicate document.
  3. Reference the single authService by name from tools' authRequired instead of redeclaring it.
  4. Grep the config file(s) for 'kind: authService' blocks and compare their names.

Example fix

// before
kind: authService
name: myauth
---
kind: authService
name: myauth
// after
kind: authService
name: myauth
---
kind: authService
name: myauth-alt
Defensive patterns

Strategy: validation

Validate before calling

func checkUniqueAuthNames(docs []map[string]any) error {
    seen := map[string]bool{}
    for _, doc := range docs {
        if k, _ := doc["kind"].(string); k == "authService" {
            n, _ := doc["name"].(string)
            if seen[n] {
                return fmt.Errorf("authService %q declared more than once", n)
            }
            seen[n] = true
        }
    }
    return nil
}

Prevention

When it happens

Trigger: ParseConfig on a multi-document YAML file where two 'kind: authService' documents use the identical name string.

Common situations: Merging config files that each define an authService with the same name; templating emitting the auth block twice; copy-paste without renaming.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/8081bb51d727ebf1. Report an issue: GitHub.