Class: Klee::MCP::Tools::CodebaseSummary

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/klee/mcp/tools/codebase_summary.rb

Class Method Summary collapse

Class Method Details

.call(patterns:, threshold: 2, ignore: [], server_context: nil) ⇒ Object



30
31
32
33
34
35
36
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
# File 'lib/klee/mcp/tools/codebase_summary.rb', line 30

def call(patterns:, threshold: 2, ignore: [], server_context: nil)
  validator = Klee::MCP::PathValidator.new
  validator.validate!(patterns)

  codebase = Klee.scan(*patterns, ignore: ignore, threshold: threshold)

  ranked = codebase.concepts.rank
  top_concepts = ranked.first(15).map(&:first)

  clusters = codebase.collaborators.clusters

  total_classes = Set.new
  total_methods = Set.new
  total_identifiers = 0

  codebase.concepts.each do |_, locs|
    total_classes.merge(locs[:classes])
    total_methods.merge(locs[:methods])
    total_identifiers += locs[:classes].size + locs[:methods].size
  end

  unique_concepts = ranked.keys.size
  vocabulary_richness = total_identifiers.zero? ? 0 : (unique_concepts.to_f / total_identifiers).round(2)

  result = {
    top_concepts: top_concepts,
    concept_clusters: clusters.size,
    total_classes: total_classes.size,
    total_methods: total_methods.size,
    vocabulary_richness: vocabulary_richness,
    cluster_preview: clusters.first(3).map { |c| c.to_a.sort }
  }

  ::MCP::Tool::Response.new([{
    type: "text",
    text: JSON.pretty_generate(result)
  }])
end