* 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
)
| 1160 | * exhaust memory before any real work runs. |
| 1161 | */ |
| 1162 | private validateString( |
| 1163 | value: unknown, |
| 1164 | name: string, |
| 1165 | maxLength: number = MAX_INPUT_LENGTH |
| 1166 | ): string | ToolResult { |
| 1167 | if (typeof value !== 'string' || value.length === 0) { |
| 1168 | return this.errorResult(`${name} must be a non-empty string`); |
| 1169 | } |
| 1170 | if (value.length > maxLength) { |
| 1171 | return this.errorResult( |
| 1172 | `${name} exceeds maximum length of ${maxLength} characters (got ${value.length})` |
| 1173 | ); |
| 1174 | } |
| 1175 | return value; |
| 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * Validate an optional path-like string input. Returns the value if |
no test coverage detected