* 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
)
| 1682 | * exhaust memory before any real work runs. |
| 1683 | */ |
| 1684 | private validateString( |
| 1685 | value: unknown, |
| 1686 | name: string, |
| 1687 | maxLength: number = MAX_INPUT_LENGTH |
| 1688 | ): string | ToolResult { |
| 1689 | if (typeof value !== 'string' || value.length === 0) { |
| 1690 | return this.errorResult(`${name} must be a non-empty string`); |
| 1691 | } |
| 1692 | if (value.length > maxLength) { |
| 1693 | return this.errorResult( |
| 1694 | `${name} exceeds maximum length of ${maxLength} characters (got ${value.length})` |
| 1695 | ); |
| 1696 | } |
| 1697 | return value; |
| 1698 | } |
| 1699 | |
| 1700 | /** |
| 1701 | * Validate an optional path-like string input. Returns the value if |
no test coverage detected