@maskera/mcp 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,21 +2,33 @@
2
2
 
3
3
  Local Swedish PII redaction for any AI agent or LLM client:
4
4
 
5
- 1. **Harness-agnostic LLM proxy (`maskera-mcp proxy`)**: sits between any agent/SDK (Claude Code, Codex, Cursor, OpenCode, Python/JS SDKs) and Anthropic/OpenAI, redacts outgoing prompts and tool results locally on-device, and transparently restores placeholders in both JSON and SSE streaming responses. Zero trust in the agent required.
6
- 2. **MCP stdio server (`maskera-mcp`)**: exposes `maskera_read_file`, `maskera_write_file`, `maskera_redact`, `maskera_restore`, and session management tools over JSON-RPC 2.0 stdio.
7
- 3. **Hook / pipe guard (`maskera-mcp guard`)**: blocks PII in Claude Code / Cursor hooks or Unix pipelines (`exit 2`, never echoes raw PII) or redacts streams via `--redact`.
5
+ 1. **One-command proxy wrapper (`maskera-mcp wrap -- <cmd>`)**: starts a local loopback proxy on a free port, verifies zero leaks automatically, injects `ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL`, `MASKERA_PROXY_URL`, and `MASKERA_MCP_URL` into your CLI (`claude`, `codex`, `opencode`, scripts), and prints a session receipt when the command exits.
6
+ 2. **Local LLM proxy + Streamable HTTP MCP (`maskera-mcp proxy` / `maskera-mcp service install`)**: sits between any client that accepts a custom API URL (Claude Code, Codex with an API key, Cursor, OpenCode, Claude Desktop via third-party inference, Python/JS SDKs) and Anthropic/OpenAI, redacts outgoing prompts and tool results locally on-device, and transparently restores placeholders in both JSON and SSE streaming responses. The same warm process also exposes Streamable HTTP MCP at `http://127.0.0.1:8787/mcp` and a live inspector with a built-in self-test button at `/_maskera`. Install it as a persistent local background service (`launchd` on macOS, `systemd --user` on Linux) with `maskera-mcp service install`.
7
+ 3. **MCP stdio server (`maskera-mcp`)**: exposes `maskera_read_file`, `maskera_write_file`, `maskera_list_files`, `maskera_search_files`, `maskera_redact`, `maskera_restore`, `maskera_list_sessions`, `maskera_clear_session`, `maskera_status` (plus `maskera_resume` in browser approval mode), along with built-in MCP `prompts` and `resources` (`maskera://skills/maskera/SKILL.md`) over JSON-RPC 2.0 stdio or Streamable HTTP.
8
+ 4. **Hook / pipe guard (`maskera-mcp guard`)**: blocks PII in Claude Code / Cursor hooks or Unix pipelines (`exit 2`, never echoes raw PII) or redacts streams via `--redact`.
9
+ 5. **Client installer and diagnostics (`maskera-mcp install` / `maskera-mcp doctor`)**: auto-detects or configures clients (`--apply`, `--project`, `--with-hook`), runs an automatic Swedish PII self-test + live `/mcp` probe, and prints (or saves via `--receipt <file.json>`) a zero-PII setup receipt (`maskera-setup-receipt/v1`).
8
10
 
9
11
  All redaction runs 100% locally using `maskera` (deterministic Swedish rules + the 43 MB open Swedish ONNX NER model `joelhagvall/maskera-sv-ner`).
10
12
 
11
- ## 1. Harness-agnostic local LLM proxy (enforced for every agent)
13
+ ## 1. Local LLM proxy + warm Streamable HTTP MCP
12
14
 
13
15
  Start the proxy on loopback (`127.0.0.1:8787`):
14
16
 
15
17
  ```bash
16
- npx -y @maskera/mcp proxy
18
+ # Fastest single-terminal launch (starts proxy, verifies 0 leaks, sets env vars, prints session summary on exit)
19
+ npx -y @maskera/mcp wrap -- claude
20
+ npx -y @maskera/mcp wrap --open -- codex
21
+
22
+ # Or keep one persistent local proxy + warm /mcp running in the foreground (or open /_maskera automatically)
23
+ npx -y @maskera/mcp proxy --root /path/to/workspace --open
24
+
25
+ # Or install as a background service (launchd on macOS, systemd --user on Linux)
26
+ npx -y @maskera/mcp service install --root /path/to/workspace --no-raw-restore
27
+ npx -y @maskera/mcp service status
28
+ npx -y @maskera/mcp service uninstall
17
29
  ```
