Class: RailVerdict::MCP::Tools::Investigate
- Inherits:
-
Object
- Object
- RailVerdict::MCP::Tools::Investigate
- Defined in:
- lib/rail_verdict/mcp/tools/investigate.rb
Instance Method Summary collapse
- #call(limit: nil, preview: nil, **_rest) ⇒ Object
-
#initialize(server:) ⇒ Investigate
constructor
A new instance of Investigate.
- #tool_annotations ⇒ Object
- #tool_description ⇒ Object
- #tool_input_schema ⇒ Object
- #tool_name ⇒ Object
- #tool_output_schema ⇒ Object
- #tool_title ⇒ Object
Constructor Details
#initialize(server:) ⇒ Investigate
Returns a new instance of Investigate.
7 8 9 |
# File 'lib/rail_verdict/mcp/tools/investigate.rb', line 7 def initialize(server:) @server = server end |
Instance Method Details
#call(limit: nil, preview: nil, **_rest) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rail_verdict/mcp/tools/investigate.rb', line 49 def call(limit: nil, preview: nil, **_rest) begin limit_v = limit.nil? ? 3 : limit unless limit_v.is_a?(Integer) && limit_v.between?(1, 3) raise ArgumentError, "limit must be an integer between 1 and 3" end preview_v = preview == true outcome = @server.cache.fetch_outcome unless outcome outcome = Check.execute(repository_root: @server.repository_root, config_path: File.join(@server.repository_root, ".railverdict.yml")) @server.cache.store_outcome(outcome) end if preview_v findings = Intelligence::Budget.select_findings(outcome.findings || [], limit: limit_v) manifests = findings.map do |f| Intelligence::ContextBuilder.build(outcome: outcome, finding_ref: f.id).to_json_hash rescue StandardError => e { "finding_id" => f.id, "error" => e. } end structured = { "preview" => true, "manifests" => manifests } structured = Serializers.scrub(structured) return Serializers.tool_response(structured, error: false) end unless ai_enabled?(outcome.configuration) return Serializers.error_response("AI is off — set ai.enabled=true and ai.remote.enabled=true in .railverdict.yml", code: "ai_disabled") end results = Intelligence::Orchestrator.investigate(outcome: outcome, configuration: outcome.configuration, limit: limit_v) payload = results.map do |r| if r[:failure] { "failure" => r[:failure].to_h, "analysis" => nil } else { "failure" => nil, "analysis" => r[:analysis]&.to_h } end end structured = { "results" => payload } structured = Serializers.scrub(structured) Serializers.tool_response(structured, error: false) rescue ArgumentError => e Serializers.error_response(e., code: "invalid_arguments") rescue StandardError => e Serializers.error_response("investigate failed: #{e.}", code: "internal_error") end end |
#tool_annotations ⇒ Object
45 46 47 |
# File 'lib/rail_verdict/mcp/tools/investigate.rb', line 45 def tool_annotations { read_only_hint: true, destructive_hint: false, idempotent_hint: true, open_world_hint: false, title: tool_title } end |
#tool_description ⇒ Object
19 20 21 |
# File 'lib/rail_verdict/mcp/tools/investigate.rb', line 19 def tool_description "Advisory AI — requires ai.enabled and ai.remote.enabled. Investigate up to 3 findings. Use preview to inspect manifests without network. Budgets enforced before provider. AI never changes gate." end |
#tool_input_schema ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rail_verdict/mcp/tools/investigate.rb', line 23 def tool_input_schema { type: "object", properties: { limit: { type: "integer", description: "Max findings to investigate (1..3, default 3)" }, preview: { type: "boolean", description: "If true, return manifests only (no provider calls)" } }, additionalProperties: false } end |
#tool_name ⇒ Object
11 12 13 |
# File 'lib/rail_verdict/mcp/tools/investigate.rb', line 11 def tool_name "investigate" end |
#tool_output_schema ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rail_verdict/mcp/tools/investigate.rb', line 34 def tool_output_schema { type: "object", properties: { preview: { type: "boolean" }, manifests: { type: "array" }, results: { type: "array" } } } end |
#tool_title ⇒ Object
15 16 17 |
# File 'lib/rail_verdict/mcp/tools/investigate.rb', line 15 def tool_title "Investigate findings (advisory AI)" end |