{"record":{"id":"1102c6f93902884d","repo":"flipped-aurora/gin-vue-admin","slug":"datascope-1-5-1-2-3-4-5","errorCode":null,"errorMessage":"dataScope 必须在 1-5 之间：1全部 2本部门及以下 3本部门 4仅本人 5自定义部门，收到 %d","messagePattern":"dataScope 必须在 1-5 之间：1全部 2本部门及以下 3本部门 4仅本人 5自定义部门，收到 (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/role_data_scope_setter.go","lineNumber":88,"sourceCode":"\t\t\tmcp.Description(\"自定义部门ID集合，JSON数组或逗号分隔字符串；仅档位5必传，其它档位忽略\"),\n\t\t),\n\t)\n}\n\nfunc (r *RoleDataScopeSetter) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {\n\targs := request.GetArguments()\n\n\tauthorityID, err := parseAuthorityID(args[\"authorityId\"])\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tdataScope, err := parseUintParam(args[\"dataScope\"], \"dataScope\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif dataScope < 1 || dataScope > 5 {\n\t\treturn nil, fmt.Errorf(\"dataScope 必须在 1-5 之间：1全部 2本部门及以下 3本部门 4仅本人 5自定义部门，收到 %d\", dataScope)\n\t}\n\tscope := int(dataScope)\n\n\tvar deptIDs []uint\n\tif scope == 5 {\n\t\tdeptIDs, err = parseUintList(args[\"deptIds\"], \"deptIds\")\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif err := requireNonEmptyList(deptIDs, \"deptIds\"); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"档位5(自定义部门)必须指定部门集合: %w\", err)\n\t\t}\n\t\tdeptIndex, err := fetchDeptIndex(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tfor _, id := range deptIDs {\n\t\t\tif _, ok := deptIndex[id]; !ok {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/role_data_scope_setter.go#L70-L106","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Resend with dataScope in 1-5: 1=全部, 2=本部门及以下, 3=本部门, 4=仅本人, 5=自定义部门","If you need custom departments, use 5 and supply deptIds","Validate the value client-side before invoking the tool"],"exampleFix":"// before\nargs := map[string]any{\"dataScope\": 6}\n// after\nargs := map[string]any{\"dataScope\": 5, \"deptIds\": []uint{2, 3}}","handlingStrategy":"validation","validationCode":"func validDataScope(v int) bool {\n    return v >= 1 && v <= 5\n}\nif !validDataScope(dataScope) {\n    return fmt.Errorf(\"dataScope must be 1-5, got %d\", dataScope)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Memorize the scale: 1全部 2本部门及以下 3本部门 4仅本人 5自定义部门","Use named constants instead of raw numbers","Validate inputs client-side before invoking the tool","Do not import scale conventions from other RBAC systems"],"tags":["mcp","validation","data-scope"],"backgroundTag":"parameter-out-of-range","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}