Class: SimpleCovMcp::Tools::ValidateTool
- Defined in:
- lib/simplecov_mcp/tools/validate_tool.rb
Constant Summary
Constants inherited from BaseTool
BaseTool::COMMON_PROPERTIES, BaseTool::ERROR_MODE_PROPERTY, BaseTool::FILE_INPUT_SCHEMA, BaseTool::PATH_PROPERTY, BaseTool::TRACKED_GLOBS_PROPERTY
Class Method Summary collapse
Methods inherited from BaseTool
coverage_schema, handle_mcp_error, input_schema_def, respond_json, with_error_handling
Class Method Details
.call(code: nil, file: nil, root: '.', resultset: nil, staleness: :off, error_mode: 'log', server_context:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/simplecov_mcp/tools/validate_tool.rb', line 37 def call(code: nil, file: nil, root: '.', resultset: nil, staleness: :off, error_mode: 'log', server_context:) with_error_handling('ValidateTool', error_mode: error_mode) do # Re-use logic from ValidateCommand, but adapt for MCP return format require_relative '../cli' # Create a minimal CLI shim to reuse command logic cli = CoverageCLI.new cli.config.root = root cli.config.resultset = resultset cli.config.staleness = staleness.to_sym cli.config.error_mode = error_mode.to_sym # We need to capture the boolean result instead of letting it exit # Commands::ValidateCommand is designed to exit, so we'll use the model and evaluator directly # This duplicates some logic from ValidateCommand#execute but avoids the exit(status) call model = CoverageModel.new(**cli.config.) result = if code PredicateEvaluator.evaluate_code(code, model) elsif file # Resolve file path relative to root if needed predicate_path = File.(file, root) PredicateEvaluator.evaluate_file(predicate_path, model) else raise UsageError, "Either 'code' or 'file' must be provided" end respond_json({ result: result }, name: 'validate_result.json', pretty: true) end end |