flipped-aurora/gin-vue-admin · error
部门 %d 不存在,可先用 query_org_structure 查询部门树
Error message
部门 %d 不存在,可先用 query_org_structure 查询部门树
What it means
For tier-5 custom scopes each supplied department ID is checked against an index of departments fetched from the upstream server. An ID not present in that index is rejected with a hint to query the org tree via the query_org_structure tool first. This prevents creating scope rows pointing at nonexistent departments.
Source
Thrown at server/mcp/role_data_scope_setter.go:107
}
scope := int(dataScope)
var deptIDs []uint
if scope == 5 {
deptIDs, err = parseUintList(args["deptIds"], "deptIds")
if err != nil {
return nil, err
}
if err := requireNonEmptyList(deptIDs, "deptIds"); err != nil {
return nil, fmt.Errorf("档位5(自定义部门)必须指定部门集合: %w", err)
}
deptIndex, err := fetchDeptIndex(ctx)
if err != nil {
return nil, err
}
for _, id := range deptIDs {
if _, ok := deptIndex[id]; !ok {
return nil, fmt.Errorf("部门 %d 不存在,可先用 query_org_structure 查询部门树", id)
}
}
}
// 读取变更前状态:角色档位来自角色树,自定义部门集来自专用接口
authority, err := fetchAuthority(ctx, authorityID)
if err != nil {
return nil, err
}
query := url.Values{}
query.Set("authorityId", strconv.FormatUint(uint64(authorityID), 10))
beforeDeptsResp, err := getUpstream[[]uint](ctx, "/authority/getDataScopeDepts", query)
if err != nil {
return nil, fmt.Errorf("读取角色当前自定义部门集失败: %w", err)
}
before := dataScopeState{
DataScope: authority.DataScope,View on GitHub (pinned to 3136500ef3)
Solutions
- Call the query_org_structure MCP tool to list valid department IDs and replace the invalid one
- Check for typos or wrong-environment IDs in deptIds
- Verify the department was not soft-deleted in the gva admin UI
Example fix
// before
deptIds := []uint{2, 999}
// after
// look up real IDs via query_org_structure first
deptIds := []uint{2, 7} Defensive patterns
Strategy: validation
Validate before calling
// resolve IDs via query_org_structure before setting scope
tree, err := queryOrgStructure(ctx)
if err != nil {
return err
}
valid := make(map[uint]struct{})
for _, d := range flatten(tree) {
valid[d.ID] = struct{}{}
}
for _, id := range deptIds {
if _, ok := valid[id]; !ok {
return fmt.Errorf("dept %d not found", id)
}
} Type guard
func allDeptsExist(ids []uint, index map[uint]struct{}) bool {
for _, id := range ids {
if _, ok := index[id]; !ok {
return false
}
}
return true
} Prevention
- Always query query_org_structure for IDs instead of hardcoding
- Re-fetch IDs after environment switches or menu/org re-seeding
- Check for soft-deleted departments in the admin UI
When it happens
Trigger: Calling set-data-scope with dataScope=5 and deptIds containing an ID that does not exist upstream (typo, stale ID, ID from a different environment, or a soft-deleted department).
Common situations: Copying dept IDs from a test database into production; department was deleted after the ID was recorded; hardcoding IDs instead of querying query_org_structure.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/9acd5d1ab578660a.
Report an issue: GitHub.