Need2Know
by hkhailee
README.md
# Need2Know
privacy layer for AI prompts
Need2Know is a local [FastMCP](https://gofastmcp.com) server that sits between
your files and Claude. Read tools replace private values with placeholders
before Claude sees them; write tools swap the real values back in locally
before saving.
Need2Know is a best-effort privacy layer. It hides the values its detectors
recognize before Claude sees them. It is not a security boundary: detection
can miss things, and a determined or prompt-injected model can recover some
hidden values. Read [Limitations](#limitations) before relying on it.
```
notes.txt on disk what Claude reads what Claude writes saved to disk
Jane Doe <jane@x.io> → [PERSON_1] <[EMAIL_1]> → Hi [PERSON_1], → Hi Jane Doe,
owns Project Falcon owns [CODENAME_1] re: [CODENAME_1] re: Project Falcon
```
## How detection works
[Presidio](https://microsoft.github.io/presidio/) is the framework, with three
kinds of recognizer:
- **Regex recognizers** for structured data: emails, phone numbers, card
numbers, IPs, IBANs, US SSNs, crypto wallets (Presidio built-ins) and API
keys/tokens/private keys (`SecretRecognizer`: AWS, GitHub, Anthropic,
OpenAI-style, Stripe, Slack, Google, JWTs, PEM keys, `api_key=...` and
`Bearer ...`). Secret detection is pattern-based: prefixed variable names
such as `DB_PASSWORD=`, `AWS_SECRET_ACCESS_KEY=` and `OPENAI_API_KEY=`, and
credentials inside URLs (`postgres://user:pass@host`), are not detected yet.
Don't point Need2Know at `.env` or other credential files.
- **GLiNER** as the NER model for people, organizations and locations, in place
of Presidio's default spaCy model. Presidio runs with its no-op NLP engine, so
no spaCy model is downloaded.
- **Custom terms** you list yourself: internal codenames, client names. See
[`terms.example.txt`](terms.example.txt).
Where spans overlap, custom terms win, then secrets, then the highest score.
## Placeholder mappings
Each value gets a stable placeholder (`[PERSON_1]` stays Jane Doe for the whole
conversation), so a read and a later write line up. Mappings:
- live only in the server process's memory, scoped to the MCP session (over
stdio that is the server process, which the client starts per conversation;
over HTTP it is the `mcp-session-id`);
- expire after `NEED2KNOW_MAPPING_TTL` seconds without use (sliding, default 1 hour);
- are never written to disk or logs, and their `repr` hides values.
If a write contains a placeholder the server no longer knows (for example after
expiry), it refuses to save rather than write `[PERSON_1]` literally.
Storage sits behind `MappingStore` (`src/need2know/store.py`). Encrypted local
persistence can be added as another implementation without touching the tools.
## Tools
| Tool | What it does |
| --- | --- |
| `read_file(path)` | Read a UTF-8 file, redacted. |
| `list_directory(path=".")` | List a folder; file names are redacted too. |
| `write_file(path, content)` | Restore placeholders, then save. |
| `edit_file(path, old_text, new_text)` | Replace one exact match; both sides may use placeholders. |
| `report_missed_redaction(text, entity_type, context?)` | Something private got through. It is redacted from then on in this conversation and logged for training. |
| `report_wrong_redaction(placeholder, correct_type?, context?)` | A placeholder hides something that is not private (or has the wrong type). Without `correct_type`, the value is shown to Claude unredacted in later reads, so only use it when you, the user, asked for it. |
| `privacy_status()` | Counts per type, expiry, NER model. No values. |
File tools only work inside `NEED2KNOW_ROOT`.
Always set `NEED2KNOW_ROOT` to a dedicated work folder. Never use your home
folder: it would expose `~/.ssh`, the fingerprint key and the correction log.
Write tools can change anything under the root, including `.git/hooks`, so
don't use a git repository you care about as the root.
## Limitations
- **Context-only detection.** A value detected only because of what's around
it (`api_key=...`, some names) can come back unredacted if Claude writes its
placeholder somewhere else and reads that file.
- **Guess confirmation.** Claude can test a guess, for example by writing a
candidate value and seeing whether it reads back as an existing placeholder,
or from the match count `edit_file` reports.
- **Wrong-redaction reports reveal values.** `report_wrong_redaction` without
`correct_type` makes the value readable in later reads. A prompt injection
in a file could trigger it.
- **Literal placeholders.** If a file already contains text shaped like
`[EMAIL_1]`, a rewrite swaps in that session's real value.
- **Correction log.** `corrections.jsonl` stores no values, but its context
lines may contain private details the detector missed. Review it before
sharing it.
- **Other paths to your files.** If Claude also has a shell or another
filesystem tool for the same folder, none of this protection applies.
See [SECURITY.md](SECURITY.md) to report a problem.
## Correction log
Corrections go to `~/.need2know/corrections.jsonl` so the model can be
fine-tuned over time, without storing raw sensitive text. Each line has the
kind of mistake, the expected and predicted types, a keyed HMAC fingerprint of
the value (to group repeats; the key is created once in
`~/.need2know/fingerprint.key` with owner-only permissions on macOS and Linux; on Windows your user folder's access rules protect it), its length and
character shape (`Xxxxx Xxxxx`), and optional context with the value replaced
by `«TARGET»` and everything else sensitive replaced by its type:
```json
{"kind": "missed", "entity_type": "CODENAME", "fingerprint": "9f2c...", "length": 8, "shape": "Xxxxx", "context": "[PERSON] said «TARGET» ships Friday", ...}
```
To fine-tune GLiNER, fill each `«TARGET»` with synthetic values matching the
type and shape, and train on the result.
## Install and run
New to this? Follow [GETTING_STARTED.md](GETTING_STARTED.md) for a step-by-step walkthrough.
```bash
pip install -e '.[ner]' # GLiNER pulls in PyTorch; CPU-only torch is enough
need2know # stdio MCP server
```
The GLiNER model (`urchade/gliner_multi_pii-v1` by default) downloads from
Hugging Face on first start. If GLiNER is not installed the server refuses to
start, because names would otherwise go through unredacted. Set
`NEED2KNOW_NER=off` to run deliberately with regex and custom terms only.
### Claude Code
```bash
claude mcp add need2know --env NEED2KNOW_ROOT=$HOME/work --env NEED2KNOW_TERMS_FILE=$HOME/.need2know/terms.txt -- need2know
```
### Claude Desktop
```json
{
"mcpServers": {
"need2know": {
"command": "need2know",
"env": {
"NEED2KNOW_ROOT": "/Users/you/work",
"NEED2KNOW_TERMS_FILE": "/Users/you/.need2know/terms.txt"
}
}
}
}
```
For the privacy guarantee to hold, Claude must reach those files only through
Need2Know, so don't also give it a filesystem server or shell over the same
folder.
### Settings
| Variable | Default | |
| --- | --- | --- |
| `NEED2KNOW_ROOT` | current directory (always set it) | Folder the file tools may use |
| `NEED2KNOW_TERMS_FILE` | none | Custom terms file |
| `NEED2KNOW_MAPPING_TTL` | `3600` | Seconds a mapping lives without use |
| `NEED2KNOW_SCORE_THRESHOLD` | `0.35` | Minimum detector score |
| `NEED2KNOW_NER` | `on` | `off` for regex and terms only |
| `NEED2KNOW_GLINER_MODEL` | `urchade/gliner_multi_pii-v1` | Any GLiNER model |
| `NEED2KNOW_GLINER_THRESHOLD` | `0.5` | GLiNER confidence |
| `NEED2KNOW_DATA_DIR` | `~/.need2know` | Correction log and key |
| `NEED2KNOW_LOG_LEVEL` | `INFO` | Logs carry counts only |
## Development
```bash
pip install -e '.[dev]'
pytest
```
Tests use a stand-in for GLiNER, so they need no model download.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues