@solongate/core 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.
@@ -0,0 +1,698 @@
1
+ import { z, ZodTypeAny } from 'zod';
2
+
3
+ /**
4
+ * Trust levels in the SolonGate security model.
5
+ *
6
+ * Core threat model principle: LLMs are UNTRUSTED by default.
7
+ * Trust is never assumed - it must be explicitly granted and is
8
+ * always scoped to specific capabilities.
9
+ *
10
+ * UNTRUSTED: Default for all LLM-originated requests. No permissions.
11
+ * VERIFIED: Passed schema validation and policy evaluation. May execute within granted scope.
12
+ * TRUSTED: System-internal only. NEVER assignable to LLM-originated requests.
13
+ */
14
+ declare const TrustLevel: {
15
+ readonly UNTRUSTED: "UNTRUSTED";
16
+ readonly VERIFIED: "VERIFIED";
17
+ readonly TRUSTED: "TRUSTED";
18
+ };
19
+ type TrustLevel = (typeof TrustLevel)[keyof typeof TrustLevel];
20
+ /**
21
+ * Validates that a trust level is a legitimate enum value.
22
+ * Prevents type confusion attacks where a string bypasses checks.
23
+ */
24
+ declare function isValidTrustLevel(value: unknown): value is TrustLevel;
25
+ /**
26
+ * Asserts that a trust level transition is valid.
27
+ * UNTRUSTED -> VERIFIED (via policy evaluation) is the only escalation path.
28
+ * TRUSTED is never reachable from external requests.
29
+ */
30
+ declare function assertValidTransition(from: TrustLevel, to: TrustLevel): void;
31
+
32
+ /**
33
+ * Permission types are ALWAYS evaluated independently.
34
+ * Having READ does NOT imply WRITE or EXECUTE.
35
+ */
36
+ declare const Permission: {
37
+ readonly READ: "READ";
38
+ readonly WRITE: "WRITE";
39
+ readonly EXECUTE: "EXECUTE";
40
+ };
41
+ type Permission = (typeof Permission)[keyof typeof Permission];
42
+ declare const PermissionSchema: z.ZodEnum<["READ", "WRITE", "EXECUTE"]>;
43
+ /** Immutable set of permissions granted to a specific scope. */
44
+ type PermissionSet = ReadonlySet<Permission>;
45
+ /** Creates an immutable permission set from an array. */
46
+ declare function createPermissionSet(permissions: Permission[]): PermissionSet;
47
+ /** Empty permission set - the default for all new tools (default-deny). */
48
+ declare const NO_PERMISSIONS: PermissionSet;
49
+ /** Read-only permission set - the maximum default for new tools. */
50
+ declare const READ_ONLY: PermissionSet;
51
+ declare function hasPermission(permissions: PermissionSet, required: Permission): boolean;
52
+ declare function hasAllPermissions(permissions: PermissionSet, required: Permission[]): boolean;
53
+ /** Maps MCP protocol methods to SolonGate permission types. */
54
+ declare function permissionForMethod(method: string): Permission;
55
+
56
+ /**
57
+ * Policy effect: the only two outcomes of policy evaluation.
58
+ * No "MAYBE" or "CONDITIONAL" - binary security decisions only.
59
+ */
60
+ declare const PolicyEffect: {
61
+ readonly ALLOW: "ALLOW";
62
+ readonly DENY: "DENY";
63
+ };
64
+ type PolicyEffect = (typeof PolicyEffect)[keyof typeof PolicyEffect];
65
+ /**
66
+ * A single policy rule that matches against execution requests.
67
+ * Rules are evaluated by priority order. First matching rule wins.
68
+ * If NO rule matches, the result is DENY (default-deny).
69
+ */
70
+ interface PolicyRule {
71
+ readonly id: string;
72
+ readonly description: string;
73
+ readonly effect: PolicyEffect;
74
+ readonly priority: number;
75
+ readonly toolPattern: string;
76
+ readonly permission: Permission;
77
+ readonly minimumTrustLevel: TrustLevel;
78
+ readonly argumentConstraints?: Record<string, unknown>;
79
+ readonly pathConstraints?: {
80
+ readonly allowed?: readonly string[];
81
+ readonly denied?: readonly string[];
82
+ readonly rootDirectory?: string;
83
+ readonly allowSymlinks?: boolean;
84
+ };
85
+ readonly commandConstraints?: {
86
+ readonly allowed?: readonly string[];
87
+ readonly denied?: readonly string[];
88
+ };
89
+ readonly enabled: boolean;
90
+ readonly createdAt: string;
91
+ readonly updatedAt: string;
92
+ }
93
+ /**
94
+ * A versioned, ordered set of policy rules.
95
+ * Modifications create new sets (immutable by convention).
96
+ */
97
+ interface PolicySet {
98
+ readonly id: string;
99
+ readonly name: string;
100
+ readonly description: string;
101
+ readonly version: number;
102
+ readonly rules: readonly PolicyRule[];
103
+ readonly createdAt: string;
104
+ readonly updatedAt: string;
105
+ }
106
+ declare const PolicyRuleSchema: z.ZodObject<{
107
+ id: z.ZodString;
108
+ description: z.ZodString;
109
+ effect: z.ZodEnum<["ALLOW", "DENY"]>;
110
+ priority: z.ZodDefault<z.ZodNumber>;
111
+ toolPattern: z.ZodString;
112
+ permission: z.ZodEnum<["READ", "WRITE", "EXECUTE"]>;
113
+ minimumTrustLevel: z.ZodEnum<["UNTRUSTED", "VERIFIED", "TRUSTED"]>;
114
+ argumentConstraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
115
+ pathConstraints: z.ZodOptional<z.ZodObject<{
116
+ allowed: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
117
+ denied: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
118
+ rootDirectory: z.ZodOptional<z.ZodString>;
119
+ allowSymlinks: z.ZodOptional<z.ZodBoolean>;
120
+ }, "strip", z.ZodTypeAny, {
121
+ allowed?: string[] | undefined;
122
+ denied?: string[] | undefined;
123
+ rootDirectory?: string | undefined;
124
+ allowSymlinks?: boolean | undefined;
125
+ }, {
126
+ allowed?: string[] | undefined;
127
+ denied?: string[] | undefined;
128
+ rootDirectory?: string | undefined;
129
+ allowSymlinks?: boolean | undefined;
130
+ }>>;
131
+ commandConstraints: z.ZodOptional<z.ZodObject<{
132
+ allowed: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
133
+ denied: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
134
+ }, "strip", z.ZodTypeAny, {
135
+ allowed?: string[] | undefined;
136
+ denied?: string[] | undefined;
137
+ }, {
138
+ allowed?: string[] | undefined;
139
+ denied?: string[] | undefined;
140
+ }>>;
141
+ enabled: z.ZodDefault<z.ZodBoolean>;
142
+ createdAt: z.ZodString;
143
+ updatedAt: z.ZodString;
144
+ }, "strip", z.ZodTypeAny, {
145
+ id: string;
146
+ description: string;
147
+ effect: "ALLOW" | "DENY";
148
+ priority: number;
149
+ toolPattern: string;
150
+ permission: "READ" | "WRITE" | "EXECUTE";
151
+ minimumTrustLevel: "UNTRUSTED" | "VERIFIED" | "TRUSTED";
152
+ enabled: boolean;
153
+ createdAt: string;
154
+ updatedAt: string;
155
+ argumentConstraints?: Record<string, unknown> | undefined;
156
+ pathConstraints?: {
157
+ allowed?: string[] | undefined;
158
+ denied?: string[] | undefined;
159
+ rootDirectory?: string | undefined;
160
+ allowSymlinks?: boolean | undefined;
161
+ } | undefined;
162
+ commandConstraints?: {
163
+ allowed?: string[] | undefined;
164
+ denied?: string[] | undefined;
165
+ } | undefined;
166
+ }, {
167
+ id: string;
168
+ description: string;
169
+ effect: "ALLOW" | "DENY";
170
+ toolPattern: string;
171
+ permission: "READ" | "WRITE" | "EXECUTE";
172
+ minimumTrustLevel: "UNTRUSTED" | "VERIFIED" | "TRUSTED";
173
+ createdAt: string;
174
+ updatedAt: string;
175
+ priority?: number | undefined;
176
+ argumentConstraints?: Record<string, unknown> | undefined;
177
+ pathConstraints?: {
178
+ allowed?: string[] | undefined;
179
+ denied?: string[] | undefined;
180
+ rootDirectory?: string | undefined;
181
+ allowSymlinks?: boolean | undefined;
182
+ } | undefined;
183
+ commandConstraints?: {
184
+ allowed?: string[] | undefined;
185
+ denied?: string[] | undefined;
186
+ } | undefined;
187
+ enabled?: boolean | undefined;
188
+ }>;
189
+ declare const PolicySetSchema: z.ZodObject<{
190
+ id: z.ZodString;
191
+ name: z.ZodString;
192
+ description: z.ZodString;
193
+ version: z.ZodNumber;
194
+ rules: z.ZodArray<z.ZodObject<{
195
+ id: z.ZodString;
196
+ description: z.ZodString;
197
+ effect: z.ZodEnum<["ALLOW", "DENY"]>;
198
+ priority: z.ZodDefault<z.ZodNumber>;
199
+ toolPattern: z.ZodString;
200
+ permission: z.ZodEnum<["READ", "WRITE", "EXECUTE"]>;
201
+ minimumTrustLevel: z.ZodEnum<["UNTRUSTED", "VERIFIED", "TRUSTED"]>;
202
+ argumentConstraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
203
+ pathConstraints: z.ZodOptional<z.ZodObject<{
204
+ allowed: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
205
+ denied: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
206
+ rootDirectory: z.ZodOptional<z.ZodString>;
207
+ allowSymlinks: z.ZodOptional<z.ZodBoolean>;
208
+ }, "strip", z.ZodTypeAny, {
209
+ allowed?: string[] | undefined;
210
+ denied?: string[] | undefined;
211
+ rootDirectory?: string | undefined;
212
+ allowSymlinks?: boolean | undefined;
213
+ }, {
214
+ allowed?: string[] | undefined;
215
+ denied?: string[] | undefined;
216
+ rootDirectory?: string | undefined;
217
+ allowSymlinks?: boolean | undefined;
218
+ }>>;
219
+ commandConstraints: z.ZodOptional<z.ZodObject<{
220
+ allowed: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
221
+ denied: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
222
+ }, "strip", z.ZodTypeAny, {
223
+ allowed?: string[] | undefined;
224
+ denied?: string[] | undefined;
225
+ }, {
226
+ allowed?: string[] | undefined;
227
+ denied?: string[] | undefined;
228
+ }>>;
229
+ enabled: z.ZodDefault<z.ZodBoolean>;
230
+ createdAt: z.ZodString;
231
+ updatedAt: z.ZodString;
232
+ }, "strip", z.ZodTypeAny, {
233
+ id: string;
234
+ description: string;
235
+ effect: "ALLOW" | "DENY";
236
+ priority: number;
237
+ toolPattern: string;
238
+ permission: "READ" | "WRITE" | "EXECUTE";
239
+ minimumTrustLevel: "UNTRUSTED" | "VERIFIED" | "TRUSTED";
240
+ enabled: boolean;
241
+ createdAt: string;
242
+ updatedAt: string;
243
+ argumentConstraints?: Record<string, unknown> | undefined;
244
+ pathConstraints?: {
245
+ allowed?: string[] | undefined;
246
+ denied?: string[] | undefined;
247
+ rootDirectory?: string | undefined;
248
+ allowSymlinks?: boolean | undefined;
249
+ } | undefined;
250
+ commandConstraints?: {
251
+ allowed?: string[] | undefined;
252
+ denied?: string[] | undefined;
253
+ } | undefined;
254
+ }, {
255
+ id: string;
256
+ description: string;
257
+ effect: "ALLOW" | "DENY";
258
+ toolPattern: string;
259
+ permission: "READ" | "WRITE" | "EXECUTE";
260
+ minimumTrustLevel: "UNTRUSTED" | "VERIFIED" | "TRUSTED";
261
+ createdAt: string;
262
+ updatedAt: string;
263
+ priority?: number | undefined;
264
+ argumentConstraints?: Record<string, unknown> | undefined;
265
+ pathConstraints?: {
266
+ allowed?: string[] | undefined;
267
+ denied?: string[] | undefined;
268
+ rootDirectory?: string | undefined;
269
+ allowSymlinks?: boolean | undefined;
270
+ } | undefined;
271
+ commandConstraints?: {
272
+ allowed?: string[] | undefined;
273
+ denied?: string[] | undefined;
274
+ } | undefined;
275
+ enabled?: boolean | undefined;
276
+ }>, "many">;
277
+ createdAt: z.ZodString;
278
+ updatedAt: z.ZodString;
279
+ }, "strip", z.ZodTypeAny, {
280
+ name: string;
281
+ id: string;
282
+ description: string;
283
+ createdAt: string;
284
+ updatedAt: string;
285
+ version: number;
286
+ rules: {
287
+ id: string;
288
+ description: string;
289
+ effect: "ALLOW" | "DENY";
290
+ priority: number;
291
+ toolPattern: string;
292
+ permission: "READ" | "WRITE" | "EXECUTE";
293
+ minimumTrustLevel: "UNTRUSTED" | "VERIFIED" | "TRUSTED";
294
+ enabled: boolean;
295
+ createdAt: string;
296
+ updatedAt: string;
297
+ argumentConstraints?: Record<string, unknown> | undefined;
298
+ pathConstraints?: {
299
+ allowed?: string[] | undefined;
300
+ denied?: string[] | undefined;
301
+ rootDirectory?: string | undefined;
302
+ allowSymlinks?: boolean | undefined;
303
+ } | undefined;
304
+ commandConstraints?: {
305
+ allowed?: string[] | undefined;
306
+ denied?: string[] | undefined;
307
+ } | undefined;
308
+ }[];
309
+ }, {
310
+ name: string;
311
+ id: string;
312
+ description: string;
313
+ createdAt: string;
314
+ updatedAt: string;
315
+ version: number;
316
+ rules: {
317
+ id: string;
318
+ description: string;
319
+ effect: "ALLOW" | "DENY";
320
+ toolPattern: string;
321
+ permission: "READ" | "WRITE" | "EXECUTE";
322
+ minimumTrustLevel: "UNTRUSTED" | "VERIFIED" | "TRUSTED";
323
+ createdAt: string;
324
+ updatedAt: string;
325
+ priority?: number | undefined;
326
+ argumentConstraints?: Record<string, unknown> | undefined;
327
+ pathConstraints?: {
328
+ allowed?: string[] | undefined;
329
+ denied?: string[] | undefined;
330
+ rootDirectory?: string | undefined;
331
+ allowSymlinks?: boolean | undefined;
332
+ } | undefined;
333
+ commandConstraints?: {
334
+ allowed?: string[] | undefined;
335
+ denied?: string[] | undefined;
336
+ } | undefined;
337
+ enabled?: boolean | undefined;
338
+ }[];
339
+ }>;
340
+ /** The result of evaluating a policy against a request. */
341
+ interface PolicyDecision {
342
+ readonly effect: PolicyEffect;
343
+ readonly matchedRule: PolicyRule | null;
344
+ readonly reason: string;
345
+ readonly timestamp: string;
346
+ readonly evaluationTimeMs: number;
347
+ readonly metadata?: {
348
+ readonly evaluatedRules: number;
349
+ readonly ruleIds: readonly string[];
350
+ readonly requestContext: {
351
+ readonly tool: string;
352
+ readonly arguments: readonly string[];
353
+ };
354
+ };
355
+ }
356
+
357
+ /**
358
+ * Declares a tool's capabilities and security requirements.
359
+ * Wraps MCP tool definitions with SolonGate-specific metadata.
360
+ */
361
+ interface ToolCapability {
362
+ readonly name: string;
363
+ readonly description: string;
364
+ readonly serverName: string;
365
+ /** Maximum permissions this tool CAN request (capability ceiling). */
366
+ readonly maxPermissions: readonly Permission[];
367
+ /** Default permissions when no explicit policy exists. Must be empty in Phase 0 (default-deny). */
368
+ readonly defaultPermissions: readonly Permission[];
369
+ readonly inputSchema: Record<string, unknown>;
370
+ /** Tools with side effects cannot be READ-only. */
371
+ readonly hasSideEffects: boolean;
372
+ /** Sensitive data access affects audit log redaction behavior. */
373
+ readonly accessesSensitiveData: boolean;
374
+ /** Max calls per minute. 0 = unlimited. */
375
+ readonly rateLimitPerMinute: number;
376
+ }
377
+ /** Creates a ToolCapability with the most restrictive secure defaults. */
378
+ declare function createToolCapability(params: Pick<ToolCapability, 'name' | 'description' | 'serverName' | 'inputSchema'> & Partial<Omit<ToolCapability, 'name' | 'description' | 'serverName' | 'inputSchema'>>): ToolCapability;
379
+
380
+ /**
381
+ * SecurityContext represents the security state of a single request.
382
+ * Created fresh for each MCP request and NEVER reused.
383
+ * All fields are readonly - state transitions create new contexts.
384
+ */
385
+ interface SecurityContext {
386
+ readonly requestId: string;
387
+ readonly trustLevel: TrustLevel;
388
+ readonly grantedPermissions: PermissionSet;
389
+ readonly sessionId: string | null;
390
+ readonly createdAt: string;
391
+ readonly metadata: Readonly<Record<string, unknown>>;
392
+ readonly capabilityToken?: string;
393
+ }
394
+ /** Extends SecurityContext with tool-specific execution information. */
395
+ interface ExecutionContext extends SecurityContext {
396
+ readonly toolName: string;
397
+ readonly serverName: string;
398
+ readonly arguments: Readonly<Record<string, unknown>>;
399
+ }
400
+ /** Creates a new SecurityContext with default-deny settings. */
401
+ declare function createSecurityContext(params: Pick<SecurityContext, 'requestId'> & Partial<Omit<SecurityContext, 'requestId' | 'createdAt' | 'trustLevel' | 'grantedPermissions'>>): SecurityContext;
402
+
403
+ /**
404
+ * Base error class for all SolonGate security errors.
405
+ * Every error includes a machine-readable code for programmatic handling.
406
+ */
407
+ declare class SolonGateError extends Error {
408
+ readonly code: string;
409
+ readonly timestamp: string;
410
+ readonly details: Record<string, unknown>;
411
+ constructor(message: string, code: string, details?: Record<string, unknown>);
412
+ /**
413
+ * Serializable representation for logging and API responses.
414
+ * Never includes stack traces (information leakage prevention).
415
+ */
416
+ toJSON(): Record<string, unknown>;
417
+ }
418
+ /** Thrown when a tool call is denied by policy. */
419
+ declare class PolicyDeniedError extends SolonGateError {
420
+ constructor(toolName: string, reason: string, details?: Record<string, unknown>);
421
+ }
422
+ /** Thrown when a trust level escalation is attempted illegally. */
423
+ declare class TrustEscalationError extends SolonGateError {
424
+ constructor(message: string);
425
+ }
426
+ /** Thrown when tool input fails schema validation. */
427
+ declare class SchemaValidationError extends SolonGateError {
428
+ constructor(toolName: string, validationErrors: readonly string[]);
429
+ }
430
+ /** Thrown when a tool exceeds its rate limit. */
431
+ declare class RateLimitError extends SolonGateError {
432
+ constructor(toolName: string, limitPerMinute: number);
433
+ }
434
+ /** Thrown when a tool is not found in the registry. */
435
+ declare class ToolNotFoundError extends SolonGateError {
436
+ constructor(toolName: string, serverName: string);
437
+ }
438
+ /** Thrown when an unsafe configuration is detected. */
439
+ declare class UnsafeConfigurationError extends SolonGateError {
440
+ constructor(message: string, field: string);
441
+ }
442
+ /** Thrown when input guard detects dangerous patterns. */
443
+ declare class InputGuardError extends SolonGateError {
444
+ constructor(toolName: string, threats: readonly {
445
+ type: string;
446
+ field: string;
447
+ description: string;
448
+ }[]);
449
+ }
450
+ /** Thrown when a network operation fails (API calls, cloud sync, etc.). */
451
+ declare class NetworkError extends SolonGateError {
452
+ constructor(operation: string, statusCode?: number, details?: Record<string, unknown>);
453
+ }
454
+
455
+ /** An execution request represents a tool call that needs security evaluation. */
456
+ interface ExecutionRequest {
457
+ readonly context: SecurityContext;
458
+ readonly toolName: string;
459
+ readonly serverName: string;
460
+ readonly arguments: Readonly<Record<string, unknown>>;
461
+ readonly requiredPermission: Permission;
462
+ readonly timestamp: string;
463
+ }
464
+ /** Discriminated union on `status` for exhaustive matching. */
465
+ type ExecutionResult = ExecutionResultAllowed | ExecutionResultDenied | ExecutionResultError;
466
+ interface ExecutionResultAllowed {
467
+ readonly status: 'ALLOWED';
468
+ readonly request: ExecutionRequest;
469
+ readonly decision: PolicyDecision;
470
+ readonly toolResult: unknown;
471
+ readonly durationMs: number;
472
+ readonly timestamp: string;
473
+ }
474
+ interface ExecutionResultDenied {
475
+ readonly status: 'DENIED';
476
+ readonly request: ExecutionRequest;
477
+ readonly decision: PolicyDecision;
478
+ readonly timestamp: string;
479
+ }
480
+ interface ExecutionResultError {
481
+ readonly status: 'ERROR';
482
+ readonly request: ExecutionRequest;
483
+ readonly error: SolonGateError;
484
+ readonly timestamp: string;
485
+ }
486
+
487
+ /** Default policy effect when no rule matches: DENY */
488
+ declare const DEFAULT_POLICY_EFFECT: "DENY";
489
+ /** Maximum number of rules in a single PolicySet */
490
+ declare const MAX_RULES_PER_POLICY_SET = 1000;
491
+ /** Maximum depth for nested argument validation */
492
+ declare const MAX_ARGUMENT_DEPTH = 10;
493
+ /** Maximum size of tool arguments in bytes */
494
+ declare const MAX_ARGUMENTS_SIZE_BYTES = 1048576;
495
+ /** Maximum length of a tool name */
496
+ declare const MAX_TOOL_NAME_LENGTH = 256;
497
+ /** Maximum length of a server name */
498
+ declare const MAX_SERVER_NAME_LENGTH = 256;
499
+ /** Default rate limit per tool per minute */
500
+ declare const DEFAULT_RATE_LIMIT_PER_MINUTE = 60;
501
+ /** Maximum rate limit per tool per minute */
502
+ declare const MAX_RATE_LIMIT_PER_MINUTE = 10000;
503
+ /** Security context timeout in milliseconds (5 minutes) */
504
+ declare const SECURITY_CONTEXT_TIMEOUT_MS: number;
505
+ /** Policy evaluation timeout in milliseconds (100ms) */
506
+ declare const POLICY_EVALUATION_TIMEOUT_MS = 100;
507
+ /** Default maximum length per string argument */
508
+ declare const INPUT_GUARD_MAX_LENGTH = 4096;
509
+ /** Shannon entropy threshold for encoded payload detection */
510
+ declare const INPUT_GUARD_ENTROPY_THRESHOLD = 4.5;
511
+ /** Minimum string length before entropy check applies */
512
+ declare const INPUT_GUARD_MIN_ENTROPY_LENGTH = 32;
513
+ /** Maximum wildcards allowed per value */
514
+ declare const INPUT_GUARD_MAX_WILDCARDS = 3;
515
+ /** Default capability token TTL in seconds */
516
+ declare const TOKEN_DEFAULT_TTL_SECONDS = 30;
517
+ /** Minimum secret key length for HMAC signing */
518
+ declare const TOKEN_MIN_SECRET_LENGTH = 32;
519
+ /** Maximum token age before forced expiry (5 minutes) */
520
+ declare const TOKEN_MAX_AGE_SECONDS = 300;
521
+ /** Default sliding window size in milliseconds (1 minute) */
522
+ declare const RATE_LIMIT_WINDOW_MS = 60000;
523
+ /** Maximum entries to keep per tool before cleanup */
524
+ declare const RATE_LIMIT_MAX_ENTRIES = 10000;
525
+ /** Warning messages for unsafe configurations. */
526
+ declare const UNSAFE_CONFIGURATION_WARNINGS: {
527
+ readonly WILDCARD_ALLOW: "Wildcard ALLOW rules grant permission to ALL tools. This bypasses the default-deny model.";
528
+ readonly TRUSTED_LEVEL_EXTERNAL: "Setting trust level to TRUSTED for external requests bypasses all security checks.";
529
+ readonly WRITE_WITHOUT_READ: "Granting WRITE without READ is unusual and may indicate a misconfiguration.";
530
+ readonly EXECUTE_WITHOUT_REVIEW: "EXECUTE permission allows tools to perform arbitrary actions. Review carefully.";
531
+ readonly RATE_LIMIT_ZERO: "A rate limit of 0 means unlimited calls. This removes protection against runaway loops.";
532
+ readonly DISABLED_VALIDATION: "Disabling schema validation removes input sanitization protections.";
533
+ };
534
+
535
+ /**
536
+ * Types that bridge between the MCP protocol and SolonGate's type system.
537
+ * Adapts MCP SDK types without creating a hard dependency.
538
+ */
539
+ interface McpToolDefinition {
540
+ readonly name: string;
541
+ readonly description?: string;
542
+ readonly inputSchema: {
543
+ readonly type: 'object';
544
+ readonly properties?: Record<string, unknown>;
545
+ readonly required?: readonly string[];
546
+ };
547
+ }
548
+ interface McpCallToolParams {
549
+ readonly name: string;
550
+ readonly arguments?: Record<string, unknown>;
551
+ }
552
+ interface McpCallToolResult {
553
+ readonly content: readonly McpToolResultContent[];
554
+ readonly isError?: boolean;
555
+ readonly structuredContent?: unknown;
556
+ }
557
+ type McpToolResultContent = {
558
+ readonly type: 'text';
559
+ readonly text: string;
560
+ } | {
561
+ readonly type: 'image';
562
+ readonly data: string;
563
+ readonly mimeType: string;
564
+ } | {
565
+ readonly type: 'resource';
566
+ readonly resource: unknown;
567
+ };
568
+ /** Wraps denied tool calls in MCP error responses. */
569
+ declare function createDeniedToolResult(reason: string): McpCallToolResult;
570
+
571
+ /**
572
+ * Result of schema validation.
573
+ * Always includes structured errors for programmatic handling.
574
+ */
575
+ interface SchemaValidationResult {
576
+ readonly valid: boolean;
577
+ readonly errors: readonly string[];
578
+ readonly sanitized: Readonly<Record<string, unknown>> | null;
579
+ }
580
+ /**
581
+ * Options for schema validation behavior.
582
+ */
583
+ interface SchemaValidatorOptions {
584
+ readonly maxDepth?: number;
585
+ readonly maxSizeBytes?: number;
586
+ readonly stripUnknown?: boolean;
587
+ }
588
+ /**
589
+ * Validates tool input against a Zod schema with strict security enforcement.
590
+ *
591
+ * - Unknown fields are REJECTED (no additionalProperties)
592
+ * - Type mismatches are REJECTED
593
+ * - Required fields are ENFORCED
594
+ * - Recursive depth is limited
595
+ * - Argument size is limited
596
+ */
597
+ declare function validateToolInput(schema: ZodTypeAny, input: unknown, options?: SchemaValidatorOptions): SchemaValidationResult;
598
+ /**
599
+ * Creates a strict Zod object schema that rejects unknown fields.
600
+ * Wraps z.object().strict() for convenience.
601
+ */
602
+ declare function createStrictSchema(shape: Record<string, ZodTypeAny>): z.ZodObject<Record<string, ZodTypeAny>, 'strict'>;
603
+
604
+ /**
605
+ * Input Guard: detects and blocks dangerous patterns in tool arguments.
606
+ *
607
+ * Prevents physical execution of injected instructions by checking for:
608
+ * - Path traversal attacks (../, ..\, encoded variants)
609
+ * - Shell injection (;, |, &, `, $(), etc.)
610
+ * - Wildcard abuse (**, recursive globs)
611
+ * - Excessive length
612
+ * - High-entropy payloads (potential encoded exploits)
613
+ */
614
+ /** Threat type detected by input guard. */
615
+ type ThreatType = 'PATH_TRAVERSAL' | 'SHELL_INJECTION' | 'WILDCARD_ABUSE' | 'LENGTH_EXCEEDED' | 'HIGH_ENTROPY' | 'SSRF' | 'SQL_INJECTION';
616
+ /** A detected threat with details. */
617
+ interface DetectedThreat {
618
+ readonly type: ThreatType;
619
+ readonly field: string;
620
+ readonly value: string;
621
+ readonly description: string;
622
+ }
623
+ /** Result of sanitization check. */
624
+ interface SanitizationResult {
625
+ readonly safe: boolean;
626
+ readonly threats: readonly DetectedThreat[];
627
+ }
628
+ /** Configuration for input guard checks. */
629
+ interface InputGuardConfig {
630
+ readonly pathTraversal: boolean;
631
+ readonly shellInjection: boolean;
632
+ readonly wildcardAbuse: boolean;
633
+ readonly lengthLimit: number;
634
+ readonly entropyLimit: boolean;
635
+ readonly ssrf: boolean;
636
+ readonly sqlInjection: boolean;
637
+ }
638
+ declare const DEFAULT_INPUT_GUARD_CONFIG: Readonly<InputGuardConfig>;
639
+ declare function detectPathTraversal(value: string): boolean;
640
+ declare function detectShellInjection(value: string): boolean;
641
+ declare function detectWildcardAbuse(value: string): boolean;
642
+ declare function detectSSRF(value: string): boolean;
643
+ declare function detectSQLInjection(value: string): boolean;
644
+ declare function checkLengthLimits(value: string, maxLength?: number): boolean;
645
+ declare function checkEntropyLimits(value: string): boolean;
646
+ /**
647
+ * Runs all input guard checks on a value.
648
+ * Returns structured result with all detected threats.
649
+ */
650
+ declare function sanitizeInput(field: string, value: unknown, config?: InputGuardConfig): SanitizationResult;
651
+
652
+ /**
653
+ * Capability Token: a signed, short-lived, single-use token
654
+ * that authorizes execution of specific tools within specific scopes.
655
+ *
656
+ * Security properties:
657
+ * - Short-lived: TTL defaults to 30 seconds
658
+ * - Single-use: nonce prevents replay attacks
659
+ * - Scoped: limited to specific tools and servers
660
+ * - Signed: HMAC-SHA256 prevents forgery
661
+ */
662
+ interface CapabilityToken {
663
+ readonly jti: string;
664
+ readonly iss: string;
665
+ readonly sub: string;
666
+ readonly iat: number;
667
+ readonly exp: number;
668
+ readonly permissions: readonly Permission[];
669
+ readonly toolScope: readonly string[];
670
+ readonly serverScope: readonly string[];
671
+ readonly pathScope?: readonly string[];
672
+ }
673
+ /**
674
+ * Configuration for token issuance.
675
+ */
676
+ interface TokenConfig {
677
+ readonly secret: string;
678
+ readonly ttlSeconds: number;
679
+ readonly algorithm: 'HS256';
680
+ readonly issuer: string;
681
+ }
682
+ /**
683
+ * Default token configuration.
684
+ * Secret must be provided - no default.
685
+ */
686
+ declare const DEFAULT_TOKEN_TTL_SECONDS = 30;
687
+ declare const TOKEN_ALGORITHM: "HS256";
688
+ declare const MIN_SECRET_LENGTH = 32;
689
+ /**
690
+ * Result of token verification.
691
+ */
692
+ interface TokenVerificationResult {
693
+ readonly valid: boolean;
694
+ readonly payload?: CapabilityToken;
695
+ readonly reason?: string;
696
+ }
697
+
698
+ export { type CapabilityToken, DEFAULT_INPUT_GUARD_CONFIG, DEFAULT_POLICY_EFFECT, DEFAULT_RATE_LIMIT_PER_MINUTE, DEFAULT_TOKEN_TTL_SECONDS, type DetectedThreat, type ExecutionContext, type ExecutionRequest, type ExecutionResult, type ExecutionResultAllowed, type ExecutionResultDenied, type ExecutionResultError, INPUT_GUARD_ENTROPY_THRESHOLD, INPUT_GUARD_MAX_LENGTH, INPUT_GUARD_MAX_WILDCARDS, INPUT_GUARD_MIN_ENTROPY_LENGTH, type InputGuardConfig, InputGuardError, MAX_ARGUMENTS_SIZE_BYTES, MAX_ARGUMENT_DEPTH, MAX_RATE_LIMIT_PER_MINUTE, MAX_RULES_PER_POLICY_SET, MAX_SERVER_NAME_LENGTH, MAX_TOOL_NAME_LENGTH, MIN_SECRET_LENGTH, type McpCallToolParams, type McpCallToolResult, type McpToolDefinition, type McpToolResultContent, NO_PERMISSIONS, NetworkError, POLICY_EVALUATION_TIMEOUT_MS, Permission, PermissionSchema, type PermissionSet, type PolicyDecision, PolicyDeniedError, PolicyEffect, type PolicyRule, PolicyRuleSchema, type PolicySet, PolicySetSchema, RATE_LIMIT_MAX_ENTRIES, RATE_LIMIT_WINDOW_MS, READ_ONLY, RateLimitError, SECURITY_CONTEXT_TIMEOUT_MS, type SanitizationResult, SchemaValidationError, type SchemaValidationResult, type SchemaValidatorOptions, type SecurityContext, SolonGateError, TOKEN_ALGORITHM, TOKEN_DEFAULT_TTL_SECONDS, TOKEN_MAX_AGE_SECONDS, TOKEN_MIN_SECRET_LENGTH, type ThreatType, type TokenConfig, type TokenVerificationResult, type ToolCapability, ToolNotFoundError, TrustEscalationError, TrustLevel, UNSAFE_CONFIGURATION_WARNINGS, UnsafeConfigurationError, assertValidTransition, checkEntropyLimits, checkLengthLimits, createDeniedToolResult, createPermissionSet, createSecurityContext, createStrictSchema, createToolCapability, detectPathTraversal, detectSQLInjection, detectSSRF, detectShellInjection, detectWildcardAbuse, hasAllPermissions, hasPermission, isValidTrustLevel, permissionForMethod, sanitizeInput, validateToolInput };