* 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
)
| 1149 | * exhaust memory before any real work runs. |
| 1150 | */ |
| 1151 | private validateString( |
| 1152 | value: unknown, |
| 1153 | name: string, |
| 1154 | maxLength: number = MAX_INPUT_LENGTH |
| 1155 | ): string | ToolResult { |
| 1156 | if (typeof value !== 'string' || value.length === 0) { |
| 1157 | return this.errorResult(`${name} must be a non-empty string`); |
| 1158 | } |
| 1159 | if (value.length > maxLength) { |
| 1160 | return this.errorResult( |
| 1161 | `${name} exceeds maximum length of ${maxLength} characters (got ${value.length})` |
| 1162 | ); |
| 1163 | } |
| 1164 | return value; |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * Validate an optional path-like string input. Returns the value if |
no test coverage detected