38 MCP tools that give AI agents live access to your Rails schema, models, routes & conventions.
Use rails-ai-context without adding it to your Gemfile.
Quickstart · CLI Reference · Configuration · Troubleshooting
gem install rails-ai-context
cd your-rails-app
rails-ai-context init
Interactive setup asks:
Creates:
.rails-ai-context.yml — YAML configurationrails-ai-context serve # Start MCP server (stdio)
rails-ai-context serve --transport http --port 6029 # HTTP transport
rails-ai-context tool schema --table users # Run a tool
rails-ai-context tool --list # List all tools
rails-ai-context context # Generate context files
rails-ai-context doctor # Run diagnostics
rails-ai-context watch # Auto-regenerate on changes
rails-ai-context version # Show version
rails-ai-context before Bundler.setup$LOAD_PATH entries that Bundler.setup strips (since the gem isn’t in the Gemfile).rails-ai-context.yml instead of a Ruby initializerThis means you get the same 38 tools, same MCP server, same context generation — without touching the project’s Gemfile.
# .rails-ai-context.yml
ai_tools:
- claude
- cursor
tool_mode: mcp
preset: full
context_mode: compact
# MCP Server
cache_ttl: 60
max_tool_response_chars: 200000
http_port: 6029
# Query safety
query_timeout: 5
query_row_limit: 100
allow_query_in_production: false
# Filtering
excluded_models:
- ApplicationRecord
excluded_paths:
- node_modules
- tmp
- log
# Skip tools
skip_tools:
- rails_security_scan
Two config options are Ruby-only and can’t be set via YAML:
custom_tools — requires Ruby class referencesexcluded_concerns — requires Regex objectsFor these, use the initializer approach (in-Gemfile mode).
If both exist, the initializer takes priority over YAML:
config/initializers/rails_ai_context.rb (highest).rails-ai-context.ymlStandalone mode works with all Ruby version managers:
| Manager | Supported |
|---|---|
| rbenv | Yes |
| rvm | Yes |
| asdf | Yes |
| mise | Yes |
| chruby | Yes |
| System Ruby | Yes |
Codex CLI is special — it env_clear()s the process before spawning MCP servers. The install generator snapshots your Ruby environment variables (PATH, GEM_HOME, GEM_PATH, GEM_ROOT, RUBY_VERSION, BUNDLE_PATH) into .codex/config.toml so Codex can find Ruby and gems.
If you switch Ruby versions, re-run rails-ai-context init to update the snapshot.
You can switch freely:
# To switch to in-Gemfile:
bundle add rails-ai-context --group development
rails generate rails_ai_context:install
# To switch to standalone:
bundle remove rails-ai-context
rails-ai-context init
The MCP config files are updated automatically. Both modes generate identical context files and provide the same 38 tools.
rails-ai-context serveThe gem’s $LOAD_PATH restoration may have failed. Check:
gem list rails-ai-context # Is it installed?
ruby -v # Right Ruby version?
Check that no initializer exists — if config/initializers/rails_ai_context.rb runs, YAML is skipped.
The serve command waits for stdio input by design. Use doctor or tool --list to verify the gem works, then let your AI tool connect to the server.