claims-desk-mcp
by Exios66
README.md
# claims-desk-mcp
An [MCP](https://modelcontextprotocol.io) server for the claims desk of **Tamarack Shoals Mutual**, a fictional
motor and home insurer, built to measure how well agents use tools against a system of record: role-based tool
exposure, row-level access, a human confirmation step for writes, an audit trail, OAuth over HTTP, and a
200-case tool-call eval with code-only grading.
All data is synthetic. No real people, policies or claims; no SSNs, street addresses or birth dates; phone
numbers are stored masked.
**Status:** everything that doesn't spend money is built and tested: data, server, HTTP + OAuth (checked against
Keycloak), the eval and its four experiments, the report, tracing, the demo rehearsal and the case-study page. The
model runs are waiting on an API key, so the case study's Results section is a marked placeholder. See
[Roadmap](#roadmap).
## Quickstart
Python 3.11 or newer.
```bash
pip install -e '.[dev]'
```
```bash
CLAIMS_ROLE=adjuster CLAIMS_USER=ADJ-05 claims-desk-mcp
```
The server speaks MCP (protocol revision 2026-07-28, official Python SDK `mcp` 2.3) over stdio, with the role
from the environment, or over Streamable HTTP as an OAuth resource server (below). Writes go to a working copy of
the database in `var/` (created on first run), so `data/claims.db` stays pristine. Override with `CLAIMS_DB` or
`CLAIMS_STATE_DIR`.
### Over HTTP with OAuth
```bash
CLAIMS_OAUTH_ISSUER=http://localhost:8080/realms/claims-desk claims-desk-mcp --transport http --port 8000
```
The server publishes protected resource metadata (RFC 9728), answers 401 with a pointer to it, verifies each JWT
against the issuer's keys (signature, issuer, expiry, and audience bound to its own URL), and gives each request
the highest role backed by both a granted scope (`claims.read`, `claims.write`, `claims.admin`) and a realm role
the user holds. Confirmations are bound to the authenticated user. [deploy/keycloak/](deploy/keycloak/README.md)
has a local realm; `python ci/check_oauth.py` runs 15 end-to-end checks against it (all pass on Keycloak 26.8.2).
### In Claude Code
`.mcp.json` registers two servers for the demo, one per role:
| Server | Role | User |
|---|---|---|
| `claims-desk-adjuster` | adjuster | `ADJ-05` |
| `claims-desk-supervisor` | supervisor | `SUP-01` |
Install the package (above), start `claude` in the repo and approve the project servers when asked. Then try:
*"Is the hail claim on Dana Ortiz's policy covered, and what's left after the deductible?"* The full runbook is
[docs/demo.md](docs/demo.md); `python scripts/demo_rehearsal.py` checks its steps without a model.
## Tools
| # | Tool | What it does | Minimum role | Kind |
|---|---|---|---|---|
| 1 | `search_policyholders` | Find customers by name, policy number or ZIP; masked matches, max 10 | viewer | read |
| 2 | `get_policy` | Coverages, limits, deductibles, status and term | viewer | read |
| 3 | `list_claims` | Claims on a policy, filtered by status and loss-date range | viewer | read |
| 4 | `get_claim` | One claim with its notes and assigned adjuster | viewer | read |
| 5 | `check_coverage` | Covered or not, the rule that decided it, deductible, limit, payable amount | viewer | read |
| 6 | `add_claim_note` | Append a note; idempotency key so retries don't duplicate | adjuster | write |
| 7 | `update_claim_status` | Move a claim to a new status with a reason, after a person confirms | supervisor | write |
| 8 | `get_risk_tier` | Telematics risk score and tier for a motor policy (stub model for now) | viewer | read |
Every tool has a typed input schema (ID patterns, enums, ISO dates), an output schema with structured content,
a description with one example, and annotations. `CLAIMS_DESCRIPTIONS=terse` swaps in one-line descriptions for
the description-quality experiment.
## Design
- **Deterministic logic lives in tools.** `check_coverage` runs the rules table in
[`coverage.py`](src/claims_mcp/coverage.py) (also stored in the `coverage_rules` table). The data build uses
the same rules to decide which synthetic claims were denied, so the data and the tool always agree.
- **Least privilege.** `tools/list` only returns the tools the caller's role may use (viewer: 1-5 and 8;
adjuster adds 6; supervisor adds 7). Calls are checked again server-side, so calling an unlisted tool by name
gets a permission error. Adjusters only see claims on their own queue; others read as "not found", worded
exactly like a claim that doesn't exist.
- **Confirmation without trusting the model.** `update_claim_status` first answers `input_required` with a
form elicitation summarizing the change. The change applies only when the client returns an explicit accept
with `confirm: true`. The pending change travels in `requestState`, which the SDK seals with AES-GCM and binds
to the original request, so a replayed or edited confirmation is rejected. Clients that can't show a prompt
get an error, not a silent apply.
- **Audit.** Every call writes a JSON line (time, caller, role, tool, argument hash, status, latency) to
`var/audit.jsonl`; notes and status changes add a line with before and after values.
- **Hardening.** Per-caller rate limit, argument size cap, parameterized SQL only, tool errors returned as
`isError` results the model can read. Note text is stripped of control and zero-width characters and has
angle brackets escaped, and `get_claim` labels notes as untrusted. A planted note tries a prompt injection
(see fixtures); real injection testing belongs to the red-team plan.
- **Observability.** The eval harness opens spans for each episode, model call and tool call; the SDK carries the
trace context to the server, whose tool-execution and SQL spans join the same trace. Counters and latency
histograms per tool, role and status go out as OpenTelemetry metrics. Install `.[telemetry]` and set
`OTEL_EXPORTER_OTLP_ENDPOINT` to export (`deploy/compose.yaml` runs Jaeger). Without a backend,
`claims-desk-audit var/audit.jsonl` summarizes calls, errors, p50/p95 latency, denials by role and writes.
## Data
`data/claims.db` (SQLite, ~12 MB): 8,401 policyholders, 9,902 policies, 4,982 claims, 8,169 payments, three
years of reported dates up to the data's "today", 2026-11-30. Built by [`data/build.py`](data/build.py) from two
open-source generators:
| Generator | Used for | License |
|---|---|---|
| [insurance-datasets](https://pypi.org/project/insurance-datasets/) 0.1.4 (Burning Cost) | Motor and home policies, claim counts and incurred totals | MIT |
| [SynthETIC](https://cran.r-project.org/package=SynthETIC) 1.1.2 (Avanzi et al.) | Reporting delay, settlement delay, partial payments | GPL-3 |
SynthETIC runs as a separate R step ([`data/synthetic/timelines.R`](data/synthetic/timelines.R), GPL-3) and only
its CSV outputs are committed, so the rest of the repo stays MIT and rebuilding the database doesn't need R.
Details, caveats and the planted eval fixtures are in [docs/data.md](docs/data.md).
## CI
CI runs locally; there is no hosted CI service. [`ci/run.sh`](ci/run.sh) is a POSIX shell script that emulates a
hosted runner: it tests a clean `git archive` of `HEAD`, runs each step under `env -i` with a fresh `HOME`,
`CI=true` and UTC, builds a fresh virtualenv per Python version, and writes logs, JUnit XML and a summary to
`.ci/reports/<run-id>/`.
```bash
make ci # every Python 3.11+ on PATH, all stages, clean checkout of HEAD
```
```bash
make ci-fast # current Python, working tree, no data rebuild (about 20 s)
```
```bash
make ci-container # the same jobs inside python:<ver>-slim images (docker or podman)
```
| Stage | Checks |
|---|---|
| lint | `ruff check`, with rules pinned in `pyproject.toml` so results don't depend on local config |
| schemas | every tool schema is valid JSON Schema 2020-12 and matches the snapshot in `ci/tool_schemas.json` |
| test | pytest (in-memory MCP client): roles, row-level access, confirmation, idempotency, limits, data invariants, grader |
| cases | eval cases regenerate identically and every expected answer still matches live tool output |
| data | rebuilds the database from the committed SynthETIC outputs and compares it table by table |
| oauth | the 15 end-to-end OAuth checks, when a local Keycloak is running (skipped otherwise) |
`make hooks` runs `ci-fast` before every `git push`. After a deliberate tool change, `make schemas-update`
refreshes the contract snapshot.
## Eval
200 cases across eight slices, a harness that runs Claude (or an open-weight model on Modal) against the real
server, a code-only grader with bootstrap confidence intervals, four experiments (models; description quality; 8 vs
25 tools; structured vs prose results), and a report that draws the case study's figures in light and dark. Details
in [docs/eval.md](docs/eval.md).
```bash
make eval-oracle # model-free self-test: 100%, no cost
```
```bash
make experiments # dry run: the plan and its estimated cost (about $39 for everything), spends nothing
```
```bash
make eval-haiku # first real run, capped at $2; needs ANTHROPIC_API_KEY
```
The case study is [docs/case-study.qmd](docs/case-study.qmd) (Quarto); `make report` fills its Results section from
`results/`.
## Roadmap
| Milestone | Status |
|---|---|
| M0: data, schema | done |
| M1: 8 tools, roles over stdio, audit, tests, works in Claude Code | done (risk tier stubbed) |
| M2: 200 eval cases, harness, grader, first Haiku run | built and verified; Haiku run waiting on `ANTHROPIC_API_KEY` |
| M3: four experiments and charts | runner, cost estimate and figures built; runs waiting on the key |
| M4: case study, demo video; Streamable HTTP and OAuth | page, runbook, rehearsal, HTTP and OAuth done; results and video pending |
## License
MIT, except [`data/synthetic/timelines.R`](data/synthetic/timelines.R), which is GPL-3 to match SynthETIC.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues