@maskera/mcp 0.2.0 → 0.3.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 +72 -15
- package/dist/cli.js +4003 -2137
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +210 -9
- package/dist/index.js +3608 -1934
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
Local Swedish PII redaction for any AI agent or LLM client:
|
|
4
4
|
|
|
5
|
-
1. **
|
|
6
|
-
2. **MCP stdio server (`maskera-mcp`)**: exposes `maskera_read_file`, `maskera_write_file`, `maskera_redact`, `maskera_restore`, and
|
|
5
|
+
1. **Local LLM proxy + Streamable HTTP MCP (`maskera-mcp proxy`)**: 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`, sharing the loaded ONNX model, session vault, browser approval broker, and live inspector.
|
|
6
|
+
2. **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.
|
|
7
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`.
|
|
8
|
+
4. **Client installer and diagnostics (`maskera-mcp install` / `maskera-mcp doctor`)**: writes or prints MCP config per client and verifies the local Swedish redaction roundtrip with made-up PII.
|
|
8
9
|
|
|
9
10
|
All redaction runs 100% locally using `maskera` (deterministic Swedish rules + the 43 MB open Swedish ONNX NER model `joelhagvall/maskera-sv-ner`).
|
|
10
11
|
|
|
11
|
-
## 1.
|
|
12
|
+
## 1. Local LLM proxy + warm Streamable HTTP MCP
|
|
12
13
|
|
|
13
14
|
Start the proxy on loopback (`127.0.0.1:8787`):
|
|
14
15
|
|
|
15
16
|
```bash
|
|
16
|
-
npx -y @maskera/mcp proxy
|
|
17
|
+
npx -y @maskera/mcp proxy --root /path/to/workspace
|
|
17
18
|
```
|
|
18
19
|
|
|
19
|
-
Point any
|
|
20
|
+
Point any client that accepts a custom API URL at it, or connect an MCP client to `/mcp` on the same warm process:
|
|
20
21
|
|
|
21
22
|
```bash
|
|
22
23
|
# Claude Code / Anthropic SDK
|
|
@@ -27,7 +28,13 @@ ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude
|
|
|
27
28
|
# use the MCP stdio server below (`codex mcp add maskera -- npx -y @maskera/mcp`) instead.
|
|
28
29
|
OPENAI_BASE_URL=http://127.0.0.1:8787/v1 codex
|
|
29
30
|
|
|
30
|
-
#
|
|
31
|
+
# Connect an HTTP MCP client to the same warm ONNX model & vault
|
|
32
|
+
claude mcp add --transport http maskera 'http://127.0.0.1:8787/mcp?no_raw_restore=1'
|
|
33
|
+
|
|
34
|
+
# Or require browser approval before raw PII ever leaves the vault
|
|
35
|
+
claude mcp add --transport http maskera 'http://127.0.0.1:8787/mcp?approval_mode=browser'
|
|
36
|
+
|
|
37
|
+
# Inspect live redactions and answer pending approvals in your browser (local RAM only)
|
|
31
38
|
open http://127.0.0.1:8787/_maskera
|
|
32
39
|
|
|
33
40
|
# Optional: write local metadata-only audit logs (counts only, never raw text)
|
|
@@ -35,29 +42,76 @@ npx -y @maskera/mcp proxy --audit-log ./maskera-audit.jsonl
|
|
|
35
42
|
```
|
|
36
43
|
|
|
37
44
|
- 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).
|
|
45
|
+
- 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
46
|
- Restores placeholders even when split across SSE stream chunks, including JSON `tool_use` / `tool_calls` arguments.
|
|
40
47
|
- Fails closed (`502`) if local redaction fails: raw PII is never forwarded upstream.
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
### Which mode to use
|
|
50
|
+
|
|
51
|
+
- **Proxy** for text typed straight into the chat. It also masks tool results, because they travel in the same request.
|
|
52
|
+
- **Streamable HTTP MCP (`/mcp`)** when multiple clients should share one warm ONNX model, one session vault, and browser approvals.
|
|
53
|
+
- **MCP stdio server** for local files the agent reads with `maskera_read_file` when no background proxy is running.
|
|
54
|
+
- 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.
|
|
55
|
+
|
|
56
|
+
### Claude Desktop through the proxy
|
|
57
|
+
|
|
58
|
+
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).
|
|
59
|
+
|
|
60
|
+
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.
|
|
61
|
+
2. In Claude Desktop, choose **Help → Troubleshooting → Enable Developer Mode**, then **Developer → Configure Third-Party Inference…**.
|
|
62
|
+
3. Under **Connection**, set **Inference provider** to **Gateway**.
|
|
63
|
+
4. Fill in **Gateway credentials**:
|
|
64
|
+
- **Credential kind**: **Static API key**
|
|
65
|
+
- **Gateway base URL**: `http://127.0.0.1:8787` (no `/v1`; Desktop adds `/v1/messages` itself)
|
|
66
|
+
- **Gateway API key**: your Anthropic API key
|
|
67
|
+
- **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.
|
|
68
|
+
5. Click **Apply Changes**, then **Save & Restart**.
|
|
69
|
+
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.
|
|
70
|
+
|
|
71
|
+
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.
|
|
72
|
+
|
|
73
|
+
## 2. MCP server setup (`install`, stdio, and scoped policies)
|
|
74
|
+
|
|
75
|
+
Generate or write the configuration for your client directly:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Supported clients: claude-code, claude-desktop, codex, cursor, opencode, t3-code
|
|
79
|
+
npx -y @maskera/mcp install cursor --root /path/to/workspace --no-raw-restore
|
|
80
|
+
npx -y @maskera/mcp install claude-code --transport http --no-raw-restore
|
|
81
|
+
npx -y @maskera/mcp doctor
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Or configure stdio manually:
|
|
43
85
|
|
|
44
86
|
```json
|
|
45
87
|
{
|
|
46
88
|
"mcpServers": {
|
|
47
89
|
"maskera": {
|
|
48
90
|
"command": "npx",
|
|
49
|
-
"args": ["-y", "@maskera/mcp", "--root", "/path/to/
|
|
91
|
+
"args": ["-y", "@maskera/mcp", "--root", "/path/to/workspace", "--no-raw-restore"]
|
|
50
92
|
}
|
|
51
93
|
}
|
|
52
94
|
}
|
|
53
95
|
```
|
|
54
96
|
|
|
55
|
-
Tools:
|
|
97
|
+
Tools (all declare `inputSchema`, `outputSchema`, and MCP tool `annotations`):
|
|
98
|
+
- `maskera_list_files`: List files inside allowed workspace roots without reading contents.
|
|
99
|
+
- `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
100
|
- `maskera_read_file`: Read a local UTF-8 file already redacted, storing the restore map locally under `session_id`.
|
|
57
101
|
- `maskera_write_file`: Restore placeholders from `session_id` and write directly to disk without exposing raw PII back to the LLM.
|
|
58
102
|
- `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.
|
|
103
|
+
- `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`).
|
|
104
|
+
- `maskera_list_sessions` / `maskera_clear_session` / `maskera_status`: Inspect counts (never raw PII), clear memory, or check model and policy status.
|
|
105
|
+
- `maskera_resume`: Exposed in `--approval-mode browser` to resume a paused raw-PII export once approved in `http://127.0.0.1:8787/_maskera`.
|
|
106
|
+
|
|
107
|
+
Built-in MCP `prompts` and `resources`:
|
|
108
|
+
- Prompts: `maskera-workflow` (with optional `profile` and `custom_terms`) and `maskera-redact-file`.
|
|
109
|
+
- Resources: `maskera://skills/maskera/SKILL.md` (full agent operating guide) and `maskera://status`.
|
|
110
|
+
|
|
111
|
+
Scoped policies (CLI flags or `/mcp` query parameters):
|
|
112
|
+
- `--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`.
|
|
113
|
+
- `--read-only` / `?read_only=1`: Hides and blocks `maskera_write_file` and `maskera_clear_session`.
|
|
114
|
+
- `--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
115
|
|
|
62
116
|
## 3. Harness-agnostic guard / hook
|
|
63
117
|
|
|
@@ -71,7 +125,7 @@ cat klient.txt | npx -y @maskera/mcp guard --redact
|
|
|
71
125
|
|
|
72
126
|
## 4. Agent skill (`SKILL.md`)
|
|
73
127
|
|
|
74
|
-
|
|
128
|
+
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
129
|
|
|
76
130
|
```bash
|
|
77
131
|
npx skills add joelhagvall/maskera
|
|
@@ -82,7 +136,7 @@ npx skills add joelhagvall/maskera
|
|
|
82
136
|
Run the built-in reusable E2E and benchmark suites locally (zero paid API calls):
|
|
83
137
|
|
|
84
138
|
```bash
|
|
85
|
-
# Protocol, security, streaming, and local ONNX E2E
|
|
139
|
+
# Protocol, security, streaming, HTTP /mcp, approvals, install, doctor, and local ONNX E2E
|
|
86
140
|
pnpm test:mcp:e2e
|
|
87
141
|
|
|
88
142
|
# Real installed agent harnesses (claude, codex, opencode) with MCP + proxy + hooks
|
|
@@ -102,6 +156,9 @@ pnpm bench:mcp
|
|
|
102
156
|
- `--rules-only` or `MASKERA_MCP_MODE=rules`: Deterministic rules only without loading the ONNX model.
|
|
103
157
|
- `--profile general|clinical`: Built-in precision profile.
|
|
104
158
|
- `--custom-term <word>` (repeatable): Extra protected words (client names, codenames, case IDs).
|
|
159
|
+
- `--no-raw-restore` or `MASKERA_MCP_NO_RAW_RESTORE=1`: Disallow raw PII export into model context.
|
|
160
|
+
- `--read-only` or `MASKERA_MCP_READ_ONLY=1`: Disallow file writes and session clears.
|
|
161
|
+
- `--approval-mode automatic|browser|native` or `MASKERA_MCP_APPROVAL_MODE`: Gate raw PII exports.
|
|
105
162
|
- `--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.
|
|
163
|
+
- `--root <dir>` (repeatable) or `MASKERA_MCP_ROOTS`: Allowed file roots for MCP file tools (works on both `mcp` and `proxy`).
|
|
107
164
|
- `MASKERA_MODEL_PATH` + `MASKERA_MODEL_ID` + `MASKERA_ALLOW_REMOTE_MODELS=0`: Load a local ONNX model directory offline.
|