flipped-aurora/gin-vue-admin · warning

单次批量授权不能超过 %d 条,收到 %d 条

Error message

单次批量授权不能超过 %d 条,收到 %d 条

What it means

Client-side batch-size guard in role_api_batch_assigner. orgBatchLimit (50) caps how many API policy items a single write tool call may contain, to limit blast radius of mistakes. Exceeding it is rejected before any upstream call is made.

Source

Thrown at server/mcp/role_api_batch_assigner.go:79

	)
}

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

	authorityID, err := parseAuthorityID(args["authorityId"])
	if err != nil {
		return nil, err
	}
	items, err := parseAPIItems(args["apis"])
	if err != nil {
		return nil, err
	}
	if len(items) == 0 {
		return nil, errors.New("apis 参数是必需的,且至少包含一条")
	}
	if len(items) > orgBatchLimit {
		return nil, fmt.Errorf("单次批量授权不能超过 %d 条,收到 %d 条", orgBatchLimit, len(items))
	}

	currentResp, err := postUpstream[map[string][]systemReq.CasbinInfo](ctx, "/casbin/getPolicyPathByAuthorityId", map[string]any{
		"authorityId": authorityID,
	})
	if err != nil {
		return nil, fmt.Errorf("获取角色当前API权限失败: %w", err)
	}

	updated := currentResp.Data["paths"]
	result := roleAPIBatchAssignResponse{Success: true, AuthorityID: authorityID}
	anyAdded := false
	for _, item := range items {
		var added bool
		updated, added = appendPolicyIfMissing(updated, item.Path, item.Method)
		path, method := normalizePolicy(item.Path, item.Method)
		result.Items = append(result.Items, batchAPIItemResult{
			Path:          path,

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Split the apis array into chunks of at most 50 and call the tool once per chunk
  2. Reduce the item list to only the APIs actually missing for the role
  3. Use role-level bulk endpoints (e.g. updateCasbin directly) if you truly need a single large write, with your own safeguards

Example fix

// before
{"authorityId": 8881, "apis": [ ...300 items... ]}
// after
{"authorityId": 8881, "apis": [ ...first 50 items... ]} // repeat for each chunk
Defensive patterns

Strategy: validation

Validate before calling

const orgBatchLimit = 50
if len(apis) > orgBatchLimit {
    chunks := (len(apis) + orgBatchLimit - 1) / orgBatchLimit
    for i := 0; i < chunks; i++ {
        end := min((i+1)*orgBatchLimit, len(apis))
        assignBatch(authorityID, apis[i*orgBatchLimit:end])
    }
    return nil
}

Prevention

When it happens

Trigger: Calling the batch API assignment tool with an apis array of more than 50 entries (len(items) > orgBatchLimit).

Common situations: Importing a whole role's permission matrix in one call; scripting a loop that accumulates all APIs into a single invocation; copying a large casbin export into one request.

Related errors


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