flipped-aurora/gin-vue-admin · error
角色 %d 不存在或当前token无权查看
Error message
角色 %d 不存在或当前token无权查看
What it means
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.
Source
Thrown at server/mcp/org_common.go:187
if list[i].AuthorityId == id {
return &list[i]
}
if found := findAuthorityInTree(list[i].Children, id); found != nil {
return found
}
}
return nil
}
// fetchAuthority 拉取角色树并定位目标角色(getAuthorityList 返回调用者可见的角色树)
func fetchAuthority(ctx context.Context, authorityID uint) (*system.SysAuthority, error) {
resp, err := postUpstream[[]system.SysAuthority](ctx, "/authority/getAuthorityList", map[string]any{})
if err != nil {
return nil, fmt.Errorf("获取角色列表失败: %w", err)
}
authority := findAuthorityInTree(resp.Data, authorityID)
if authority == nil {
return nil, fmt.Errorf("角色 %d 不存在或当前token无权查看", authorityID)
}
return authority, nil
}
// scanUsersByIDs 按ID集合补全用户信息:上游 getUserList 不支持按ID过滤,翻页扫描至集齐或达页数上限,
// 返回 命中映射 与 未解析ID 列表(行级可见范围由主服务侧 datascope 引擎决定)
func scanUsersByIDs(ctx context.Context, ids []uint) (map[uint]system.SysUser, []uint, error) {
want := make(map[uint]struct{}, len(ids))
for _, id := range ids {
want[id] = struct{}{}
}
found := make(map[uint]system.SysUser, len(ids))
for page := 1; page <= orgUserScanMaxPages && len(found) < len(want); page++ {
resp, err := postUpstream[pageResultData[[]system.SysUser]](ctx, "/user/getUserList", map[string]any{
"page": page,
"pageSize": orgUserScanPageSize,
})View on GitHub (pinned to 3136500ef3)
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)
Defensive patterns
Strategy: validation
Validate before calling
// verify the role ID is visible in the caller's tree before the write
const tree = await fetchAuthorityList()
function roleExists(tree, id) {
return tree.some(a => a.authorityId === id || roleExists(a.children || [], id))
}
if (!roleExists(tree, targetAuthorityId)) { /* abort or re-scope token */ } Type guard
function findAuthority(tree, id) {
for (const a of tree) {
if (a.authorityId === id) return a
const hit = findAuthority(a.children || [], id)
if (hit) return hit
}
return null
} Try / catch
try {
await callMcpTool(tool, args)
} catch (e) {
if (/角色 \d+ 不存在或当前token无权查看/.test(e.message)) {
// re-fetch role list, pick a valid ID, or use a token with broader role visibility
}
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- 获取角色列表失败: %w
- 未找到 ID 为 %d 的用户(已扫描前 %d 条,大用户量场景请传 username 参数精确定位)
- 部门 %d 不存在,可先用 query_org_structure 查询部门树
- 岗位 %d 校验失败: %w
- 未找到 MCP 独立配置文件,请在当前目录、cmd/mcp 目录或通过 -config / GVA_MCP_CONFIG
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/e55f7be63f2f0d92.
Report an issue: GitHub.