Skip to main content
Glama
People MCP

People MCP

by colekm297
README.md
# People MCP

A read-only, access-controlled MCP server over real US federal workforce data. Connect it to Claude Code or Claude Desktop to answer workforce questions (headcount, attrition, pay distributions, occupation mix, tenure, unit comparisons, and draft reorg proposals) while enforcing every access rule in deterministic server code.

The core principle is where access control lives: in the server and query layer, before any row ever reaches the language model. The model never decides who can see pay, which org units are in scope, or whether a group is too small to report. A prompt can be talked out of a rule. A bound SQL `WHERE` clause cannot.

## Architecture

```text
Claude Code / Claude Desktop (MCP stdio)
  |
  v
server.py        FastMCP transport adapter (binds 1 Principal at startup; no role/scope tool args)
  |
  v
service.py       PeopleService (single audited application boundary for all 9 tools + denials)
  |                |
  |                +--> audit.py        append-only SHA-256 hash-chained JSONL log
  |
  +--> rbac.py          deterministic role & org-scope predicates (Workday-style concepts)
  +--> privacy.py       primary + secondary small-cell suppression (n < 5) & field redaction
  +--> repository.py    read-only DuckDB queries (whitelisted SQL constants + bound params)
  +--> eib.py           validated DRAFT Workday-style EIB proposal + diff (never auto-loads)
  |
  v
data/people.duckdb      real OPM Federal Workforce Data (Commerce & Labor, loaded by load.py)
```

## What it does

- **9 MCP tools** (FastMCP, Python `mcp` SDK v1): `whoami`, `list_org_units`, `headcount`, `pay_summary`, `attrition`, `occupation_mix`, `tenure_distribution`, `compare_units`, `propose_reorg_eib`.
- **Roles modeled on Workday security concepts** (modeled on those primitives; nothing here connects to a Workday tenant):

| Role | Scope | Pay | Reorg drafts |
|---|---|---|---|
| `SubAgency_HRBP` | one sub-agency (e.g., U.S. Census Bureau) | visible | yes |
| `Agency_Comp_Analyst` | one agency, all sub-agencies (Department of Commerce) | visible | no |
| `Unit_Manager_NoComp` | one sub-agency (NOAA) | redacted or refused | no |

- **How each Workday-style primitive maps to code:**

| Concept | Implementation |
|---|---|
| Constrained security group on an organization | `rbac.py` + `repository.py`; caller scope is always the first bound parameter in every SQL `WHERE` clause |
| Domain / field-level security for compensation | Pay-only tools raise `AccessDenied`; mixed tools omit pay from SQL and return `"REDACTED"` |
| Reporting thresholds / disclosure control | `privacy.py` hides counts under 5 (`None`) plus secondary suppression so a single hidden cell cannot be recovered by subtraction |
| Business process with human approval | `eib.py` writes a `DRAFT` CSV, `validation_report.json`, and `diff.json` for HRIS admin review and never loads anything |
| Tamper-evident audit trail | `audit.py` writes append-only JSONL where each record carries the SHA-256 hash of the prior line |

## Real public data (OPM)

US Office of Personnel Management, Federal Workforce Data (successor to FedScope), fetched from the public unauthenticated API at https://data.opm.gov/get-data/api-access.

- **Employment (EHRI Status):** 14 month-end snapshots, Aug 2025 through Sep 2026 (28,896,320 national rows; 746,982 kept for Commerce and Labor).
- **Separations (EHRI Dynamics):** 13 monthly files, Sep 2025 through Sep 2026 (349,796 national rows; 10,331 kept).
- **Accessions (EHRI Dynamics):** same 13 months (190,015 national rows; 6,366 kept).
- Exact source file names, versions, publish dates, and URLs are recorded in the DuckDB `sources` table.

Why two departments (`CM` Commerce and `DL` Labor): loading two full federal departments keeps the local DuckDB around ~50 MB while ensuring cross-agency denials are tested against real loaded rows.

Data caveats:
- OPM microdata is de-identified: there are no employee IDs, names, or manager reporting trees. Nothing here invents synthetic IDs. Security operates on real agency and sub-agency org units, and EIB drafts leave `Worker` and `Position` for the HRIS admin to resolve.
- OPM itself redacts sensitive pay records; those are excluded from pay quantiles and counted explicitly.
- Attrition is counted by action effective month; late-processed actions effective before Sep 2025 are dropped and logged in `dynamics_dropped`.
- September and December 2025 include deferred resignation separations flagged by OPM's `drp_indicator` (1,145 of Commerce's 1,588 September 2025 separations).

## Quickstart

```bash
make setup      # create .venv (Python 3.12) and install editable package + pytest
make data       # download OPM parquet files (~830 MB, cached in data/raw/) and build data/people.duckdb
make test       # run unit, adversarial, EIB, and live FastMCP server tests
make verify     # independently recompute headline figures straight from raw OPM parquets
```

### Connect to Claude Code

```bash
claude mcp add people-mcp --env PEOPLE_MCP_CALLER=census_hrbp -- \
  /absolute/path/to/people-mcp/.venv/bin/python -m people_mcp.server
```

### Connect to Claude Desktop (`claude_desktop_config.json`)

Register one entry per caller to see the exact same question return three policy-scoped answers:

