rails-ai-bridge
AI coding assistants work better when they know your app's actual structure. This gem gives them a map — so they write code that fits your conventions, not generic Rails patterns.
The problem
Result: slower responses, more corrections, higher token bills.
Result: faster first useful response, fewer corrections.
The mental model
Think of it as giving your AI both a guidebook and a librarian. The guidebook sets orientation. The librarian answers follow-up questions.
Compact, assistant-specific files generated once and committed to your repo. They give the AI passive orientation every time a session starts.
≤ 150 lines each. Compact by default.
A read-only server that answers exact questions on demand. The AI calls these only when it needs a specific detail.
11 built-in tools. All read-only.
How it works
Up to 27 built-in scanners read your app: schema, models, routes, controllers, gems, tests, conventions, views, Turbo, Stimulus, auth, API, DevOps, and more.
rails ai:bridge writes compact files tailored to each AI tool's format and size limits. Split rules keep per-file guidance focused.
rails ai:serve starts an MCP server Claude Code and Cursor auto-detect. Supports stdio and HTTP transports.
Concrete example
Here is how a tool call works in practice. Start broad, then drill in.
{"detail": "summary"}
users ............... 12 columns
orders .............. 8 columns
order_items ......... 6 columns
products ............ 14 columns
categories .......... 4 columns
The AI gets oriented fast without drowning in detail.
{"model": "Order"}
belongs_to :user
has_many :order_items
dependent: :destroy
validates :total, numericality: { >= 0 }
scope :pending, -> { where(status: 'pending') }
enum status: { pending: 0, paid: 1, shipped: 2 }
Exact details, only when needed. No hallucinated columns.
Models are classified by importance so the AI knows where to focus first:
Safety
Every MCP tool inspects structure. None write files or mutate the database.
Credentials, .env files, master.key, and private config paths are excluded from generated context.
HTTP MCP requires explicit opt-in and an auth token in production. stdio is local-only.
database_stats is opt-in because it queries PostgreSQL table statistics.
Next steps
Add the gem, run the installer, generate your bridge files, and start the MCP server.
bundle add rails-ai-bridge
rails generate rails_ai_bridge:install
rails ai:bridge
rails ai:serve
Commit the generated files so your whole team benefits from the same AI context.