18
30
 
19
- Point any harness at it:
31
+ Point any client that accepts a custom API URL at it, or connect an MCP client to `/mcp` on the same warm process:
20
32
 
21
33
  ```bash
22
34
  # Claude Code / Anthropic SDK
@@ -27,7 +39,13 @@ ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude
27
39
  # use the MCP stdio server below (`codex mcp add maskera -- npx -y @maskera/mcp`) instead.
28
40
  OPENAI_BASE_URL=http://127.0.0.1:8787/v1 codex
29
41
 
30
- # Inspect live redactions in your browser (local RAM only, screen-share safe by default)
42
+ # Connect an HTTP MCP client to the same warm ONNX model & vault
43
+ claude mcp add --transport http maskera 'http://127.0.0.1:8787/mcp?no_raw_restore=1'
44
+
45
+ # Or require browser approval before raw PII ever leaves the vault
46
+ claude mcp add --transport http maskera 'http://127.0.0.1:8787/mcp?approval_mode=browser'
47
+
48
+ # Inspect live redactions and answer pending approvals in your browser (local RAM only)
31
49
  open http://127.0.0.1:8787/_maskera
32
50
 
33
51
  # Optional: write local metadata-only audit logs (counts only, never raw text)
@@ -35,43 +53,95 @@ npx -y @maskera/mcp proxy --audit-log ./maskera-audit.jsonl
35
53
  ```
36
54
 
37
55
  - Routes Anthropic (`/v1/messages`, `/anthropic/*`) and OpenAI (`/v1/chat/completions`, `/v1/responses`, `/openai/*`) automatically, or use `--upstream <url>` for any OpenAI/Anthropic-compatible endpoint (Azure, OpenRouter, LiteLLM).
38
- - Built-in local live inspector at `http://127.0.0.1:8787/_maskera`: see every proxied request, entity counts, and the exact masked text sent upstream in real time (originals hidden by default until you toggle reveal).
56
+ - Built-in local live inspector at `http://127.0.0.1:8787/_maskera`: see every proxied request and MCP tool call, entity counts, pending approvals, and the exact masked text sent upstream in real time (originals hidden by default until you toggle reveal).
39
57
  - Restores placeholders even when split across SSE stream chunks, including JSON `tool_use` / `tool_calls` arguments.
40
58
  - Fails closed (`502`) if local redaction fails: raw PII is never forwarded upstream.
41
59
 
