MCP server for Rails app introspection. Exposes all ask-rails tools over the Model Context Protocol.
Coding agents like Claude Code, Cursor, or any MCP-compatible client can connect to inspect your Rails schema, query your database, read models, and more — all through the same tools ask-rails uses internally.
bundle add ask-rails-mcpRun from your Rails app root:
cd my-rails-app
ask-rails-mcpThis boots your Rails app and starts an MCP stdio server. Configure in ~/.zcode/cli/config.json (or your agent's MCP config):
{
"mcp": {
"servers": {
"ask-rails-mcp": {
"type": "stdio",
"command": "ask-rails-mcp",
"args": []
}
}
}
}Mount in config/routes.rb behind your existing auth:
Rails.application.routes.draw do
authenticate :user, ->(u) { u.admin? } do
post "ask/mcp", to: "ask/rails/mcp#handle"
end
endThen configure any MCP-compatible agent:
{
"mcp": {
"servers": {
"ask-rails-mcp": {
"type": "http",
"url": "https://myapp.com/ask/mcp"
}
}
}
}The agent discovers 9 tools automatically:
| Tool | What it does |
|---|---|
schema_graph |
Full schema introspection — all models, tables, columns, associations, validations |
query_database |
Read-only SQL queries with safety guards |
read_model |
Introspect a single ActiveRecord model |
route_inspector |
Parsed route table with filters |
read_log |
Read Rails log files with level/search filtering |
search_codebase |
Full-text grep search |
read_file |
Read any file from Rails.root |
run_command |
Run shell commands in the app root |
read_routes |
Read the raw config/routes.rb |
The MCP endpoint uses the same Ask::Rails::Auth system as the chat UI:
Ask::Rails::Auth.check = -> {
redirect_to main_app.login_path unless current_user&.admin?
}All ask-rails safety features apply automatically:
- Permissions — access modes (
:read_only,:ask_before_changes,:full_access) - Command allowlists —
allowed_commands/denied_commandsforRunCommand - Write guards —
INSERT/UPDATE/DELETEblocked byQueryDatabase - Audit log — every tool call recorded in
ask_audit_logs
bundle exec rake testMIT