{"record":{"id":"e55f7be63f2f0d92","repo":"flipped-aurora/gin-vue-admin","slug":"d-token","errorCode":null,"errorMessage":"角色 %d 不存在或当前token无权查看","messagePattern":"角色 (.+?) 不存在或当前token无权查看","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/org_common.go","lineNumber":187,"sourceCode":"\t\tif list[i].AuthorityId == id {\n\t\t\treturn &list[i]\n\t\t}\n\t\tif found := findAuthorityInTree(list[i].Children, id); found != nil {\n\t\t\treturn found\n\t\t}\n\t}\n\treturn nil\n}\n\n// fetchAuthority 拉取角色树并定位目标角色(getAuthorityList 返回调用者可见的角色树)\nfunc fetchAuthority(ctx context.Context, authorityID uint) (*system.SysAuthority, error) {\n\tresp, err := postUpstream[[]system.SysAuthority](ctx, \"/authority/getAuthorityList\", map[string]any{})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"获取角色列表失败: %w\", err)\n\t}\n\tauthority := findAuthorityInTree(resp.Data, authorityID)\n\tif authority == nil {\n\t\treturn nil, fmt.Errorf(\"角色 %d 不存在或当前token无权查看\", authorityID)\n\t}\n\treturn authority, nil\n}\n\n// scanUsersByIDs 按ID集合补全用户信息:上游 getUserList 不支持按ID过滤,翻页扫描至集齐或达页数上限,\n// 返回 命中映射 与 未解析ID 列表(行级可见范围由主服务侧 datascope 引擎决定)\nfunc scanUsersByIDs(ctx context.Context, ids []uint) (map[uint]system.SysUser, []uint, error) {\n\twant := make(map[uint]struct{}, len(ids))\n\tfor _, id := range ids {\n\t\twant[id] = struct{}{}\n\t}\n\tfound := make(map[uint]system.SysUser, len(ids))\n\n\tfor page := 1; page <= orgUserScanMaxPages && len(found) < len(want); page++ {\n\t\tresp, err := postUpstream[pageResultData[[]system.SysUser]](ctx, \"/user/getUserList\", map[string]any{\n\t\t\t\"page\":     page,\n\t\t\t\"pageSize\": orgUserScanPageSize,\n\t\t})","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/org_common.go#L169-L205","documentation":"After loading the role tree, fetchAuthority searches it (findAuthorityInTree) for the requested authorityID; if no node matches, this error is returned. getAuthorityList only returns the roles visible to the caller, so a missing role means it either truly does not exist or the current token's permissions exclude it.","triggerScenarios":"Calling an MCP org tool that resolves a role with an authorityId that (a) does not exist in the system, (b) is soft-deleted, or (c) exists but is outside the caller's visible role tree (e.g. a child role of another admin).","commonSituations":"Typo or stale role ID in configuration/automation; using a role ID from a different environment; MCP token belongs to a user who cannot see the target role; role was deleted after the ID was recorded.","solutions":["Verify the authorityId exists via query tools or the admin UI role management page","Ensure the MCP token's user has visibility over that role (re-scope or use a more privileged token)","Re-fetch the role list to get current valid IDs","Check you are targeting the correct environment (dev vs prod role IDs differ)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify the role ID is visible in the caller's tree before the write\nconst tree = await fetchAuthorityList()\nfunction roleExists(tree, id) {\n  return tree.some(a => a.authorityId === id || roleExists(a.children || [], id))\n}\nif (!roleExists(tree, targetAuthorityId)) { /* abort or re-scope token */ }","typeGuard":"function findAuthority(tree, id) {\n  for (const a of tree) {\n    if (a.authorityId === id) return a\n    const hit = findAuthority(a.children || [], id)\n    if (hit) return hit\n  }\n  return null\n}","tryCatchPattern":"try {\n  await callMcpTool(tool, args)\n} catch (e) {\n  if (/角色 \\d+ 不存在或当前token无权查看/.test(e.message)) {\n    // re-fetch role list, pick a valid ID, or use a token with broader role visibility\n  }\n}","preventionTips":["Fetch the visible role tree first and pick IDs from it instead of hardcoding","Avoid copying role IDs across environments","Use a token whose role visibility covers the target role"],"tags":["mcp","roles","permissions","not-found"],"backgroundTag":"resource-not-found-or-unauthorized","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}