42
- ## 2. MCP stdio server (Claude Desktop / Cursor / Claude Code / Codex / T3 Code)
60
+ ### Which mode to use
61
+
62
+ - **Proxy** for text typed straight into the chat. It also masks tool results, because they travel in the same request.
63
+ - **Streamable HTTP MCP (`/mcp`)** when multiple clients should share one warm ONNX model, one session vault, and browser approvals.
64
+ - **MCP stdio server** for local files the agent reads with `maskera_read_file` when no background proxy is running.
65
+ - Before you send real personal data, run `npx -y @maskera/mcp doctor` or test with made-up data: send a fictional address and check that `http://127.0.0.1:8787/_maskera` shows a placeholder going upstream.
66
+
67
+ ### Claude Desktop through the proxy
68
+
69
+ Claude Desktop can send its chat traffic to an Anthropic-compatible gateway. Point it at the proxy and everything you type in the chat is masked on your machine before it reaches Anthropic. Requests are billed to the API key you enter, not to a Claude plan. Setup reference: [Claude Desktop in-app configuration](https://claude.com/docs/third-party/claude-desktop/in-app-configuration).
70
+
71
+ 1. Start the proxy and keep it running: `npx -y @maskera/mcp proxy`. While it is stopped, Desktop's chat fails instead of sending unmasked text.
72
+ 2. In Claude Desktop, choose **Help → Troubleshooting → Enable Developer Mode**, then **Developer → Configure Third-Party Inference…**.
73
+ 3. Under **Connection**, set **Inference provider** to **Gateway**.
74
+ 4. Fill in **Gateway credentials**:
75
+ - **Credential kind**: **Static API key**
76
+ - **Gateway base URL**: `http://127.0.0.1:8787` (no `/v1`; Desktop adds `/v1/messages` itself)
77
+ - **Gateway API key**: your Anthropic API key
78
+ - **Gateway auth scheme**: **x-api-key**. Anthropic's API takes API keys in this header, and it tells the proxy to route the request to Anthropic. The default **Bearer** is forwarded as-is and Anthropic rejects it.
79
+ 5. Click **Apply Changes**, then **Save & Restart**.
80
+ 6. Test with made-up data. Open `http://127.0.0.1:8787/_maskera` and send `Skriv ett kort mejl till provnamn.maskera@example.com och bekräfta mötet.` The inspector shows `[EPOST_1]` going upstream, and Desktop's reply shows the address restored.
81
+
82
+ To go back to your Claude account, choose the Anthropic sign-in option on the sign-in screen. The gateway settings stay on the device and can be changed in the same window.
83
+
84
+ ## 2. MCP server setup (`install`, stdio, and scoped policies)
85
+
86
+ Generate or write the configuration for your client directly:
87
+
88
+ ```bash
89
+ # Auto-detect installed clients, or target one (claude-code, claude-desktop, codex, cursor, opencode, t3-code, or all)
90
+ # install runs a synthetic Swedish PII roundtrip automatically and prints a setup receipt
91
+ npx -y @maskera/mcp install
92
+ npx -y @maskera/mcp install cursor --root /path/to/workspace --no-raw-restore --with-hook
93
+ npx -y @maskera/mcp install claude-code --transport http --no-raw-restore --apply --with-hook --receipt ./maskera-receipt.json
94
+ npx -y @maskera/mcp doctor --receipt ./maskera-receipt.json
95
+ ```
96
+
97
+ Pass `--apply` to execute `claude mcp add` / `codex mcp add` directly, `--project` to write project-local `.mcp.json` for Claude Code, `--with-hook` to add a `maskera-mcp guard` prompt hook, or `--no-verify` to skip the verification receipt. When a local proxy is running, both `install` and `doctor` also execute a live JSON-RPC `maskera_redact` probe against `/mcp` and verify zero leaked PII.
98
+
99
+ Or configure stdio manually:
43
100
 
44
101
  ```json
45
102
  {
46
103
  "mcpServers": {
47
104
  "maskera": {
48
105
  "command": "npx",
49
- "args": ["-y", "@maskera/mcp", "--root", "/path/to/your/workspace"]
106
+ "args": ["-y", "@maskera/mcp", "--root", "/path/to/workspace", "--no-raw-restore"]
50
107
  }
51
108
  }
52
109
  }
53
110
  ```
54
111
 
55
- Tools:
112
+ Tools (all declare `inputSchema`, `outputSchema`, and MCP tool `annotations`):
113
+ - `maskera_list_files`: List files inside allowed workspace roots without reading contents.
114
+ - `maskera_search_files`: Search UTF-8 files locally and redact every matched line before returning (supports searching by an existing placeholder like `[NAMN_1]`).
56
115
  - `maskera_read_file`: Read a local UTF-8 file already redacted, storing the restore map locally under `session_id`.
57
116
  - `maskera_write_file`: Restore placeholders from `session_id` and write directly to disk without exposing raw PII back to the LLM.
58
117
  - `maskera_redact`: Redact text locally (`mode: "auto"` or `"rules"`, `profile: "general" | "clinical"`, `custom_terms`).
59
- - `maskera_restore`: Restore placeholders using `session_id` or an explicit map.
60
- - `maskera_list_sessions` / `maskera_clear_session` / `maskera_status`: Inspect counts (never raw PII), clear memory, or check model status.
118
+ - `maskera_restore`: Restore placeholders using `session_id` or an explicit map (hidden and blocked under `--no-raw-restore`, or gated under `--approval-mode browser|native`).
119
+ - `maskera_list_sessions` / `maskera_clear_session` / `maskera_status`: Inspect counts (never raw PII), clear memory, or check model and policy status.
120
+ - `maskera_resume`: Exposed in `--approval-mode browser` to resume a paused raw-PII export once approved in `http://127.0.0.1:8787/_maskera`.
121
+
122
+ Built-in MCP `prompts` and `resources`:
123
+ - Prompts: `maskera-workflow` (with optional `profile` and `custom_terms`) and `maskera-redact-file`.
124
+ - Resources: `maskera://skills/maskera/SKILL.md` (full agent operating guide) and `maskera://status`.
125
+
126
+ Scoped policies (CLI flags or `/mcp` query parameters):
127
+ - `--no-raw-restore` / `?no_raw_restore=1`: Hides and blocks `maskera_restore` and `include_map: true`. The agent can still write restored output directly to disk via `maskera_write_file`.
128
+ - `--read-only` / `?read_only=1`: Hides and blocks `maskera_write_file` and `maskera_clear_session`.
129
+ - `--approval-mode automatic|browser|native` / `?approval_mode=browser`: Gates raw PII exports (`maskera_restore`, `include_map: true`) behind either browser approval in `/_maskera` or native MCP form elicitation (`elicitation/create`). Query parameters may only tighten server defaults, never weaken them.
61
130
 
62
131
  ## 3. Harness-agnostic guard / hook
63
132
 
64
133
  ```bash
65
- # Block prompts or hook JSON containing PII (exits 2 on match, 0 if clean)
134
+ # Block prompts or hook JSON containing PII (exits 2 on match, 0 if clean).
135
+ # Automatically reuses a running local proxy's warm ONNX model on 127.0.0.1:8787 when available.
66
136
  echo '{"prompt":"Ring 070-174 06 58"}' | npx -y @maskera/mcp guard
67
137
 
68
- # Redact any pipe locally
138
+ # Redact any pipe locally (pass --no-proxy to force in-process execution)
69
139
  cat klient.txt | npx -y @maskera/mcp guard --redact
70
140
  ```
71
141
 
72
142
  ## 4. Agent skill (`SKILL.md`)
73
143
 
74
- Install the workflow skill (`skills/maskera/SKILL.md`) in Claude Code, Codex, Cursor, or OpenCode:
144
+ The skill is served automatically over MCP at `maskera://skills/maskera/SKILL.md` and prompt `maskera-workflow`. You can also install it directly in Claude Code, Codex, Cursor, or OpenCode:
75
145
 
76
146
  ```bash
77
147
  npx skills add joelhagvall/maskera
@@ -82,7 +152,7 @@ npx skills add joelhagvall/maskera
82
152
  Run the built-in reusable E2E and benchmark suites locally (zero paid API calls):
83
153
 
84
154
  ```bash
85
- # Protocol, security, streaming, and local ONNX E2E (also runs in CI)
155
+ # Protocol, security, streaming, HTTP /mcp, approvals, install, doctor, and local ONNX E2E
86
156
  pnpm test:mcp:e2e
87
157
 
88
158
  # Real installed agent harnesses (claude, codex, opencode) with MCP + proxy + hooks
@@ -102,6 +172,9 @@ pnpm bench:mcp
102
172
  - `--rules-only` or `MASKERA_MCP_MODE=rules`: Deterministic rules only without loading the ONNX model.
103
173
  - `--profile general|clinical`: Built-in precision profile.
104
174
  - `--custom-term <word>` (repeatable): Extra protected words (client names, codenames, case IDs).
175
+ - `--no-raw-restore` or `MASKERA_MCP_NO_RAW_RESTORE=1`: Disallow raw PII export into model context.
176
+ - `--read-only` or `MASKERA_MCP_READ_ONLY=1`: Disallow file writes and session clears.
177
+ - `--approval-mode automatic|browser|native` or `MASKERA_MCP_APPROVAL_MODE`: Gate raw PII exports.
105
178
  - `--port <n>` / `--host <addr>` / `--upstream <url>` / `--no-restore`: Proxy options.
106
- - `--root <dir>` (repeatable) or `MASKERA_MCP_ROOTS`: Allowed file roots for MCP file tools.
179
+ - `--root <dir>` (repeatable) or `MASKERA_MCP_ROOTS`: Allowed file roots for MCP file tools (works on both `mcp` and `proxy`).
107
180
  - `MASKERA_MODEL_PATH` + `MASKERA_MODEL_ID` + `MASKERA_ALLOW_REMOTE_MODELS=0`: Load a local ONNX model directory offline.