contextguard 0.2.3 → 0.2.4

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/agent.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { Logger, ContextGuardConfig } from "./logger";
8
- import { AgentPolicyRow } from "./types/database.types";
8
+ import { AgentPolicyRow } from "./types/agent.types";
9
9
  /**
10
10
  * Agent interface
11
11
  */
package/dist/agent.js CHANGED
@@ -21,7 +21,7 @@ const mcp_1 = require("./types/mcp");
21
21
  */
22
22
  const createAgent = (serverCommand, policyConfig, agentId, contextGuardConfig) => {
23
23
  const policy = (0, security_engine_1.createPolicyChecker)(policyConfig);
24
- const logger = (0, logger_1.createLogger)(policyConfig.logPath, agentId, policyConfig.alertWebhook, policyConfig.alertOnSeverity, contextGuardConfig);
24
+ const logger = (0, logger_1.createLogger)(agentId, policyConfig.alertWebhook, policyConfig.alertOnSeverity, contextGuardConfig);
25
25
  const sessionId = (0, mcp_1.generateSessionId)();
26
26
  const state = {
27
27
  process: null,
package/dist/index.d.ts CHANGED
@@ -11,4 +11,4 @@ export { createPolicyChecker, DEFAULT_POLICY } from "./security-engine";
11
11
  export type { PolicyChecker } from "./security-engine";
12
12
  export { createLogger } from "./logger";
13
13
  export type { Logger, SecurityStatistics, ContextGuardConfig } from "./logger";
14
- export type { AgentPolicyRow, AgentPolicyInsert, AgentPolicyUpdate, SecurityEventRow, SecurityEventInsert, SecurityEventUpdate, AgentStatusRow, AgentStatusInsert, AgentStatusUpdate, EventStatisticsRow, SecuritySeverity, AgentStatus, } from "./types/database.types";
14
+ export type { AgentPolicyRow, SecurityEventRow, SecuritySeverity, } from "./types/agent.types";
package/dist/init.js CHANGED
@@ -78,13 +78,12 @@ function isAlreadyWrapped(server) {
78
78
  }
79
79
  /**
80
80
  * Wrap an MCP server entry:
81
- * { command, args } → { command: "npx", args: ["-y", "contextguard", "--", <original command+args>] }
81
+ * { command, args } → { command: "npx", args: ["-y", "contextguard", "--", command, ...args] }
82
82
  */
83
83
  function wrapServer(server, apiKey) {
84
- const originalCmd = [server.command, ...(server.args ?? [])];
85
84
  return {
86
85
  command: "npx",
87
- args: ["-y", "contextguard", "--", ...originalCmd],
86
+ args: ["-y", "contextguard", "--", server.command, ...(server.args ?? [])],
88
87
  env: {
89
88
  ...server.env,
90
89
  CONTEXTGUARD_API_KEY: apiKey,
package/dist/logger.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { SecurityEventRow, SecuritySeverity } from "./types/database.types";
7
+ import { SecurityEventRow, SecuritySeverity } from "./types/agent.types";
8
8
  /**
9
9
  * ContextGuard API configuration
10
10
  */
@@ -32,11 +32,10 @@ export interface Logger {
32
32
  }
33
33
  /**
34
34
  * Create a security event logger
35
- * @param logFile - Path to log file
36
35
  * @param agentId - Agent identifier for event attribution
37
36
  * @param alertWebhook - Optional webhook URL for HIGH/CRITICAL alerts
38
37
  * @param alertOnSeverity - Severity levels that trigger webhook alerts
39
38
  * @param contextGuardConfig - Optional ContextGuard API config for remote logging
40
39
  * @returns Logger functions
41
40
  */
42
- export declare const createLogger: (logFile?: string, agentId?: string, alertWebhook?: string, alertOnSeverity?: string[], contextGuardConfig?: ContextGuardConfig) => Logger;
41
+ export declare const createLogger: (agentId?: string, alertWebhook?: string, alertOnSeverity?: string[], contextGuardConfig?: ContextGuardConfig) => Logger;
package/dist/logger.js CHANGED
@@ -5,44 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
- Object.defineProperty(o, "default", { enumerable: true, value: v });
21
- }) : function(o, v) {
22
- o["default"] = v;
23
- });
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
8
  Object.defineProperty(exports, "__esModule", { value: true });
42
9
  exports.createLogger = void 0;
43
- const fs = __importStar(require("fs"));
44
- const os = __importStar(require("os"));
45
- const path = __importStar(require("path"));
46
10
  const MAX_STORED_EVENTS = 1000;
47
11
  /**
48
12
  * Count events by a specific field
@@ -72,14 +36,13 @@ const fireWebhookAlert = (webhookUrl, event) => {
72
36
  };
73
37
  /**
74
38
  * Create a security event logger
75
- * @param logFile - Path to log file
76
39
  * @param agentId - Agent identifier for event attribution
77
40
  * @param alertWebhook - Optional webhook URL for HIGH/CRITICAL alerts
78
41
  * @param alertOnSeverity - Severity levels that trigger webhook alerts
79
42
  * @param contextGuardConfig - Optional ContextGuard API config for remote logging
80
43
  * @returns Logger functions
81
44
  */
82
- const createLogger = (logFile = path.join(os.homedir(), ".contextguard", "mcp_security.log"), agentId = "", alertWebhook, alertOnSeverity = ["HIGH", "CRITICAL"], contextGuardConfig) => {
45
+ const createLogger = (agentId = "", alertWebhook, alertOnSeverity = ["HIGH", "CRITICAL"], contextGuardConfig) => {
83
46
  let events = [];
84
47
  return {
85
48
  /**
@@ -101,15 +64,6 @@ const createLogger = (logFile = path.join(os.homedir(), ".contextguard", "mcp_se
101
64
  if (events.length > MAX_STORED_EVENTS) {
102
65
  events = events.slice(-MAX_STORED_EVENTS);
103
66
  }
104
- // Write to log file (silently fail if filesystem is read-only)
105
- try {
106
- fs.mkdirSync(path.dirname(logFile), { recursive: true });
107
- fs.appendFileSync(logFile, JSON.stringify(event) + "\n");
108
- }
109
- catch {
110
- // Silently ignore filesystem errors to avoid polluting stderr
111
- // This can happen in read-only environments like Claude Desktop
112
- }
113
67
  // Alert on high/critical severity
114
68
  if (severity === "HIGH" || severity === "CRITICAL") {
115
69
  console.error(`[SECURITY ALERT] ${eventType}: ${JSON.stringify(details)}`);
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { AgentPolicyRow } from "./types/database.types";
7
+ import { AgentPolicyRow } from "./types/agent.types";
8
8
  /**
9
9
  * Policy checker interface
10
10
  */
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { Logger } from "./logger";
8
- import { AgentPolicyRow } from "./types/database.types";
8
+ import { AgentPolicyRow } from "./types/agent.types";
9
9
  /**
10
10
  * SSE/HTTP Proxy interface
11
11
  */
package/dist/sse-proxy.js CHANGED
@@ -53,7 +53,7 @@ const mcp_1 = require("./types/mcp");
53
53
  */
54
54
  const createSSEProxy = (policyConfig, agentId = "sse-proxy") => {
55
55
  const policy = (0, security_engine_1.createPolicyChecker)(policyConfig);
56
- const logger = (0, logger_1.createLogger)(policyConfig.logPath, agentId);
56
+ const logger = (0, logger_1.createLogger)(agentId);
57
57
  const sessionId = (0, mcp_1.generateSessionId)();
58
58
  let toolCallTimestamps = [];
59
59
  /**
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Copyright (c) 2026 Amir Mironi
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export type SecuritySeverity = "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
8
+ export interface SecurityEventRow {
9
+ id: string;
10
+ agent_id: string;
11
+ session_id: string;
12
+ event_type: string;
13
+ severity: SecuritySeverity;
14
+ details: Record<string, unknown>;
15
+ timestamp: string;
16
+ created_at: string;
17
+ }
18
+ export interface AgentPolicyRow {
19
+ id: string;
20
+ agent_id: string;
21
+ maxToolCallsPerMinute?: number;
22
+ blockedPatterns?: string[];
23
+ allowedFilePaths?: string[];
24
+ alertThreshold?: number;
25
+ enablePromptInjectionDetection?: boolean;
26
+ enableSensitiveDataDetection?: boolean;
27
+ enablePathTraversalPrevention?: boolean;
28
+ mode?: "monitor" | "block";
29
+ logPath?: string;
30
+ enableProFeatures?: boolean;
31
+ licenseFilePath?: string;
32
+ transport?: "stdio" | "sse" | "http";
33
+ port?: number;
34
+ targetUrl?: string;
35
+ allowedTools?: string[];
36
+ blockedTools?: string[];
37
+ alertWebhook?: string;
38
+ alertOnSeverity?: string[];
39
+ enableSQLInjectionDetection?: boolean;
40
+ enableSemanticDetection?: boolean;
41
+ enableXSSDetection?: boolean;
42
+ customRules?: Array<{
43
+ name: string;
44
+ pattern: string;
45
+ severity?: string;
46
+ }>;
47
+ created_at: string;
48
+ updated_at: string;
49
+ }
@@ -0,0 +1,8 @@
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 });
@@ -12,28 +12,28 @@ export interface Database {
12
12
  Row: {
13
13
  id: string;
14
14
  agent_id: string;
15
- maxToolCallsPerMinute?: number;
16
- blockedPatterns?: string[];
17
- allowedFilePaths?: string[];
18
- alertThreshold?: number;
19
- enablePromptInjectionDetection?: boolean;
20
- enableSensitiveDataDetection?: boolean;
21
- enablePathTraversalPrevention?: boolean;
15
+ max_tool_calls_per_minute?: number;
16
+ blocked_patterns?: string[];
17
+ allowed_file_paths?: string[];
18
+ alert_threshold?: number;
19
+ enable_prompt_injection_detection?: boolean;
20
+ enable_sensitive_data_detection?: boolean;
21
+ enable_path_traversal_prevention?: boolean;
22
+ enable_sql_injection_detection?: boolean;
23
+ enable_semantic_detection?: boolean;
24
+ enable_xss_detection?: boolean;
22
25
  mode?: "monitor" | "block";
23
- logPath?: string;
24
- enableProFeatures?: boolean;
25
- licenseFilePath?: string;
26
+ log_path?: string;
27
+ enable_pro_features?: boolean;
28
+ license_file_path?: string;
26
29
  transport?: "stdio" | "sse" | "http";
27
30
  port?: number;
28
- targetUrl?: string;
29
- allowedTools?: string[];
30
- blockedTools?: string[];
31
- alertWebhook?: string;
32
- alertOnSeverity?: string[];
33
- enableSQLInjectionDetection?: boolean;
34
- enableSemanticDetection?: boolean;
35
- enableXSSDetection?: boolean;
36
- customRules?: Array<{
31
+ target_url?: string;
32
+ allowed_tools?: string[];
33
+ blocked_tools?: string[];
34
+ alert_webhook?: string;
35
+ alert_on_severity?: string[];
36
+ custom_rules?: Array<{
37
37
  name: string;
38
38
  pattern: string;
39
39
  severity?: string;
@@ -44,28 +44,28 @@ export interface Database {
44
44
  Insert: {
45
45
  id?: string;
46
46
  agent_id: string;
47
- maxToolCallsPerMinute?: number;
48
- blockedPatterns?: string[];
49
- allowedFilePaths?: string[];
50
- alertThreshold?: number;
51
- enablePromptInjectionDetection?: boolean;
52
- enableSensitiveDataDetection?: boolean;
53
- enablePathTraversalPrevention?: boolean;
47
+ max_tool_calls_per_minute?: number;
48
+ blocked_patterns?: string[];
49
+ allowed_file_paths?: string[];
50
+ alert_threshold?: number;
51
+ enable_prompt_injection_detection?: boolean;
52
+ enable_sensitive_data_detection?: boolean;
53
+ enable_path_traversal_prevention?: boolean;
54
+ enable_sql_injection_detection?: boolean;
55
+ enable_semantic_detection?: boolean;
56
+ enable_xss_detection?: boolean;
54
57
  mode?: "monitor" | "block";
55
- logPath?: string;
56
- enableProFeatures?: boolean;
57
- licenseFilePath?: string;
58
+ log_path?: string;
59
+ enable_pro_features?: boolean;
60
+ license_file_path?: string;
58
61
  transport?: "stdio" | "sse" | "http";
59
62
  port?: number;
60
- targetUrl?: string;
61
- allowedTools?: string[];
62
- blockedTools?: string[];
63
- alertWebhook?: string;
64
- alertOnSeverity?: string[];
65
- enableSQLInjectionDetection?: boolean;
66
- enableSemanticDetection?: boolean;
67
- enableXSSDetection?: boolean;
68
- customRules?: Array<{
63
+ target_url?: string;
64
+ allowed_tools?: string[];
65
+ blocked_tools?: string[];
66
+ alert_webhook?: string;
67
+ alert_on_severity?: string[];
68
+ custom_rules?: Array<{
69
69
  name: string;
70
70
  pattern: string;
71
71
  severity?: string;
@@ -76,28 +76,28 @@ export interface Database {
76
76
  Update: {
77
77
  id?: string;
78
78
  agent_id?: string;
79
- maxToolCallsPerMinute?: number;
80
- blockedPatterns?: string[];
81
- allowedFilePaths?: string[];
82
- alertThreshold?: number;
83
- enablePromptInjectionDetection?: boolean;
84
- enableSensitiveDataDetection?: boolean;
85
- enablePathTraversalPrevention?: boolean;
79
+ max_tool_calls_per_minute?: number;
80
+ blocked_patterns?: string[];
81
+ allowed_file_paths?: string[];
82
+ alert_threshold?: number;
83
+ enable_prompt_injection_detection?: boolean;
84
+ enable_sensitive_data_detection?: boolean;
85
+ enable_path_traversal_prevention?: boolean;
86
+ enable_sql_injection_detection?: boolean;
87
+ enable_semantic_detection?: boolean;
88
+ enable_xss_detection?: boolean;
86
89
  mode?: "monitor" | "block";
87
- logPath?: string;
88
- enableProFeatures?: boolean;
89
- licenseFilePath?: string;
90
+ log_path?: string;
91
+ enable_pro_features?: boolean;
92
+ license_file_path?: string;
90
93
  transport?: "stdio" | "sse" | "http";
91
94
  port?: number;
92
- targetUrl?: string;
93
- allowedTools?: string[];
94
- blockedTools?: string[];
95
- alertWebhook?: string;
96
- alertOnSeverity?: string[];
97
- enableSQLInjectionDetection?: boolean;
98
- enableSemanticDetection?: boolean;
99
- enableXSSDetection?: boolean;
100
- customRules?: Array<{
95
+ target_url?: string;
96
+ allowed_tools?: string[];
97
+ blocked_tools?: string[];
98
+ alert_webhook?: string;
99
+ alert_on_severity?: string[];
100
+ custom_rules?: Array<{
101
101
  name: string;
102
102
  pattern: string;
103
103
  severity?: string;
@@ -165,25 +165,8 @@ export interface Database {
165
165
  };
166
166
  };
167
167
  };
168
- Views: {
169
- event_statistics: {
170
- Row: {
171
- agent_id: string;
172
- event_type: string;
173
- severity: SecuritySeverity;
174
- count: number;
175
- hour: string;
176
- };
177
- };
178
- };
179
- Functions: {
180
- cleanup_old_events: {
181
- Args: {
182
- days_to_keep?: number;
183
- };
184
- Returns: number;
185
- };
186
- };
168
+ Views: Record<string, never>;
169
+ Functions: Record<string, never>;
187
170
  };
188
171
  }
189
172
  /**
@@ -202,10 +185,6 @@ export type AgentPolicyRow = Database["public"]["Tables"]["policies"]["Row"];
202
185
  * Agent status from database
203
186
  */
204
187
  export type AgentStatusRow = Database["public"]["Tables"]["agents"]["Row"];
205
- /**
206
- * Event statistics from view
207
- */
208
- export type EventStatisticsRow = Database["public"]["Views"]["event_statistics"]["Row"];
209
188
  /**
210
189
  * Insert types for convenience
211
190
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contextguard",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Security monitoring wrapper for MCP servers with enterprise features",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "test": "jest",
30
30
  "lint": "eslint . && pnpm tsc --noEmit",
31
31
  "prepublishOnly": "npm run build",
32
- "release": "npm publish && npm install -g contextguard"
32
+ "pub": "npm publish && npm install -g contextguard"
33
33
  },
34
34
  "keywords": [
35
35
  "mcp",
@@ -50,21 +50,21 @@
50
50
  "url": "https://github.com/amironi/contextguard/issues"
51
51
  },
52
52
  "devDependencies": {
53
- "@eslint/js": "^9.37.0",
54
- "@types/jest": "^29.5.0",
55
- "@types/node": "^24.7.0",
56
- "@typescript-eslint/eslint-plugin": "^8.46.0",
57
- "@typescript-eslint/parser": "^8.46.0",
58
- "eslint": "^9.37.0",
59
- "globals": "^16.4.0",
53
+ "@eslint/js": "^9.39.4",
54
+ "@types/jest": "^29.5.14",
55
+ "@types/node": "^24.12.0",
56
+ "@typescript-eslint/eslint-plugin": "^8.57.0",
57
+ "@typescript-eslint/parser": "^8.57.0",
58
+ "eslint": "^9.39.4",
59
+ "globals": "^16.5.0",
60
60
  "jest": "^29.7.0",
61
- "ts-jest": "^29.2.0",
61
+ "ts-jest": "^29.4.6",
62
62
  "ts-node": "^10.9.2",
63
63
  "typescript": "^5.9.3",
64
- "typescript-eslint": "^8.46.0"
64
+ "typescript-eslint": "^8.57.0"
65
65
  },
66
66
  "dependencies": {
67
67
  "@anthropic-ai/sdk": "^0.54.0",
68
- "@supabase/supabase-js": "^2.79.0"
68
+ "@supabase/supabase-js": "^2.99.1"
69
69
  }
70
70
  }