Class: RailVerdict::MCP::Tools::GetPRIntelligence

Inherits:
Object
  • Object
show all
Defined in:
lib/rail_verdict/mcp/tools/get_pr_intelligence.rb

Instance Method Summary collapse

Constructor Details

#initialize(server:) ⇒ GetPRIntelligence

Returns a new instance of GetPRIntelligence.



9
10
11
# File 'lib/rail_verdict/mcp/tools/get_pr_intelligence.rb', line 9

def initialize(server:)
  @server = server
end

Instance Method Details

#call(**_rest) ⇒ Object



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
96
97
# File 'lib/rail_verdict/mcp/tools/get_pr_intelligence.rb', line 50

def call(**_rest)
  root = @server.repository_root
  effective_paths = begin
    RailVerdict::Check.effective_input_paths(root: File.realpath(root), config_path: File.join(File.realpath(root), ".railverdict.yml"))
  rescue StandardError
    nil
  end
  current_state = RailVerdict::RepositoryState.capture(repository_root: root, configuration_paths: effective_paths)
  current_env = begin
    outcome = @server.cache.fetch_outcome
    config = outcome&.configuration
    RailVerdict::VerificationEnvironment.capture(repository_root: root, configuration: config)
  rescue StandardError
    nil
  end
  case @server.cache.verification_state(current_state, current_env)
  when "fresh"
    entry = @server.cache.fresh_entry(current_state, current_env)
    document = entry&.pr_intelligence_document
    if document.is_a?(Hash)
      payload = { "status" => "fresh", "pr_intelligence" => Serializers.scrub(document) }
    else
      payload = {
        "status" => "state_unavailable",
        "code" => "pr_intelligence_unavailable",
        "message" => "last verification did not produce PR Intelligence (changed scope required)"
      }
    end
    Serializers.tool_response(payload, error: false)
  when "stale"
    Serializers.tool_response(
      { "status" => "verification_required", "code" => "stale_intelligence", "message" => "repository state changed since the last verify; run verify again" },
      error: false
    )
  when "state_unavailable"
    Serializers.tool_response(
      { "status" => "state_unavailable", "code" => "repository_state_unavailable", "message" => "current repository state could not be determined fail-closed" },
      error: false
    )
  else
    Serializers.tool_response(
      { "status" => "verification_required", "code" => "no_verification_yet", "message" => "run verify before requesting PR intelligence" },
      error: false
    )
  end
rescue StandardError => e
  Serializers.error_response("get_pr_intelligence failed: #{e.message}", code: "internal_error")
end

#tool_annotationsObject



46
47
48
# File 'lib/rail_verdict/mcp/tools/get_pr_intelligence.rb', line 46

def tool_annotations
  { read_only_hint: true, destructive_hint: false, idempotent_hint: true, open_world_hint: false, title: tool_title }
end

#tool_descriptionObject



21
22
23
# File 'lib/rail_verdict/mcp/tools/get_pr_intelligence.rb', line 21

def tool_description
  "Return the PR Intelligence document from the most recent changed-scope verify, WITHOUT rerunning analyzers. Same canonical verification as the receipt. Stale or unavailable evidence is reported explicitly."
end

#tool_input_schemaObject



25
26
27
28
29
30
31
# File 'lib/rail_verdict/mcp/tools/get_pr_intelligence.rb', line 25

def tool_input_schema
  {
    type: "object",
    properties: {},
    additionalProperties: false
  }
end

#tool_nameObject



13
14
15
# File 'lib/rail_verdict/mcp/tools/get_pr_intelligence.rb', line 13

def tool_name
  "get_pr_intelligence"
end

#tool_output_schemaObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rail_verdict/mcp/tools/get_pr_intelligence.rb', line 33

def tool_output_schema
  {
    type: "object",
    properties: {
      status: { type: "string", enum: %w[fresh stale verification_required state_unavailable] },
      pr_intelligence: { type: ["object", "null"] },
      code: { type: "string" },
      message: { type: "string" }
    },
    required: %w[status]
  }
end

#tool_titleObject



17
18
19
# File 'lib/rail_verdict/mcp/tools/get_pr_intelligence.rb', line 17

def tool_title
  "Get PR intelligence"
end