flipped-aurora/gin-vue-admin · error
获取部门树失败: %w
Error message
获取部门树失败: %w
What it means
fetchDeptIndex calls the upstream gin-vue-admin endpoint /department/getDepartmentList to load the department tree; any transport or upstream API error is wrapped as 获取部门树失败. This is a pre-flight existence check so invalid department IDs are rejected before writes.
Source
Thrown at server/mcp/org_common.go:159
}
return true
}
// flattenDeptTree 把部门树摊平成 id→名称 映射,供存在性校验与名称补全
func flattenDeptTree(list []system.SysDepartment, into map[uint]string) {
for i := range list {
into[list[i].ID] = list[i].Name
if len(list[i].Children) > 0 {
flattenDeptTree(list[i].Children, into)
}
}
}
// fetchDeptIndex 拉取部门树并摊平,一次上游调用完成全部部门ID校验
func fetchDeptIndex(ctx context.Context) (map[uint]string, error) {
resp, err := postUpstream[[]system.SysDepartment](ctx, "/department/getDepartmentList", map[string]any{})
if err != nil {
return nil, fmt.Errorf("获取部门树失败: %w", err)
}
index := make(map[uint]string)
flattenDeptTree(resp.Data, index)
return index, nil
}
// findAuthorityInTree 在角色树中按 authorityId 查找角色
func findAuthorityInTree(list []system.SysAuthority, id uint) *system.SysAuthority {
for i := range list {
if list[i].AuthorityId == id {
return &list[i]
}
if found := findAuthorityInTree(list[i].Children, id); found != nil {
return found
}
}
return nil
}View on GitHub (pinned to 3136500ef3)
Solutions
- Check connectivity from the MCP server to the main service (base URL, DNS, ports)
- Verify the upstream token is valid and not expired
- Call /department/getDepartmentList manually to inspect the upstream error message
- Check MCP server logs for the wrapped cause (%w chain) to see the root error
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check upstream reachability before the tool call
const res = await fetch(baseUrl + '/department/getDepartmentList', { method: 'POST' })
if (!res.ok) throw new Error('upstream unreachable') Try / catch
try {
await callMcpTool('assign_user_org', args)
} catch (e) {
if (String(e.message).includes('获取部门树失败')) {
// inspect e.cause for transport vs upstream-code error; check token + baseUrl, then retry
}
} Prevention
- Monitor upstream main-service health from the MCP server
- Refresh tokens before expiry; handle 401 centrally
- Use %w cause chain in logs to distinguish network vs API errors
When it happens
Trigger: Any MCP org tool that validates deptIds (e.g. assign_user_org) while the upstream POST /department/getDepartmentList fails: network error, invalid/expired token, upstream 4xx/5xx, or non-success code in the response envelope.
Common situations: MCP server cannot reach the main gin-vue-admin service (wrong base URL, service down); token expired or lacking department visibility; upstream returns an error code in the JSON body.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/65add3e988eb2715.
Report an issue: GitHub.