@dotsetlabs/tollgate 0.1.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.
Files changed (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +885 -0
  3. package/dist/analyzers/filesystem.d.ts +26 -0
  4. package/dist/analyzers/filesystem.d.ts.map +1 -0
  5. package/dist/analyzers/filesystem.js +284 -0
  6. package/dist/analyzers/filesystem.js.map +1 -0
  7. package/dist/analyzers/http.d.ts +90 -0
  8. package/dist/analyzers/http.d.ts.map +1 -0
  9. package/dist/analyzers/http.js +433 -0
  10. package/dist/analyzers/http.js.map +1 -0
  11. package/dist/analyzers/index.d.ts +101 -0
  12. package/dist/analyzers/index.d.ts.map +1 -0
  13. package/dist/analyzers/index.js +342 -0
  14. package/dist/analyzers/index.js.map +1 -0
  15. package/dist/analyzers/loader.d.ts +114 -0
  16. package/dist/analyzers/loader.d.ts.map +1 -0
  17. package/dist/analyzers/loader.js +184 -0
  18. package/dist/analyzers/loader.js.map +1 -0
  19. package/dist/analyzers/prompt-injection.d.ts +95 -0
  20. package/dist/analyzers/prompt-injection.d.ts.map +1 -0
  21. package/dist/analyzers/prompt-injection.js +725 -0
  22. package/dist/analyzers/prompt-injection.js.map +1 -0
  23. package/dist/analyzers/sdk.d.ts +230 -0
  24. package/dist/analyzers/sdk.d.ts.map +1 -0
  25. package/dist/analyzers/sdk.js +283 -0
  26. package/dist/analyzers/sdk.js.map +1 -0
  27. package/dist/analyzers/shell.d.ts +20 -0
  28. package/dist/analyzers/shell.d.ts.map +1 -0
  29. package/dist/analyzers/shell.js +297 -0
  30. package/dist/analyzers/shell.js.map +1 -0
  31. package/dist/analyzers/sql.d.ts +37 -0
  32. package/dist/analyzers/sql.d.ts.map +1 -0
  33. package/dist/analyzers/sql.js +455 -0
  34. package/dist/analyzers/sql.js.map +1 -0
  35. package/dist/analyzers/types.d.ts +117 -0
  36. package/dist/analyzers/types.d.ts.map +1 -0
  37. package/dist/analyzers/types.js +46 -0
  38. package/dist/analyzers/types.js.map +1 -0
  39. package/dist/approval/interactive.d.ts +72 -0
  40. package/dist/approval/interactive.d.ts.map +1 -0
  41. package/dist/approval/interactive.js +550 -0
  42. package/dist/approval/interactive.js.map +1 -0
  43. package/dist/approval/terminal.d.ts +59 -0
  44. package/dist/approval/terminal.d.ts.map +1 -0
  45. package/dist/approval/terminal.js +238 -0
  46. package/dist/approval/terminal.js.map +1 -0
  47. package/dist/approval/types.d.ts +66 -0
  48. package/dist/approval/types.d.ts.map +1 -0
  49. package/dist/approval/types.js +2 -0
  50. package/dist/approval/types.js.map +1 -0
  51. package/dist/audit/exporter.d.ts +138 -0
  52. package/dist/audit/exporter.d.ts.map +1 -0
  53. package/dist/audit/exporter.js +366 -0
  54. package/dist/audit/exporter.js.map +1 -0
  55. package/dist/audit/logger.d.ts +156 -0
  56. package/dist/audit/logger.d.ts.map +1 -0
  57. package/dist/audit/logger.js +406 -0
  58. package/dist/audit/logger.js.map +1 -0
  59. package/dist/audit/redaction.d.ts +110 -0
  60. package/dist/audit/redaction.d.ts.map +1 -0
  61. package/dist/audit/redaction.js +307 -0
  62. package/dist/audit/redaction.js.map +1 -0
  63. package/dist/audit/schema.d.ts +76 -0
  64. package/dist/audit/schema.d.ts.map +1 -0
  65. package/dist/audit/schema.js +122 -0
  66. package/dist/audit/schema.js.map +1 -0
  67. package/dist/cli/commands/doctor.d.ts +34 -0
  68. package/dist/cli/commands/doctor.d.ts.map +1 -0
  69. package/dist/cli/commands/doctor.js +431 -0
  70. package/dist/cli/commands/doctor.js.map +1 -0
  71. package/dist/cli/commands/export.d.ts +18 -0
  72. package/dist/cli/commands/export.d.ts.map +1 -0
  73. package/dist/cli/commands/export.js +63 -0
  74. package/dist/cli/commands/export.js.map +1 -0
  75. package/dist/cli/commands/init.d.ts +12 -0
  76. package/dist/cli/commands/init.d.ts.map +1 -0
  77. package/dist/cli/commands/init.js +102 -0
  78. package/dist/cli/commands/init.js.map +1 -0
  79. package/dist/cli/commands/logs.d.ts +11 -0
  80. package/dist/cli/commands/logs.d.ts.map +1 -0
  81. package/dist/cli/commands/logs.js +60 -0
  82. package/dist/cli/commands/logs.js.map +1 -0
  83. package/dist/cli/commands/scan.d.ts +29 -0
  84. package/dist/cli/commands/scan.d.ts.map +1 -0
  85. package/dist/cli/commands/scan.js +251 -0
  86. package/dist/cli/commands/scan.js.map +1 -0
  87. package/dist/cli/commands/serve.d.ts +26 -0
  88. package/dist/cli/commands/serve.d.ts.map +1 -0
  89. package/dist/cli/commands/serve.js +424 -0
  90. package/dist/cli/commands/serve.js.map +1 -0
  91. package/dist/cli/commands/start.d.ts +20 -0
  92. package/dist/cli/commands/start.d.ts.map +1 -0
  93. package/dist/cli/commands/start.js +82 -0
  94. package/dist/cli/commands/start.js.map +1 -0
  95. package/dist/cli/commands/stats.d.ts +10 -0
  96. package/dist/cli/commands/stats.d.ts.map +1 -0
  97. package/dist/cli/commands/stats.js +42 -0
  98. package/dist/cli/commands/stats.js.map +1 -0
  99. package/dist/cli/commands/templates.d.ts +26 -0
  100. package/dist/cli/commands/templates.d.ts.map +1 -0
  101. package/dist/cli/commands/templates.js +221 -0
  102. package/dist/cli/commands/templates.js.map +1 -0
  103. package/dist/cli/commands/validate.d.ts +12 -0
  104. package/dist/cli/commands/validate.d.ts.map +1 -0
  105. package/dist/cli/commands/validate.js +107 -0
  106. package/dist/cli/commands/validate.js.map +1 -0
  107. package/dist/cli/commands/wrap.d.ts +19 -0
  108. package/dist/cli/commands/wrap.d.ts.map +1 -0
  109. package/dist/cli/commands/wrap.js +59 -0
  110. package/dist/cli/commands/wrap.js.map +1 -0
  111. package/dist/cli/index.d.ts +17 -0
  112. package/dist/cli/index.d.ts.map +1 -0
  113. package/dist/cli/index.js +202 -0
  114. package/dist/cli/index.js.map +1 -0
  115. package/dist/cli/ui.d.ts +139 -0
  116. package/dist/cli/ui.d.ts.map +1 -0
  117. package/dist/cli/ui.js +271 -0
  118. package/dist/cli/ui.js.map +1 -0
  119. package/dist/constants.d.ts +33 -0
  120. package/dist/constants.d.ts.map +1 -0
  121. package/dist/constants.js +54 -0
  122. package/dist/constants.js.map +1 -0
  123. package/dist/errors.d.ts +28 -0
  124. package/dist/errors.d.ts.map +1 -0
  125. package/dist/errors.js +37 -0
  126. package/dist/errors.js.map +1 -0
  127. package/dist/index.d.ts +49 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.js +82 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/orchestrator/index.d.ts +11 -0
  132. package/dist/orchestrator/index.d.ts.map +1 -0
  133. package/dist/orchestrator/index.js +10 -0
  134. package/dist/orchestrator/index.js.map +1 -0
  135. package/dist/orchestrator/manager.d.ts +127 -0
  136. package/dist/orchestrator/manager.d.ts.map +1 -0
  137. package/dist/orchestrator/manager.js +498 -0
  138. package/dist/orchestrator/manager.js.map +1 -0
  139. package/dist/orchestrator/types.d.ts +141 -0
  140. package/dist/orchestrator/types.d.ts.map +1 -0
  141. package/dist/orchestrator/types.js +9 -0
  142. package/dist/orchestrator/types.js.map +1 -0
  143. package/dist/policy/engine.d.ts +55 -0
  144. package/dist/policy/engine.d.ts.map +1 -0
  145. package/dist/policy/engine.js +288 -0
  146. package/dist/policy/engine.js.map +1 -0
  147. package/dist/policy/natural-language.d.ts +141 -0
  148. package/dist/policy/natural-language.d.ts.map +1 -0
  149. package/dist/policy/natural-language.js +552 -0
  150. package/dist/policy/natural-language.js.map +1 -0
  151. package/dist/policy/parser.d.ts +141 -0
  152. package/dist/policy/parser.d.ts.map +1 -0
  153. package/dist/policy/parser.js +314 -0
  154. package/dist/policy/parser.js.map +1 -0
  155. package/dist/policy/types.d.ts +428 -0
  156. package/dist/policy/types.d.ts.map +1 -0
  157. package/dist/policy/types.js +32 -0
  158. package/dist/policy/types.js.map +1 -0
  159. package/dist/policy/validator.d.ts +72 -0
  160. package/dist/policy/validator.d.ts.map +1 -0
  161. package/dist/policy/validator.js +453 -0
  162. package/dist/policy/validator.js.map +1 -0
  163. package/dist/proxy/bridge.d.ts +84 -0
  164. package/dist/proxy/bridge.d.ts.map +1 -0
  165. package/dist/proxy/bridge.js +217 -0
  166. package/dist/proxy/bridge.js.map +1 -0
  167. package/dist/proxy/client.d.ts +130 -0
  168. package/dist/proxy/client.d.ts.map +1 -0
  169. package/dist/proxy/client.js +290 -0
  170. package/dist/proxy/client.js.map +1 -0
  171. package/dist/proxy/server.d.ts +111 -0
  172. package/dist/proxy/server.d.ts.map +1 -0
  173. package/dist/proxy/server.js +444 -0
  174. package/dist/proxy/server.js.map +1 -0
  175. package/dist/scanner.d.ts +91 -0
  176. package/dist/scanner.d.ts.map +1 -0
  177. package/dist/scanner.js +373 -0
  178. package/dist/scanner.js.map +1 -0
  179. package/dist/session/index.d.ts +32 -0
  180. package/dist/session/index.d.ts.map +1 -0
  181. package/dist/session/index.js +31 -0
  182. package/dist/session/index.js.map +1 -0
  183. package/dist/session/manager.d.ts +166 -0
  184. package/dist/session/manager.d.ts.map +1 -0
  185. package/dist/session/manager.js +454 -0
  186. package/dist/session/manager.js.map +1 -0
  187. package/dist/session/sqlite-store.d.ts +54 -0
  188. package/dist/session/sqlite-store.d.ts.map +1 -0
  189. package/dist/session/sqlite-store.js +209 -0
  190. package/dist/session/sqlite-store.js.map +1 -0
  191. package/dist/session/types.d.ts +179 -0
  192. package/dist/session/types.d.ts.map +1 -0
  193. package/dist/session/types.js +38 -0
  194. package/dist/session/types.js.map +1 -0
  195. package/dist/templates.d.ts +64 -0
  196. package/dist/templates.d.ts.map +1 -0
  197. package/dist/templates.js +451 -0
  198. package/dist/templates.js.map +1 -0
  199. package/dist/utils/config.d.ts +57 -0
  200. package/dist/utils/config.d.ts.map +1 -0
  201. package/dist/utils/config.js +104 -0
  202. package/dist/utils/config.js.map +1 -0
  203. package/dist/utils/errors.d.ts +18 -0
  204. package/dist/utils/errors.d.ts.map +1 -0
  205. package/dist/utils/errors.js +35 -0
  206. package/dist/utils/errors.js.map +1 -0
  207. package/dist/utils/logger.d.ts +144 -0
  208. package/dist/utils/logger.d.ts.map +1 -0
  209. package/dist/utils/logger.js +300 -0
  210. package/dist/utils/logger.js.map +1 -0
  211. package/dist/wizard.d.ts +68 -0
  212. package/dist/wizard.d.ts.map +1 -0
  213. package/dist/wizard.js +395 -0
  214. package/dist/wizard.js.map +1 -0
  215. package/package.json +99 -0
@@ -0,0 +1,428 @@
1
+ /**
2
+ * Policy Type Definitions for Tollgate
3
+ *
4
+ * This module defines the core types for Tollgate's policy system:
5
+ *
6
+ * - **PolicyAction**: The possible actions (allow, deny, prompt, smart)
7
+ * - **ToolPolicy**: Configuration for individual tool access control
8
+ * - **ServerConfig**: MCP server configuration with tool policies
9
+ * - **TollgateConfig**: Root configuration schema
10
+ * - **ResilienceConfig**: Failure handling and health monitoring settings
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import type { TollgateConfig, PolicyAction } from './types.js';
15
+ *
16
+ * const config: TollgateConfig = {
17
+ * version: '1',
18
+ * servers: {
19
+ * postgres: {
20
+ * command: 'npx',
21
+ * args: ['-y', '@modelcontextprotocol/server-postgres'],
22
+ * tools: {
23
+ * 'query': { action: 'allow' },
24
+ * 'execute': { action: 'prompt' }
25
+ * }
26
+ * }
27
+ * }
28
+ * };
29
+ * ```
30
+ */
31
+ import type { RiskLevel, RiskMapping } from '../analyzers/types.js';
32
+ /**
33
+ * Available policy actions for tool access control.
34
+ *
35
+ * - `allow`: Permit the tool call without user approval
36
+ * - `deny`: Block the tool call entirely
37
+ * - `prompt`: Ask the user for approval before proceeding
38
+ * - `smart`: Use content analysis to determine the appropriate action
39
+ */
40
+ export type PolicyAction = 'allow' | 'deny' | 'prompt' | 'smart';
41
+ /**
42
+ * Configuration for controlling access to a specific tool.
43
+ *
44
+ * Tool policies define how Tollgate should handle requests to invoke
45
+ * a particular tool. The simplest form just specifies an action, but
46
+ * policies can include smart analysis, session memory, and custom messages.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Simple policy
51
+ * const readPolicy: ToolPolicy = { action: 'allow' };
52
+ *
53
+ * // Smart analysis policy
54
+ * const sqlPolicy: ToolPolicy = {
55
+ * action: 'smart',
56
+ * analyzer: 'sql',
57
+ * risks: {
58
+ * read: 'allow',
59
+ * write: 'prompt',
60
+ * destructive: 'deny'
61
+ * }
62
+ * };
63
+ * ```
64
+ */
65
+ export interface ToolPolicy {
66
+ /** The action to take when this tool is invoked */
67
+ action: PolicyAction;
68
+ /** Custom message to display when prompting for approval */
69
+ message?: string;
70
+ /** Reason for the policy decision (shown when denying) */
71
+ reason?: string;
72
+ /** Analyzer to use for smart content analysis ('sql', 'filesystem', 'shell', or 'auto') */
73
+ analyzer?: string;
74
+ /** Risk level to action mapping for smart analysis */
75
+ risks?: RiskMapping;
76
+ /** Session-based approval configuration */
77
+ session?: SessionConfig;
78
+ }
79
+ /**
80
+ * Configuration for session-based approval memory.
81
+ *
82
+ * When enabled, Tollgate can remember approval decisions for a period of time,
83
+ * reducing approval fatigue for repetitive operations.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const sessionConfig: SessionConfig = {
88
+ * remember: true,
89
+ * scope: 'tool', // Remember for all calls to this tool
90
+ * ttl: 300 // For 5 minutes
91
+ * };
92
+ * ```
93
+ */
94
+ export interface SessionConfig {
95
+ /** Whether to remember approval decisions */
96
+ remember?: boolean;
97
+ /** Scope of the remembered approval */
98
+ scope?: 'exact' | 'tool' | 'server';
99
+ /** Time-to-live for the approval in seconds */
100
+ ttl?: number;
101
+ }
102
+ /**
103
+ * Configuration for an upstream MCP server.
104
+ *
105
+ * Defines how to launch an MCP server and what policies apply to its tools.
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const postgresConfig: ServerConfig = {
110
+ * command: 'npx',
111
+ * args: ['-y', '@modelcontextprotocol/server-postgres'],
112
+ * env: { DATABASE_URL: '${DATABASE_URL}' },
113
+ * tools: {
114
+ * 'query': { action: 'allow' },
115
+ * 'execute': { action: 'prompt' }
116
+ * },
117
+ * defaults: { action: 'deny' }
118
+ * };
119
+ * ```
120
+ */
121
+ export interface ServerConfig {
122
+ /** Command to execute to start the server */
123
+ command: string;
124
+ /** Arguments to pass to the command */
125
+ args?: string[];
126
+ /** Environment variables for the server process */
127
+ env?: Record<string, string>;
128
+ /** Working directory for the server process */
129
+ cwd?: string;
130
+ /** Tool-specific policies (tool name or glob pattern to policy) */
131
+ tools?: Record<string, ToolPolicy | PolicyAction>;
132
+ /** Default settings for this server */
133
+ defaults?: {
134
+ /** Default action when no tool policy matches */
135
+ action?: PolicyAction;
136
+ /** Default analyzer for smart analysis */
137
+ analyzer?: string;
138
+ };
139
+ }
140
+ /**
141
+ * Failure mode determines behavior when the upstream server is unavailable.
142
+ *
143
+ * - `fail-closed`: Deny all requests (safest, recommended for production)
144
+ * - `fail-open`: Allow all requests (useful for development/debugging)
145
+ * - `fail-readonly`: Allow only read operations (balanced approach)
146
+ */
147
+ export type FailureMode = 'fail-closed' | 'fail-open' | 'fail-readonly';
148
+ /**
149
+ * Configuration for periodic health checks of upstream servers.
150
+ *
151
+ * Health checks help detect upstream server failures proactively,
152
+ * enabling faster failure mode activation.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const healthConfig: HealthCheckConfig = {
157
+ * enabled: true,
158
+ * intervalMs: 15000, // Check every 15 seconds
159
+ * timeoutMs: 3000, // 3 second timeout per check
160
+ * failureThreshold: 2 // Mark unhealthy after 2 failures
161
+ * };
162
+ * ```
163
+ */
164
+ export interface HealthCheckConfig {
165
+ /** Enable periodic health checks (default: true) */
166
+ enabled?: boolean;
167
+ /** Interval between health checks in milliseconds (default: 30000) */
168
+ intervalMs?: number;
169
+ /** Timeout for each health check operation in milliseconds (default: 5000) */
170
+ timeoutMs?: number;
171
+ /** Number of consecutive failures before marking server unhealthy (default: 3) */
172
+ failureThreshold?: number;
173
+ }
174
+ /**
175
+ * Configuration for graceful shutdown behavior.
176
+ *
177
+ * Controls how Tollgate handles shutdown signals (SIGINT, SIGTERM),
178
+ * ensuring in-flight requests complete before termination.
179
+ */
180
+ export interface ShutdownConfig {
181
+ /** Maximum time to wait for graceful shutdown in milliseconds (default: 10000) */
182
+ timeoutMs?: number;
183
+ /** Time to wait for in-flight requests to complete in milliseconds (default: 5000) */
184
+ drainTimeoutMs?: number;
185
+ }
186
+ /**
187
+ * Complete resilience configuration for failure handling and monitoring.
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * const resilienceConfig: ResilienceConfig = {
192
+ * failureMode: 'fail-readonly',
193
+ * upstreamTimeoutMs: 60000,
194
+ * healthCheck: { enabled: true, intervalMs: 15000 },
195
+ * shutdown: { timeoutMs: 15000, drainTimeoutMs: 10000 }
196
+ * };
197
+ * ```
198
+ */
199
+ export interface ResilienceConfig {
200
+ /** Behavior when upstream is unavailable (default: 'fail-closed') */
201
+ failureMode?: FailureMode;
202
+ /** Timeout for upstream tool calls in milliseconds (default: 30000) */
203
+ upstreamTimeoutMs?: number;
204
+ /** Health check configuration */
205
+ healthCheck?: HealthCheckConfig;
206
+ /** Graceful shutdown configuration */
207
+ shutdown?: ShutdownConfig;
208
+ }
209
+ /**
210
+ * Action to take when a guardrail is triggered.
211
+ *
212
+ * - `deny`: Block the request entirely (recommended for production)
213
+ * - `warn`: Log a warning but allow the request to proceed
214
+ * - `prompt`: Ask the user for approval before proceeding
215
+ */
216
+ export type GuardrailAction = 'deny' | 'warn' | 'prompt';
217
+ /**
218
+ * Configuration for the prompt injection detection guardrail.
219
+ *
220
+ * This guardrail scans all tool arguments for common prompt injection
221
+ * patterns before the request is processed by other analyzers.
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * const promptInjection: PromptInjectionGuardrailConfig = {
226
+ * enabled: true,
227
+ * action: 'deny',
228
+ * sensitivity: 'balanced',
229
+ * allowlist: ['system_prompt_tool'],
230
+ * };
231
+ * ```
232
+ */
233
+ export interface PromptInjectionGuardrailConfig {
234
+ /** Enable prompt injection detection (default: false) */
235
+ enabled?: boolean;
236
+ /** Action to take when injection is detected (default: 'deny') */
237
+ action?: GuardrailAction;
238
+ /**
239
+ * Detection sensitivity level.
240
+ * - 'strict': Flag any suspicious patterns (may have false positives)
241
+ * - 'balanced': Balance between security and usability (default)
242
+ * - 'permissive': Only flag high-confidence attacks
243
+ */
244
+ sensitivity?: 'strict' | 'balanced' | 'permissive';
245
+ /**
246
+ * Tools to exclude from prompt injection scanning.
247
+ * Useful for tools that legitimately need to handle prompts.
248
+ */
249
+ allowlist?: string[];
250
+ /**
251
+ * Servers to exclude from prompt injection scanning.
252
+ * All tools from these servers will bypass the guardrail.
253
+ */
254
+ serverAllowlist?: string[];
255
+ }
256
+ /**
257
+ * Configuration for all guardrails.
258
+ *
259
+ * Guardrails are security checks that run before normal policy evaluation.
260
+ * They provide an additional layer of protection against common attack patterns.
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * const guardrails: GuardrailsConfig = {
265
+ * promptInjection: {
266
+ * enabled: true,
267
+ * action: 'deny',
268
+ * },
269
+ * };
270
+ * ```
271
+ */
272
+ export interface GuardrailsConfig {
273
+ /** Prompt injection detection configuration */
274
+ promptInjection?: PromptInjectionGuardrailConfig;
275
+ }
276
+ /**
277
+ * Root configuration schema for Tollgate.
278
+ *
279
+ * This is the top-level configuration object parsed from tollgate.yaml.
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const config: TollgateConfig = {
284
+ * version: '1',
285
+ * defaults: { action: 'prompt', timeout: 60000 },
286
+ * servers: {
287
+ * postgres: { command: 'npx', args: ['-y', '@modelcontextprotocol/server-postgres'] }
288
+ * },
289
+ * audit: { enabled: true, path: './audit.db' },
290
+ * guardrails: {
291
+ * promptInjection: { enabled: true, action: 'deny' }
292
+ * }
293
+ * };
294
+ * ```
295
+ */
296
+ export interface TollgateConfig {
297
+ /** Configuration schema version */
298
+ version: string;
299
+ /** Global default settings */
300
+ defaults?: {
301
+ /** Default action when no policy matches */
302
+ action?: PolicyAction;
303
+ /** Default approval timeout in milliseconds */
304
+ timeout?: number;
305
+ };
306
+ /** Server configurations keyed by server name */
307
+ servers?: Record<string, ServerConfig>;
308
+ /** Approval handler configuration */
309
+ approval?: {
310
+ /** Approval method: terminal prompt, interactive web UI, or webhook */
311
+ method?: 'terminal' | 'interactive' | 'webhook';
312
+ /** Timeout for approval requests in milliseconds */
313
+ timeout?: number;
314
+ /** Port for interactive approval UI (default: 9847) */
315
+ port?: number;
316
+ /** Webhook URL for remote approvals */
317
+ url?: string;
318
+ };
319
+ /** Audit logging configuration */
320
+ audit?: {
321
+ /** Enable audit logging */
322
+ enabled?: boolean;
323
+ /** Path to audit database file */
324
+ path?: string;
325
+ };
326
+ /** Session management configuration */
327
+ session?: {
328
+ /** Enable persistent session storage (default: false, uses in-memory) */
329
+ persist?: boolean;
330
+ /** Path to session database (default: ~/.tollgate/sessions.db) */
331
+ path?: string;
332
+ };
333
+ /** Resilience and failure handling configuration */
334
+ resilience?: ResilienceConfig;
335
+ /** Guardrails configuration for additional security protections */
336
+ guardrails?: GuardrailsConfig;
337
+ /**
338
+ * Custom analyzers to load.
339
+ *
340
+ * Specify paths to custom analyzer modules that export a default analyzer
341
+ * created with `defineAnalyzer()` or `defineAsyncAnalyzer()`.
342
+ *
343
+ * @example
344
+ * ```yaml
345
+ * analyzers:
346
+ * - ./analyzers/graphql.ts
347
+ * - ./analyzers/redis-commands.js
348
+ * - @myorg/custom-analyzers/pii
349
+ * ```
350
+ */
351
+ analyzers?: string[];
352
+ /**
353
+ * Natural language policy definitions.
354
+ *
355
+ * Define policies using plain English statements that will be parsed
356
+ * and converted to structured tool policies.
357
+ *
358
+ * @example
359
+ * ```yaml
360
+ * policies:
361
+ * - "Allow read operations on postgres"
362
+ * - "Deny destructive queries on any database"
363
+ * - "Prompt for file writes outside /tmp"
364
+ * - "Block dangerous shell commands"
365
+ * ```
366
+ */
367
+ policies?: string[];
368
+ }
369
+ /**
370
+ * The result of a guardrail check.
371
+ */
372
+ export interface GuardrailResult {
373
+ /** Whether the guardrail was triggered */
374
+ triggered: boolean;
375
+ /** The guardrail that was triggered */
376
+ guardrail: string;
377
+ /** Risk level detected */
378
+ risk: RiskLevel;
379
+ /** Reason for the trigger */
380
+ reason: string;
381
+ /** Patterns that triggered the guardrail */
382
+ triggers?: string[];
383
+ }
384
+ /**
385
+ * The result of policy evaluation for a tool call.
386
+ *
387
+ * A PolicyDecision represents the resolved action after evaluating all
388
+ * applicable policies. The 'smart' action is always resolved to a concrete
389
+ * action (allow, deny, or prompt) before returning.
390
+ */
391
+ export interface PolicyDecision {
392
+ /** The resolved action (never 'smart', always concrete) */
393
+ action: Exclude<PolicyAction, 'smart'>;
394
+ /** Human-readable reason for the decision */
395
+ reason?: string;
396
+ /** Custom message for approval prompts */
397
+ message?: string;
398
+ /** The policy rule that matched (for debugging) */
399
+ matchedRule?: string;
400
+ /** Analysis metadata when smart analysis was used */
401
+ analysis?: {
402
+ /** Which analyzer processed the request */
403
+ analyzer: string;
404
+ /** Determined risk level */
405
+ risk: RiskLevel;
406
+ /** Patterns or keywords that triggered the risk level */
407
+ triggers?: string[];
408
+ };
409
+ /** Guardrail result when a guardrail was triggered */
410
+ guardrail?: GuardrailResult;
411
+ }
412
+ /**
413
+ * Context for a tool call being evaluated.
414
+ *
415
+ * Captures all relevant information about a tool invocation for
416
+ * policy evaluation, approval prompts, and audit logging.
417
+ */
418
+ export interface ToolCallContext {
419
+ /** Name of the MCP server */
420
+ server: string;
421
+ /** Name of the tool being invoked */
422
+ tool: string;
423
+ /** Arguments passed to the tool */
424
+ args: Record<string, unknown>;
425
+ /** Timestamp of the request */
426
+ timestamp: Date;
427
+ }
428
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/policy/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMpE;;;;;;;GAOG;AACH,MAAM,M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MAAM,EAAE,CAAC;CACrB;AAMD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,SAAS,EAAE,OAAO,CAAC;IAEnB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAElB,0BAA0B;IAC1B,IAAI,EAAE,SAAS,CAAC;IAEhB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IAEf,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,2DAA2D;IAC3D,MAAM,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAEvC,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,qDAAqD;IACrD,QAAQ,CAAC,EAAE;QACT,2CAA2C;QAC3C,QAAQ,EAAE,MAAM,CAAC;QACjB,4BAA4B;QAC5B,IAAI,EAAE,SAAS,CAAC;QAChB,yDAAyD;QACzD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IAEF,sDAAsD;IACtD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IAEf,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IAEb,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE9B,+BAA+B;IAC/B,SAAS,EAAE,IAAI,CAAC;CACjB"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Policy Type Definitions for Tollgate
3
+ *
4
+ * This module defines the core types for Tollgate's policy system:
5
+ *
6
+ * - **PolicyAction**: The possible actions (allow, deny, prompt, smart)
7
+ * - **ToolPolicy**: Configuration for individual tool access control
8
+ * - **ServerConfig**: MCP server configuration with tool policies
9
+ * - **TollgateConfig**: Root configuration schema
10
+ * - **ResilienceConfig**: Failure handling and health monitoring settings
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import type { TollgateConfig, PolicyAction } from './types.js';
15
+ *
16
+ * const config: TollgateConfig = {
17
+ * version: '1',
18
+ * servers: {
19
+ * postgres: {
20
+ * command: 'npx',
21
+ * args: ['-y', '@modelcontextprotocol/server-postgres'],
22
+ * tools: {
23
+ * 'query': { action: 'allow' },
24
+ * 'execute': { action: 'prompt' }
25
+ * }
26
+ * }
27
+ * }
28
+ * };
29
+ * ```
30
+ */
31
+ export {};
32
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/policy/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Policy Validator for Tollgate
3
+ *
4
+ * Provides comprehensive validation of Tollgate configuration files
5
+ * with detailed error messages and suggestions for common issues.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { validateConfigWithDetails } from './validator.js';
10
+ *
11
+ * const issues = validateConfigWithDetails(config);
12
+ * if (issues.some(i => i.level === 'error')) {
13
+ * console.error('Configuration has errors');
14
+ * process.exit(1);
15
+ * }
16
+ * ```
17
+ */
18
+ import type { TollgateConfig } from './types.js';
19
+ /**
20
+ * Validation issue severity level.
21
+ */
22
+ export type ValidationLevel = 'error' | 'warning' | 'info';
23
+ /**
24
+ * A validation issue found in the configuration.
25
+ */
26
+ export interface ValidationIssue {
27
+ /** Severity level */
28
+ level: ValidationLevel;
29
+ /** Configuration path where the issue was found (e.g., "servers.postgres.tools.query") */
30
+ path: string;
31
+ /** Human-readable description of the issue */
32
+ message: string;
33
+ /** Suggested fix (optional) */
34
+ suggestion?: string;
35
+ /** Additional context */
36
+ details?: Record<string, unknown>;
37
+ }
38
+ /**
39
+ * Summary of validation results.
40
+ */
41
+ export interface ValidationResult {
42
+ /** Whether the configuration is valid (no errors) */
43
+ valid: boolean;
44
+ /** All issues found */
45
+ issues: ValidationIssue[];
46
+ /** Count of errors */
47
+ errorCount: number;
48
+ /** Count of warnings */
49
+ warningCount: number;
50
+ /** Count of informational messages */
51
+ infoCount: number;
52
+ /** Summary statistics */
53
+ stats: {
54
+ serversConfigured: number;
55
+ toolPoliciesConfigured: number;
56
+ smartAnalysisEnabled: boolean;
57
+ analyzersUsed: string[];
58
+ };
59
+ }
60
+ /**
61
+ * Validates a Tollgate configuration with detailed error reporting.
62
+ *
63
+ * @param config - The configuration to validate
64
+ * @param serverFilter - Optional: only validate a specific server
65
+ * @returns Validation result with all issues found
66
+ */
67
+ export declare function validateConfigWithDetails(config: TollgateConfig, serverFilter?: string): ValidationResult;
68
+ /**
69
+ * Formats validation issues for console output.
70
+ */
71
+ export declare function formatValidationIssues(issues: ValidationIssue[]): string;
72
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/policy/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EACV,cAAc,EAIf,MAAM,YAAY,CAAC;AAOpB;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,qBAAqB;IACrB,KAAK,EAAE,eAAe,CAAC;IAEvB,0FAA0F;IAC1F,IAAI,EAAE,MAAM,CAAC;IAEb,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAEhB,+BAA+B;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAA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