@maskera/mcp 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +106 -2
- package/dist/cli.js +3312 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +309 -0
- package/dist/index.js +2980 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joel Hägvall
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @maskera/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Local Swedish PII redaction for any AI agent or LLM client:
|
|
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`.
|
|
8
|
+
|
|
9
|
+
All redaction runs 100% locally using `maskera` (deterministic Swedish rules + the 43 MB open Swedish ONNX NER model `joelhagvall/maskera-sv-ner`).
|
|
10
|
+
|
|
11
|
+
## 1. Harness-agnostic local LLM proxy (enforced for every agent)
|
|
12
|
+
|
|
13
|
+
Start the proxy on loopback (`127.0.0.1:8787`):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx -y @maskera/mcp proxy
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Point any harness at it:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Claude Code / Anthropic SDK
|
|
23
|
+
ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude
|
|
24
|
+
|
|
25
|
+
# Codex (API key) / OpenAI SDK / Cursor custom OpenAI base URL
|
|
26
|
+
# Note: Codex logged in with a ChatGPT subscription requires HTTPS on chatgpt_base_url;
|
|
27
|
+
# use the MCP stdio server below (`codex mcp add maskera -- npx -y @maskera/mcp`) instead.
|
|
28
|
+
OPENAI_BASE_URL=http://127.0.0.1:8787/v1 codex
|
|
29
|
+
|
|
30
|
+
# Inspect live redactions in your browser (local RAM only, screen-share safe by default)
|
|
31
|
+
open http://127.0.0.1:8787/_maskera
|
|
32
|
+
|
|
33
|
+
# Optional: write local metadata-only audit logs (counts only, never raw text)
|
|
34
|
+
npx -y @maskera/mcp proxy --audit-log ./maskera-audit.jsonl
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- 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).
|
|
39
|
+
- Restores placeholders even when split across SSE stream chunks, including JSON `tool_use` / `tool_calls` arguments.
|
|
40
|
+
- Fails closed (`502`) if local redaction fails: raw PII is never forwarded upstream.
|
|
41
|
+
|
|
42
|
+
## 2. MCP stdio server (Claude Desktop / Cursor / Claude Code / Codex / T3 Code)
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"mcpServers": {
|
|
47
|
+
"maskera": {
|
|
48
|
+
"command": "npx",
|
|
49
|
+
"args": ["-y", "@maskera/mcp", "--root", "/path/to/your/workspace"]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Tools:
|
|
56
|
+
- `maskera_read_file`: Read a local UTF-8 file already redacted, storing the restore map locally under `session_id`.
|
|
57
|
+
- `maskera_write_file`: Restore placeholders from `session_id` and write directly to disk without exposing raw PII back to the LLM.
|
|
58
|
+
- `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.
|
|
61
|
+
|
|
62
|
+
## 3. Harness-agnostic guard / hook
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Block prompts or hook JSON containing PII (exits 2 on match, 0 if clean)
|
|
66
|
+
echo '{"prompt":"Ring 070-174 06 58"}' | npx -y @maskera/mcp guard
|
|
67
|
+
|
|
68
|
+
# Redact any pipe locally
|
|
69
|
+
cat klient.txt | npx -y @maskera/mcp guard --redact
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 4. Agent skill (`SKILL.md`)
|
|
73
|
+
|
|
74
|
+
Install the workflow skill (`skills/maskera/SKILL.md`) in Claude Code, Codex, Cursor, or OpenCode:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npx skills add joelhagvall/maskera
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 5. Verification scripts (Claude Code, Codex, OpenCode)
|
|
81
|
+
|
|
82
|
+
Run the built-in reusable E2E and benchmark suites locally (zero paid API calls):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Protocol, security, streaming, and local ONNX E2E (also runs in CI)
|
|
86
|
+
pnpm test:mcp:e2e
|
|
87
|
+
|
|
88
|
+
# Real installed agent harnesses (claude, codex, opencode) with MCP + proxy + hooks
|
|
89
|
+
pnpm test:mcp:harnesses
|
|
90
|
+
pnpm test:mcp:harnesses -- --only claude,codex --mode rules
|
|
91
|
+
pnpm test:mcp:harnesses -- --live # opt-in live subscription proof
|
|
92
|
+
|
|
93
|
+
# Clean npm tarball pack + binary smoke (--cold-hf tests a fresh HF model download)
|
|
94
|
+
pnpm test:mcp:pack
|
|
95
|
+
|
|
96
|
+
# Latency & throughput benchmark (CLI startup, multi-turn ONNX cache, SSE restorer)
|
|
97
|
+
pnpm bench:mcp
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Options and environment
|
|
101
|
+
|
|
102
|
+
- `--rules-only` or `MASKERA_MCP_MODE=rules`: Deterministic rules only without loading the ONNX model.
|
|
103
|
+
- `--profile general|clinical`: Built-in precision profile.
|
|
104
|
+
- `--custom-term <word>` (repeatable): Extra protected words (client names, codenames, case IDs).
|
|
105
|
+
- `--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.
|
|
107
|
+
- `MASKERA_MODEL_PATH` + `MASKERA_MODEL_ID` + `MASKERA_ALLOW_REMOTE_MODELS=0`: Load a local ONNX model directory offline.
|