All files / src/tools/shared errors.ts

100% Statements 7/7
100% Branches 4/4
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                20x 20x 20x 20x 20x 20x 7x        
/**
 * Structured error class for MCP tool error reporting.
 *
 * ISMS Policy: SC-002 (Input Validation), AC-003 (Least Privilege), AU-002 (Audit Logging)
 */
 
/**
 * Structured error class that all MCP tools use for consistent error reporting.
 * Ensures tool name, operation, and safe context are always included without
 * leaking internal implementation details to clients.
 */
export class ToolError extends Error {
  readonly toolName: string;
  readonly operation: string;
  readonly isRetryable: boolean;
  override readonly cause?: Error;
 
  constructor(options: {
    toolName: string;
    operation: string;
    message: string;
    isRetryable?: boolean;
    cause?: unknown;
  }) {
    super(`[${options.toolName}] ${options.operation}: ${options.message}`);
    this.name = 'ToolError';
    this.toolName = options.toolName;
    this.operation = options.operation;
    this.isRetryable = options.isRetryable ?? false;
    if (options.cause instanceof Error) {
      this.cause = options.cause;
    }
  }
}