@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 +91 -18
- package/dist/cli.js +4661 -1481
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +404 -9
- package/dist/index.js +3494 -764
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,60 @@
|
|
|
1
1
|
import { NerRecognizer, NerOptions, RedactionProfile, RedactResult, Detector } from 'maskera';
|
|
2
2
|
import { ServerResponse, Server } from 'node:http';
|
|
3
3
|
|
|
4
|
+
type ApprovalMode = "automatic" | "browser" | "native";
|
|
5
|
+
type ApprovalStatus = "pending" | "approved" | "declined" | "expired" | "completed";
|
|
6
|
+
interface ApprovalSummary {
|
|
7
|
+
id: string;
|
|
8
|
+
tool: string;
|
|
9
|
+
reason: string;
|
|
10
|
+
sessionId: string | null;
|
|
11
|
+
placeholderCount: number;
|
|
12
|
+
status: ApprovalStatus;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
expiresAt: string;
|
|
15
|
+
decidedAt: string | null;
|
|
16
|
+
}
|
|
17
|
+
type ApprovalResumeResult = {
|
|
18
|
+
status: "completed";
|
|
19
|
+
result: Record<string, unknown>;
|
|
20
|
+
summary: ApprovalSummary;
|
|
21
|
+
} | {
|
|
22
|
+
status: "pending" | "declined" | "expired" | "not_found";
|
|
23
|
+
summary?: ApprovalSummary;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Process-local approval broker for sensitive MCP actions that would return
|
|
27
|
+
* raw PII into model context (such as `maskera_restore` or `maskera_redact`
|
|
28
|
+
* with `include_map: true`). Summaries never store or emit raw PII values.
|
|
29
|
+
*/
|
|
30
|
+
declare class ApprovalBroker {
|
|
31
|
+
private readonly records;
|
|
32
|
+
private readonly listeners;
|
|
33
|
+
private readonly ttlMs;
|
|
34
|
+
constructor(ttlMs?: number);
|
|
35
|
+
private expireStale;
|
|
36
|
+
private notify;
|
|
37
|
+
onChange(listener: (summaries: ApprovalSummary[]) => void): () => void;
|
|
38
|
+
create(input: {
|
|
39
|
+
tool: string;
|
|
40
|
+
reason: string;
|
|
41
|
+
sessionId?: string | null;
|
|
42
|
+
placeholderCount: number;
|
|
43
|
+
execute: () => Promise<Record<string, unknown>>;
|
|
44
|
+
}): ApprovalSummary;
|
|
45
|
+
list(): ApprovalSummary[];
|
|
46
|
+
decide(id: string, decision: "approve" | "decline"): ApprovalSummary | null;
|
|
47
|
+
resume(id: string): Promise<ApprovalResumeResult>;
|
|
48
|
+
clearAll(): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
4
51
|
type MaskMode = "auto" | "rules";
|
|
52
|
+
interface ModelLoadEvent {
|
|
53
|
+
phase: "loading" | "ready" | "error";
|
|
54
|
+
model: string;
|
|
55
|
+
elapsedMs?: number;
|
|
56
|
+
error?: string;
|
|
57
|
+
}
|
|
5
58
|
interface EngineOptions {
|
|
6
59
|
/** Default mode when a tool call omits `mode`. Default: `"auto"` (hybrid NER + rules). */
|
|
7
60
|
defaultMode?: MaskMode;
|
|
@@ -9,6 +62,8 @@ interface EngineOptions {
|
|
|
9
62
|
recognizer?: NerRecognizer;
|
|
10
63
|
/** Forwarded to `createNerRecognizer` when no custom recognizer is passed. */
|
|
11
64
|
nerOptions?: NerOptions;
|
|
65
|
+
/** Optional lifecycle hook fired when the local ONNX model starts/finishes loading. */
|
|
66
|
+
onModelStatus?: (event: ModelLoadEvent) => void;
|
|
12
67
|
/**
|
|
13
68
|
* Max entries in the in-memory span cache (stores only SHA-256 digest keys
|
|
14
69
|
* and `{ start, end, label }` offsets, never raw PII text). Default: `512`.
|
|
@@ -52,7 +107,65 @@ interface MaskeraEngine {
|
|
|
52
107
|
*/
|
|
53
108
|
declare function buildCustomTermsDetector(rawTerms: readonly string[]): Detector | null;
|
|
54
109
|
declare function createMaskeraEngine(options?: EngineOptions): MaskeraEngine;
|
|
110
|
+
/**
|
|
111
|
+
* Returns an `onModelStatus` handler that prints a concise progress line on
|
|
112
|
+
* stderr only when model loading takes longer than `delayMs` (default 350ms),
|
|
113
|
+
* keeping warm/cached runs quiet while reassuring users during the initial
|
|
114
|
+
* 43 MB ONNX download.
|
|
115
|
+
*/
|
|
116
|
+
declare function createModelProgressLogger(write?: (line: string) => void, delayMs?: number): (event: ModelLoadEvent) => void;
|
|
55
117
|
|
|
118
|
+
type DoctorCheckStatus = "ok" | "warn" | "fail";
|
|
119
|
+
interface DoctorCheck {
|
|
120
|
+
name: string;
|
|
121
|
+
status: DoctorCheckStatus;
|
|
122
|
+
detail: string;
|
|
123
|
+
}
|
|
124
|
+
interface DoctorSampleProof {
|
|
125
|
+
modeUsed: "hybrid" | "rules";
|
|
126
|
+
maskedCount: number;
|
|
127
|
+
countsByLabel: Record<string, number>;
|
|
128
|
+
redactedPreview: string;
|
|
129
|
+
rawPiiLeaked: boolean;
|
|
130
|
+
roundtripRestored: boolean;
|
|
131
|
+
elapsedMs: number;
|
|
132
|
+
}
|
|
133
|
+
interface DoctorReport {
|
|
134
|
+
schema: "maskera-setup-receipt/v1";
|
|
135
|
+
timestamp: string;
|
|
136
|
+
version: string;
|
|
137
|
+
ok: boolean;
|
|
138
|
+
mode: MaskMode;
|
|
139
|
+
client?: string;
|
|
140
|
+
transport?: string;
|
|
141
|
+
configPath?: string | null;
|
|
142
|
+
sampleProof: DoctorSampleProof | null;
|
|
143
|
+
checks: DoctorCheck[];
|
|
144
|
+
}
|
|
145
|
+
declare function runDoctor(options: {
|
|
146
|
+
engine: MaskeraEngine;
|
|
147
|
+
roots: readonly string[];
|
|
148
|
+
mode?: MaskMode;
|
|
149
|
+
profile?: RedactionProfile;
|
|
150
|
+
customTerms?: readonly string[];
|
|
151
|
+
proxyUrl?: string;
|
|
152
|
+
mcpUrl?: string;
|
|
153
|
+
client?: string;
|
|
154
|
+
transport?: string;
|
|
155
|
+
configPath?: string | null;
|
|
156
|
+
}): Promise<DoctorReport>;
|
|
157
|
+
declare function writeDoctorReceipt(filePath: string, report: DoctorReport): Promise<string>;
|
|
158
|
+
declare function formatDoctorReport(report: DoctorReport, heading?: string): string;
|
|
159
|
+
|
|
160
|
+
interface ListedFile {
|
|
161
|
+
path: string;
|
|
162
|
+
bytes: number;
|
|
163
|
+
}
|
|
164
|
+
interface SearchMatch {
|
|
165
|
+
path: string;
|
|
166
|
+
line: number;
|
|
167
|
+
lineText: string;
|
|
168
|
+
}
|
|
56
169
|
interface FileGuard {
|
|
57
170
|
readonly allowedRoots: readonly string[];
|
|
58
171
|
readText(filePath: string): Promise<{
|
|
@@ -66,11 +179,30 @@ interface FileGuard {
|
|
|
66
179
|
resolvedPath: string;
|
|
67
180
|
bytes: number;
|
|
68
181
|
}>;
|
|
182
|
+
listFiles(dirPath?: string, options?: {
|
|
183
|
+
maxEntries?: number;
|
|
184
|
+
maxDepth?: number;
|
|
185
|
+
}): Promise<{
|
|
186
|
+
root: string;
|
|
187
|
+
files: ListedFile[];
|
|
188
|
+
truncated: boolean;
|
|
189
|
+
}>;
|
|
190
|
+
searchFiles(query: string, options?: {
|
|
191
|
+
path?: string;
|
|
192
|
+
caseSensitive?: boolean;
|
|
193
|
+
maxMatches?: number;
|
|
194
|
+
maxFiles?: number;
|
|
195
|
+
}): Promise<{
|
|
196
|
+
root: string;
|
|
197
|
+
scannedFiles: number;
|
|
198
|
+
matches: SearchMatch[];
|
|
199
|
+
truncated: boolean;
|
|
200
|
+
}>;
|
|
69
201
|
}
|
|
70
202
|
/**
|
|
71
|
-
* Confines file reads and
|
|
72
|
-
* resolving symlinks to prevent path-traversal
|
|
73
|
-
* oversized files.
|
|
203
|
+
* Confines file reads, writes, directory listings, and searches to explicitly
|
|
204
|
+
* allowed local directories, resolving symlinks to prevent path-traversal
|
|
205
|
+
* escapes and rejecting binary or oversized files.
|
|
74
206
|
*/
|
|
75
207
|
declare function createFileGuard(roots?: readonly string[]): FileGuard;
|
|
76
208
|
|
|
@@ -97,6 +229,24 @@ declare function runGuard(rawInput: string, engine: MaskeraEngine, options?: {
|
|
|
97
229
|
customTerms?: readonly string[];
|
|
98
230
|
preserveJsonStructure?: boolean;
|
|
99
231
|
}): Promise<GuardResult>;
|
|
232
|
+
/**
|
|
233
|
+
* Sends a `guard` check to an already-running local loopback Maskera proxy
|
|
234
|
+
* (`POST /_maskera/guard`) to reuse its warm ONNX NER model (~5-15ms instead of
|
|
235
|
+
* cold-loading the 43 MB model per hook call).
|
|
236
|
+
*
|
|
237
|
+
* Returns `null` when no compatible local proxy is listening (so callers fall
|
|
238
|
+
* back transparently to local in-process redaction). Rejects non-loopback URLs
|
|
239
|
+
* and rethrows explicit proxy `502` fail-closed errors.
|
|
240
|
+
*/
|
|
241
|
+
declare function runGuardViaWarmProxy(rawInput: string, options?: {
|
|
242
|
+
proxyUrl?: string;
|
|
243
|
+
mode?: MaskMode;
|
|
244
|
+
profile?: RedactionProfile;
|
|
245
|
+
customTerms?: readonly string[];
|
|
246
|
+
preserveJsonStructure?: boolean;
|
|
247
|
+
includeRedacted?: boolean;
|
|
248
|
+
timeoutMs?: number;
|
|
249
|
+
}): Promise<GuardResult | null>;
|
|
100
250
|
|
|
101
251
|
interface InspectedRequest {
|
|
102
252
|
id: string;
|
|
@@ -114,14 +264,16 @@ interface InspectedRequest {
|
|
|
114
264
|
redactedPreview: string[];
|
|
115
265
|
}
|
|
116
266
|
/**
|
|
117
|
-
* In-memory ring buffer and SSE fan-out for the local proxy inspector.
|
|
267
|
+
* In-memory ring buffer and SSE fan-out for the local proxy and MCP inspector.
|
|
118
268
|
* Keeps only metadata and already-redacted previews (never raw PII).
|
|
119
269
|
*/
|
|
120
270
|
declare class ProxyInspector {
|
|
121
271
|
private readonly items;
|
|
122
272
|
private readonly subscribers;
|
|
273
|
+
private approvalsSnapshot;
|
|
123
274
|
private seq;
|
|
124
275
|
record(entry: Omit<InspectedRequest, "id">): InspectedRequest;
|
|
276
|
+
publishApprovals(approvals: ApprovalSummary[]): void;
|
|
125
277
|
list(): readonly InspectedRequest[];
|
|
126
278
|
clear(): void;
|
|
127
279
|
subscribe(res: ServerResponse, extraHeaders?: Record<string, string>): void;
|
|
@@ -129,10 +281,69 @@ declare class ProxyInspector {
|
|
|
129
281
|
}
|
|
130
282
|
declare function renderInspectorHtml(info: {
|
|
131
283
|
url: string;
|
|
284
|
+
mcpUrl?: string;
|
|
132
285
|
defaultMode: string;
|
|
133
286
|
restoreResponses: boolean;
|
|
134
287
|
}): string;
|
|
135
288
|
|
|
289
|
+
declare const SUPPORTED_CLIENTS: readonly ["claude-code", "claude-desktop", "codex", "cursor", "opencode", "t3-code"];
|
|
290
|
+
type InstallClient = (typeof SUPPORTED_CLIENTS)[number];
|
|
291
|
+
type InstallTransport = "stdio" | "http";
|
|
292
|
+
type CommandRunner = (command: string, args: readonly string[], cwd: string) => {
|
|
293
|
+
status: number | null;
|
|
294
|
+
stdout: string;
|
|
295
|
+
stderr: string;
|
|
296
|
+
error?: Error;
|
|
297
|
+
};
|
|
298
|
+
interface InstallOptions {
|
|
299
|
+
client: InstallClient;
|
|
300
|
+
transport?: InstallTransport;
|
|
301
|
+
mcpUrl?: string;
|
|
302
|
+
roots?: readonly string[];
|
|
303
|
+
noRawRestore?: boolean;
|
|
304
|
+
readOnly?: boolean;
|
|
305
|
+
approvalMode?: ApprovalMode;
|
|
306
|
+
rulesOnly?: boolean;
|
|
307
|
+
profile?: RedactionProfile;
|
|
308
|
+
customTerms?: readonly string[];
|
|
309
|
+
configPath?: string;
|
|
310
|
+
/** Run CLI registration commands directly (`claude mcp add` / `codex mcp add`). */
|
|
311
|
+
apply?: boolean;
|
|
312
|
+
/** Write project-local `.mcp.json` when configuring `claude-code`. */
|
|
313
|
+
project?: boolean;
|
|
314
|
+
/** Also install a `maskera-mcp guard` prompt hook (supported for `claude-code` and `cursor`). */
|
|
315
|
+
withHook?: boolean;
|
|
316
|
+
dryRun?: boolean;
|
|
317
|
+
cwd?: string;
|
|
318
|
+
homeDir?: string;
|
|
319
|
+
platform?: NodeJS.Platform;
|
|
320
|
+
execCommand?: CommandRunner;
|
|
321
|
+
}
|
|
322
|
+
interface InstallResult {
|
|
323
|
+
client: InstallClient;
|
|
324
|
+
transport: InstallTransport;
|
|
325
|
+
configPath: string | null;
|
|
326
|
+
command: string | null;
|
|
327
|
+
snippet: string;
|
|
328
|
+
written: boolean;
|
|
329
|
+
applied?: boolean;
|
|
330
|
+
applyOutput?: string;
|
|
331
|
+
hookPath?: string | null;
|
|
332
|
+
hookWritten?: boolean;
|
|
333
|
+
verifyStep: string;
|
|
334
|
+
}
|
|
335
|
+
declare function isInstallClient(value: string): value is InstallClient;
|
|
336
|
+
/**
|
|
337
|
+
* Auto-detects supported AI coding clients present in the workspace or on PATH.
|
|
338
|
+
*/
|
|
339
|
+
declare function detectInstalledClients(options?: {
|
|
340
|
+
cwd?: string;
|
|
341
|
+
homeDir?: string;
|
|
342
|
+
platform?: NodeJS.Platform;
|
|
343
|
+
pathEnv?: string;
|
|
344
|
+
}): Promise<InstallClient[]>;
|
|
345
|
+
declare function runInstall(options: InstallOptions): Promise<InstallResult>;
|
|
346
|
+
|
|
136
347
|
interface SessionSummary {
|
|
137
348
|
sessionId: string;
|
|
138
349
|
entityCount: number;
|
|
@@ -201,6 +412,16 @@ interface ProxyOptions {
|
|
|
201
412
|
engine?: MaskeraEngine;
|
|
202
413
|
/** Optional custom SessionVault. */
|
|
203
414
|
vault?: SessionVault;
|
|
415
|
+
/** Optional custom ApprovalBroker for browser MCP approvals. */
|
|
416
|
+
approvals?: ApprovalBroker;
|
|
417
|
+
/** Allowed workspace roots for the co-hosted Streamable HTTP `/mcp` endpoint. */
|
|
418
|
+
mcpRoots?: readonly string[];
|
|
419
|
+
/** Allow `maskera_restore` / `include_map: true` over `/mcp`. Default `true`. */
|
|
420
|
+
allowRawRestore?: boolean;
|
|
421
|
+
/** Disable file writes and session clears over `/mcp`. Default `false`. */
|
|
422
|
+
readOnly?: boolean;
|
|
423
|
+
/** Default approval mode for `/mcp` raw PII exports. Default `"automatic"`. */
|
|
424
|
+
approvalMode?: ApprovalMode;
|
|
204
425
|
/** Default mode if creating a new engine (`"auto"` or `"rules"`). */
|
|
205
426
|
defaultMode?: MaskMode;
|
|
206
427
|
/** Optional built-in precision profile (`"general"` or `"clinical"`). */
|
|
@@ -214,14 +435,23 @@ interface ProxyOptions {
|
|
|
214
435
|
/** Optional safe metadata logger (never receives raw PII). */
|
|
215
436
|
onLog?: (message: string) => void;
|
|
216
437
|
}
|
|
438
|
+
interface ProxyStats {
|
|
439
|
+
requests: number;
|
|
440
|
+
redactions: number;
|
|
441
|
+
counts: Record<string, number>;
|
|
442
|
+
sessions: number;
|
|
443
|
+
}
|
|
217
444
|
interface RunningMaskeraProxy {
|
|
218
445
|
readonly url: string;
|
|
446
|
+
readonly mcpUrl: string;
|
|
219
447
|
readonly inspectorUrl: string;
|
|
220
448
|
readonly host: string;
|
|
221
449
|
readonly port: number;
|
|
222
450
|
readonly server: Server;
|
|
223
451
|
readonly vault: SessionVault;
|
|
224
452
|
readonly inspector: ProxyInspector;
|
|
453
|
+
readonly approvals: ApprovalBroker;
|
|
454
|
+
stats(): ProxyStats;
|
|
225
455
|
close(): Promise<void>;
|
|
226
456
|
}
|
|
227
457
|
/**
|
|
@@ -276,12 +506,13 @@ declare function createSseRestorer(map: Readonly<Record<string, string>>): {
|
|
|
276
506
|
* Point `ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL`, or any OpenAI/Anthropic SDK
|
|
277
507
|
* at this proxy to automatically redact Swedish PII locally before prompts or
|
|
278
508
|
* tool results leave the machine, and transparently restore placeholders in
|
|
279
|
-
* both JSON and SSE streaming responses.
|
|
509
|
+
* both JSON and SSE streaming responses. Also serves Streamable HTTP MCP on
|
|
510
|
+
* `/mcp` sharing the same warm ONNX model, session vault, and live inspector.
|
|
280
511
|
*/
|
|
281
512
|
declare function startMaskeraProxy(options?: ProxyOptions): Promise<RunningMaskeraProxy>;
|
|
282
513
|
|
|
283
514
|
declare const SERVER_NAME = "maskera-mcp";
|
|
284
|
-
declare const SERVER_VERSION = "0.
|
|
515
|
+
declare const SERVER_VERSION = "0.4.0";
|
|
285
516
|
interface JsonRpcResponse {
|
|
286
517
|
jsonrpc: "2.0";
|
|
287
518
|
id: string | number | null;
|
|
@@ -292,18 +523,182 @@ interface JsonRpcResponse {
|
|
|
292
523
|
data?: unknown;
|
|
293
524
|
};
|
|
294
525
|
}
|
|
295
|
-
interface
|
|
526
|
+
interface ElicitationRequest {
|
|
527
|
+
message: string;
|
|
528
|
+
requestedSchema: Record<string, unknown>;
|
|
529
|
+
}
|
|
530
|
+
interface ElicitationResponse {
|
|
531
|
+
action: "accept" | "decline" | "cancel";
|
|
532
|
+
content?: Record<string, unknown>;
|
|
533
|
+
}
|
|
534
|
+
interface ToolCallTelemetry {
|
|
535
|
+
tool: string;
|
|
536
|
+
sessionId?: string;
|
|
537
|
+
redactions: number;
|
|
538
|
+
counts: Record<string, number>;
|
|
539
|
+
durationMs: number;
|
|
540
|
+
isError: boolean;
|
|
541
|
+
}
|
|
542
|
+
interface MaskeraMcpPolicy {
|
|
543
|
+
/** Block `maskera_restore` and `maskera_redact(..., { include_map: true })`. Default: `true` (allowed). */
|
|
544
|
+
allowRawRestore?: boolean;
|
|
545
|
+
/** Omit and block state-changing tools (`maskera_write_file`, `maskera_clear_session`). Default: `false`. */
|
|
546
|
+
readOnly?: boolean;
|
|
547
|
+
/** Gate raw PII release (`automatic`, `browser`, or `native` MCP elicitation). Default: `"automatic"`. */
|
|
548
|
+
approvalMode?: ApprovalMode;
|
|
549
|
+
}
|
|
550
|
+
interface MaskeraMcpOptions extends MaskeraMcpPolicy {
|
|
296
551
|
engine?: MaskeraEngine;
|
|
297
552
|
vault?: SessionVault;
|
|
298
553
|
files?: FileGuard;
|
|
299
554
|
allowedRoots?: readonly string[];
|
|
300
555
|
defaultProfile?: RedactionProfile;
|
|
301
556
|
defaultCustomTerms?: readonly string[];
|
|
557
|
+
approvals?: ApprovalBroker;
|
|
558
|
+
approvalBaseUrl?: string;
|
|
559
|
+
requestElicitation?: (req: ElicitationRequest) => Promise<ElicitationResponse>;
|
|
560
|
+
onToolCall?: (event: ToolCallTelemetry) => void;
|
|
302
561
|
}
|
|
303
562
|
interface MaskeraMcpServer {
|
|
304
|
-
handleMessage(raw: unknown): Promise<JsonRpcResponse | null>;
|
|
563
|
+
handleMessage(raw: unknown, policyOverride?: MaskeraMcpPolicy): Promise<JsonRpcResponse | null>;
|
|
305
564
|
readonly vault: SessionVault;
|
|
306
565
|
}
|
|
307
566
|
declare function createMaskeraMcpServer(options?: MaskeraMcpOptions): MaskeraMcpServer;
|
|
308
567
|
|
|
309
|
-
|
|
568
|
+
type ServiceAction = "install" | "status" | "uninstall";
|
|
569
|
+
interface ServiceOptions {
|
|
570
|
+
action: ServiceAction;
|
|
571
|
+
host?: string;
|
|
572
|
+
port?: number;
|
|
573
|
+
roots?: readonly string[];
|
|
574
|
+
rulesOnly?: boolean;
|
|
575
|
+
noRawRestore?: boolean;
|
|
576
|
+
readOnly?: boolean;
|
|
577
|
+
approvalMode?: ApprovalMode;
|
|
578
|
+
profile?: RedactionProfile;
|
|
579
|
+
customTerms?: readonly string[];
|
|
580
|
+
auditLogPath?: string;
|
|
581
|
+
dryRun?: boolean;
|
|
582
|
+
platform?: NodeJS.Platform;
|
|
583
|
+
homeDir?: string;
|
|
584
|
+
nodePath?: string;
|
|
585
|
+
cliPath?: string;
|
|
586
|
+
pathEnv?: string;
|
|
587
|
+
uid?: number;
|
|
588
|
+
execCommand?: CommandRunner;
|
|
589
|
+
}
|
|
590
|
+
interface ServiceResult {
|
|
591
|
+
action: ServiceAction;
|
|
592
|
+
platform: NodeJS.Platform;
|
|
593
|
+
manager: "launchd" | "systemd" | "unsupported";
|
|
594
|
+
serviceName: string;
|
|
595
|
+
serviceFile: string | null;
|
|
596
|
+
proxyUrl: string;
|
|
597
|
+
mcpUrl: string;
|
|
598
|
+
inspectorUrl: string;
|
|
599
|
+
installed: boolean;
|
|
600
|
+
running: boolean;
|
|
601
|
+
written: boolean;
|
|
602
|
+
snippet?: string;
|
|
603
|
+
detail: string;
|
|
604
|
+
}
|
|
605
|
+
declare const LAUNCHD_LABEL = "dev.maskera.proxy";
|
|
606
|
+
declare const SYSTEMD_UNIT = "maskera-proxy.service";
|
|
607
|
+
declare function renderLaunchdPlist(options: {
|
|
608
|
+
programArguments: readonly string[];
|
|
609
|
+
stdoutLogPath: string;
|
|
610
|
+
stderrLogPath: string;
|
|
611
|
+
pathEnv?: string;
|
|
612
|
+
}): string;
|
|
613
|
+
declare function renderSystemdUnit(options: {
|
|
614
|
+
programArguments: readonly string[];
|
|
615
|
+
pathEnv?: string;
|
|
616
|
+
}): string;
|
|
617
|
+
declare function runService(options: ServiceOptions): Promise<ServiceResult>;
|
|
618
|
+
|
|
619
|
+
declare const MASKERA_SKILL_URI = "maskera://skills/maskera/SKILL.md";
|
|
620
|
+
declare const MASKERA_STATUS_URI = "maskera://status";
|
|
621
|
+
/**
|
|
622
|
+
* Bundled Maskera agent workflow skill served directly over MCP resources and
|
|
623
|
+
* prompts so connected clients get the full operating guide without a separate
|
|
624
|
+
* skill install step. Kept in sync with `skills/maskera/SKILL.md` by unit test.
|
|
625
|
+
*/
|
|
626
|
+
declare const MASKERA_SKILL_MARKDOWN = "---\nname: maskera\ndescription: Redact Swedish personal data (names, personnummer, addresses, phones, emails, IBAN, org numbers) locally before text or files reach an AI model, and restore answers locally. Use when working with Swedish client files, HR/CVs, legal or municipal cases, healthcare notes, support transcripts, or when setting up @maskera/mcp (local LLM proxy, Streamable HTTP or stdio MCP server, guard) or the maskera npm SDK.\n---\n\n# Maskera: local Swedish PII redaction\n\nMaskera runs 100% locally on-device using deterministic Swedish rules plus the 43 MB Swedish ONNX NER model (`joelhagvall/maskera-sv-ner`). Raw PII and restore maps stay local so cloud LLMs only see placeholders such as `[NAMN_1]` and `[PERSONNUMMER_1]`.\n\n## Choose the right mode\n\nPick by where the text comes from: **proxy for text typed straight into the chat**, **MCP for files the agent reads with the Maskera tools**. Before the user sends real personal data, verify the setup with made-up data (a fictional address) and confirm a placeholder in the local inspector at `http://127.0.0.1:8787/_maskera`, or run `npx -y @maskera/mcp doctor`.\n\n1. **Local LLM proxy + warm Streamable HTTP MCP (`maskera-mcp wrap` / `proxy` / `service`):**\n Use when no prompt, history or tool output may leave the machine unredacted, or when multiple clients should share one warm ONNX model and session vault.\n ```bash\n # Single-command launch (starts local proxy, verifies 0 leaks, injects env vars, prints session receipt on exit):\n npx -y @maskera/mcp wrap -- claude\n # Or run a persistent local proxy (+ Streamable HTTP /mcp + live inspector with self-test button):\n npx -y @maskera/mcp proxy --root /path/to/workspace --open\n # Or install as a background service (launchd on macOS, systemd --user on Linux):\n npx -y @maskera/mcp service install --root /path/to/workspace --no-raw-restore\n # Point any harness or SDK at the loopback proxy:\n ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude\n OPENAI_BASE_URL=http://127.0.0.1:8787/v1 codex # API key mode; ChatGPT-login Codex requires HTTPS so use MCP below\n # Same warm process also serves Streamable HTTP MCP:\n # http://127.0.0.1:8787/mcp (supports ?no_raw_restore=1&read_only=1&approval_mode=browser)\n ```\n - Claude Desktop: Help -> Troubleshooting -> Enable Developer Mode, then Developer -> Configure Third-Party Inference. Set Inference provider to **Gateway**, Credential kind **Static API key**, Gateway base URL `http://127.0.0.1:8787` (no `/v1`), Gateway API key = the user's Anthropic API key, Gateway auth scheme **x-api-key**. Apply Changes, then Save & Restart. Full guide: `https://maskera.dev/docs/guides`.\n - Routes Anthropic (`/v1/messages`) and OpenAI (`/v1/chat/completions`, `/v1/responses`) automatically, or set `--upstream <url>`.\n - Restores placeholders transparently in JSON, tool arguments and chunk-split SSE streams.\n - Fails closed (`502`) if local redaction fails. Inspect counts only at `http://127.0.0.1:8787/_maskera/status`.\n\n2. **Working with sensitive local Swedish files (MCP stdio or Streamable HTTP):**\n Auto-detect or install automatically with `npx -y @maskera/mcp install [client|all]` (`claude-code`, `claude-desktop`, `codex`, `cursor`, `opencode`, `t3-code`; pass `--apply` to run `claude`/`codex mcp add`, `--with-hook` to install a `guard` hook). It verifies local Swedish PII masking (and any running `/mcp` server) automatically and prints a zero-PII setup receipt (`--receipt <file.json>` to save it, `--no-verify` to skip). Or configure manually:\n - Claude Code / Cursor (`mcpServers`):\n ```json\n {\n \"mcpServers\": {\n \"maskera\": {\n \"command\": \"npx\",\n \"args\": [\"-y\", \"@maskera/mcp\", \"--root\", \"/path/to/workspace\", \"--no-raw-restore\"]\n }\n }\n }\n ```\n - Codex CLI:\n ```bash\n codex mcp add maskera -- npx -y @maskera/mcp --root /path/to/workspace --no-raw-restore\n ```\n - OpenCode v2:\n ```bash\n opencode mcp add maskera -- npx -y @maskera/mcp --root /path/to/workspace --no-raw-restore\n ```\n Workflow rules when the Maskera MCP tools are available:\n - List and search sensitive Swedish directories with `maskera_list_files` and `maskera_search_files` instead of raw `grep`/`rg` so matched lines are redacted before entering context.\n - Read sensitive Swedish files with `maskera_read_file` instead of raw file-reading tools. Reuse one `session_id` across related files so `[NAMN_1]` stays consistent.\n - Pass `custom_terms` for client codenames, project names or case references not covered by built-in rules.\n - Pass `profile: \"clinical\"` for Swedish medical or care notes so diagnoses, doses and measurements stay intact while personal data is masked.\n - Write finished drafts directly to disk with `maskera_write_file` so placeholders are restored locally without echoing raw PII back into the conversation.\n - Use `--no-raw-restore` (or `--approval-mode browser`) when the agent should never pull raw PII back into chat via `maskera_restore` or `include_map: true`.\n - Clear the in-memory restore map with `maskera_clear_session` once the task is done.\n\n3. **Hooks and Unix pipes (guard):**\n ```bash\n # Block prompts or JSON hook payloads containing PII (exits 2, prints counts only):\n npx -y @maskera/mcp guard\n # Redact text locally in a pipeline:\n cat input.txt | npx -y @maskera/mcp guard --redact\n ```\n\n4. **Embedding in application code (browser or Node 18+):**\n ```bash\n npm install maskera @huggingface/transformers\n ```\n Reuse one `createNerRecognizer()` instance across calls and run `await redactWithNer(text, { recognizer })` (or `redact(text)` from `@maskera/core` for zero-dependency structured rules only).\n\n## Boundaries\n\n- A skill guides agent behaviour; for hard enforcement that cannot be bypassed by raw shell or file tools, use `maskera-mcp proxy` or restrict file access to `maskera-mcp` with `--no-raw-restore`.\n- Automated masking reduces exposure risk but is not a zero-leak guarantee. Never log restore maps or write them next to redacted outputs.\n- Reference docs and machine-readable details: `https://maskera.dev/docs` and `https://maskera.dev/llms.txt`.\n";
|
|
627
|
+
interface McpPromptDefinition {
|
|
628
|
+
name: string;
|
|
629
|
+
description: string;
|
|
630
|
+
arguments?: Array<{
|
|
631
|
+
name: string;
|
|
632
|
+
description: string;
|
|
633
|
+
required?: boolean;
|
|
634
|
+
}>;
|
|
635
|
+
}
|
|
636
|
+
declare const MASKERA_PROMPTS: readonly McpPromptDefinition[];
|
|
637
|
+
declare function renderMaskeraPrompt(name: string, args: Record<string, unknown>): {
|
|
638
|
+
description: string;
|
|
639
|
+
messages: Array<{
|
|
640
|
+
role: "user";
|
|
641
|
+
content: {
|
|
642
|
+
type: "text";
|
|
643
|
+
text: string;
|
|
644
|
+
};
|
|
645
|
+
}>;
|
|
646
|
+
} | null;
|
|
647
|
+
|
|
648
|
+
interface WrapOptions {
|
|
649
|
+
command: string;
|
|
650
|
+
args: readonly string[];
|
|
651
|
+
engine: MaskeraEngine;
|
|
652
|
+
roots: readonly string[];
|
|
653
|
+
host?: string;
|
|
654
|
+
/** Defaults to `0` (ephemeral free port) so multiple wrapped sessions never collide. */
|
|
655
|
+
port?: number;
|
|
656
|
+
upstream?: string;
|
|
657
|
+
anthropicUpstream?: string;
|
|
658
|
+
openaiUpstream?: string;
|
|
659
|
+
allowRawRestore?: boolean;
|
|
660
|
+
readOnly?: boolean;
|
|
661
|
+
approvalMode?: ApprovalMode;
|
|
662
|
+
profile?: RedactionProfile;
|
|
663
|
+
customTerms?: readonly string[];
|
|
664
|
+
restoreResponses?: boolean;
|
|
665
|
+
auditLogPath?: string;
|
|
666
|
+
verify?: boolean;
|
|
667
|
+
receiptPath?: string;
|
|
668
|
+
openInspector?: boolean;
|
|
669
|
+
env?: NodeJS.ProcessEnv;
|
|
670
|
+
onStderr?: (line: string) => void;
|
|
671
|
+
}
|
|
672
|
+
interface WrapReceipt {
|
|
673
|
+
schema: "maskera-wrap-receipt/v1";
|
|
674
|
+
timestamp: string;
|
|
675
|
+
command: string;
|
|
676
|
+
exitCode: number;
|
|
677
|
+
proxyUrl: string;
|
|
678
|
+
mcpUrl: string;
|
|
679
|
+
startupReceipt: DoctorReport | null;
|
|
680
|
+
session: ProxyStats;
|
|
681
|
+
}
|
|
682
|
+
interface WrapResult {
|
|
683
|
+
exitCode: number;
|
|
684
|
+
signal: NodeJS.Signals | null;
|
|
685
|
+
proxyUrl: string;
|
|
686
|
+
mcpUrl: string;
|
|
687
|
+
startupReceipt: DoctorReport | null;
|
|
688
|
+
session: ProxyStats;
|
|
689
|
+
receiptPath?: string;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Best-effort opener for a local loopback URL in the user's default browser.
|
|
693
|
+
* Never throws if running headless or on a system without a GUI opener.
|
|
694
|
+
*/
|
|
695
|
+
declare function openUrlInBrowser(url: string, platform?: NodeJS.Platform): boolean;
|
|
696
|
+
/**
|
|
697
|
+
* Starts a local Maskera proxy on a loopback port, runs an optional zero-PII
|
|
698
|
+
* startup self-check, injects `ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL`,
|
|
699
|
+
* `MASKERA_PROXY_URL`, and `MASKERA_MCP_URL` into the wrapped child command,
|
|
700
|
+
* forwards stdio transparently, and shuts down cleanly with a session receipt.
|
|
701
|
+
*/
|
|
702
|
+
declare function runWrap(options: WrapOptions): Promise<WrapResult>;
|
|
703
|
+
|
|
704
|
+
export { ApprovalBroker, type ApprovalMode, type ApprovalResumeResult, type ApprovalStatus, type ApprovalSummary, type CommandRunner, type DoctorCheck, type DoctorCheckStatus, type DoctorReport, type DoctorSampleProof, type ElicitationRequest, type ElicitationResponse, type EngineOptions, type FileGuard, type GuardResult, type InspectedRequest, type InstallClient, type InstallOptions, type InstallResult, type InstallTransport, type JsonRpcResponse, LAUNCHD_LABEL, type ListedFile, MASKERA_PROMPTS, MASKERA_SKILL_MARKDOWN, MASKERA_SKILL_URI, MASKERA_STATUS_URI, type MaskMode, type MaskeraEngine, type MaskeraMcpOptions, type MaskeraMcpPolicy, type MaskeraMcpServer, type McpPromptDefinition, type ModelLoadEvent, ProxyInspector, type ProxyOptions, type ProxyStats, type RedactFieldKind, type RedactInputOptions, type RunningMaskeraProxy, SERVER_NAME, SERVER_VERSION, SUPPORTED_CLIENTS, SYSTEMD_UNIT, type SearchMatch, type ServiceAction, type ServiceOptions, type ServiceResult, type SessionSummary, SessionVault, StreamingRestorer, type ToolCallTelemetry, type WrapOptions, type WrapReceipt, type WrapResult, buildCustomTermsDetector, createFileGuard, createMaskeraEngine, createMaskeraMcpServer, createModelProgressLogger, createSseRestorer, detectInstalledClients, extractGuardText, formatDoctorReport, isInstallClient, openUrlInBrowser, redactLlmRequestBody, renderInspectorHtml, renderLaunchdPlist, renderMaskeraPrompt, renderSystemdUnit, restoreLlmResponseBody, runDoctor, runGuard, runGuardViaWarmProxy, runInstall, runService, runWrap, startMaskeraProxy, writeDoctorReceipt };
|