count_reports
Count direct or total reports for a person using their ID. Set recursive to true for full team size.
Instructions
Count reports for a person. recursive=False gives direct reports only; True gives the full subtree size.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| person_id | Yes | ||
| recursive | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- humaans_mcp/server.py:222-244 (handler)The count_reports async function is the handler for the tool. It counts direct reports (non-recursive mode) or the full recursive subtree of reports (recursive=True).
async def count_reports(person_id: str, recursive: bool = False) -> dict[str, int]: """Count reports for a person. recursive=False gives direct reports only; True gives the full subtree size.""" if not recursive: person = await client().get(f"/people/{person_id}") return {"direct": len(person.get("directReports") or [])} by_id, _, _ = await _people_index() if person_id not in by_id: raise ValueError(f"Person {person_id} not found") total = 0 stack = list(by_id[person_id].get("directReports") or []) direct = len(stack) visited: set[str] = set() while stack: cur = stack.pop() if cur in visited or cur not in by_id: continue visited.add(cur) total += 1 stack.extend(by_id[cur].get("directReports") or []) return {"direct": direct, "total_recursive": total} - humaans_mcp/server.py:221-221 (registration)The @mcp.tool() decorator registers count_reports as an MCP tool on the FastMCP instance.
@mcp.tool() - humaans_mcp/server.py:127-148 (helper)The _people_index() helper is used by count_reports when recursive=True to build the full people index (by_id map) for traversing the org tree.
async def _people_index() -> tuple[dict[str, dict[str, Any]], dict[str, str], dict[str, dict[str, Any]]]: """Return (by_id, parent_of, custom_by_person). parent_of maps a report's id to their manager's id; custom_by_person maps personId to {fieldName: value}.""" all_people = await client().list_all("/people") by_id = {p["id"]: p for p in all_people if "id" in p} parent_of: dict[str, str] = {} for p in all_people: mgr_id = p.get("id") for child_id in p.get("directReports") or []: parent_of[child_id] = mgr_id names = await _custom_field_names() all_values = await client().list_all("/custom-values") values_by_person: dict[str, list[dict[str, Any]]] = {} for v in all_values: pid = v.get("personId") if pid: values_by_person.setdefault(pid, []).append(v) custom_by_person = { pid: _resolve_custom(vs, names) for pid, vs in values_by_person.items() } return by_id, parent_of, custom_by_person - humaans_mcp/server.py:11-15 (helper)The client() helper returns the HumaansClient instance, used by count_reports in non-recursive mode to fetch the person record.
def client() -> HumaansClient: global _client if _client is None: _client = HumaansClient() return _client