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

  1. Verify the authorityId exists via query tools or the admin UI role management page
  2. Ensure the MCP token's user has visibility over that role (re-scope or use a more privileged token)
  3. Re-fetch the role list to get current valid IDs
  4. 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

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


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