
Rails AI Context
io.github.crisnahine由 GitHub 帳號 crisnahine 發布v5.39.1更新於 Nov 7, 2026
35 MCP tools give AI agents live Rails schema, routes, models, and conventions.
發布方自己的服務:Job Bot by Agent Rails
概覽
唯讀 MCP 伺服器,讓 AI 編碼助理直接查詢 Rails 應用程式的資料庫結構、模型、路由、控制器、檢視與程式碼,而不是憑空猜測。
- 可以做什麼
- 搜尋與追蹤程式碼,trace 模式一次回傳方法定義、依檔案分組的呼叫端與測試
- 檢視資料庫結構、模型、關聯、驗證、scope、enum、callback 與 concern
- 讀取控制器(含繼承的 filter 與 strong parameters)、路由、檢視、Stimulus 與 Turbo 對應
- 檢視測試設定並產生測試,執行驗證、安全掃描與效能檢查
- 讀取應用程式設定、gem、helper、service、job、mailer 與元件目錄
- 執行唯讀 SQL 查詢、讀取去識別化日誌、檢視變更並診斷應用程式
- 適用情境
- 當助理在某個特定 Rails 應用程式中撰寫或審查程式碼,卻不斷編造不存在的欄位、關聯、filter 或測試設定時使用。應用程式無法啟動時也適用,因為許多工具會退回對路由、schema 匯出檔與原始碼的靜態分析。
- 執行需求
- 以 stdio 程序在 Rails 應用程式內本機執行:需要 Ruby 3.1+ 與 Rails 7.0 至 8.1,支援 Linux、macOS 或 Windows。以 gem 安裝(Gemfile 的 development 群組或獨立安裝),再用安裝產生器或 init 指令為所選 AI 工具寫入 MCP 設定與情境檔案。選用:brakeman、listen 與 ripgrep 供部分工具使用。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Rails AI Context,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
[rails-ai-context: ground truth for your coding agent]
Your coding agent guesses your Rails app. Let it ask.
[Works with] [Claude Code] [Cursor] [GitHub Copilot] [OpenCode] [Codex CLI] [Any terminal]
[Gem version] [Downloads] [CI status] [Ruby 3.1 to 4.0] [Rails 7.0 to 8.1] [MIT license] [Listed in the MCP Registry]
Website · Quick start · FAQ · What it does · A closer look · How it works · Tools reference · Contributing
Contents
- What it does
- Try it in your Rails app
- A closer look: the schema, the model, the inherited filters, the trace, the app that cannot boot, the six rules
- The tools
- How it works
- What it costs
- Questions you should ask first
- What it will not do
- Install options and configuration
- Troubleshooting
- Development
- Contributing and security
- Learn more
What it does
An assistant writing Rails code knows what an average Rails app looks like. Yours has its own columns,
associations, filters and test setup, and the assistant starts every session with none of that. It
writes a migration for a column that exists, calls user.posts when the association is user.articles,
scaffolds FactoryBot into a fixture suite, and misses the before_action a parent controller adds. You
catch it, fix it, re-prompt, and something next to it breaks.
rails-ai-context gives the assistant 35 tools that read the app itself, over MCP from the AI tool or from the command line. Every answer is read from the app and says how sure it is, and most end with a hint for the next call.
Each line comes from the sample app in this repository, a blog with Devise, an admin namespace, a JSON API, a Sidekiq job and a FactoryBot suite. The website records the whole answers every time it is built, by running the gem at that commit: crisnahine.github.io/rails-ai-context.
The install writes the files each AI tool reads, so the assistant knows the tools exist and how to ask: the MCP config, one root context file with six anti-hallucination rules, and rules that load when a model, a controller or a migration is open. The tools are read-only, the SQL tool runs inside a read-only transaction, and files that hold secrets are never served.
Try it in your Rails app
Open your AI tool at the root of your Rails app and paste this. It installs the gem, sets up the AI tool you are in, checks the result and tells you the one step left.
Rather type it yourself? In the Gemfile:
Standalone, with no Gemfile change:
As a Claude Code plugin, which adds the MCP server and gives each session the six rules, and writes no context files. It runs the installed gem, so install that first, and run it in the app's folder:
Commit the .claude/settings.json it writes; the install generator and init then leave Claude Code's
.mcp.json to the plugin (details).
--tools takes claude, cursor, copilot, opencode, codex or all. Without --defaults the
generator asks which AI tools you use and what to write. Re-running is safe: it keeps what you have,
adds what is missing, and in a CLAUDE.md you wrote it touches only the block between its
<!-- BEGIN/END rails-ai-context --> markers.
You need Ruby 3.1 or newer and Rails 7.0 to 8.1, on Linux, macOS or Windows. Optional:
brakeman for security_scan, listen for watch, ripgrep for a faster search_code.
Then one step in your AI tool
Every AI tool holds a new project MCP server back until you say yes. The install prints the step for each tool you picked:
Then ask something only your app knows, such as "what columns does the users table have?", and watch
it call rails_get_schema instead of guessing. Every other setup has a prompt: no
Gemfile change, CLI only, MCP only, a whole team, a folder of apps, nothing committed, MCP over HTTP,
Ruby in Docker, another MCP client.
A closer look
Every block below is the gem's own output for the sample app, read without booting it, trimmed: the tier line and the report line that end every answer are cut, and each note names what else is. The website shows each answer whole, recorded at the commit it was built from.
The schema, with the model on it
Trimmed to seven of its twelve columns and two of its three indexes. With the app booted, the columns
come from the database connection; here they come from db/schema.rb, and db/structure.sql or the
migrations would do.
Before it calls an association
The model is read with the Prism parser. A scope with a literal body is [VERIFIED], one built at
runtime is [INFERRED], and in the static tier every record is capped at [STATIC], since no record
can claim more than the tier that carries it. The columns, the primary key, the static-tier note on
associations, the instance methods and the next-call hint are trimmed out above. The published scope
is declared in the Publishable concern, and the Concerns section lists the methods each concern brings.
Before it writes an action
Every filter that applies, with where it was inherited from, so the assistant never misses the
authenticate_user! two classes up. The schema hints for the models the controller touches, and the
next-call hints, follow in the full answer.
Tracing a method
One call in place of a file-by-file search: the definition, what it calls, its siblings, every caller grouped by file and labelled by kind, with the route a controller caller answers, and the tests. The "Calls internally" and "Sibling methods" sections are trimmed out above.
When the app cannot boot
The app-reading commands try a full boot for live reflection. When the boot fails, from a missing
environment variable, an unreachable service or a broken initializer, they answer from the static
tier instead of dying: routes from config/routes.rb, the schema from db/schema.rb,
db/structure.sql or the migrations, models and controllers from their source. Every answer carries
a tier line, a section that needs a booted app says [UNAVAILABLE] with the reason, and
--no-boot asks for that tier outright:
32 of the 40 introspectors answer here. Each declares which of three kinds it is: it reads files only, it needs live reflection, or it answers from another source such as the schema dump. What a tier can say is a declaration, so an answer never guesses at what it could not read (ADR-0002). The routes engines and gems draw at boot, and an association a gem adds at boot, are not listed, and the answer says so.
The six rules
The root context file carries six rules the assistant reads before writing code. That file is
AGENTS.md, which Cursor, OpenCode and Codex read and CLAUDE.md imports, or CLAUDE.md itself when
none of those three is chosen; Copilot reads its own copy in .github/copilot-instructions.md.
- Verify before you write. Never reference a column, association, route, helper, method, class, partial or gem that a tool call in this turn did not confirm.
- Mark every assumption with
[ASSUMPTION]. "I'd need to check X first" is a good answer. - Training data describes average Rails. This app isn't average. When something feels obviously standard, query anyway.
- Check the inheritance chain before every edit: inherited filters, concerns, includes, STI parents.
- Empty tool output is information. "0 callers found" means investigate, or ask.
- Stale context lies. Re-query after writes.
On by default. Turn off with config.anti_hallucination_rules = false if you prefer your own. In an
MCP-only or CLI setup, the ground rules prompt gives
the assistant the same rules for one session.
The tools
Every tool is read-only and answers from your app. Over MCP each name carries a rails_ prefix
(rails_get_schema). From the CLI the short name works: schema, get_schema and rails_get_schema
all resolve. About half take detail=summary|standard|full.
Four worth knowing on day one:
search_codewithmatch_type=tracereturns the definition, the source, every caller grouped by file and labelled by kind, and the tests, in one call.get_controllersreturns the action source with inherited filters, strong params and the render map.get_model_detailsreturns associations, validations, scopes, enums and macros from the AST, each tagged[VERIFIED]or[INFERRED].queryruns read-only SQL inside a read-only transaction, with a timeout, a row limit and column redaction.
Parameters for all 35 are in the tools reference; worked examples in
recipes. MCP clients can also read five resource templates, such as
rails-ai-context://models/{name} and rails-ai-context://controllers/{name}/{action}, and nine
static resources, such as rails://schema and rails://routes.
How it works
40 introspectors read the app, one per kind of fact: the schema, the models, the routes, the
controllers, the views, the jobs, the gems, the conventions and so on. Each returns a hash and is
registered under a key, so a preset is a list of keys: :full runs all 40 and :standard runs 17.
The models and the controllers are read with Prism, Ruby's own parser. Each file is parsed once into a
cache keyed by its content, and a single walk over the tree feeds every listener at the same time:
associations, validations, scopes, enums, callbacks, macros, strong parameters. A listener tags each
record by how it was read: [VERIFIED] for a literal, [INFERRED] for an expression that only runs at
runtime. Introspection is cached with a fingerprint of the app's files, so an edit to a model is seen
on the next call without a restart.
A tool composes its answer from that context, hydrates it with schema hints for the models it touches, cuts it at the response budget, and ends it with a tier line and, for most tools, a hint for the next call. Three transports reach the same registry: MCP over stdio, MCP over HTTP mounted inside the app, and the command line with no server at all.
Architecture has the modules and the request lifecycle, Introspectors the catalogue of listeners and the rule for what is read from the AST, and the ADRs the decisions with their reasons.
What it costs
It is free and MIT licensed. What you pay is tokens, and only when the assistant asks:
- A tool answer is sized by its
detaillevel and cut atmax_tool_response_chars, 200,000 characters by default. Start withsummaryand drill down. - The root context file is held to 12,000 bytes in its default compact mode, and a rule file to 8,000, since they share the agent's context with your own instructions.
- The last line of every answer, which asks the assistant to offer you an issue when the gem itself
answered wrong, costs about 40 tokens.
config.report_issue_line = falseleaves it out.
Questions you should ask first
Does it send my code anywhere? No. The tools run on your machine, in your app's process or in a
child of it. Two things go online: search_docs fetches Rails guides from GitHub when called with
fetch: true, and the standalone binary asks rubygems.org for the latest version at most once a day,
in a child process that sends nothing about the app. RAILS_AI_CONTEXT_NO_UPDATE_CHECK=1 turns that
off, and it is off in CI.
Can it read my secrets? Files that hold them are never served: .env, config/master.key,
credentials.yml.enc, config/database.yml, keys and certificates, on a list you can extend. Logs
are redacted before they leave the process, get_config shows credential key names without values,
and query never returns an encrypted column. Security has every layer.
Can it change my database? No. Every tool is read-only. query allows SELECT, WITH, SHOW,
EXPLAIN and DESCRIBE, runs inside a read-only transaction with a statement timeout, caps the rows,
redacts secret columns, and on PostgreSQL plans the statement first and refuses a plan that reaches a
secret column by another name.
What does it write into my repository? The MCP config for each AI tool you picked, one root
context file with a copy for Copilot, rules files per tool, its own config and a .gitignore line.
A re-run keeps your lines and adds what is missing; uninstall takes back only what it wrote. A team
that wants no AI files in the repo can skip the install: the tools work with none of it.
Is the HTTP endpoint safe? Mounted inside the app it inherits your routing, auth and middleware.
Outside development and test it refuses every request with a 403 unless you set
config.allow_http_in_production = true, since it has no authentication of its own.
Which AI tools? Claude Code, Cursor, GitHub Copilot, OpenCode and Codex CLI get context files and
MCP config written for them. Any other MCP client, such as Claude Desktop, Windsurf, Zed or a JetBrains
IDE (Copilot or AI Assistant), gets an entry from rails-ai-context mcp-entry. A tool with no MCP at all
gets the CLI setup, where the context files name the shell commands.
Still wondering about something? The FAQ
answers the rest: install, the tools, configuration, context files, performance, security, and how it
compares to a hand-written CLAUDE.md or pasting schema.rb into the prompt.
What it will not do
- Write to your app or your database from a tool. Every tool reads. The assistant still decides what to do with the facts, and the six rules ask it to verify before writing; nothing enforces that.
- Say more than it read. Without a boot, 32 of 40 introspectors answer and the rest say
[UNAVAILABLE].query,runtime_infoanddoctorneed a booted app, andquerya database. - Support Rails 9. The gemspec caps
railtiesbelow 9.0, and the standalone binary warns when it boots one. Compatibility has the CI matrix: 17 Ruby and Rails pairs on Linux, plus macOS and Windows legs. - Time-limit
queryon SQLite under Windows. There is noforkthere, so that query runs without its limit, and the MCP configs start the server throughcmd /d /c, since a gem's executables on Windows are batch files.
Install options and configuration
Three setups, picked at install time with a flag, or afterwards with the change the setup prompt:
MCP over stdio is the default. Each AI tool gets its own config file (.mcp.json,
.cursor/mcp.json, .vscode/mcp.json and .github/mcp.json, opencode.json, .codex/config.toml) that starts
bundle exec rails-ai-context serve, or rails-ai-context serve standalone. MCP over HTTP mounts
the server inside your app:
The if keeps the routes file loading where the gem is not installed, as in production, where Bundler
skips the development group. There is also a standalone HTTP process:
rails-ai-context serve --transport http --port 6029. The CLI runs the same 35 tools with no server:
The commands, in the Gemfile and standalone:
The binary finds the app the way bin/rails does, so it runs from any subdirectory. Flags shared by
the app-reading commands: --app-path PATH to target another directory, --environment ENV to set
RAILS_ENV, and --no-boot to answer from source. The full list is in the CLI reference.
A Gemfile install writes an initializer and .rails-ai-context.yml; a standalone install writes the
YAML file alone, with the same keys. Every option with its default is in
Configuration:
Custom tools
Register your own tools next to the built-in ones:
Test them with the bundled helper (RSpec or Minitest):
See Custom tools.
Observability
Every MCP call fires an ActiveSupport::Notifications event:
To take it out again:
It removes the context files, the MCP entries, its config, its .gitignore lines and its pre-commit
hook, and keeps what you wrote: your lines in CLAUDE.md, other servers in an MCP config, a hook you
edited. Or paste the uninstall prompt.
Troubleshooting
bundle exec rails-ai-context doctor (or bin/rails ai:doctor) boots the app, checks every file the
install wrote, the MCP configs and the plugins, and prints a readiness score with what to fix. It needs
a bootable app, since diagnosing the boot is its job. The fix it prompt
hands the same checks to the assistant, and Troubleshooting has the
problems people hit most: a server the AI tool never lists, a boot that fails, a Windows path, a
bundle that resolves the wrong Rails.
Development
The website is site/, filled in by scripts/site.rb from the repository: the install prompt from
docs/PROMPTS.md, the tool list from the registry, every docs/ page rendered beside it, and the
answers recorded by running the gem against site/sample_app. To see it before pushing:
.github/workflows/pages.yml builds it on every pull request and deploys it from main. CONTRIBUTING.md has the layout of lib/, how to add an
introspector, a tool or a Prism listener, and how to run the specs against real database servers.
Contributing and security
Pull requests are welcome; CONTRIBUTING.md has the process, and the code of conduct applies to everyone taking part. Bugs go to the issue tracker with the Ruby, Rails and gem versions and the steps to reproduce. A security problem goes by email, the way SECURITY.md says, and never in a public issue. Only the latest 5.x release gets security fixes.
Learn more
If it saves you a correction loop, star it on GitHub, and if it saves you time, consider sponsoring the project.
來源:README.md,提交 c3578a6
工具
0版本歷史
28- v5.39.1最新Oct 31, 2026
- v5.39.0Oct 31, 2026
- v5.38.2Oct 29, 2026
- v5.37.0Oct 25, 2026
- v5.36.9Oct 23, 2026
- v5.36.8Oct 23, 2026
- v5.36.7Oct 22, 2026
- v5.36.6Oct 21, 2026
- v5.36.5Oct 19, 2026
- v5.36.4Oct 16, 2026
- v5.36.3Oct 15, 2026
- v5.36.2Oct 15, 2026
- v5.36.1Oct 14, 2026
- v5.35.2Oct 14, 2026
- v5.35.1Oct 13, 2026
- v5.35.0Oct 12, 2026
- v5.34.1Oct 12, 2026
- v5.33.0Oct 11, 2026
- v5.32.2Oct 7, 2026
- v5.32.1Oct 6, 2026
- v5.31.0Oct 5, 2026
- v5.30.2Oct 1, 2026
- v5.30.1Sep 28, 2026
- v5.30.0Sep 28, 2026
- v5.29.0Sep 23, 2026
- v5.28.0Sep 22, 2026
- v5.27.0Sep 22, 2026
- v5.26.0Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分
其他 Rails 整合
Job Bot by Agent Rails
so.rails官方發布者
遠端求職 MCP 伺服器,產生的文件每一行都引用可查證的事實,且不會替你送出任何內容。
Unblock by Agent Rails
so.rails官方發布者
讓代理在手機上向你提問,等待你的回答後繼續執行工作。
Language Tutor by Agent Rails
so.rails官方發布者
讓助理以簡短對話練習西班牙語、法語或俄語,並提供糾正。
Rolodex by Agent Rails
so.rails官方發布者
遠端 MCP 伺服器,用來維護關係記憶:誰該走下一步,並為每筆紀錄附上依據。
Recruiter by Agent Rails
so.rails官方發布者
遠端 MCP 伺服器:輸入職缺後回傳依各項要求附上證據的候選人,以及待你核准的聯繫草稿。