contextguard 0.1.8 → 0.2.1

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.
Files changed (60) hide show
  1. package/LICENSE +23 -17
  2. package/README.md +157 -109
  3. package/dist/agent.d.ts +24 -0
  4. package/dist/agent.js +376 -0
  5. package/dist/cli.d.ts +11 -0
  6. package/dist/cli.js +298 -0
  7. package/dist/config.d.ts +23 -0
  8. package/dist/config.js +56 -0
  9. package/dist/database.d.ts +116 -0
  10. package/dist/database.js +291 -0
  11. package/dist/index.d.ts +16 -0
  12. package/dist/index.js +18 -0
  13. package/dist/init.d.ts +7 -0
  14. package/dist/init.js +178 -0
  15. package/dist/lib/supabase-client.d.ts +27 -0
  16. package/dist/lib/supabase-client.js +97 -0
  17. package/dist/logger.d.ts +36 -0
  18. package/dist/logger.js +145 -0
  19. package/dist/mcp-security-wrapper.d.ts +84 -0
  20. package/dist/mcp-security-wrapper.js +389 -147
  21. package/dist/mcp-traceability-integration.d.ts +118 -0
  22. package/dist/mcp-traceability-integration.js +302 -0
  23. package/dist/policy.d.ts +30 -0
  24. package/dist/policy.js +273 -0
  25. package/dist/premium-features.d.ts +364 -0
  26. package/dist/premium-features.js +950 -0
  27. package/dist/security-logger.d.ts +45 -0
  28. package/dist/security-logger.js +125 -0
  29. package/dist/security-policy.d.ts +55 -0
  30. package/dist/security-policy.js +140 -0
  31. package/dist/semantic-detector.d.ts +21 -0
  32. package/dist/semantic-detector.js +49 -0
  33. package/dist/sse-proxy.d.ts +21 -0
  34. package/dist/sse-proxy.js +276 -0
  35. package/dist/supabase-client.d.ts +27 -0
  36. package/dist/supabase-client.js +89 -0
  37. package/dist/types/database.types.d.ts +220 -0
  38. package/dist/types/database.types.js +8 -0
  39. package/dist/types/mcp.d.ts +27 -0
  40. package/dist/types/mcp.js +15 -0
  41. package/dist/types/types.d.ts +65 -0
  42. package/dist/types/types.js +8 -0
  43. package/dist/types.d.ts +84 -0
  44. package/dist/types.js +8 -0
  45. package/dist/wrapper.d.ts +115 -0
  46. package/dist/wrapper.js +417 -0
  47. package/package.json +35 -11
  48. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -57
  49. package/CONTRIBUTING.md +0 -532
  50. package/SECURITY.md +0 -254
  51. package/assets/demo.mp4 +0 -0
  52. package/eslint.config.mts +0 -23
  53. package/examples/config/config.json +0 -19
  54. package/examples/mcp-server/demo.js +0 -228
  55. package/examples/mcp-server/package-lock.json +0 -978
  56. package/examples/mcp-server/package.json +0 -16
  57. package/examples/mcp-server/pnpm-lock.yaml +0 -745
  58. package/src/mcp-security-wrapper.ts +0 -570
  59. package/test/test-server.ts +0 -295
  60. package/tsconfig.json +0 -16
