googleapis/mcp-toolbox · error

error parsing argument: %w

Error message

error parsing argument: %w

What it means

The custom UnmarshalYAML for prompt arguments expects each list item to be a map of parameter properties (name -> {type, description, ...}). It throws this error when an item in the arguments list cannot be unmarshaled into map[string]any — typically a scalar, string, or wrongly nested YAML value.

Source

Thrown at internal/prompts/arguments.go:45

type Argument struct {
	parameters.Parameter
}

// Arguments is a slice of Argument.
type Arguments []Argument

// UnmarshalYAML provides custom unmarshaling logic for Arguments.
func (args *Arguments) UnmarshalYAML(ctx context.Context, unmarshal func(interface{}) error) error {
	*args = make(Arguments, 0)
	var rawList []util.DelayedUnmarshaler
	if err := unmarshal(&rawList); err != nil {
		return err
	}

	for _, u := range rawList {
		var p map[string]any
		if err := u.Unmarshal(&p); err != nil {
			return fmt.Errorf("error parsing argument: %w", err)
		}

		// If 'type' is missing, default it to string.
		paramType, ok := p["type"]
		if !ok {
			p["type"] = parameters.TypeString
			paramType = parameters.TypeString
		}

		// Call the clean, exported parser from the tools package. No more duplicated logic!
		param, err := parameters.ParseParameter(ctx, p, paramType.(string))
		if err != nil {
			return err
		}

		*args = append(*args, Argument{Parameter: param})
	}
	return nil

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Ensure every item under `arguments:` is a mapping with at least `name` (and optionally `type`, `description`).
  2. Quote or reformat any shorthand string entries into proper YAML maps.
  3. Validate YAML indentation so items are list entries of maps, not flattened strings.
  4. Read the wrapped %w error to see the YAML node that failed to decode.

Example fix

// before
arguments:
  - name
  - location
// after
arguments:
  - name: name
    type: string
    description: The name parameter
  - name: location
    type: string
Defensive patterns

Strategy: validation

Validate before calling

// Validate prompt arguments shape before loading config
for i, arg := range cfg.PromptArguments {
	if arg == nil || len(arg.(map[string]any)) == 0 {
		return fmt.Errorf("arguments[%d] must be a mapping with a 'name' field", i)
	}
}

Try / catch

var p PromptConfig
if err := yaml.Unmarshal(data, &p); err != nil {
	if strings.Contains(err.Error(), "error parsing argument") {
		return fmt.Errorf("each arguments: entry must be a map like {name: ..., type: string}: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: A prompt's YAML `arguments:` list contains a plain string (e.g. `- name`) instead of a mapping (e.g. `- name: myparam\n type: string`), or the whole arguments block is a string rather than a list of maps.

Common situations: Hand-editing tools.yaml and forgetting the per-argument mapping; copying an older config format that used shorthand strings; indentation mistakes that turn a map into a scalar.

Related errors


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