0.0
The project is in a healthy, maintained state
Mount an MCP endpoint in your Rails app that exposes SchemaGraph, QueryDatabase, ReadModel, RouteInspector, and all other ask-rails tools as MCP tools. Coding agents like Claude Code, Cursor, or any MCP-compatible client can connect to inspect your schema, query your database, read models, and more.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 5.25
~> 2.0
~> 13.0

Runtime

>= 0.1
>= 0.10
>= 7.1
 Project Readme

ask-rails-mcp

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.

Installation

bundle add ask-rails-mcp

Usage

Option 1: stdio (local development — recommended)

Run from your Rails app root:

cd my-rails-app
ask-rails-mcp

This 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": []
      }
    }
  }
}

Option 2: HTTP endpoint (remote/production)

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
end

Then 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

Authentication

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?
}

Safety

All ask-rails safety features apply automatically:

  • Permissions — access modes (:read_only, :ask_before_changes, :full_access)
  • Command allowlistsallowed_commands / denied_commands for RunCommand
  • Write guardsINSERT/UPDATE/DELETE blocked by QueryDatabase
  • Audit log — every tool call recorded in ask_audit_logs

Development

bundle exec rake test

License

MIT