* 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
)
| 2735 | * exhaust memory before any real work runs. |
| 2736 | */ |
| 2737 | private validateString( |
| 2738 | value: unknown, |
| 2739 | name: string, |
| 2740 | maxLength: number = MAX_INPUT_LENGTH |
| 2741 | ): string | ToolResult { |
| 2742 | if (typeof value !== 'string' || value.length === 0) { |
| 2743 | return this.errorResult(`${name} must be a non-empty string`); |
| 2744 | } |
| 2745 | if (value.length > maxLength) { |
| 2746 | return this.errorResult( |
| 2747 | `${name} exceeds maximum length of ${maxLength} characters (got ${value.length})` |
| 2748 | ); |
| 2749 | } |
| 2750 | return value; |
| 2751 | } |
| 2752 | |
| 2753 | /** |
| 2754 | * Validate an optional path-like string input. Returns the value if |
no test coverage detected