{"record":{"id":"14415a1dd1991aa5","repo":"flipped-aurora/gin-vue-admin","slug":"d-query-org-structure","errorCode":null,"errorMessage":"部门 %d 不存在,可先用 query_org_structure 查询部门树","messagePattern":"部门 (.+?) 不存在,可先用 query_org_structure 查询部门树","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/org_member_assigner.go","lineNumber":109,"sourceCode":"\t}\n\tif len(deptIDs) > orgBatchLimit || len(positionIDs) > orgBatchLimit {\n\t\treturn nil, fmt.Errorf(\"单次分配的部门/岗位数量各不能超过 %d 个\", orgBatchLimit)\n\t}\n\t// primaryDeptId 只在设置部门(deptIds)时生效;仅传 primaryDeptId 不传 deptIds 会被静默丢弃,\n\t// 显式挡回避免调用方误以为主部门已变更\n\tif value, ok := args[\"primaryDeptId\"]; ok && value != nil && len(deptIDs) == 0 {\n\t\treturn nil, errors.New(\"primaryDeptId 需与 deptIds 一起传入(主部门必须属于本次追加或已有的部门集合);仅调整主部门请到前端组织管理页操作\")\n\t}\n\n\t// 校验目标部门/岗位真实存在,把无效ID挡在写入之前\n\tif len(deptIDs) > 0 {\n\t\tdeptIndex, err := fetchDeptIndex(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tfor _, id := range deptIDs {\n\t\t\tif _, ok := deptIndex[id]; !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"部门 %d 不存在,可先用 query_org_structure 查询部门树\", id)\n\t\t\t}\n\t\t}\n\t}\n\tfor _, id := range positionIDs {\n\t\tquery := url.Values{}\n\t\tquery.Set(\"id\", strconv.FormatUint(uint64(id), 10))\n\t\tif _, err := getUpstream[system.SysPosition](ctx, \"/position/findPosition\", query); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"岗位 %d 校验失败: %w\", id, err)\n\t\t}\n\t}\n\n\tuser, err := findUserByID(ctx, userID, usernameHint)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcurrentDeptIDs := make([]uint, 0, len(user.Departments))\n\tfor _, dept := range user.Departments {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/org_member_assigner.go#L91-L127","documentation":"Before writing, assign_user_org validates every deptId against the flattened department tree fetched from upstream. Any ID absent from the tree is rejected with this error, suggesting the query_org_structure tool to discover valid IDs.","triggerScenarios":"Calling assign_user_org with a deptId that does not exist (typo, deleted department, or an ID from another environment).","commonSituations":"Hardcoded department IDs that changed after reorg/department deletion; copying IDs between dev and prod; LLM hallucinating plausible-looking department IDs.","solutions":["Run the query_org_structure MCP tool to list the actual department tree and pick valid IDs","Verify the department exists in the admin UI organization page","Check you are in the correct environment (IDs differ between dev/prod)","Remove the stale ID from your automation/config"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// load the department tree first and filter to known-good IDs\nconst tree = await fetch('/department/getDepartmentList', { method: 'POST' }).then(r => r.json())\nconst valid = new Set(flatten(tree.data).map(d => d.ID))\nconst safe = deptIds.filter(id => valid.has(id))","typeGuard":"function deptExists(deptIndex, id) {\n  return Object.prototype.hasOwnProperty.call(deptIndex, id)\n}","tryCatchPattern":"try {\n  await callMcpTool('assign_user_org', args)\n} catch (e) {\n  if (/部门 \\d+ 不存在/.test(e.message)) {\n    // call query_org_structure, refresh your ID map, re-issue with valid IDs\n  }\n}","preventionTips":["Discover department IDs via query_org_structure instead of hardcoding","Never reuse dept IDs across environments","Re-sync your ID cache after org restructures or deletions"],"tags":["mcp","validation","not-found","departments"],"backgroundTag":"referenced-entity-not-found","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}