38 MCP tools that give AI agents live access to your Rails schema, models, routes & conventions.
[!TIP] Always start with
rails ai:doctor. It runs 23 checks and catches most issues automatically.
rails ai:doctor # In-Gemfile
rails-ai-context doctor # Standalone
This runs 23 checks and returns an AI readiness score (0-100). Each failed check includes a fix suggestion.
gem install rails-ai-context
# or
bundle update rails-ai-context
The gem is likely in a :development group but you’re running in another environment:
# config/initializers/rails_ai_context.rb
if defined?(RailsAiContext)
RailsAiContext.configure do |config|
# ...
end
end
The if defined? guard prevents crashes when the gem isn’t loaded.
File system permissions. Check that your user can write to the project directory:
ls -la .mcp.json .cursor/ .vscode/ .github/
.mcp.json.cursor/mcp.json.vscode/mcp.jsonopencode.json.codex/config.tomlbundle exec rails ai:serve
# Should output nothing (waiting for stdio input)
# Ctrl+C to stop
rails generate rails_ai_context:install
Check for Bundler/Ruby path issues:
which bundle
which rails
ruby -v
For Codex CLI specifically, the env section in .codex/config.toml must match your current Ruby environment. Re-run install if you changed Ruby versions.
rails runner "puts 'ok'"ls db/schema.rb or ls db/structure.sqlrails ai:doctorconfig.cache_ttl — lower values mean more frequent re-introspectionconfig.preset — :standard is faster than :fullrails ai:doctor — it checks schema size and view countls app/models/ls db/schema.rbconfig.context_mode = :fullrails ai:contextRegeneration is not automatic unless you’re running watch mode:
rails ai:watch
Or regenerate manually:
rails ai:context
The gem uses section markers (<!-- BEGIN/END rails-ai-context -->) to preserve user content. Content outside these markers is preserved. If markers were removed, the gem may overwrite.
Use compact mode (default):
config.context_mode = :compact
config.claude_max_lines = 150
Or disable root files and use only split rules:
config.generate_root_files = false
By design. Override if needed:
config.allow_query_in_production = true
The 4-layer SQL validator blocks write operations and injection patterns. Ensure you’re only running SELECT queries.
Common false positives:
#>>) → preserved correctly since v5.6.0Columns matching sensitive patterns are redacted. Configure:
config.query_redacted_columns = %w[password_digest encrypted_password]
config.search_extensions defaults to common web typesconfig.excluded_paths excludes node_modules, tmp, log, etc.Install ripgrep for faster search:
# macOS
brew install ripgrep
# Ubuntu
apt install ripgrep
The gem falls back to Ruby regex if ripgrep isn’t available. Search still works, just slower on large codebases.
Standalone mode pre-loads the gem before Rails boot and restores $LOAD_PATH entries stripped by Bundler.setup. If this fails:
gem list rails-ai-contextruby -vYAML config (.rails-ai-context.yml) is skipped if an initializer runs. Check precedence:
config/initializers/rails_ai_context.rb) — highest priority.rails-ai-context.yml)Corrupted YAML degrades gracefully with a warning.
The rails_security_scan tool requires Brakeman:
gem install brakeman
# or
bundle add brakeman --group development
Without it, the tool reports “not installed” but the gem works fine otherwise.
:standard preset (17 introspectors vs 31)config.cache_ttl = 300rails ai:doctor warns if too largeIncrease the debounce:
config.live_reload_debounce = 3.0 # seconds (default: 1.5)
Or disable:
config.live_reload = false
rails ai:doctor first — it catches most issues