* Validate that a value is a non-empty string within length bounds. * * The `maxLength` cap protects against MCP clients that ship huge * payloads (10MB+ query strings either by accident or maliciously). * Without this, a single oversized input can pin the FTS5 index or * exhaust memo
(
value: unknown,
name: string,
maxLength: number = MAX_INPUT_LENGTH
)
| 2803 | * exhaust memory before any real work runs. |
| 2804 | */ |
| 2805 | private validateString( |
| 2806 | value: unknown, |
| 2807 | name: string, |
| 2808 | maxLength: number = MAX_INPUT_LENGTH |
| 2809 | ): string | ToolResult { |
| 2810 | if (typeof value !== 'string' || value.length === 0) { |
| 2811 | return this.errorResult(`${name} must be a non-empty string`); |
| 2812 | } |
| 2813 | if (value.length > maxLength) { |
| 2814 | return this.errorResult( |
| 2815 | `${name} exceeds maximum length of ${maxLength} characters (got ${value.length})` |
| 2816 | ); |
| 2817 | } |
| 2818 | return value; |
| 2819 | } |
| 2820 | |
| 2821 | /** |
| 2822 | * Validate an optional path-like string input. Returns the value if |
no test coverage detected