* 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
)
| 2761 | * exhaust memory before any real work runs. |
| 2762 | */ |
| 2763 | private validateString( |
| 2764 | value: unknown, |
| 2765 | name: string, |
| 2766 | maxLength: number = MAX_INPUT_LENGTH |
| 2767 | ): string | ToolResult { |
| 2768 | if (typeof value !== 'string' || value.length === 0) { |
| 2769 | return this.errorResult(`${name} must be a non-empty string`); |
| 2770 | } |
| 2771 | if (value.length > maxLength) { |
| 2772 | return this.errorResult( |
| 2773 | `${name} exceeds maximum length of ${maxLength} characters (got ${value.length})` |
| 2774 | ); |
| 2775 | } |
| 2776 | return value; |
| 2777 | } |
| 2778 | |
| 2779 | /** |
| 2780 | * Validate an optional path-like string input. Returns the value if |
no test coverage detected