@maskera/mcp 0.1.0 → 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/README.md +38 -4
- package/dist/cli.js +1821 -241
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +80 -8
- package/dist/index.js +1702 -198
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NerRecognizer, NerOptions, RedactionProfile, RedactResult, Detector } from 'maskera';
|
|
2
|
-
import { Server } from 'node:http';
|
|
2
|
+
import { ServerResponse, Server } from 'node:http';
|
|
3
3
|
|
|
4
4
|
type MaskMode = "auto" | "rules";
|
|
5
5
|
interface EngineOptions {
|
|
@@ -9,6 +9,12 @@ interface EngineOptions {
|
|
|
9
9
|
recognizer?: NerRecognizer;
|
|
10
10
|
/** Forwarded to `createNerRecognizer` when no custom recognizer is passed. */
|
|
11
11
|
nerOptions?: NerOptions;
|
|
12
|
+
/**
|
|
13
|
+
* Max entries in the in-memory span cache (stores only SHA-256 digest keys
|
|
14
|
+
* and `{ start, end, label }` offsets, never raw PII text). Default: `512`.
|
|
15
|
+
* Set to `0` to disable caching.
|
|
16
|
+
*/
|
|
17
|
+
maxCacheEntries?: number;
|
|
12
18
|
}
|
|
13
19
|
interface RedactInputOptions {
|
|
14
20
|
mode?: MaskMode;
|
|
@@ -21,12 +27,23 @@ interface MaskeraEngine {
|
|
|
21
27
|
modeUsed: "hybrid" | "rules";
|
|
22
28
|
fallbackReason?: string;
|
|
23
29
|
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Starts loading the local ONNX NER model in the background when defaultMode
|
|
32
|
+
* is `"auto"`. Safe to call on server startup: rejections are captured in
|
|
33
|
+
* `status().nerError` and never cause unhandled promise rejections.
|
|
34
|
+
*/
|
|
35
|
+
warmup(): void;
|
|
36
|
+
/** Clears the in-memory span cache. */
|
|
37
|
+
clearCache(): void;
|
|
24
38
|
status(): {
|
|
25
39
|
defaultMode: MaskMode;
|
|
26
40
|
model: string;
|
|
27
41
|
revision: string;
|
|
28
42
|
nerLoaded: boolean;
|
|
29
43
|
nerError: string | null;
|
|
44
|
+
cacheSize: number;
|
|
45
|
+
cacheHits: number;
|
|
46
|
+
cacheMisses: number;
|
|
30
47
|
};
|
|
31
48
|
}
|
|
32
49
|
/**
|
|
@@ -66,8 +83,9 @@ interface GuardResult {
|
|
|
66
83
|
}
|
|
67
84
|
/**
|
|
68
85
|
* Extracts text from either a plain string or a JSON hook envelope (such as
|
|
69
|
-
* Claude Code / Cursor `UserPromptSubmit
|
|
70
|
-
* same guard command works across any
|
|
86
|
+
* Claude Code / Cursor `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, or
|
|
87
|
+
* `beforeSubmitPrompt` stdin JSON) so the same guard command works across any
|
|
88
|
+
* agent harness or shell pipeline without missing sibling fields or attachments.
|
|
71
89
|
*/
|
|
72
90
|
declare function extractGuardText(rawInput: string): {
|
|
73
91
|
text: string;
|
|
@@ -77,8 +95,44 @@ declare function runGuard(rawInput: string, engine: MaskeraEngine, options?: {
|
|
|
77
95
|
mode?: MaskMode;
|
|
78
96
|
profile?: RedactionProfile;
|
|
79
97
|
customTerms?: readonly string[];
|
|
98
|
+
preserveJsonStructure?: boolean;
|
|
80
99
|
}): Promise<GuardResult>;
|
|
81
100
|
|
|
101
|
+
interface InspectedRequest {
|
|
102
|
+
id: string;
|
|
103
|
+
timestamp: string;
|
|
104
|
+
method: string;
|
|
105
|
+
path: string;
|
|
106
|
+
upstream: string;
|
|
107
|
+
sessionId: string;
|
|
108
|
+
status: number;
|
|
109
|
+
streamed: boolean;
|
|
110
|
+
durationMs: number;
|
|
111
|
+
redactions: number;
|
|
112
|
+
counts: Record<string, number>;
|
|
113
|
+
/** Redacted snippets sent upstream (never raw PII). */
|
|
114
|
+
redactedPreview: string[];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* In-memory ring buffer and SSE fan-out for the local proxy inspector.
|
|
118
|
+
* Keeps only metadata and already-redacted previews (never raw PII).
|
|
119
|
+
*/
|
|
120
|
+
declare class ProxyInspector {
|
|
121
|
+
private readonly items;
|
|
122
|
+
private readonly subscribers;
|
|
123
|
+
private seq;
|
|
124
|
+
record(entry: Omit<InspectedRequest, "id">): InspectedRequest;
|
|
125
|
+
list(): readonly InspectedRequest[];
|
|
126
|
+
clear(): void;
|
|
127
|
+
subscribe(res: ServerResponse, extraHeaders?: Record<string, string>): void;
|
|
128
|
+
closeAll(): void;
|
|
129
|
+
}
|
|
130
|
+
declare function renderInspectorHtml(info: {
|
|
131
|
+
url: string;
|
|
132
|
+
defaultMode: string;
|
|
133
|
+
restoreResponses: boolean;
|
|
134
|
+
}): string;
|
|
135
|
+
|
|
82
136
|
interface SessionSummary {
|
|
83
137
|
sessionId: string;
|
|
84
138
|
entityCount: number;
|
|
@@ -97,7 +151,8 @@ interface SessionSummary {
|
|
|
97
151
|
declare class SessionVault {
|
|
98
152
|
private readonly sessions;
|
|
99
153
|
private readonly maxSessions;
|
|
100
|
-
|
|
154
|
+
private readonly maxEntitiesPerSession;
|
|
155
|
+
constructor(maxSessions?: number, maxEntitiesPerSession?: number);
|
|
101
156
|
private getOrCreate;
|
|
102
157
|
/**
|
|
103
158
|
* Re-number a RedactResult's replacements into a persistent session so that
|
|
@@ -120,6 +175,12 @@ declare class SessionVault {
|
|
|
120
175
|
knownPlaceholders: number;
|
|
121
176
|
};
|
|
122
177
|
getMap(sessionId: string): Record<string, string>;
|
|
178
|
+
entries(): Array<{
|
|
179
|
+
sessionId: string;
|
|
180
|
+
token: string;
|
|
181
|
+
value: string;
|
|
182
|
+
}>;
|
|
183
|
+
clearAll(): void;
|
|
123
184
|
list(): SessionSummary[];
|
|
124
185
|
clear(sessionId: string): boolean;
|
|
125
186
|
get size(): number;
|
|
@@ -148,15 +209,19 @@ interface ProxyOptions {
|
|
|
148
209
|
customTerms?: readonly string[];
|
|
149
210
|
/** Restore placeholders in upstream responses. Default `true`. */
|
|
150
211
|
restoreResponses?: boolean;
|
|
212
|
+
/** Optional local JSONL file for metadata-only audit logs (counts only, never raw PII). */
|
|
213
|
+
auditLogPath?: string;
|
|
151
214
|
/** Optional safe metadata logger (never receives raw PII). */
|
|
152
215
|
onLog?: (message: string) => void;
|
|
153
216
|
}
|
|
154
217
|
interface RunningMaskeraProxy {
|
|
155
218
|
readonly url: string;
|
|
219
|
+
readonly inspectorUrl: string;
|
|
156
220
|
readonly host: string;
|
|
157
221
|
readonly port: number;
|
|
158
222
|
readonly server: Server;
|
|
159
223
|
readonly vault: SessionVault;
|
|
224
|
+
readonly inspector: ProxyInspector;
|
|
160
225
|
close(): Promise<void>;
|
|
161
226
|
}
|
|
162
227
|
/**
|
|
@@ -181,17 +246,22 @@ declare class StreamingRestorer {
|
|
|
181
246
|
flush(): string;
|
|
182
247
|
private drain;
|
|
183
248
|
}
|
|
249
|
+
type RedactFieldKind = "message" | "system" | "tool_description";
|
|
184
250
|
/**
|
|
185
251
|
* Redacts all user/tool/system text fields in an Anthropic Messages, OpenAI
|
|
186
252
|
* Chat Completions, or OpenAI Responses request body before it leaves the
|
|
187
253
|
* local machine.
|
|
188
254
|
*/
|
|
189
|
-
declare function redactLlmRequestBody(body: Record<string, unknown>, redactString: (text: string) => Promise<string
|
|
255
|
+
declare function redactLlmRequestBody(body: Record<string, unknown>, redactString: (text: string, kind: RedactFieldKind) => Promise<string>, options?: {
|
|
256
|
+
mutate?: boolean;
|
|
257
|
+
}): Promise<Record<string, unknown>>;
|
|
190
258
|
/**
|
|
191
259
|
* Restores Maskera placeholders in a non-streaming Anthropic or OpenAI JSON
|
|
192
260
|
* response without touching IDs, model names, or usage metadata.
|
|
193
261
|
*/
|
|
194
|
-
declare function restoreLlmResponseBody(body: unknown, map: Readonly<Record<string, string
|
|
262
|
+
declare function restoreLlmResponseBody(body: unknown, map: Readonly<Record<string, string>>, options?: {
|
|
263
|
+
mutate?: boolean;
|
|
264
|
+
}): unknown;
|
|
195
265
|
/**
|
|
196
266
|
* Transforms an SSE (`text/event-stream`) stream from Anthropic or OpenAI,
|
|
197
267
|
* incrementally restoring Maskera placeholders even when split across chunks.
|
|
@@ -211,7 +281,7 @@ declare function createSseRestorer(map: Readonly<Record<string, string>>): {
|
|
|
211
281
|
declare function startMaskeraProxy(options?: ProxyOptions): Promise<RunningMaskeraProxy>;
|
|
212
282
|
|
|
213
283
|
declare const SERVER_NAME = "maskera-mcp";
|
|
214
|
-
declare const SERVER_VERSION = "0.
|
|
284
|
+
declare const SERVER_VERSION = "0.2.0";
|
|
215
285
|
interface JsonRpcResponse {
|
|
216
286
|
jsonrpc: "2.0";
|
|
217
287
|
id: string | number | null;
|
|
@@ -227,6 +297,8 @@ interface MaskeraMcpOptions {
|
|
|
227
297
|
vault?: SessionVault;
|
|
228
298
|
files?: FileGuard;
|
|
229
299
|
allowedRoots?: readonly string[];
|
|
300
|
+
defaultProfile?: RedactionProfile;
|
|
301
|
+
defaultCustomTerms?: readonly string[];
|
|
230
302
|
}
|
|
231
303
|
interface MaskeraMcpServer {
|
|
232
304
|
handleMessage(raw: unknown): Promise<JsonRpcResponse | null>;
|
|
@@ -234,4 +306,4 @@ interface MaskeraMcpServer {
|
|
|
234
306
|
}
|
|
235
307
|
declare function createMaskeraMcpServer(options?: MaskeraMcpOptions): MaskeraMcpServer;
|
|
236
308
|
|
|
237
|
-
export { type EngineOptions, type FileGuard, type GuardResult, type JsonRpcResponse, type MaskMode, type MaskeraEngine, type MaskeraMcpOptions, type MaskeraMcpServer, type ProxyOptions, type RedactInputOptions, type RunningMaskeraProxy, SERVER_NAME, SERVER_VERSION, type SessionSummary, SessionVault, StreamingRestorer, buildCustomTermsDetector, createFileGuard, createMaskeraEngine, createMaskeraMcpServer, createSseRestorer, extractGuardText, redactLlmRequestBody, restoreLlmResponseBody, runGuard, startMaskeraProxy };
|
|
309
|
+
export { type EngineOptions, type FileGuard, type GuardResult, type InspectedRequest, type JsonRpcResponse, type MaskMode, type MaskeraEngine, type MaskeraMcpOptions, type MaskeraMcpServer, ProxyInspector, type ProxyOptions, type RedactFieldKind, type RedactInputOptions, type RunningMaskeraProxy, SERVER_NAME, SERVER_VERSION, type SessionSummary, SessionVault, StreamingRestorer, buildCustomTermsDetector, createFileGuard, createMaskeraEngine, createMaskeraMcpServer, createSseRestorer, extractGuardText, redactLlmRequestBody, renderInspectorHtml, restoreLlmResponseBody, runGuard, startMaskeraProxy };
|