package/dist/policy.js ADDED
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 Amir Mironi
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DEFAULT_POLICY = exports.createPolicyChecker = void 0;
10
+ /**
11
+ * Initialize patterns for detecting sensitive data
12
+ */
13
+ const initSensitiveDataPatterns = () => [
14
+ // Generic secrets
15
+ /(?:password|secret|api[_-]?key|token)\s*[:=]\s*['"]?[\w\-.]+['"]?/gi,
16
+ // Email addresses
17
+ /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
18
+ // Social Security Numbers
19
+ /\b\d{3}-\d{2}-\d{4}\b/g,
20
+ // OpenAI API keys
21
+ /sk-[a-zA-Z0-9]{20,}/g,
22
+ // GitHub tokens
23
+ /ghp_[a-zA-Z0-9]{36}/g,
24
+ // AWS Access Keys
25
+ /AKIA[0-9A-Z]{16}/g,
26
+ // Stripe API keys
27
+ /sk_(live|test)_[a-zA-Z0-9]{24,}/g,
28
+ ];
29
+ /**
30
+ * Initialize patterns for detecting SQL injection
31
+ */
32
+ const initSQLInjectionPatterns = () => [
33
+ /\bUNION\b.{0,50}\bSELECT\b/gi,
34
+ /\bDROP\b\s+\b(TABLE|DATABASE|SCHEMA)\b/gi,
35
+ /\bDELETE\b\s+\bFROM\b/gi,
36
+ /\bTRUNCATE\b\s+\bTABLE\b/gi,
37
+ /\bINSERT\b\s+\bINTO\b.{0,50}\bVALUES\b/gi,
38
+ /\bEXEC\s*\(|\bEXECUTE\s*\(/gi,
39
+ /--\s*$|\/\*[\s\S]*?\*\//gm,
40
+ /\bOR\b\s+['"]?\d+['"]?\s*=\s*['"]?\d+['"]?/gi,
41
+ /'\s*OR\s*'1'\s*=\s*'1/gi,
42
+ /;\s*(DROP|DELETE|INSERT|UPDATE|CREATE|ALTER)\b/gi,
43
+ ];
44
+ /**
45
+ * Initialize patterns for detecting XSS attacks
46
+ */
47
+ const initXSSPatterns = () => [
48
+ /<script[\s>]/gi,
49
+ /javascript:/gi,
50
+ /on\w+\s*=\s*["']?[^"'>]*/gi, // onerror=, onload=, onclick=, etc.
51
+ /<iframe[\s>]/gi,
52
+ /<object[\s>]/gi,
53
+ /<embed[\s>]/gi,
54
+ /eval\s*\(/gi,
55
+ /document\.(cookie|write|location)/gi,
56
+ /window\.(location|open)\s*[=(]/gi,
57
+ /<img[^>]+src\s*=\s*["']?javascript:/gi,
58
+ ];
59
+ /**
60
+ * Initialize patterns for detecting prompt injection
61
+ */
62
+ const initPromptInjectionPatterns = () => [
63
+ /ignore\s+(previous|all)\s+(instructions|prompts)/gi,
64
+ /system:\s*you\s+are\s+now/gi,
65
+ /forget\s+(everything|all)/gi,
66
+ /new\s+instructions:/gi,
67
+ /\[INST\].*?\[\/INST\]/gs,
68
+ /<\|im_start\|>/g,
69
+ /disregard\s+previous/gi,
70
+ /override\s+previous/gi,
71
+ ];
72
+ /**
73
+ * Create a policy checker with the given configuration
74
+ * @param config - Policy configuration
75
+ * @returns Policy checker functions
76
+ */
77
+ const createPolicyChecker = (config) => {
78
+ const sensitiveDataPatterns = initSensitiveDataPatterns();
79
+ const promptInjectionPatterns = initPromptInjectionPatterns();
80
+ const sqlInjectionPatterns = initSQLInjectionPatterns();
81
+ const xssPatterns = initXSSPatterns();
82
+ return {
83
+ /**
84
+ * Check text for prompt injection attempts
85
+ */
86
+ checkPromptInjection: (text) => {
87
+ if (!config.enablePromptInjectionDetection) {
88
+ return [];
89
+ }
90
+ const violations = [];
91
+ for (const pattern of promptInjectionPatterns) {
92
+ const matches = text.match(pattern);
93
+ if (matches) {
94
+ violations.push(`Potential prompt injection detected: "${matches[0].substring(0, 50)}..."`);
95
+ }
96
+ }
97
+ return violations;
98
+ },
99
+ /**
100
+ * Check text for sensitive data exposure
101
+ */
102
+ checkSensitiveData: (text) => {
103
+ if (!config.enableSensitiveDataDetection) {
104
+ return [];
105
+ }
106
+ const violations = [];
107
+ for (const pattern of sensitiveDataPatterns) {
108
+ const matches = text.match(pattern);
109
+ if (matches) {
110
+ violations.push(`Sensitive data pattern detected (redacted): ${pattern.source.substring(0, 30)}...`);
111
+ }
112
+ }
113
+ return violations;
114
+ },
115
+ /**
116
+ * Check file path for security violations
117
+ */
118
+ checkFileAccess: (filePath) => {
119
+ if (!config.enablePathTraversalPrevention) {
120
+ return [];
121
+ }
122
+ const violations = [];
123
+ // Check for path traversal
124
+ if (filePath.includes("..")) {
125
+ violations.push(`Path traversal attempt detected: ${filePath}`);
126
+ }
127
+ // Check for dangerous system paths
128
+ const dangerousPaths = [
129
+ "/etc",
130
+ "/root",
131
+ "/sys",
132
+ "/proc",
133
+ "C:\\Windows\\System32",
134
+ ];
135
+ if (dangerousPaths.some((dangerous) => filePath.startsWith(dangerous))) {
136
+ violations.push(`Access to dangerous path detected: ${filePath}`);
137
+ }
138
+ // Check against allowed paths whitelist
139
+ if (config.allowedFilePaths.length > 0) {
140
+ const isAllowed = config.allowedFilePaths.some((allowed) => filePath.startsWith(allowed));
141
+ if (!isAllowed) {
142
+ violations.push(`File path not in allowed list: ${filePath}`);
143
+ }
144
+ }
145
+ return violations;
146
+ },
147
+ /**
148
+ * Check if rate limit is exceeded
149
+ */
150
+ checkRateLimit: (timestamps) => {
151
+ const oneMinuteAgo = Date.now() - 60000;
152
+ const recentCalls = timestamps.filter((t) => t > oneMinuteAgo);
153
+ return recentCalls.length < config.maxToolCallsPerMinute;
154
+ },
155
+ /**
156
+ * Check text against blocked patterns
157
+ */
158
+ checkBlockedPatterns: (text) => {
159
+ const violations = [];
160
+ for (const pattern of config.blockedPatterns) {
161
+ if (text.toLowerCase().includes(pattern.toLowerCase())) {
162
+ violations.push(`Blocked pattern detected: "${pattern}"`);
163
+ }
164
+ }
165
+ return violations;
166
+ },
167
+ /**
168
+ * Check if a tool is allowed or blocked
169
+ */
170
+ checkToolAccess: (toolName) => {
171
+ const violations = [];
172
+ if (config.blockedTools.includes(toolName)) {
173
+ violations.push(`Tool "${toolName}" is explicitly blocked`);
174
+ }
175
+ else if (config.allowedTools.length > 0 &&
176
+ !config.allowedTools.includes(toolName)) {
177
+ violations.push(`Tool "${toolName}" is not in the allowed list: [${config.allowedTools.join(", ")}]`);
178
+ }
179
+ return violations;
180
+ },
181
+ /**
182
+ * Check text for SQL injection attempts
183
+ */
184
+ checkSQLInjection: (text) => {
185
+ if (!config.enableSQLInjectionDetection) {
186
+ return [];
187
+ }
188
+ const violations = [];
189
+ for (const pattern of sqlInjectionPatterns) {
190
+ if (pattern.test(text)) {
191
+ violations.push(`SQL injection pattern detected: ${pattern.source.substring(0, 40)}...`);
192
+ pattern.lastIndex = 0; // reset stateful regex
193
+ }
194
+ }
195
+ return violations;
196
+ },
197
+ /**
198
+ * Check text for XSS attack patterns
199
+ */
200
+ checkXSS: (text) => {
201
+ if (!config.enableXSSDetection) {
202
+ return [];
203
+ }
204
+ const violations = [];
205
+ for (const pattern of xssPatterns) {
206
+ if (pattern.test(text)) {
207
+ violations.push(`XSS pattern detected: ${pattern.source.substring(0, 40)}...`);
208
+ pattern.lastIndex = 0; // reset stateful regex
209
+ }
210
+ }
211
+ return violations;
212
+ },
213
+ /**
214
+ * Check text against custom user-defined rules
215
+ */
216
+ checkCustomRules: (text) => {
217
+ const violations = [];
218
+ for (const rule of config.customRules) {
219
+ try {
220
+ const regex = new RegExp(rule.pattern, "gi");
221
+ if (regex.test(text)) {
222
+ violations.push(`Custom rule "${rule.name}" triggered`);
223
+ }
224
+ }
225
+ catch {
226
+ // Invalid regex pattern — skip silently
227
+ }
228
+ }
229
+ return violations;
230
+ },
231
+ /**
232
+ * Check if blocking mode is enabled
233
+ */
234
+ isBlockingMode: () => {
235
+ return config.mode === "block";
236
+ },
237
+ /**
238
+ * Get the full configuration
239
+ */
240
+ getConfig: () => {
241
+ return config;
242
+ },
243
+ };
244
+ };
245
+ exports.createPolicyChecker = createPolicyChecker;
246
+ exports.DEFAULT_POLICY = {
247
+ id: "",
248
+ agent_id: "",
249
+ created_at: "",
250
+ updated_at: "",
251
+ maxToolCallsPerMinute: 30,
252
+ blockedPatterns: [],
253
+ allowedFilePaths: [],
254
+ alertThreshold: 5,
255
+ enablePromptInjectionDetection: true,
256
+ enableSensitiveDataDetection: true,
257
+ enablePathTraversalPrevention: true,
258
+ enableSQLInjectionDetection: true,
259
+ enableSemanticDetection: false,
260
+ enableXSSDetection: true,
261
+ customRules: [],
262
+ mode: "monitor",
263
+ logPath: "mcp_security.log",
264
+ enableProFeatures: false,
265
+ licenseFilePath: ".contextguard-license",
266
+ transport: "stdio",
267
+ port: 3100,
268
+ targetUrl: "",
269
+ allowedTools: [],
270
+ blockedTools: [],
271
+ alertWebhook: "",
272
+ alertOnSeverity: ["HIGH", "CRITICAL"],
273
+ };
@@ -0,0 +1,364 @@
1
+ /**
2
+ * Copyright (c) 2025 Amir Mironi
3
+ *
4
+ * Premium/Enterprise Features for ContextGuard
5
+ * These features require a valid license key
6
+ */
7
+ export declare enum LicenseTier {
8
+ FREE = "free",
9
+ PRO = "pro",
10
+ ENTERPRISE = "enterprise"
11
+ }
12
+ export interface LicenseInfo {
13
+ tier: LicenseTier;
14
+ key: string;
15
+ expiresAt: Date;
16
+ features: string[];
17
+ organizationId?: string;
18
+ maxUsers?: number;
19
+ }
20
+ export interface AnalyticsData {
21
+ timestamp: Date;
22
+ eventType: string;
23
+ severity: string;
24
+ metadata: Record<string, unknown>;
25
+ }
26
+ export interface ComplianceReport {
27
+ reportId: string;
28
+ generatedAt: Date;
29
+ standard: "SOC2" | "GDPR" | "HIPAA";
30
+ findings: ComplianceFinding[];
31
+ status: "PASS" | "FAIL" | "WARNING";
32
+ }
33
+ export interface ComplianceFinding {
34
+ control: string;
35
+ status: "PASS" | "FAIL" | "WARNING";
36
+ details: string;
37
+ remediation?: string;
38
+ }
39
+ export interface CustomRule {
40
+ id: string;
41
+ name: string;
42
+ description: string;
43
+ pattern: RegExp;
44
+ severity: "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
45
+ action: "LOG" | "BLOCK";
46
+ enabled: boolean;
47
+ }
48
+ export interface TeamMember {
49
+ userId: string;
50
+ email: string;
51
+ role: "ADMIN" | "MEMBER" | "VIEWER";
52
+ permissions: string[];
53
+ }
54
+ /**
55
+ * License Manager - Validates and manages license keys
56
+ */
57
+ export declare class LicenseManager {
58
+ private licenseInfo;
59
+ private licenseFilePath;
60
+ constructor(licenseFilePath?: string);
61
+ private loadLicense;
62
+ validateLicense(): boolean;
63
+ getTier(): LicenseTier;
64
+ hasFeature(feature: string): boolean;
65
+ getLicenseInfo(): LicenseInfo | null;
66
+ }
67
+ /**
68
+ * Web Dashboard Analytics - Collects and aggregates security metrics
69
+ * PRO FEATURE
70
+ */
71
+ export declare class DashboardAnalytics {
72
+ private licenseManager;
73
+ private analyticsData;
74
+ private readonly maxStoredEvents;
75
+ constructor(licenseManager: LicenseManager);
76
+ trackEvent(eventType: string, severity: string, metadata: Record<string, unknown>): void;
77
+ getMetrics(timeRange: "1h" | "24h" | "7d" | "30d"): Record<string, unknown>;
78
+ private groupBy;
79
+ private getTimeline;
80
+ }
81
+ /**
82
+ * Team Collaboration Manager
83
+ * PRO FEATURE
84
+ */
85
+ export declare class TeamCollaboration {
86
+ private licenseManager;
87
+ private teamMembers;
88
+ constructor(licenseManager: LicenseManager);
89
+ addMember(member: TeamMember): boolean;
90
+ removeMember(userId: string): boolean;
91
+ getMember(userId: string): TeamMember | undefined;
92
+ listMembers(): TeamMember[];
93
+ hasPermission(userId: string, permission: string): boolean;
94
+ }
95
+ /**
96
+ * Custom Detection Rules Engine
97
+ * PRO FEATURE
98
+ */
99
+ export declare class CustomRulesEngine {
100
+ private licenseManager;
101
+ private rules;
102
+ constructor(licenseManager: LicenseManager);
103
+ addRule(rule: CustomRule): boolean;
104
+ removeRule(ruleId: string): boolean;
105
+ evaluateRules(text: string): Array<{
106
+ rule: CustomRule;
107
+ matches: string[];
108
+ }>;
109
+ listRules(): CustomRule[];
110
+ }
111
+ /**
112
+ * SSO/SAML Authentication Provider
113
+ * ENTERPRISE FEATURE
114
+ */
115
+ export declare class SSOProvider {
116
+ private licenseManager;
117
+ private samlConfig;
118
+ constructor(licenseManager: LicenseManager);
119
+ configureSAML(config: Record<string, unknown>): boolean;
120
+ validateSAMLToken(token: string): {
121
+ valid: boolean;
122
+ userId?: string;
123
+ };
124
+ }
125
+ /**
126
+ * Advanced ML-Based Detection
127
+ * PRO FEATURE
128
+ */
129
+ export declare class MLDetectionEngine {
130
+ private licenseManager;
131
+ private anomalyThreshold;
132
+ constructor(licenseManager: LicenseManager);
133
+ detectAnomalies(text: string, _context?: Record<string, unknown>): {
134
+ isAnomaly: boolean;
135
+ confidence: number;
136
+ reason?: string;
137
+ };
138
+ }
139
+ /**
140
+ * Compliance Reporting Generator
141
+ * PRO FEATURE
142
+ */
143
+ export declare class ComplianceReporter {
144
+ private licenseManager;
145
+ constructor(licenseManager: LicenseManager);
146
+ generateReport(standard: "SOC2" | "GDPR" | "HIPAA", _events?: Array<Record<string, unknown>>): ComplianceReport | null;
147
+ exportReport(report: ComplianceReport, format: "JSON" | "PDF"): string;
148
+ }
149
+ /**
150
+ * Priority Support Manager
151
+ * PRO/ENTERPRISE FEATURE
152
+ */
153
+ export declare class PrioritySupport {
154
+ private licenseManager;
155
+ constructor(licenseManager: LicenseManager);
156
+ createTicket(subject: string, description: string, priority: "LOW" | "MEDIUM" | "HIGH" | "CRITICAL"): {
157
+ ticketId: string;
158
+ sla: string;
159
+ } | null;
160
+ }
161
+ /**
162
+ * SLA Monitor
163
+ * ENTERPRISE FEATURE
164
+ */
165
+ export declare class SLAMonitor {
166
+ private licenseManager;
167
+ private uptimeStart;
168
+ private downtimeEvents;
169
+ constructor(licenseManager: LicenseManager);
170
+ recordDowntime(): void;
171
+ recordUptime(): void;
172
+ getUptimePercentage(): number;
173
+ }
174
+ /**
175
+ * MCP Traceability - Track which user used which MCP, tool, and context
176
+ * PRO FEATURE
177
+ */
178
+ export interface MCPTraceRecord {
179
+ traceId: string;
180
+ timestamp: Date;
181
+ userId: string;
182
+ userEmail?: string;
183
+ sessionId: string;
184
+ mcpServerName: string;
185
+ mcpServerId: string;
186
+ mcpServerVersion?: string;
187
+ toolName: string;
188
+ toolMethod?: string;
189
+ toolParameters: Record<string, unknown>;
190
+ contextUsed: ContextSnapshot;
191
+ executionTimeMs: number;
192
+ status: "success" | "failure" | "blocked" | "timeout";
193
+ errorMessage?: string;
194
+ responseSize?: number;
195
+ responseType?: string;
196
+ securityLevel: "public" | "internal" | "confidential" | "restricted";
197
+ dataClassification?: "public" | "pii" | "phi" | "financial";
198
+ complianceTags: string[];
199
+ threatDetected: boolean;
200
+ securityViolations: string[];
201
+ tokensUsed?: number;
202
+ apiCallsCount?: number;
203
+ dataTransferredBytes?: number;
204
+ metadata?: Record<string, unknown>;
205
+ tags?: string[];
206
+ }
207
+ export interface ContextSnapshot {
208
+ filesAccessed: Array<{
209
+ path: string;
210
+ operation: "read" | "write" | "delete" | "list";
211
+ size?: number;
212
+ }>;
213
+ envVarsAccessed: string[];
214
+ externalApisCalled: Array<{
215
+ url: string;
216
+ method: string;
217
+ statusCode?: number;
218
+ }>;
219
+ databaseQueries?: Array<{
220
+ query: string;
221
+ database: string;
222
+ rowsAffected?: number;
223
+ }>;
224
+ memoryUsedMB?: number;
225
+ cpuTimeMs?: number;
226
+ userPrompt?: string;
227
+ userPromptHash?: string;
228
+ }
229
+ export interface TraceabilityQuery {
230
+ userId?: string;
231
+ userIds?: string[];
232
+ mcpServerName?: string;
233
+ toolName?: string;
234
+ sessionId?: string;
235
+ status?: string;
236
+ threatDetected?: boolean;
237
+ startDate?: Date;
238
+ endDate?: Date;
239
+ limit?: number;
240
+ offset?: number;
241
+ sortBy?: string;
242
+ sortOrder?: "asc" | "desc";
243
+ }
244
+ export interface UsageStatistics {
245
+ totalTraces: number;
246
+ uniqueUsers: number;
247
+ uniqueMCPServers: number;
248
+ uniqueTools: number;
249
+ byMCPServer: Record<string, {
250
+ count: number;
251
+ successRate: number;
252
+ avgExecutionTimeMs: number;
253
+ totalTokensUsed: number;
254
+ }>;
255
+ byTool: Record<string, {
256
+ count: number;
257
+ successRate: number;
258
+ avgExecutionTimeMs: number;
259
+ }>;
260
+ byUser: Record<string, {
261
+ count: number;
262
+ mcpServersUsed: string[];
263
+ toolsUsed: string[];
264
+ totalExecutionTimeMs: number;
265
+ }>;
266
+ securityEvents: {
267
+ totalThreats: number;
268
+ threatsBySeverity: Record<string, number>;
269
+ blockedRequests: number;
270
+ };
271
+ timeline: Array<{
272
+ timestamp: Date;
273
+ count: number;
274
+ successCount: number;
275
+ failureCount: number;
276
+ }>;
277
+ }
278
+ export declare class MCPTraceabilityManager {
279
+ private licenseManager;
280
+ private traces;
281
+ private readonly maxTraces;
282
+ private persistenceEnabled;
283
+ constructor(licenseManager: LicenseManager, persistenceEnabled?: boolean);
284
+ /**
285
+ * Record a new trace entry
286
+ */
287
+ recordTrace(trace: Omit<MCPTraceRecord, "traceId" | "timestamp">): string | null;
288
+ /**
289
+ * Query traces with filters
290
+ */
291
+ queryTraces(query: TraceabilityQuery): MCPTraceRecord[];
292
+ /**
293
+ * Get trace by ID
294
+ */
295
+ getTrace(traceId: string): MCPTraceRecord | null;
296
+ /**
297
+ * Get usage statistics
298
+ */
299
+ getUsageStatistics(query?: TraceabilityQuery): UsageStatistics;
300
+ /**
301
+ * Export traces for compliance/audit
302
+ */
303
+ exportTraces(query: TraceabilityQuery, format: "JSON" | "CSV"): string;
304
+ /**
305
+ * Get user activity timeline
306
+ */
307
+ getUserActivityTimeline(userId: string, startDate: Date, endDate: Date): Array<MCPTraceRecord>;
308
+ /**
309
+ * Detect anomalous usage patterns
310
+ */
311
+ detectAnomalies(userId?: string): Array<{
312
+ type: string;
313
+ severity: "LOW" | "MEDIUM" | "HIGH";
314
+ description: string;
315
+ traces: MCPTraceRecord[];
316
+ }>;
317
+ private persistTrace;
318
+ private getEmptyStatistics;
319
+ }
320
+ /**
321
+ * Context Tracker - Track context usage and data flow
322
+ * PRO FEATURE
323
+ */
324
+ export declare class ContextTracker {
325
+ private licenseManager;
326
+ private activeContexts;
327
+ constructor(licenseManager: LicenseManager);
328
+ /**
329
+ * Start tracking context for a session
330
+ */
331
+ startTracking(sessionId: string): void;
332
+ /**
333
+ * Record file access
334
+ */
335
+ recordFileAccess(sessionId: string, path: string, operation: "read" | "write" | "delete" | "list", size?: number): void;
336
+ /**
337
+ * Record environment variable access
338
+ */
339
+ recordEnvVarAccess(sessionId: string, varName: string): void;
340
+ /**
341
+ * Record external API call
342
+ */
343
+ recordApiCall(sessionId: string, url: string, method: string, statusCode?: number): void;
344
+ /**
345
+ * Record database query
346
+ */
347
+ recordDatabaseQuery(sessionId: string, query: string, database: string, rowsAffected?: number): void;
348
+ /**
349
+ * Get context snapshot
350
+ */
351
+ getContextSnapshot(sessionId: string): ContextSnapshot | null;
352
+ /**
353
+ * Stop tracking and return final snapshot
354
+ */
355
+ stopTracking(sessionId: string): ContextSnapshot | null;
356
+ /**
357
+ * Analyze context for security risks
358
+ */
359
+ analyzeContextSecurity(context: ContextSnapshot): Array<{
360
+ risk: string;
361
+ severity: "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
362
+ details: string;
363
+ }>;
364
+ }