Class: RailsActiveMcp::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/rails_active_mcp/install/install_generator.rb

Constant Summary collapse

MCP_CLIENTS =
{
  'claude_code' => { name: 'Claude Code', path: '.mcp.json', key: 'mcpServers' },
  'cursor' => { name: 'Cursor', path: '.cursor/mcp.json', key: 'mcpServers' },
  'vscode' => { name: 'VS Code / GitHub Copilot', path: '.vscode/mcp.json', key: 'servers' },
  'claude_desktop' => { name: 'Claude Desktop', path: nil },
  'windsurf' => { name: 'Windsurf', path: nil }
}.freeze

Instance Method Summary collapse

Instance Method Details

#create_initializerObject



18
19
20
# File 'lib/generators/rails_active_mcp/install/install_generator.rb', line 18

def create_initializer
  template 'initializer.rb', 'config/initializers/rails_active_mcp.rb'
end

#create_mcp_client_configsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/rails_active_mcp/install/install_generator.rb', line 36

def create_mcp_client_configs
  return unless behavior == :invoke

  say "\nWhich MCP clients do you use?", :green
  say '(Select all that apply, separated by commas)', :yellow
  say ''

  client_keys = MCP_CLIENTS.keys
  client_keys.each_with_index do |key, index|
    say "  #{index + 1}. #{MCP_CLIENTS[key][:name]}", :cyan
  end
  say "  #{client_keys.size + 1}. Skip (configure manually later)", :cyan
  say ''

  response = ask('Enter your choices (e.g. 1,2,3):', :green)
  @selected_clients = parse_client_selections(response, client_keys)

  generate_client_configs
end

#create_mcp_configObject



32
33
34
# File 'lib/generators/rails_active_mcp/install/install_generator.rb', line 32

def create_mcp_config
  template 'mcp.ru', 'mcp.ru'
end

#create_server_scriptObject



27
28
29
30
# File 'lib/generators/rails_active_mcp/install/install_generator.rb', line 27

def create_server_script
  template 'rails-active-mcp-server', 'bin/rails-active-mcp-server'
  chmod 'bin/rails-active-mcp-server', 0o755
end

#create_wrapper_scriptObject



22
23
24
25
# File 'lib/generators/rails_active_mcp/install/install_generator.rb', line 22

def create_wrapper_script
  template 'rails-active-mcp-wrapper', 'bin/rails-active-mcp-wrapper'
  chmod 'bin/rails-active-mcp-wrapper', 0o755
end

#show_post_install_instructionsObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/generators/rails_active_mcp/install/install_generator.rb', line 56

def show_post_install_instructions
  return unless behavior == :invoke

  say "\n#{'=' * 50}", :green
  say 'Rails Active MCP Installation Complete!', :green
  say('=' * 50, :green)

  show_created_files
  show_quick_test
  show_global_client_instructions
  show_available_tools
  show_example_prompts
  show_troubleshooting
  show_next_steps
end