Class: RailsMcpCodeSearch::Tools::StatusTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/rails_mcp_code_search/tools/status_tool.rb

Class Method Summary collapse

Class Method Details

.call(server_context:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
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
# File 'lib/rails_mcp_code_search/tools/status_tool.rb', line 18

def self.call(server_context:)
  runtime = runtime_for(server_context:)
  worker = runtime.worker

  chunk_count = Chunk.count
  file_count = Chunk.distinct.pluck(:file_path).size

  state = if worker.state == :error
    "error"
  elsif worker.state == :indexing
    "indexing"
  elsif chunk_count == 0
    "empty"
  else
    "ready"
  end

  db_size = File.size(runtime.db_path) rescue 0

  top_chunks = Chunk.where("hit_count > 0").order(hit_count: :desc).limit(5).map do |c|
    { file_path: c.file_path, qualified_name: c.qualified_name, hit_count: c.hit_count }
  end

  text_response({
    state:,
    chunk_count:,
    file_count:,
    db_size_bytes: db_size,
    index_completeness: worker.state == :idle ? 1.0 : worker.progress,
    embedding_provider: runtime.embedding_adapter.class.name.split("::").last.sub("Adapter", "").downcase,
    embedding_dimensions: runtime.embedding_adapter.dimensions,
    project_path: runtime.project_path,
    indexing_errors: worker.errors.first(10),
    stats: {
      total_searches: Database::Metadata.get("total_searches").to_i,
      total_reindexes: Database::Metadata.get("total_reindexes").to_i,
      last_search_at: Database::Metadata.get("last_search_at"),
      last_reindex_at: Database::Metadata.get("last_reindex_at")
    },
    top_chunks_by_hits: top_chunks
  })
rescue => e
  error_response(error: "status_error", message: e.message, recoverable: true)
end