Class: RailsMcpServer::Analyzers::ProjectInfo

Inherits:
BaseAnalyzer
  • Object
show all
Defined in:
lib/rails-mcp-server/analyzers/project_info.rb

Instance Method Summary collapse

Instance Method Details

#call(max_depth: 2, include_files: true, detail_level: "full") ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
# File 'lib/rails-mcp-server/analyzers/project_info.rb', line 4

def call(max_depth: 2, include_files: true, detail_level: "full")
  unless current_project
    message = "No active project. Please switch to a project first."
    log(:warn, message)
    return message
  end

  max_depth = [[max_depth.to_i, 1].max, 5].min # rubocop:disable Style/ComparableClamp
  detail_level = "full" unless %w[minimal summary full].include?(detail_level)

  gemfile_path = File.join(active_project_path, "Gemfile")
  gemfile_content = File.exist?(gemfile_path) ? File.read(gemfile_path) : "Gemfile not found"

  rails_version = gemfile_content.match(/gem ['"]rails['"],\s*['"](.+?)['"]/)&.captures&.first || "Unknown"

  config_application_path = File.join(active_project_path, "config", "application.rb")
  is_api_only = File.exist?(config_application_path) &&
    File.read(config_application_path).include?("config.api_only = true")

  log(:info, "Project info: Rails v#{rails_version}, API-only: #{is_api_only}")

  case detail_level
  when "minimal"
    <<~INFO
      Project: #{current_project}
      Path: #{active_project_path}
      Rails version: #{rails_version}
      API only: #{is_api_only ? "Yes" : "No"}
    INFO

  when "summary"
    key_dirs = get_key_directories
    <<~INFO
      Project: #{current_project}
      Path: #{active_project_path}
      Rails version: #{rails_version}
      API only: #{is_api_only ? "Yes" : "No"}

      Key directories:
      #{key_dirs}
    INFO

  when "full"
    <<~INFO
      Current project: #{current_project}
      Path: #{active_project_path}
      Rails version: #{rails_version}
      API only: #{is_api_only ? "Yes" : "No"}

      Project structure:
      #{get_directory_structure(active_project_path, max_depth: max_depth, include_files: include_files)}
    INFO
  end
end