A Model Context Protocol (MCP) server that provides access to Ruby console functionality for AI assistants. Execute Rails console, IRB, or Racksh commands, query models, and interact with your Ruby/Rails application through natural language with persistent session support.
- 🚀 Execute Rails console, IRB, or Racksh commands through MCP
- 💾 Persistent session - variables and state are preserved between commands
- ⚙️ Configurable console command (supports Rails, IRB, Racksh, or any Ruby REPL)
- 🔌 Easy integration with MCP-compatible AI assistants (Claude, Cursor, etc.)
- 📝 Clear error messages and helpful diagnostics
- 🎯 Uses PTY for proper TTY support (works with Rails 8+, IRB, Racksh)
# Install globally
npm install -g ruby-console-mcp
# Or use with npx (no installation needed)
npx ruby-console-mcp# Clone or navigate to the project directory
git clone https://github.com/tuhalang/ruby-console-mcp.git
cd ruby-console-mcp
# Install dependencies
npm install
# Build the project
npm run buildCreate a configuration file or set environment variables:
RUBY_APP_PATH: Path to your Rails/Rack application (default: current directory). Optional if using Docker/remote commands or IRB.RUBY_CONSOLE_COMMAND: Command to start console (default:bundle exec rails c). Can be Rails console, IRB, Racksh, or any Ruby REPL.COMMAND_TIMEOUT: Timeout for command execution in milliseconds (default: 30000)
Local Rails app:
export RUBY_APP_PATH=/path/to/your/rails/app
export RUBY_CONSOLE_COMMAND="bundle exec rails c"Docker (no RUBY_APP_PATH needed):
export RUBY_CONSOLE_COMMAND="docker-compose exec -T web bundle exec rails c"Running from Rails directory (no RUBY_APP_PATH needed):
# Just use default command, it will use current directory
export RUBY_CONSOLE_COMMAND="bundle exec rails c"You can customize the command used to start the console. Examples for Rails, IRB, and Racksh:
# Production environment
RUBY_CONSOLE_COMMAND="bundle exec rails c production"
# Sandbox mode (changes are rolled back)
RUBY_CONSOLE_COMMAND="bundle exec rails c --sandbox"
# Using Docker (no RUBY_APP_PATH needed)
RUBY_CONSOLE_COMMAND="docker-compose exec -T web bundle exec rails c"
# Using Kubernetes (no RUBY_APP_PATH needed)
RUBY_CONSOLE_COMMAND="kubectl exec -it rails-pod -- bundle exec rails c"
# Using specific Ruby version
RUBY_CONSOLE_COMMAND="rbenv exec bundle exec rails c"
# Remote server via SSH (no RUBY_APP_PATH needed)
RUBY_CONSOLE_COMMAND="ssh user@server 'cd /app && bundle exec rails c'"
# IRB (standalone Ruby)
RUBY_CONSOLE_COMMAND="irb"
# Racksh (Rack console)
RUBY_CONSOLE_COMMAND="bundle exec racksh"Note: When using Docker, Kubernetes, or remote commands, you typically don't need to set RUBY_APP_PATH since the command itself handles the context.
Add to your Claude Desktop configuration file:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
Using npm package (Recommended):
{
"mcpServers": {
"ruby-console": {
"command": "npx",
"args": ["-y", "ruby-console-mcp"],
"env": {
"RUBY_APP_PATH": "/path/to/your/rails/app"
}
}
}
}Or using globally installed package:
{
"mcpServers": {
"ruby-console": {
"command": "ruby-console-mcp",
"env": {
"RUBY_APP_PATH": "/path/to/your/rails/app"
}
}
}
}Local Rails app (from source):
{
"mcpServers": {
"ruby-console": {
"command": "node",
"args": ["/path/to/ruby-console-mcp/build/index.js"],
"env": {
"RUBY_APP_PATH": "/path/to/your/rails/app"
}
}
}
}Docker (no RUBY_APP_PATH needed):
{
"mcpServers": {
"ruby-console": {
"command": "npx",
"args": ["-y", "ruby-console-mcp"],
"env": {
"RUBY_CONSOLE_COMMAND": "docker-compose exec -T web bundle exec rails c"
}
}
}
}Using npm package:
npx -y ruby-console-mcpOr if installed globally:
ruby-console-mcpFrom source:
node /path/to/ruby-console-mcp/build/index.jsThe server spawns a persistent console process (Rails console, IRB, or Racksh) using a pseudo-terminal (PTY) and communicates with it via stdin/stdout. Commands are sent to the console, and responses are captured and returned to the AI assistant.
The console runs in a persistent session, which means:
- Variables persist: Variables defined in one command are available in subsequent commands
- State is maintained: ActiveRecord connections, loaded classes, and other state persist
- Efficient: No need to reload the Rails environment for each command
Simple query:
Command: User.count
Result: 42
Using variables across commands:
Command: a = User.first
Result: => #<User id: 1...>
Command: a.email
Result: => "user@example.com"
Complex operations:
Command: users = User.where('created_at > ?', 1.week.ago)
Result: => #<ActiveRecord::Relation...>
Command: users.count
Result: => 15
Execute a single-line command in the console (Rails console, IRB, or Racksh).
Parameters:
command(string, required): The console command to execute
Examples:
// Query a model
{
"command": "User.count"
}
// Complex query
{
"command": "User.where('created_at > ?', 1.week.ago).group(:role).count"
}
// Using variables (persists across commands)
{
"command": "user = User.first"
}
// Accessing previous variable
{
"command": "user.email"
}Execute a multi-line Ruby script in the console. Useful for complex operations, method definitions, or blocks of code.
Parameters:
script(string, required): Multi-line Ruby script to execute
Examples:
// Multi-line script
{
"script": "user = User.first\nputs user.email\nuser.update(name: 'New Name')"
}
// Method definition
{
"script": "def greet(name)\n puts \"Hello, #{name}!\"\nend\ngreet('World')"
}Check if the console is healthy and responsive. Executes a simple test command and measures response time.
Returns:
HEALTHY: Console responds quickly (< 5s)DEGRADED: Console responds but slowly (5-10s)UNHEALTHY: Console fails or very slow (> 10s)
Examples:
// Check health
{}Connect to the Ruby console. Starts the console if it is not already running. Returns the connection status and console information.
Parameters:
- None
Examples:
// Connect to console
{}Disconnect from the Ruby console. Stops the console process and releases resources. All variables and state will be lost after disconnecting.
Parameters:
- None
Examples:
// Disconnect from console
{}- Persistent Session: Variables and state persist between commands for efficient workflow
- Multi-line Script Support: Execute complex Ruby scripts with multiple lines
- Health Monitoring: Check console health and responsiveness
- Connection Management: Connect and disconnect from console manually
- Timeout Protection: Commands timeout after 30 seconds (configurable via
COMMAND_TIMEOUT) with progress feedback - Error Parsing: Beautifully formatted error messages with stack traces
- Error Handling: Clear error messages for common issues
- Process Management: Automatic cleanup on server shutdown
- PTY Support: Uses pseudo-terminal for proper Rails console output (compatible with Rails 8+)
Problem: "Failed to start console"
Solutions:
- Verify
RUBY_APP_PATHpoints to a valid Rails application - Run
bundle installin your Rails application directory - Check that
RUBY_CONSOLE_COMMANDis correct for your setup - Ensure all dependencies are installed
Problem: Commands return timeout message
Solutions:
- Increase
COMMAND_TIMEOUTfor long-running queries - Check if the Rails console is hanging (test manually)
- Optimize the query or command
Problem: Command executes but returns "(No output)"
Solutions:
- Some operations may not return output (this is normal)
- Try adding
.inspectorppto the command for better output - Check for errors in the Rails application logs
Problem: Rails console disconnects unexpectedly
Solutions:
- Check Rails application logs for errors
- Verify database connection is stable
- Restart the MCP server
# Clone the repository
git clone https://github.com/tuhalang/ruby-console-mcp.git
cd ruby-console-mcp
# Install dependencies
npm install
# Watch mode for development
npm run dev
# Build
npm run build
# Start the server
npm start┌─────────────────┐
│ MCP Client │
│ (Claude, etc) │
└────────┬────────┘
│ stdio
│
┌────────▼────────┐
│ MCP Server │
│ (index.ts) │
└────────┬────────┘
│
┌────────▼────────┐
│ Ruby Console │
│ Manager │
│ (ruby-console) │
└────────┬────────┘
│ PTY (pseudo-terminal)
┌────────▼────────┐
│ Ruby Console │
│ (rails c/irb) │
└─────────────────┘
- This tool provides powerful access to your Rails application
- All commands are executed immediately without confirmation
- Consider running in sandbox mode for testing:
RUBY_CONSOLE_COMMAND="bundle exec rails c --sandbox" - Be cautious in production environments
- Review commands carefully before execution
- Consider implementing additional access controls based on your needs
MIT
Contributions are welcome! Please feel free to submit issues or pull requests.