@maskera/mcp 0.1.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 CHANGED
@@ -2,56 +2,116 @@
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.
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. Harness-agnostic local LLM proxy (enforced for every agent)
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 harness at it:
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
23
24
  ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude
24
25
 
25
- # Codex / OpenAI SDK / Cursor custom OpenAI base URL
26
+ # Codex (API key) / OpenAI SDK / Cursor custom OpenAI base URL
27
+ # Note: Codex logged in with a ChatGPT subscription requires HTTPS on chatgpt_base_url;
28
+ # use the MCP stdio server below (`codex mcp add maskera -- npx -y @maskera/mcp`) instead.
26
29
  OPENAI_BASE_URL=http://127.0.0.1:8787/v1 codex
27
30
 
28
- # Inspect local redaction counts (never raw PII)
29
- curl http://127.0.0.1:8787/_maskera/status
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)
38
+ open http://127.0.0.1:8787/_maskera
39
+
40
+ # Optional: write local metadata-only audit logs (counts only, never raw text)
41
+ npx -y @maskera/mcp proxy --audit-log ./maskera-audit.jsonl
30
42
  ```
31
43
 
32
- - Routes Anthropic (`/v1/messages`, `/anthropic/*`) and OpenAI (`/v1/chat/completions`, `/v1/responses`, `/openai/*`) automatically, or use `--upstream <url>` for any OpenAI/Anthropic-compatible gateway (Azure, OpenRouter, LiteLLM).
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).
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).
33
46
  - Restores placeholders even when split across SSE stream chunks, including JSON `tool_use` / `tool_calls` arguments.
34
47
  - Fails closed (`502`) if local redaction fails: raw PII is never forwarded upstream.
35
48
 
36
- ## 2. MCP stdio server (Claude Desktop / Cursor / Claude Code / Codex / T3 Code)
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:
37
85
 
38
86
  ```json
39
87
  {
40
88
  "mcpServers": {
41
89
  "maskera": {
42
90
  "command": "npx",
43
- "args": ["-y", "@maskera/mcp", "--root", "/path/to/your/workspace"]
91
+ "args": ["-y", "@maskera/mcp", "--root", "/path/to/workspace", "--no-raw-restore"]
44
92
  }
45
93
  }
46
94
  }
47
95
  ```
48
96
 
49
- 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]`).
50
100
  - `maskera_read_file`: Read a local UTF-8 file already redacted, storing the restore map locally under `session_id`.
51
101
  - `maskera_write_file`: Restore placeholders from `session_id` and write directly to disk without exposing raw PII back to the LLM.
52
102
  - `maskera_redact`: Redact text locally (`mode: "auto"` or `"rules"`, `profile: "general" | "clinical"`, `custom_terms`).
53
- - `maskera_restore`: Restore placeholders using `session_id` or an explicit map.
54
- - `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.
55
115
 
56
116
  ## 3. Harness-agnostic guard / hook
57
117
 
@@ -63,11 +123,42 @@ echo '{"prompt":"Ring 070-174 06 58"}' | npx -y @maskera/mcp guard
63
123
  cat klient.txt | npx -y @maskera/mcp guard --redact
64
124
  ```
65
125
 
126
+ ## 4. Agent skill (`SKILL.md`)
127
+
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:
129
+
130
+ ```bash
131
+ npx skills add joelhagvall/maskera
132
+ ```
133
+
134
+ ## 5. Verification scripts (Claude Code, Codex, OpenCode)
135
+
136
+ Run the built-in reusable E2E and benchmark suites locally (zero paid API calls):
137
+
138
+ ```bash
139
+ # Protocol, security, streaming, HTTP /mcp, approvals, install, doctor, and local ONNX E2E
140
+ pnpm test:mcp:e2e
141
+
142
+ # Real installed agent harnesses (claude, codex, opencode) with MCP + proxy + hooks
143
+ pnpm test:mcp:harnesses
144
+ pnpm test:mcp:harnesses -- --only claude,codex --mode rules
145
+ pnpm test:mcp:harnesses -- --live # opt-in live subscription proof
146
+
147
+ # Clean npm tarball pack + binary smoke (--cold-hf tests a fresh HF model download)
148
+ pnpm test:mcp:pack
149
+
150
+ # Latency & throughput benchmark (CLI startup, multi-turn ONNX cache, SSE restorer)
151
+ pnpm bench:mcp
152
+ ```
153
+
66
154
  ## Options and environment
67
155
 
68
156
  - `--rules-only` or `MASKERA_MCP_MODE=rules`: Deterministic rules only without loading the ONNX model.
69
157
  - `--profile general|clinical`: Built-in precision profile.
70
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.
71
162
  - `--port <n>` / `--host <addr>` / `--upstream <url>` / `--no-restore`: Proxy options.
72
- - `--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`).
73
164
  - `MASKERA_MODEL_PATH` + `MASKERA_MODEL_ID` + `MASKERA_ALLOW_REMOTE_MODELS=0`: Load a local ONNX model directory offline.