googleapis/mcp-toolbox · error

can't convert types to array of strings

Error message

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

What it means

InvokeSearchCatalog converts the types parameter (Dataplex entry type filters such as TABLE, DATASET) from []any to []string using parameters.ConvertAnySliceToTyped. If elements are not strings the conversion fails with this wrapped error, preventing invalid type filters from reaching ConstructSearchQuery.

Solutions

  1. Send types as an array of strings, e.g. ["TABLE","VIEW"], or [] if empty
  2. Ensure the key exists (empty array rather than omitted) if the client always serializes it
  3. Normalize any enum-like values to plain uppercase strings
  4. Validate client-side that every element is a string before invoking

Example fix

// before
{"types": [null, {"type": "TABLE"}]}
// after
{"types": ["TABLE"]}
Defensive patterns

Strategy: validation

Validate before calling

func allStrings(v []any) bool {
	for _, e := range v { if _, ok := e.(string); !ok { return false } }
	return true
}
// require types (if present) to be []any of strings

Type guard

t, ok := paramsMap["types"].([]any); if ok && !allStrings(t) { return errors.New("types must be strings") }

Try / catch

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

Prevention

When it happens

Trigger: Invoking search_catalog with types containing non-string values (numbers, booleans, null entries) or the key absent so the type assertion to []any fails.

Common situations: Clients omitting types (key missing) instead of sending an empty array; agents passing type objects/dicts instead of plain strings; casing mistakes are fine value-wise but only string type matters here.

Related errors


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

Appendix: source

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

) ([]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,
	}

	catalogClient, err := getCatalogClient(ctx, tokenStr)
	if err != nil {
		return nil, fmt.Errorf("failed to get catalog client: %w", err)
	}

	return ExecuteSearch(ctx, catalogClient, req, typeMap)

View on GitHub (pinned to 8cc6e09de2)