xpzouying/xiaohongshu-mcp · error

%s 不支持 %q,可选:%s

Error message

%s 不支持 %q,可选:%s

What it means

collectFilters() validates every non-empty field of FilterOption against each filter group's allowed list before any browser navigation happens. Passing a value that is not one of the exact allowed Chinese option strings for that group returns this error, naming the group label, the bad value, and the allowed options.

Source

Thrown at xiaohongshu/search.go:76

	group  string // 组标签
	option string // 选项文本
}

// collectFilters 把入参展开成待应用的筛选项,顺便校验取值。
//
// 校验放在这里是为了在打开浏览器之前就挡掉写错的值——否则要等导航、悬停、
// 在面板里找不到之后才能报错,等于为了说一句"你写错了"先向平台发一次请求。
func collectFilters(filters []FilterOption) ([]pendingFilter, error) {
	var pending []pendingFilter

	for _, f := range filters {
		for _, g := range filterGroups {
			value := g.pick(f)
			if value == "" {
				continue
			}
			if !slices.Contains(g.allowed, value) {
				return nil, fmt.Errorf("%s 不支持 %q,可选:%s",
					g.label, value, strings.Join(g.allowed, "、"))
			}
			pending = append(pending, pendingFilter{group: g.label, option: value})
		}
	}

	return pending, nil
}

type SearchAction struct {
	page *rod.Page
}

func NewSearchAction(page *rod.Page) *SearchAction {
	pp := page.Timeout(60 * time.Second)

	return &SearchAction{page: pp}
}

View on GitHub (pinned to 332d196854)

Solutions

  1. Use exactly the allowed strings shown in the error: 排序依据∈{综合,最新,最多点赞,最多评论,最多收藏}; 笔记类型∈{不限,视频,图文}; 发布时间∈{不限,一天内,一周内,半年内}; 搜索范围∈{不限,已看过,未看过,已关注}; 位置距离∈{不限,同城,附近}
  2. Omit the field entirely (empty string) instead of passing "不限" if you mean the default
  3. Trim whitespace and avoid any case/variant mapping before constructing FilterOption
  4. Wrap filter construction in a small mapper that validates against the same enum lists

Example fix

// before
FilterOption{SortBy: "likes", PublishTime: "7d"}
// after
FilterOption{SortBy: "最多点赞", PublishTime: "一周内"}
Defensive patterns

Strategy: validation

Validate before calling

var allowed = map[string][]string{
    "sort_by":      {"综合", "最新", "最多点赞", "最多评论", "最多收藏"},
    "note_type":    {"不限", "视频", "图文"},
    "publish_time": {"不限", "一天内", "一周内", "半年内"},
    "search_scope": {"不限", "已看过", "未看过", "已关注"},
    "location":     {"不限", "同城", "附近"},
}
func check(k, v string) error {
    if v == "" || slices.Contains(allowed[k], v) { return nil }
    return fmt.Errorf("%s 不支持 %q,可选:%v", k, v, allowed[k])
}

Prevention

When it happens

Trigger: Search(ctx, keyword, FilterOption{...}) with e.g. SortBy="likes" (English) instead of "最多点赞", NoteType="image" instead of "图文", PublishTime="7d" instead of "一周内", or extra whitespace/case variants in any field.

Common situations: LLM/tool callers generating English filter values; mapping from another API's enum without translating to the exact Chinese strings; typos like "最多点赞"; using deprecated option names after the allowed list was updated.

Related errors


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/23927283a99dd5dd. Report an issue: GitHub.