Metadata-Version: 2.5
Name: obscate-mcp
Version: 0.2.1
Summary: MCP server for Obscate: reversible PII redaction (redact, restore, detect, JSON) for AI agents
Project-URL: Homepage, https://obscate.com
Project-URL: Documentation, https://obscate.com/docs/mcp
Author: Skycast
License-Expression: MIT
License-File: LICENSE
Keywords: agents,dpdp,gdpr,llm,mcp,pii,privacy,redaction
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: mcp<3,>=2.0
Provides-Extra: test
Requires-Dist: anyio>=4; extra == 'test'
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# obscate-mcp

An MCP server that gives any AI agent reversible PII redaction. Your agent
redacts personal data before a payload leaves (for another model, a tool or a
third-party API), then restores the real values in the reply.

It is a thin wrapper over the [Obscate](https://obscate.com) HTTP API.
Full docs: [obscate.com/docs/mcp](https://obscate.com/docs/mcp).
Detection runs in the hosted API (a self-hosted edition is in pilot). This
package only forwards calls.

<!-- mcp-name: com.obscate/mcp -->

| tool | what it does | API units |
|---|---|---|
| `redact` | redact a text; default `fpe` keeps formats and needs no map to restore | 1 per 100 KB |
| `restore` | put the original values back | free |
| `detect` | classify what PII a text contains (labels, offsets, counts) without changing it | 1 per 100 KB |
| `redact_json` | redact values inside a JSON object/array; keys and shape are unchanged | 1 per 100 KB |
| `restore_json` | restore any JSON reply | free |
| `list_entities` | supported labels and strategies | free, no key |

What to expect from detection: structured IDs (email, phone, cards, Aadhaar,
PAN, GSTIN, IBAN, SSN, IPs, AWS keys) are near-perfect because they are
regex- and checksum-based. Names and places come from an NER model and are
best-effort. Check the output if recall on those matters to you.
([Detectors and accuracy](https://obscate.com/docs/detectors),
[benchmark methodology](https://obscate.com/docs/benchmark).)

## Known limitation: partial values come back wrong

If the model quotes only **part** of a redacted value ("your card ending in
7588", "the email starting with…"), restore can't fix it: it matches whole
tokens, and a fragment isn't one. With `fpe` this fails **silently and
plausibly**. The fake card looks like a real card, so its last four digits
look like real digits, and your user sees a confident, wrong statement about
their own data. Assistants paraphrase values like this all the time, so expect
it in normal use.

What we measured: 1,800 replies from Claude Haiku 5.5, Sonnet 5.5 and Opus 5.5
(5 synthetic support scenarios, 20 runs per condition, 2026-11-19):

| setup | replies stating wrong-but-real-looking digits after restore |
|---|---|
| `fpe`, plain prompt | 204 of 300 (68%) |
| `synthetic`, plain prompt | 173 of 300 (58%) |
| `tokenize`, plain prompt | 0 of 300 |

`synthetic` has a second variant: models greet the customer by the stand-in's
first name, which can't be restored (241 of 300 plain-prompt replies).

For output a person will read:

- Use `strategy="tokenize"`: models treat `[CREDIT_CARD_1]` as a unit and don't split
  it, and restore only touches tokens in its map.
- Don't rely on a "repeat values exactly and in full" system-prompt line. It cut
  wrong digits to about 1%, but about two-thirds of replies then printed the
  **full** card or Aadhaar number to the customer.
- Better still (not yet measured): ask the model not to restate identifiers,
  and render any masked form ("ending in 4242") in your own code from the
  original value after restore.

Method, per-model results and limitations: [We measured how often LLMs quote
part of a redacted value](https://obscate.com/blog/partial-values-research).

Partial references are a boundary of any reversible-redaction approach, not
only ours: once the model only sees a stand-in, a fragment of the stand-in can
never map back to a fragment of the original.

## Quickstart (about 3 minutes)

1. **Get a free API key** at [obscate.com](https://obscate.com) ([quickstart](https://obscate.com/docs/quickstart)). It is free
   for 1,000 requests a month at 60 a minute, with no card. The key is shown
   once.
2. **Install** with one of these:
   ```bash
   uvx obscate-mcp --version          # no install, runs from PyPI
   pip install obscate-mcp            # or install into an environment
   ```
3. **Add it to your MCP client** (below), with the key in the `env` block.
4. Ask your agent: *"Redact this before you send it to the CRM: Ravi Kumar,
   ravi@example.com, +91 98765 43210"*.

### Claude Desktop

`~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or
`%APPDATA%\Claude\claude_desktop_config.json` (Windows):

```json
{
  "mcpServers": {
    "obscate": {
      "command": "uvx",
      "args": ["obscate-mcp"],
      "env": { "OBSCATE_API_KEY": "ob_..." }
    }
  }
}
```

### Claude Code

```bash
claude mcp add obscate --env OBSCATE_API_KEY=ob_... -- uvx obscate-mcp
```

### Cursor

`~/.cursor/mcp.json` (global) or `.cursor/mcp.json` (per project). Use the
same JSON block as Claude Desktop.

### Configuration

| env var | default | |
|---|---|---|
| `OBSCATE_API_KEY` | none | required for every tool except `list_entities` |
| `OBSCATE_BASE_URL` | `https://api.obscate.com` | point at a self-hosted Obscate (the self-hosted edition is in pilot; ask contact@obscate.com) |

Do not commit config files that contain the key. If your client supports env
files or secret references, use them.

`obscate-mcp --transport streamable-http` serves over HTTP instead of stdio.

## Proxy mode: redact another MCP server's results

New in 0.2.0.

`obscate-mcp proxy` puts Obscate between the model and **any other MCP
server**. The model never has to remember to call `redact`:

```text
model ──tools/call──▶ obscate-mcp proxy ──restored args──▶ upstream MCP server
model ◀─redacted result── obscate-mcp proxy ◀──raw result── upstream MCP server
                      (Obscate API: /v1/redact-json)
```

- It launches the upstream over stdio (`-- <command>`), or connects to a
  streamable-HTTP one (`--upstream-url`). It re-exposes the upstream's tools
  under the same names, descriptions and input schemas.
- Every result goes through one `/v1/redact-json` call before the model sees
  it: text blocks, JSON inside text blocks, `structuredContent`, embedded text
  resources, and **error** results. That is 1 API unit per tool call up to
  100 KB.
- Placeholders in the model's tool arguments are put back before the call is
  forwarded, so the upstream gets real values. This is a local substitution
  and costs no API call.
- The six Obscate tools stay available alongside (`--no-obscate-tools` hides them).

**Cost: every proxied tool result is 1 API unit** (per 100 KB), whether or
not it contains any PII. The free tier is 1,000 units a month at 60 a minute.
An agent that loops over a tool (paging through files, polling a ticket
queue) can use that up in minutes, and once it does, results are withheld
with a quota error until the month resets. Use `--passthrough` for tools whose
output never holds personal data, so they cost nothing.

### Try it in under 5 minutes

```bash
uvx obscate-mcp proxy --help                # check it runs; no install needed
git clone https://github.com/AstracoreAI/obscate-integrations && cd obscate-integrations/obscate-mcp
uv venv && uv pip install -e .              # or: python -m venv .venv && .venv/bin/pip install -e .
export OBSCATE_API_KEY=ob_...               # free key at https://obscate.com
.venv/bin/python examples/proxy_demo.py     # about 2 API units
```

The demo script lives in the repository, not the package, so it needs the
clone. It runs `obscate-mcp proxy -- python examples/crm_server.py` exactly as
an MCP client would, then plays the model. It prints what the model sees
(`[PERSON_1], [EMAIL_1], [PHONE_1], card [CREDIT_CARD_1]`), calls
`send_email(to="[EMAIL_1]", ...)`, and shows that the toy CRM received the
real address.

### Claude Desktop

Wrap any stdio server by putting its command after `--`. Here it wraps the
reference filesystem server, so file contents are redacted before Claude
reads them:

```json
{
  "mcpServers": {
    "notes-redacted": {
      "command": "uvx",
      "args": ["obscate-mcp", "proxy", "--",
               "npx", "-y", "@modelcontextprotocol/server-filesystem", "/Users/you/notes"],
      "env": { "OBSCATE_API_KEY": "ob_..." }
    }
  }
}
```

Environment variables you set in `env` reach the upstream too, **except every `OBSCATE_*` variable**: a third-party
server never sees your Obscate key.

### Options

Each option is a flag or an environment variable. Flags win.

| flag | env var | default | |
|---|---|---|---|
| `--strategy` | `OBSCATE_PROXY_STRATEGY` | `tokenize` | `tokenize` or `fpe` (restorable), `mask` or `hash` (one-way, nothing is restored) |
| `--labels` | `OBSCATE_PROXY_LABELS` | all | comma-separated, e.g. `EMAIL,PHONE,CREDIT_CARD` |
| `--min-confidence` | `OBSCATE_PROXY_MIN_CONFIDENCE` | `0.0` | see the caveat below before raising it |
| `--passthrough` | `OBSCATE_PROXY_PASSTHROUGH` | none | comma-separated upstream tool names left **untouched**: no redaction, no restore |
| `--resources` | `OBSCATE_PROXY_RESOURCES=1` | off | also proxy upstream resources (text contents redacted) |
| `--allow-binary` | `OBSCATE_PROXY_ALLOW_BINARY=1` | off | pass images, audio and blobs through. By default they are replaced with a "withheld" note because they can't be redacted |
| `--max-tokens` | `OBSCATE_PROXY_MAX_TOKENS` | `10000` | cap on placeholders remembered for restore |
| `--upstream-stderr` | `OBSCATE_PROXY_UPSTREAM_STDERR` | `inherit` | `discard` drops a launched upstream's stderr (see Privacy) |
| `--no-obscate-tools` | `OBSCATE_PROXY_NO_OBSCATE_TOOLS=1` | off | expose only the upstream's tools |
| `--upstream-url URL` | | | streamable-HTTP upstream instead of `-- <command>` |

**Confidence caveat.** In a live check on 2026-11-29, a real name ("Ravi
Kumar") was detected as PERSON at **0.6**, the same score as the known
false positive on a sentence-initial "Email". So `--min-confidence 0.7`
silences that false positive but also lets real names through. To cut noise,
prefer `--labels`.

### Why `tokenize` is the default here

The plain `redact` tool defaults to `fpe`. The proxy defaults to `tokenize`
because it restores **every** tool call the model makes, automatically, with
no person checking:

- A placeholder like `[EMAIL_3]` is plainly not a real value. Models copy it
  verbatim, and in our measurements they never split it (see the partial-values
  table above).
- An `fpe` value looks real. Under a map-free fpe restore, an email address
  the model *invents* would be decrypted into a different, real-looking address
  and sent upstream.

So in **both** restorable strategies the proxy restores from a session map of
values it issued on the way in. It never decrypts whatever the model wrote.
With `--strategy fpe` that map is built from the redact response, so an
invented value is forwarded unchanged. The API numbers tokenize placeholders
per request (every response starts at `[EMAIL_1]`). The proxy renumbers them
per session, so `[EMAIL_2]` in the third result still means the same person
as `[EMAIL_2]` in the first.

### Limits (read before relying on it)

- **Detection limits apply.** Structured IDs are near-perfect. Names and
  places are best-effort, so an NER miss reaches the model unredacted.
- **Only tool results (and, with `--resources`, resource contents) are
  redacted.** The upstream's tool names, descriptions, server instructions
  and resource names and URIs pass through as they are.
- `outputSchema` is **dropped** from re-exposed tools. Redaction can change a
  value's type or format (a numeric phone number becomes `"[PHONE_1]"`), and a
  client validating against the original schema would reject the result.
- If the Obscate API is unreachable or over quota, the result is **withheld**
  and the model gets an error. It never gets the raw output. Upstream protocol
  errors are passed through with their message redacted.
- A placeholder evicted by `--max-tokens` (least recently used first) is
  forwarded as literal text. Placeholders are never reused for a different
  value.
- A JSON text block is re-serialized after redaction, so whitespace may
  change. Integers that fpe kept numeric are restored only if they have 6 or
  more digits.
- No list-changed notifications are forwarded. Tool and resource lists are
  re-fetched on every list request.
- The partial-values limitation above still applies to anything the model
  writes for a person to read.

## Example agent flow

The agent has a customer record and must create a ticket in a third-party
helpdesk tool, which should never see the raw PII.

```text
user:   File a ticket: Ravi Kumar (ravi@example.com, +91 98765 43210) was double-charged on card 4242 4242 4242 4242.

agent → redact_json({"json": {"customer": "Ravi Kumar", "email": "ravi@example.com",
                              "phone": "+91 98765 43210", "issue": "double-charged on card 4242 4242 4242 4242"}})
      ← {"redacted": {"customer": "[PERSON:…]", "email": "<email-shaped value>", "phone": "<phone-shaped value>",
                      "issue": "double-charged on card <valid-looking card number>"},
         "type_changes": [], "keys_redacted": false, …}

agent → helpdesk.create_ticket(<the redacted object>)        # the tool only sees redacted values
      ← {"ticket": 812, "summary": "Refund for [PERSON:…], reply to <email-shaped value>"}

agent → restore_json({"json": <the tool's reply>, "type_changes": []})
      ← {"json": {"ticket": 812, "summary": "Refund for Ravi Kumar, reply to ravi@example.com"}}
```

With `strategy: "tokenize"` the redacted values look like `[EMAIL_1]`, and
you pass the returned `token_map` to `restore` / `restore_json`. With `fpe`
(the default) no map exists. Restore needs only your key, plus the
`key_version` that `redact` returned. Pass it back to `restore` or
`restore_json`. It names the version of your account's key that made the
tokens, so restore keeps working if Obscate rotates keys in between. If it is
left out, the current version is used.

**If you store redacted text to restore later**, store `key_version` with it.

**Pass `restore_context` back with fpe** (since 0.2.1). `redact` and
`redact_json` return a `restore_context` (an opaque `c1.` string with no PII).
Give it to `restore` / `restore_json` and only tokens Obscate issued are
decrypted, so a number the model wrote itself (a helpline, a reference) comes
back unchanged. Without it, restore is key-only: an email, phone or ID the
model *invents* looks like an fpe token and is turned into a different value
(in a lender test, "1800 266 3201" became "5209 286 3201"). Proxy mode
restores from its own session map and never had this problem. See
[strategies](https://obscate.com/docs/strategies).

## Privacy

- The server never logs, prints or stores the text, the detected values or
  the token map. Errors carry the HTTP status and the API's fixed message
  only. This is enforced by `tests/test_server.py::test_privacy_*`.
- Proxy mode has the same rule. The session map of placeholders lives in
  memory only, is bounded, is hidden from `repr()`, and is gone when the
  process exits. Canary values are checked against logs, stdout, stderr and
  the working directory by `tests/test_proxy.py::test_privacy_*`, and by
  `tests/test_proxy_e2e.py` against the real CLI's stderr.
- What the proxy can't control: a launched upstream writes its own stderr,
  and by default that goes to the same place as ours (in Claude Desktop, the
  MCP log file). Some servers log the data they handle, and the reference
  Python SDK logs a failing tool's error message. `--upstream-stderr discard`
  drops it. The upstream also sees the real values it was always going to
  see. The proxy protects the model's context, not the upstream.
- `redact` and `detect` do not echo the original values back into the model's
  context (`detect` can with `include_values: true`).
- The Obscate API has the same contract on its side: it does not log or store
  payloads. The hosted API runs in DigitalOcean Bangalore. Traffic passes
  through DigitalOcean's Cloudflare edge. See
  [security & limits](https://obscate.com/docs/security).

## Develop

```bash
pip install -e '.[test]' && pytest -q      # unit tests (fake API, fake upstream) + proxy e2e over real stdio
OBSCATE_API_KEY=ob_... python ../scripts/live_e2e.py mcp   # real end-to-end against the live API
```

License: MIT.
