protect-mcp 0.3.0 → 0.3.2

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.mts CHANGED
@@ -21,6 +21,8 @@ interface ToolPolicy {
21
21
  rate_limit?: string;
22
22
  /** Explicitly block this tool */
23
23
  block?: boolean;
24
+ /** Require human approval before executing (non-blocking: returns MCP error for LLM to suspend) */
25
+ require_approval?: boolean;
24
26
  /** Minimum trust tier required for this tool (v2) */
25
27
  min_tier?: TrustTier;
26
28
  /** Tier-specific rate limits (v2) */
@@ -113,7 +115,7 @@ interface DecisionLog {
113
115
  /** Tool name that was called */
114
116
  tool: string;
115
117
  /** Decision: allow or deny */
116
- decision: 'allow' | 'deny';
118
+ decision: 'allow' | 'deny' | 'require_approval';
117
119
  /** Why this decision was made */
118
120
  reason_code: string;
119
121
  /** SHA-256 digest of the canonicalized policy file */
@@ -152,6 +154,27 @@ interface ProtectConfig {
152
154
  signing?: SigningConfig;
153
155
  /** Credential vault: maps credential labels to injection config */
154
156
  credentials?: Record<string, CredentialConfig>;
157
+ /** Multi-agent mode: identify calling agents and apply per-agent policy */
158
+ multiAgent?: MultiAgentConfig;
159
+ }
160
+ /**
161
+ * Multi-agent mode configuration.
162
+ *
163
+ * When enabled, protect-mcp resolves the calling agent's passport kid
164
+ * from request metadata (x-passport-kid header or _passport_kid param)
165
+ * and applies agent-specific policy overrides.
166
+ */
167
+ interface MultiAgentConfig {
168
+ /** Enable multi-agent mode */
169
+ enabled: boolean;
170
+ /** Registry endpoint for agent manifest lookup */
171
+ registryUrl?: string;
172
+ /** Per-agent policy overrides: maps kid → tool policy overrides */
173
+ agentPolicies?: Record<string, Record<string, ToolPolicy>>;
174
+ /** Default policy for unrecognized agents (default: use base policy) */
175
+ unknownAgentPolicy?: 'base' | 'deny' | 'shadow-only';
176
+ /** Cache TTL for agent manifests in ms (default: 300000 = 5 min) */
177
+ cacheTtlMs?: number;
155
178
  }
156
179
 
157
180
  /**
@@ -284,8 +307,13 @@ declare class ProtectGateway {
284
307
  private rateLimitStore;
285
308
  private clientReader;
286
309
  private logFilePath;
310
+ private receiptFilePath;
287
311
  private evidenceStore;
288
312
  private receiptBuffer;
313
+ /** Approval grants keyed by request_id (scoped to the specific action that was requested) */
314
+ private approvalStore;
315
+ /** Random nonce generated at startup — required for approval endpoint authentication */
316
+ private readonly approvalNonce;
289
317
  private currentTier;
290
318
  private admissionResult;
291
319
  constructor(config: ProtectConfig);
@@ -563,6 +591,132 @@ declare function createAuditBundle(opts: AuditBundleOptions): AuditBundle;
563
591
  */
564
592
  declare function collectSignedReceipts(logs: DecisionLog[]): Record<string, unknown>[];
565
593
 
594
+ /**
595
+ * protect-mcp simulate — dry-run policy evaluation
596
+ *
597
+ * Reads a recorded log file (.protect-mcp-log.jsonl) and evaluates
598
+ * each tool call against a policy file. Shows what would have been
599
+ * blocked, rate-limited, or approved — without wrapping a live server.
600
+ *
601
+ * Usage:
602
+ * npx protect-mcp simulate --policy strict.json [--log .protect-mcp-log.jsonl] [--json]
603
+ */
604
+
605
+ interface LogEntry {
606
+ v: number;
607
+ tool: string;
608
+ decision: string;
609
+ reason_code: string;
610
+ mode: string;
611
+ timestamp: number;
612
+ tier?: string;
613
+ rate_limit_remaining?: number;
614
+ [key: string]: unknown;
615
+ }
616
+ interface SimulationResult {
617
+ tool: string;
618
+ calls: number;
619
+ results: {
620
+ allow: number;
621
+ block: number;
622
+ rate_limited: number;
623
+ require_approval: number;
624
+ tier_insufficient: number;
625
+ };
626
+ original: {
627
+ allow: number;
628
+ deny: number;
629
+ };
630
+ }
631
+ interface SimulationSummary {
632
+ policy_file: string;
633
+ log_file: string;
634
+ total_calls: number;
635
+ results: {
636
+ allow: number;
637
+ block: number;
638
+ rate_limited: number;
639
+ require_approval: number;
640
+ tier_insufficient: number;
641
+ };
642
+ original: {
643
+ allow: number;
644
+ deny: number;
645
+ };
646
+ tool_breakdown: SimulationResult[];
647
+ changes: string[];
648
+ }
649
+ /**
650
+ * Parse a JSONL log file into log entries.
651
+ */
652
+ declare function parseLogFile(path: string): LogEntry[];
653
+ /**
654
+ * Simulate a policy against a set of log entries.
655
+ * Evaluates each entry against the policy's per-tool rules,
656
+ * including block, rate_limit, min_tier, and require_approval.
657
+ */
658
+ declare function simulate(entries: LogEntry[], policy: ProtectPolicy, tier?: TrustTier): SimulationSummary;
659
+ /**
660
+ * Format simulation results for terminal output.
661
+ */
662
+ declare function formatSimulation(summary: SimulationSummary): string;
663
+
664
+ /**
665
+ * protect-mcp report — compliance report generation
666
+ *
667
+ * Generates structured compliance reports from local log and receipt files.
668
+ * Output as JSON (machine-readable) or Markdown (human-readable, PDF-convertible).
669
+ *
670
+ * Usage:
671
+ * npx protect-mcp report --period 30d --output report.json
672
+ * npx protect-mcp report --period 30d --format md --output report.md
673
+ */
674
+ interface ComplianceReport {
675
+ generated_at: string;
676
+ period: {
677
+ from: string;
678
+ to: string;
679
+ };
680
+ signing_identity: {
681
+ kid: string;
682
+ issuer: string;
683
+ } | null;
684
+ summary: {
685
+ total_decisions: number;
686
+ allowed: number;
687
+ blocked: number;
688
+ rate_limited: number;
689
+ approval_required: number;
690
+ unique_tools: number;
691
+ unique_tiers: number;
692
+ };
693
+ tool_breakdown: Array<{
694
+ tool: string;
695
+ total: number;
696
+ allowed: number;
697
+ blocked: number;
698
+ rate_limited: number;
699
+ approval_required: number;
700
+ }>;
701
+ policy_changes: Array<{
702
+ at: string;
703
+ policy_digest: string;
704
+ }>;
705
+ verification: {
706
+ receipts_signed: number;
707
+ receipts_unsigned: number;
708
+ verify_command: string;
709
+ };
710
+ }
711
+ /**
712
+ * Generate a compliance report from local log and receipt files.
713
+ */
714
+ declare function generateReport(logPath: string, receiptPath: string, periodDays: number): ComplianceReport;
715
+ /**
716
+ * Format a compliance report as Markdown.
717
+ */
718
+ declare function formatReportMarkdown(report: ComplianceReport): string;
719
+
566
720
  /**
567
721
  * Agent identity format: sb:agent:{first 32 hex chars of SHA-256(public key bytes)}
568
722
  * Example: "sb:agent:a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6"
@@ -844,4 +998,4 @@ declare function validateManifest(manifest: unknown): string[];
844
998
  */
845
999
  declare function validateEvidenceReceipt(receipt: unknown): string[];
846
1000
 
847
- export { type AdmissionResult, type AgentId, type AgentManifest, type ArenaPayload, type ArenaReceipt, type AttestationPayload, type AttestationReceipt, type AuditBundle, type AuditBundleOptions, type BenchmarkPayload, type BenchmarkReceipt, type BuilderId, type CredentialConfig, type DecisionContext, type DecisionLog, type DisclosureMode, type Ed25519PublicKey, type EvidenceIssuer, type EvidenceReceipt, type EvidenceReceiptBase, type EvidenceSummary, type EvidenceSummaryEntry, type EvidenceType, type ExternalDecision, type ExternalPDPConfig, type IssuerType, type JsonRpcRequest, type JsonRpcResponse, type LeaseCompatibility, type ManifestBuilder, type ManifestCapabilities, type ManifestConfig, type ManifestIdentity, type ManifestPresentation, type ManifestSignature, type ManifestStatus, type PolicyEngineMode, type ProtectConfig, ProtectGateway, type ProtectPolicy, type RateLimit, type RestraintPayload, type RestraintReceipt, type SHA256Hash, type SigningConfig, type TierOverrides, type ToolPolicy, type TrustTier, type WorkPayload, type WorkReceipt, buildDecisionContext, checkRateLimit, collectSignedReceipts, createAuditBundle, evaluateTier, getSignerInfo, getToolPolicy, initSigning, isAgentId, isDisclosureMode, isEvidenceType, isManifestStatus, isSigningEnabled, listCredentialLabels, loadPolicy, meetsMinTier, parseRateLimit, queryExternalPDP, resolveCredential, signDecision, validateCredentials, validateEvidenceReceipt, validateManifest };
1001
+ export { type AdmissionResult, type AgentId, type AgentManifest, type ArenaPayload, type ArenaReceipt, type AttestationPayload, type AttestationReceipt, type AuditBundle, type AuditBundleOptions, type BenchmarkPayload, type BenchmarkReceipt, type BuilderId, type ComplianceReport, type CredentialConfig, type DecisionContext, type DecisionLog, type DisclosureMode, type Ed25519PublicKey, type EvidenceIssuer, type EvidenceReceipt, type EvidenceReceiptBase, type EvidenceSummary, type EvidenceSummaryEntry, type EvidenceType, type ExternalDecision, type ExternalPDPConfig, type IssuerType, type JsonRpcRequest, type JsonRpcResponse, type LeaseCompatibility, type ManifestBuilder, type ManifestCapabilities, type ManifestConfig, type ManifestIdentity, type ManifestPresentation, type ManifestSignature, type ManifestStatus, type PolicyEngineMode, type ProtectConfig, ProtectGateway, type ProtectPolicy, type RateLimit, type RestraintPayload, type RestraintReceipt, type SHA256Hash, type SigningConfig, type SimulationResult, type SimulationSummary, type TierOverrides, type ToolPolicy, type TrustTier, type WorkPayload, type WorkReceipt, buildDecisionContext, checkRateLimit, collectSignedReceipts, createAuditBundle, evaluateTier, formatReportMarkdown, formatSimulation, generateReport, getSignerInfo, getToolPolicy, initSigning, isAgentId, isDisclosureMode, isEvidenceType, isManifestStatus, isSigningEnabled, listCredentialLabels, loadPolicy, meetsMinTier, parseLogFile, parseRateLimit, queryExternalPDP, resolveCredential, signDecision, simulate, validateCredentials, validateEvidenceReceipt, validateManifest };
package/dist/index.d.ts CHANGED
@@ -21,6 +21,8 @@ interface ToolPolicy {
21
21
  rate_limit?: string;
22
22
  /** Explicitly block this tool */
23
23
  block?: boolean;
24
+ /** Require human approval before executing (non-blocking: returns MCP error for LLM to suspend) */
25
+ require_approval?: boolean;
24
26
  /** Minimum trust tier required for this tool (v2) */
25
27
  min_tier?: TrustTier;
26
28
  /** Tier-specific rate limits (v2) */
@@ -113,7 +115,7 @@ interface DecisionLog {
113
115
  /** Tool name that was called */
114
116
  tool: string;
115
117
  /** Decision: allow or deny */
116
- decision: 'allow' | 'deny';
118
+ decision: 'allow' | 'deny' | 'require_approval';
117
119
  /** Why this decision was made */
118
120
  reason_code: string;
119
121
  /** SHA-256 digest of the canonicalized policy file */
@@ -152,6 +154,27 @@ interface ProtectConfig {
152
154
  signing?: SigningConfig;
153
155
  /** Credential vault: maps credential labels to injection config */
154
156
  credentials?: Record<string, CredentialConfig>;
157
+ /** Multi-agent mode: identify calling agents and apply per-agent policy */
158
+ multiAgent?: MultiAgentConfig;
159
+ }
160
+ /**
161
+ * Multi-agent mode configuration.
162
+ *
163
+ * When enabled, protect-mcp resolves the calling agent's passport kid
164
+ * from request metadata (x-passport-kid header or _passport_kid param)
165
+ * and applies agent-specific policy overrides.
166
+ */
167
+ interface MultiAgentConfig {
168
+ /** Enable multi-agent mode */
169
+ enabled: boolean;
170
+ /** Registry endpoint for agent manifest lookup */
171
+ registryUrl?: string;
172
+ /** Per-agent policy overrides: maps kid → tool policy overrides */
173
+ agentPolicies?: Record<string, Record<string, ToolPolicy>>;
174
+ /** Default policy for unrecognized agents (default: use base policy) */
175
+ unknownAgentPolicy?: 'base' | 'deny' | 'shadow-only';
176
+ /** Cache TTL for agent manifests in ms (default: 300000 = 5 min) */
177
+ cacheTtlMs?: number;
155
178
  }
156
179
 
157
180
  /**
@@ -284,8 +307,13 @@ declare class ProtectGateway {
284
307
  private rateLimitStore;
285
308
  private clientReader;
286
309
  private logFilePath;
310
+ private receiptFilePath;
287
311
  private evidenceStore;
288
312
  private receiptBuffer;
313
+ /** Approval grants keyed by request_id (scoped to the specific action that was requested) */
314
+ private approvalStore;
315
+ /** Random nonce generated at startup — required for approval endpoint authentication */
316
+ private readonly approvalNonce;
289
317
  private currentTier;
290
318
  private admissionResult;
291
319
  constructor(config: ProtectConfig);
@@ -563,6 +591,132 @@ declare function createAuditBundle(opts: AuditBundleOptions): AuditBundle;
563
591
  */
564
592
  declare function collectSignedReceipts(logs: DecisionLog[]): Record<string, unknown>[];
565
593
 
594
+ /**
595
+ * protect-mcp simulate — dry-run policy evaluation
596
+ *
597
+ * Reads a recorded log file (.protect-mcp-log.jsonl) and evaluates
598
+ * each tool call against a policy file. Shows what would have been
599
+ * blocked, rate-limited, or approved — without wrapping a live server.
600
+ *
601
+ * Usage:
602
+ * npx protect-mcp simulate --policy strict.json [--log .protect-mcp-log.jsonl] [--json]
603
+ */
604
+
605
+ interface LogEntry {
606
+ v: number;
607
+ tool: string;
608
+ decision: string;
609
+ reason_code: string;
610
+ mode: string;
611
+ timestamp: number;
612
+ tier?: string;
613
+ rate_limit_remaining?: number;
614
+ [key: string]: unknown;
615
+ }
616
+ interface SimulationResult {
617
+ tool: string;
618
+ calls: number;
619
+ results: {
620
+ allow: number;
621
+ block: number;
622
+ rate_limited: number;
623
+ require_approval: number;
624
+ tier_insufficient: number;
625
+ };
626
+ original: {
627
+ allow: number;
628
+ deny: number;
629
+ };
630
+ }
631
+ interface SimulationSummary {
632
+ policy_file: string;
633
+ log_file: string;
634
+ total_calls: number;
635
+ results: {
636
+ allow: number;
637
+ block: number;
638
+ rate_limited: number;
639
+ require_approval: number;
640
+ tier_insufficient: number;
641
+ };
642
+ original: {
643
+ allow: number;
644
+ deny: number;
645
+ };
646
+ tool_breakdown: SimulationResult[];
647
+ changes: string[];
648
+ }
649
+ /**
650
+ * Parse a JSONL log file into log entries.
651
+ */
652
+ declare function parseLogFile(path: string): LogEntry[];
653
+ /**
654
+ * Simulate a policy against a set of log entries.
655
+ * Evaluates each entry against the policy's per-tool rules,
656
+ * including block, rate_limit, min_tier, and require_approval.
657
+ */
658
+ declare function simulate(entries: LogEntry[], policy: ProtectPolicy, tier?: TrustTier): SimulationSummary;
659
+ /**
660
+ * Format simulation results for terminal output.
661
+ */
662
+ declare function formatSimulation(summary: SimulationSummary): string;
663
+
664
+ /**
665
+ * protect-mcp report — compliance report generation
666
+ *
667
+ * Generates structured compliance reports from local log and receipt files.
668
+ * Output as JSON (machine-readable) or Markdown (human-readable, PDF-convertible).
669
+ *
670
+ * Usage:
671
+ * npx protect-mcp report --period 30d --output report.json
672
+ * npx protect-mcp report --period 30d --format md --output report.md
673
+ */
674
+ interface ComplianceReport {
675
+ generated_at: string;
676
+ period: {
677
+ from: string;
678
+ to: string;
679
+ };
680
+ signing_identity: {
681
+ kid: string;
682
+ issuer: string;
683
+ } | null;
684
+ summary: {
685
+ total_decisions: number;
686
+ allowed: number;
687
+ blocked: number;
688
+ rate_limited: number;
689
+ approval_required: number;
690
+ unique_tools: number;
691
+ unique_tiers: number;
692
+ };
693
+ tool_breakdown: Array<{
694
+ tool: string;
695
+ total: number;
696
+ allowed: number;
697
+ blocked: number;
698
+ rate_limited: number;
699
+ approval_required: number;
700
+ }>;
701
+ policy_changes: Array<{
702
+ at: string;
703
+ policy_digest: string;
704
+ }>;
705
+ verification: {
706
+ receipts_signed: number;
707
+ receipts_unsigned: number;
708
+ verify_command: string;
709
+ };
710
+ }
711
+ /**
712
+ * Generate a compliance report from local log and receipt files.
713
+ */
714
+ declare function generateReport(logPath: string, receiptPath: string, periodDays: number): ComplianceReport;
715
+ /**
716
+ * Format a compliance report as Markdown.
717
+ */
718
+ declare function formatReportMarkdown(report: ComplianceReport): string;
719
+
566
720
  /**
567
721
  * Agent identity format: sb:agent:{first 32 hex chars of SHA-256(public key bytes)}
568
722
  * Example: "sb:agent:a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6"
@@ -844,4 +998,4 @@ declare function validateManifest(manifest: unknown): string[];
844
998
  */
845
999
  declare function validateEvidenceReceipt(receipt: unknown): string[];
846
1000
 
847
- export { type AdmissionResult, type AgentId, type AgentManifest, type ArenaPayload, type ArenaReceipt, type AttestationPayload, type AttestationReceipt, type AuditBundle, type AuditBundleOptions, type BenchmarkPayload, type BenchmarkReceipt, type BuilderId, type CredentialConfig, type DecisionContext, type DecisionLog, type DisclosureMode, type Ed25519PublicKey, type EvidenceIssuer, type EvidenceReceipt, type EvidenceReceiptBase, type EvidenceSummary, type EvidenceSummaryEntry, type EvidenceType, type ExternalDecision, type ExternalPDPConfig, type IssuerType, type JsonRpcRequest, type JsonRpcResponse, type LeaseCompatibility, type ManifestBuilder, type ManifestCapabilities, type ManifestConfig, type ManifestIdentity, type ManifestPresentation, type ManifestSignature, type ManifestStatus, type PolicyEngineMode, type ProtectConfig, ProtectGateway, type ProtectPolicy, type RateLimit, type RestraintPayload, type RestraintReceipt, type SHA256Hash, type SigningConfig, type TierOverrides, type ToolPolicy, type TrustTier, type WorkPayload, type WorkReceipt, buildDecisionContext, checkRateLimit, collectSignedReceipts, createAuditBundle, evaluateTier, getSignerInfo, getToolPolicy, initSigning, isAgentId, isDisclosureMode, isEvidenceType, isManifestStatus, isSigningEnabled, listCredentialLabels, loadPolicy, meetsMinTier, parseRateLimit, queryExternalPDP, resolveCredential, signDecision, validateCredentials, validateEvidenceReceipt, validateManifest };
1001
+ export { type AdmissionResult, type AgentId, type AgentManifest, type ArenaPayload, type ArenaReceipt, type AttestationPayload, type AttestationReceipt, type AuditBundle, type AuditBundleOptions, type BenchmarkPayload, type BenchmarkReceipt, type BuilderId, type ComplianceReport, type CredentialConfig, type DecisionContext, type DecisionLog, type DisclosureMode, type Ed25519PublicKey, type EvidenceIssuer, type EvidenceReceipt, type EvidenceReceiptBase, type EvidenceSummary, type EvidenceSummaryEntry, type EvidenceType, type ExternalDecision, type ExternalPDPConfig, type IssuerType, type JsonRpcRequest, type JsonRpcResponse, type LeaseCompatibility, type ManifestBuilder, type ManifestCapabilities, type ManifestConfig, type ManifestIdentity, type ManifestPresentation, type ManifestSignature, type ManifestStatus, type PolicyEngineMode, type ProtectConfig, ProtectGateway, type ProtectPolicy, type RateLimit, type RestraintPayload, type RestraintReceipt, type SHA256Hash, type SigningConfig, type SimulationResult, type SimulationSummary, type TierOverrides, type ToolPolicy, type TrustTier, type WorkPayload, type WorkReceipt, buildDecisionContext, checkRateLimit, collectSignedReceipts, createAuditBundle, evaluateTier, formatReportMarkdown, formatSimulation, generateReport, getSignerInfo, getToolPolicy, initSigning, isAgentId, isDisclosureMode, isEvidenceType, isManifestStatus, isSigningEnabled, listCredentialLabels, loadPolicy, meetsMinTier, parseLogFile, parseRateLimit, queryExternalPDP, resolveCredential, signDecision, simulate, validateCredentials, validateEvidenceReceipt, validateManifest };