by crisnahine
38 MCP tools that give AI agents live access to your Rails schema, models, routes & conventions. Works with Claude Code, Cursor, Copilot, OpenCode, Codex CLI. Zero config.
# Add to your Claude Code skills
git clone https://github.com/crisnahine/rails-ai-contextYour AI is guessing your Rails app. Every guess costs you time.
You've seen it. Your AI:
user.posts when it's user.articlesNo comments yet. Be the first to share your thoughts!
before_action filters from parent controllers — then wonders why auth failsYou catch it. You fix it. You re-prompt. It breaks something else.
The real cost of AI coding isn't the tokens — it's the correction loop. Every guess is a round-trip: you catch it, you fix it, you re-prompt, and something adjacent breaks. This gem kills the guessing at its source.
gem "rails-ai-context", group: :development
rails generate rails_ai_context:install
gem install rails-ai-context
cd your-rails-app
rails-ai-context init # interactive setup
rails-ai-context serve # start MCP server

Now your AI doesn't guess — it asks your app directly. 38 tools and 5 resource templates that query your schema, models, routes, controllers, views, and conventions on demand. Model introspection uses Prism AST parsing — every result carries a [VERIFIED] or [INFERRED] confidence tag so AI knows what's ground truth and what needs runtime checking.

One call returns: definition + source code + every caller grouped by type + tests. Replaces 4-5 sequential file reads.
Real scenarios where AI goes sideways — and what it does instead with ground truth:
| You ask AI to... | Without — AI guesses | With — AI verifies first |
|:-----|:-----|:-----|
| Add a subscription_tier column to users | Writes the migration, duplicates an existing column | Reads live schema, spots subscription_status already exists, asks before migrating |
| Call user.posts in a controller | Uses the guess; runtime NoMethodError | Resolves the actual association (user.articles) from the model |
| Write tests for a new model | Scaffolds with FactoryBot | Detects your fixture-based suite and matches it |
| Fix a failing create action | Misses inherited before_action :authenticate_user! | Returns parent-controller filters inline with the action source |
| Build a dashboard page | Invents Tailwind classes from memory | Returns your actual button/card/alert patterns, copy-paste ready |
| Trace where can_cook? is used | Reads 6 files sequentially, still misses callers | Single call: definition + source + every caller + tests |
Run these before and after installing to see what changes in your codebase:
# Schema: does AI know what columns exist?
rails 'ai:tool[schema]' table=users
# Trace: find every caller of a method across the codebase
rails 'ai:tool[search_code]' pattern=your_method match_type=trace
# Model: associations, scopes, callbacks, concerns — all resolved
rails 'ai:tool[model_details]' model=User
# Controllers: action source + inherited filters + strong params in one shot
rails 'ai:tool[controllers]' controller=UsersController action=create
Compare what AI outputs with and without these tools wired in. The difference is measured in corrections avoided, not bytes saved.
AI calls tools directly via the protocol. Each AI tool gets its own config file — auto-detected on project open.
rails ai:serve
→ rails_search_code(pattern: "can_cook?", match_type: "trace")
→ rails_get_schema(table: "users")
→ rails_analyze_feature(feature: "billing")
Mount inside your Rails app — inherits routing, auth, and middleware.
# config/routes.rb
mount RailsAiContext::Engine, at: "/mcp"
Native Rails controller transport. No separate process needed.
Same 38 tools, no server needed. Works in any terminal, any AI tool.
rails 'ai:tool[search_code]' pattern="can_cook?" match_type=trace
rails 'ai:tool[schema]' table=users
rails 'ai:tool[analyze_feature]' feature=billing
Full Guide → — every command, every parameter, every configuration option.
rails 'ai:tool[schema]' table=users
## Table: users
| Column | Type | Null | Default |
|---------------------|---------|------|---------|
| email | string | NO | [unique] |
| subscription_status | string | yes | "free" |
| created_at | datetime| NO | |
AI sees subscription_status already exists. Checks the model, then generates a correct migration — first attempt.
rails 'ai:tool[controllers]' controller=CooksController action=create
# CooksController#create
Filters: before_action :authenticate_user!, before_action :set_cook (only: show, edit)
Strong params: cook_params → name, specialty, bio
Renders: redirect_to @cook | render :new
AI sees the inherited authenticate_user! filter, the actual strong params, and the render paths. No guessing.
# Check existing view patterns
rails 'ai:tool[view]' controller=dashboard
# → templates with ivars, Turbo frames, Stimulus controllers, partial locals
# See existing components + usage examples
rails 'ai:tool[component_catalog]' detail=standard
# → ViewComponent/Phlex props, slots, previews, sidecar assets
# Get Stimulus data-attributes
rails 'ai:tool[stimulus]' controller=chart
# → correct HTML with dashes (not underscores) + reverse view lookup
Every tool is read-only and returns data verified against your actual app — not guesses, not training data.
| Tool | What it does |
|:-----|:------------|
| search_code | Trace: definition + source + callers + tests. Also: definition, call, class filters |
| get_edit_context | Method-aware code extraction with class context |
| Tool | What it does |
|:-----|:------------|
| analyze_feature | Full-stack: models + controllers + routes + services + jobs + views + tests |
| get_context | Composite: schema + model + controller + routes + views in one call |
| onboard | Narrative app walkthrough (quick/standard/full) |
| Tool | What it does |
|:-----|:------------|
| get_schema | Columns with indexed/unique/encrypted/default hints |
| get_model_details | AST-parsed associations, validations, scopes, enums, macros — each result tagged [VERIFIED] or [INFERRED] |
| get_callbacks | Callbacks in Rails execution order with source |
| get_concern | Concern methods + source + which models include it |
| Tool | What it does |
|:-----|:------------|
| get_controllers | Actions + inherited filters + render map + strong params |
| `