@maskera/mcp 0.4.7 → 0.5.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/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { NerRecognizer, NerOptions, RedactionProfile, RedactResult, Detector } from 'maskera';
1
+ import { NerRecognizer, NerOptions, RedactionProfile, RedactResult, Detector, Redaction } from 'maskera';
2
+ import { FileFormat, RedactedFileResult } from '@maskera/files';
2
3
  import { ServerResponse, Server, IncomingMessage } from 'node:http';
3
4
 
4
5
  type ApprovalMode = "automatic" | "browser" | "native";
5
- type ApprovalStatus = "pending" | "approved" | "declined" | "expired" | "completed";
6
+ type ApprovalStatus = "pending" | "approved" | "executing" | "declined" | "expired" | "completed" | "failed";
6
7
  interface ApprovalSummary {
7
8
  id: string;
8
9
  tool: string;
@@ -13,13 +14,18 @@ interface ApprovalSummary {
13
14
  createdAt: string;
14
15
  expiresAt: string;
15
16
  decidedAt: string | null;
17
+ error?: string;
16
18
  }
17
19
  type ApprovalResumeResult = {
18
20
  status: "completed";
19
21
  result: Record<string, unknown>;
20
22
  summary: ApprovalSummary;
21
23
  } | {
22
- status: "pending" | "declined" | "expired" | "not_found";
24
+ status: "failed";
25
+ error: string;
26
+ summary: ApprovalSummary;
27
+ } | {
28
+ status: "pending" | "executing" | "declined" | "expired" | "already_completed" | "not_found";
23
29
  summary?: ApprovalSummary;
24
30
  };
25
31
  /**
@@ -51,6 +57,7 @@ declare class ApprovalBroker {
51
57
  }
52
58
 
53
59
  type MaskMode = "auto" | "rules";
60
+ type NerPhase = "idle" | "loading" | "ready" | "failed";
54
61
  interface ModelLoadEvent {
55
62
  phase: "loading" | "ready" | "error";
56
63
  model: string;
@@ -98,6 +105,7 @@ interface MaskeraEngine {
98
105
  defaultMode: MaskMode;
99
106
  model: string;
100
107
  revision: string;
108
+ nerPhase: NerPhase;
101
109
  nerLoaded: boolean;
102
110
  nerError: string | null;
103
111
  cacheSize: number;
@@ -173,6 +181,17 @@ interface SearchMatch {
173
181
  line: number;
174
182
  lineText: string;
175
183
  }
184
+ interface ReadDocumentResult {
185
+ resolvedPath: string;
186
+ content: string;
187
+ bytes: number;
188
+ format: FileFormat;
189
+ mimeType: string;
190
+ metadataFields: string[];
191
+ warnings: string[];
192
+ scannedPages: number[];
193
+ totalPages?: number;
194
+ }
176
195
  interface FileGuard {
177
196
  readonly allowedRoots: readonly string[];
178
197
  readText(filePath: string): Promise<{
@@ -180,12 +199,26 @@ interface FileGuard {
180
199
  content: string;
181
200
  bytes: number;
182
201
  }>;
202
+ readDocument(filePath: string): Promise<ReadDocumentResult>;
203
+ readBytes(filePath: string, options?: {
204
+ maxBytes?: number;
205
+ }): Promise<{
206
+ resolvedPath: string;
207
+ bytes: Uint8Array;
208
+ }>;
183
209
  writeText(filePath: string, content: string, options?: {
184
210
  overwrite?: boolean;
185
211
  }): Promise<{
186
212
  resolvedPath: string;
187
213
  bytes: number;
188
214
  }>;
215
+ writeBytes(filePath: string, bytes: Uint8Array, options?: {
216
+ overwrite?: boolean;
217
+ maxBytes?: number;
218
+ }): Promise<{
219
+ resolvedPath: string;
220
+ bytes: number;
221
+ }>;
189
222
  listFiles(dirPath?: string, options?: {
190
223
  maxEntries?: number;
191
224
  maxDepth?: number;
@@ -387,6 +420,7 @@ declare class SessionVault {
387
420
  counts: Record<string, number>;
388
421
  totalRedactions: number;
389
422
  map: Record<string, string>;
423
+ redactions: Redaction[];
390
424
  };
391
425
  restore(text: string, options: {
392
426
  sessionId?: string;
@@ -516,6 +550,10 @@ declare function isLikelyEnglishSystemPrompt(text: string): boolean;
516
550
  * consistency within the same client thread.
517
551
  */
518
552
  declare function deriveProxySessionId(headers: IncomingMessage["headers"], body?: Record<string, unknown>): string;
553
+ type ProxyDocumentRedactor = (bytes: Uint8Array, info: {
554
+ fileName?: string;
555
+ mimeType?: string;
556
+ }) => Promise<RedactedFileResult>;
519
557
  /**
520
558
  * Redacts all user/tool/system text fields in an Anthropic Messages, OpenAI
521
559
  * Chat Completions, or OpenAI Responses request body before it leaves the
@@ -524,6 +562,7 @@ declare function deriveProxySessionId(headers: IncomingMessage["headers"], body?
524
562
  declare function redactLlmRequestBody(body: Record<string, unknown>, redactString: (text: string, kind: RedactFieldKind) => Promise<string>, options?: {
525
563
  mutate?: boolean;
526
564
  onBinaryAttachment?: (kind: string) => void;
565
+ redactDocument?: ProxyDocumentRedactor;
527
566
  }): Promise<Record<string, unknown>>;
528
567
  /**
529
568
  * Restores Maskera placeholders in a non-streaming Anthropic or OpenAI JSON
@@ -604,8 +643,18 @@ interface MaskeraMcpOptions extends MaskeraMcpPolicy {
604
643
  requestElicitation?: (req: ElicitationRequest) => Promise<ElicitationResponse>;
605
644
  onToolCall?: (event: ToolCallTelemetry) => void;
606
645
  }
646
+ type ClientHandshakeState = {
647
+ status: "uninitialized";
648
+ } | {
649
+ status: "initialized";
650
+ protocolVersion: string;
651
+ supportsElicitation: boolean;
652
+ };
607
653
  interface MaskeraMcpServer {
608
654
  handleMessage(raw: unknown, policyOverride?: MaskeraMcpPolicy): Promise<JsonRpcResponse | null>;
655
+ getClientState(owner?: string): ClientHandshakeState;
656
+ clearOwner(owner: string): void;
657
+ clearAllOwners(): void;
609
658
  readonly vault: SessionVault;
610
659
  }
611
660
  declare function createMaskeraMcpServer(options?: MaskeraMcpOptions): MaskeraMcpServer;
@@ -690,6 +739,29 @@ declare function renderMaskeraPrompt(name: string, args: Record<string, unknown>
690
739
  }>;
691
740
  } | null;
692
741
 
742
+ type StdioTransportPhase = "open" | "closed";
743
+ interface StdioMcpTransportOptions {
744
+ writeStdout: (line: string) => void;
745
+ writeStderr: (line: string) => void;
746
+ }
747
+ interface StdioMcpTransport {
748
+ readonly phase: StdioTransportPhase;
749
+ requestElicitation(req: ElicitationRequest): Promise<ElicitationResponse>;
750
+ handleLine(line: string, handleMessage: (raw: unknown) => Promise<JsonRpcResponse | null>): void;
751
+ close(): void;
752
+ whenIdle(): Promise<void>;
753
+ }
754
+ /**
755
+ * Explicit open/closed state machine for stdio JSON-RPC framing with
756
+ * bidirectional server-initiated `elicitation/create` requests.
757
+ *
758
+ * Responses to server-initiated elicitations resolve outside the sequential
759
+ * request chain so in-flight tool calls never deadlock, and closing stdin
760
+ * cancels both pending and any subsequent elicitation requests immediately
761
+ * instead of hanging the process.
762
+ */
763
+ declare function createStdioMcpTransport(options: StdioMcpTransportOptions): StdioMcpTransport;
764
+
693
765
  interface WrapOptions {
694
766
  command: string;
695
767
  args: readonly string[];
@@ -747,4 +819,4 @@ declare function openUrlInBrowser(url: string, platform?: NodeJS.Platform): bool
747
819
  */
748
820
  declare function runWrap(options: WrapOptions): Promise<WrapResult>;
749
821
 
750
- 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, deriveProxySessionId, detectInstalledClients, extractGuardText, formatDoctorReport, isInstallClient, isLikelyEnglishSystemPrompt, normalizeMixedScriptHomoglyphs, openUrlInBrowser, redactLlmRequestBody, renderInspectorHtml, renderLaunchdPlist, renderMaskeraPrompt, renderSystemdUnit, restoreLlmResponseBody, runDoctor, runGuard, runGuardViaWarmProxy, runInstall, runService, runWrap, startMaskeraProxy, writeDoctorReceipt };
822
+ export { ApprovalBroker, type ApprovalMode, type ApprovalResumeResult, type ApprovalStatus, type ApprovalSummary, type ClientHandshakeState, 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, type NerPhase, 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, type StdioMcpTransport, type StdioMcpTransportOptions, type StdioTransportPhase, StreamingRestorer, type ToolCallTelemetry, type WrapOptions, type WrapReceipt, type WrapResult, buildCustomTermsDetector, createFileGuard, createMaskeraEngine, createMaskeraMcpServer, createModelProgressLogger, createSseRestorer, createStdioMcpTransport, deriveProxySessionId, detectInstalledClients, extractGuardText, formatDoctorReport, isInstallClient, isLikelyEnglishSystemPrompt, normalizeMixedScriptHomoglyphs, openUrlInBrowser, redactLlmRequestBody, renderInspectorHtml, renderLaunchdPlist, renderMaskeraPrompt, renderSystemdUnit, restoreLlmResponseBody, runDoctor, runGuard, runGuardViaWarmProxy, runInstall, runService, runWrap, startMaskeraProxy, writeDoctorReceipt };