flipped-aurora/gin-vue-admin · error

dataScope 必须在 1-5 之间:1全部 2本部门及以下 3本部门 4仅本人 5自定义部门,收到 %d

Error message

dataScope 必须在 1-5 之间:1全部 2本部门及以下 3本部门 4仅本人 5自定义部门,收到 %d

What it means

The role data-scope setter validates the `dataScope` parameter against the five gva data-scope tiers (1..5). Values outside this range are rejected with a message that also documents each tier's meaning. This is a pre-validation guard before any upstream call.

Source

Thrown at server/mcp/role_data_scope_setter.go:88

			mcp.Description("自定义部门ID集合,JSON数组或逗号分隔字符串;仅档位5必传,其它档位忽略"),
		),
	)
}

func (r *RoleDataScopeSetter) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
	args := request.GetArguments()

	authorityID, err := parseAuthorityID(args["authorityId"])
	if err != nil {
		return nil, err
	}

	dataScope, err := parseUintParam(args["dataScope"], "dataScope")
	if err != nil {
		return nil, err
	}
	if dataScope < 1 || dataScope > 5 {
		return nil, fmt.Errorf("dataScope 必须在 1-5 之间:1全部 2本部门及以下 3本部门 4仅本人 5自定义部门,收到 %d", dataScope)
	}
	scope := int(dataScope)

	var deptIDs []uint
	if scope == 5 {
		deptIDs, err = parseUintList(args["deptIds"], "deptIds")
		if err != nil {
			return nil, err
		}
		if err := requireNonEmptyList(deptIDs, "deptIds"); err != nil {
			return nil, fmt.Errorf("档位5(自定义部门)必须指定部门集合: %w", err)
		}
		deptIndex, err := fetchDeptIndex(ctx)
		if err != nil {
			return nil, err
		}
		for _, id := range deptIDs {
			if _, ok := deptIndex[id]; !ok {

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Resend with dataScope in 1-5: 1=全部, 2=本部门及以下, 3=本部门, 4=仅本人, 5=自定义部门
  2. If you need custom departments, use 5 and supply deptIds
  3. Validate the value client-side before invoking the tool

Example fix

// before
args := map[string]any{"dataScope": 6}
// after
args := map[string]any{"dataScope": 5, "deptIds": []uint{2, 3}}
Defensive patterns

Strategy: validation

Validate before calling

func validDataScope(v int) bool {
    return v >= 1 && v <= 5
}
if !validDataScope(dataScope) {
    return fmt.Errorf("dataScope must be 1-5, got %d", dataScope)
}

Prevention

When it happens

Trigger: Calling the set-data-scope MCP tool with dataScope = 0, negative numbers, or >= 6 (e.g. 6, 99, or a level parsed from a wrong field).

Common situations: Confusing gva's 1-5 scale with other RBAC systems' 0-based scales; passing an enum constant from a different codebase; off-by-one when mapping 'custom' which is 5 here.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/1102c6f93902884d. Report an issue: GitHub.