```json
{
  "mcpServers": {
    "people-hrbp": {
      "command": "/absolute/path/to/people-mcp/.venv/bin/python",
      "args": ["-m", "people_mcp.server"],
      "cwd": "/absolute/path/to/people-mcp",
      "env": { "PEOPLE_MCP_CALLER": "census_hrbp" }
    },
    "people-comp": {
      "command": "/absolute/path/to/people-mcp/.venv/bin/python",
      "args": ["-m", "people_mcp.server"],
      "cwd": "/absolute/path/to/people-mcp",
      "env": { "PEOPLE_MCP_CALLER": "commerce_comp" }
    },
    "people-manager": {
      "command": "/absolute/path/to/people-mcp/.venv/bin/python",
      "args": ["-m", "people_mcp.server"],
      "cwd": "/absolute/path/to/people-mcp",
      "env": { "PEOPLE_MCP_CALLER": "noaa_manager" }
    }
  }
}
```

In local runs, `PEOPLE_MCP_CALLER` selects a principal from `config/principals.json` once at server startup. In production, that identity comes from an authenticated OAuth/SSO session mapped to HRIS security groups. No tool accepts a caller, role, or scope argument.

## Example tool outputs (real OPM data, Sep 2026)

As `commerce_comp` (`Agency_Comp_Analyst`, Department of Commerce), `compare_units(units=["CM56","CM63","CM54","CM57"])`:

| Sub-agency | Headcount | Median service | Median pay | Window separation rate (13m) |
|---|---:|---:|---:|---:|
| Patent and Trademark Office | 13,516 | 15.5 yrs | $171,378 | 12.0% |
| U.S. Census Bureau | 10,907 | 7.2 yrs | $50,241 | 27.5% |
| NOAA | 9,872 | 16.3 yrs | $130,786 | 11.1% |
| NIST | 3,177 | 15.7 yrs | $160,984 | 14.0% |

As `noaa_manager` (`Unit_Manager_NoComp`, NOAA):

```text
> pay_summary()
AccessDenied: role Unit_Manager_NoComp cannot view compensation

> headcount(group_by=["occupation_group"], include_pay=true)
{"occupational_group": "PHYSICAL SCIENCES GROUP",   "headcount": 3776, "median_annual_pay": "REDACTED"}
{"occupational_group": "BIOLOGICAL SCIENCES GROUP", "headcount": 1435, "median_annual_pay": "REDACTED"}
"redacted_fields": ["median_annual_pay"]
```

As `census_hrbp` (`SubAgency_HRBP`, U.S. Census Bureau):

```text
> headcount(filters={"sub_agency": "CM56"})
AccessDenied: sub_agency ['CM56'] is outside caller scope sub_agency_code=CM63

> headcount(filters={"occupation_series": "1530' OR '1'='1"})
{"rows": [{"headcount": null}]}   # bound parameter; matches nothing

> propose_reorg_eib(source_sub_agency="CM63", target_org="Census Data Science Office",
                    effective_date="2027-01-01", selection={"occupation_series": "1530"})
status READY_FOR_HRIS_REVIEW, loaded false, 1,276 positions in 16 draft rows
WARN  'Census Data Science Office' is not an existing sub-agency; HRIS must create the organization before any load
WARN  555 supervisory positions move; HRIS must assign managers in the new structure
INFO  source data has no worker or position IDs; Worker and Position are left for HRIS to resolve
```

Every call above (including `whoami` and all refusals) is recorded in `audit/audit.jsonl`.

## Draft EIB output

`propose_reorg_eib` writes three local files under `out/eib/<proposal_id>/`:

- `change_organization_assignments_DRAFT.csv`: Workday-style template columns from public documentation, with `DRAFT - NOT LOADED` on every row. Position groups under 5 people are folded into a single remainder row.
- `validation_report.json`: structured `PASS`, `WARN`, `FAIL`, and `INFO` checks. Any `FAIL` blocks CSV generation.
- `diff.json`: source and target before/after headcounts (showing `"OUTSIDE CALLER SCOPE"` if the target org is outside the caller's scope).

## Tests

`make test` runs the full suite across:
- **RBAC:** allowed, denied, and redacted behavior for every role.
- **Disclosure control:** primary + secondary small-cell suppression and remainder protection.
- **Adversarial inputs:** SQL injection in filter values, group-by dimensions, and filter keys; cross-agency and mixed-scope filters; manager pay probing; oversized/malformed values; audit hash-chain tamper and corruption detection.
- **EIB validation:** date/reason/scope/size checks, no pay columns, never-load guarantee.
- **MCP transport (`test_server.py`):** real `FastMCP` tool registration, schema check ensuring zero caller/scope arguments exist on any tool, `whoami` auditing, and live `call_tool` enforcement.

## Known limits

- Repeated differencing across overlapping queries (e.g., total minus one narrow filter) can still narrow small groups; production deployments add query budgeting or differential noise.
- Pay grades remain visible to managers and federal GS pay tables are public; compensation redaction here demonstrates the field-level enforcement mechanism rather than a hidden secret.
- Principals are statically configured in `config/principals.json` for local use rather than bound to a live OAuth/OIDC provider.

## Repository layout

```text
people_mcp/
  config.py      env-resolved Settings
  domain.py      roles, Principal, AccessDenied, whitelisted SQL dimension specs
  privacy.py     small-cell primary/secondary suppression & field redaction
  rbac.py        principal registry & authorization predicates
  audit.py       append-only SHA-256 hash-chained JSONL audit log
  repository.py  scoped read-only DuckDB queries
  eib.py         reorg validation, headcount diff, and DRAFT EIB writer
  service.py     audited application service boundary
  server.py      FastMCP transport adapter (CLI entrypoint)
  load.py        OPM public parquet downloader & atomic DuckDB builder
config/          demo principals
tests/           pytest suite (RBAC, suppression, adversarial, EIB, FastMCP server)
tools/           verify_numbers.py (raw parquet cross-check)
```

License: MIT.