googleapis/mcp-toolbox · error

can't convert to array of strings

Error message

can't convert %s to array of strings: %w

What it means

InvokeSearchCatalog converts the optional parent parameter (parentParamName, e.g. a location/collection parent resource list) from []any to []string. Non-string elements or an absent value fail the conversion and produce this formatted error naming the parameter. It enforces the tool's declared parameter types at runtime.

Solutions

  1. Provide the parent param as a JSON array of strings, or omit it entirely only if the tool schema permits
  2. Convert null to [] before sending
  3. Check the tool manifest to confirm the exact parentParamName and its type
  4. Add client-side validation that all list elements are strings

Example fix

// before
{"parent": null}
// after
{"parent": ["projects/my-project/locations/us-central1"]}
Defensive patterns

Strategy: validation

Validate before calling

if v, present := paramsMap[parentParamName]; present && v == nil { delete(paramsMap, parentParamName) }
// or coerce: if v == nil { paramsMap[parentParamName] = []any{} }

Type guard

parents, ok := paramsMap[parentParamName].([]any); if ok && !allStrings(parents) { ... }

Try / catch

res, err := searchcatalog.InvokeSearchCatalog(ctx, src, params)
if err != nil {
	if strings.Contains(err.Error(), fmt.Sprintf("can't convert %s", parentParamName)) {
		return fmt.Errorf("%s must be an array of strings", parentParamName)
	}
	return err
}

Prevention

When it happens

Trigger: Invoking search_catalog with the parent parameter containing non-string values or being nil when unmarshaled (null instead of an array).

Common situations: Agents sending null for optional list params; mixing numeric enum values into the parent list; schema drift between the client tool manifest and the server's expected types.

Related errors


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

Appendix: source

Thrown at internal/sources/dataplex/searchcatalog/search_catalog.go:152

	tokenStr string,
	systemName string,
	parentParamName string,
	typeMap map[string]string,
	projectID string,
	getCatalogClient func(ctx context.Context, token string) (*dataplexapi.CatalogClient, error),
) ([]DataplexSearchResponse, error) {
	pageSize := int32(paramsMap["pageSize"].(int))
	prompt, _ := paramsMap["prompt"].(string)

	projectIdSlice, err := parameters.ConvertAnySliceToTyped(paramsMap["projectIds"].([]any), "string")
	if err != nil {
		return nil, fmt.Errorf("can't convert projectIds to array of strings: %w", err)
	}
	projectIds := projectIdSlice.([]string)

	parentIdSlice, err := parameters.ConvertAnySliceToTyped(paramsMap[parentParamName].([]any), "string")
	if err != nil {
		return nil, fmt.Errorf("can't convert %s to array of strings: %w", parentParamName, err)
	}
	parentIds := parentIdSlice.([]string)

	typesSlice, err := parameters.ConvertAnySliceToTyped(paramsMap["types"].([]any), "string")
	if err != nil {
		return nil, fmt.Errorf("can't convert types to array of strings: %w", err)
	}
	types := typesSlice.([]string)

	query := ConstructSearchQuery(prompt, projectIds, parentIds, types, systemName)

	req := &dataplexpb.SearchEntriesRequest{
		Query:          query,
		Name:           fmt.Sprintf("projects/%s/locations/global", projectID),
		PageSize:       pageSize,
		SemanticSearch: true,
	}

View on GitHub (pinned to 8cc6e09de2)