SSH Rails Runner MCP server

Enables safe remote execution of Rails console commands via SSH for efficient data operations and administrative tasks on production Rails applications.
Back to servers
Setup instructions
Provider
Tadas Antanavicius
Release date
Feb 02, 2025
Language
TypeScript
Package
Stats
370 downloads
10 stars

The MCP Server: SSH Rails Runner enables secure remote execution of Rails console commands via SSH, providing tools for both read-only operations and carefully managed mutations in deployed Rails environments. It works excellently with Cursor, allowing you to use Cursor Composer to pull in Rails model files as context and execute various operations without navigating complex Admin UIs.

Installation

Install and build the server with npm:

npm install
npm run build

Configuration

Configure the server by setting the following environment variables:

SSH_HOST=your.remote.host
SSH_USER=your_ssh_user
SSH_PRIVATE_KEY_PATH=your_SSH_PRIVATE_KEY_PATH
RAILS_WORKING_DIR=/path/to/rails/app

Integration with Claude Desktop

Add the MCP server to your Claude Desktop configuration:

{
  "mcpServers": {
    "ssh-rails-runner": {
      "command": "npx",
      "args": ["mcp-server-ssh-rails-runner"],
      "env": {
        "SSH_HOST": "your.remote.host",
        "SSH_USER": "your_ssh_user",
        "SSH_PRIVATE_KEY_PATH": "your_SSH_PRIVATE_KEY_PATH",
        "RAILS_WORKING_DIR": "/path/to/rails/app/root",
        "PROJECT_NAME_AS_CONTEXT": "Name that shows up in tool descriptions to help the LLM describe what kind of Rails project we're working with.",
        "CODE_SNIPPET_FILE_DIRECTORY": "/path/to/store/code/snippets/locally"
      }
    }
  }
}

Configuration Notes:

  • If CODE_SNIPPET_FILE_DIRECTORY is not specified, snippets will be stored in a temporary directory (e.g., /tmp/mcp-ssh-rails-runner-code-snippets)
  • PROJECT_NAME_AS_CONTEXT is optional and helps identify the project context in tool descriptions

Using the Tools

The server operates with a Prepare -> Execute workflow through the following tools:

Preparing Code Snippets

Use the mcp_ssh_rails_runner_prepare_code_snippet tool:

  • Arguments:

    • name (string): Filename for the snippet
    • type (enum): Either "readOnly" or "mutate"
    • code (string): The Ruby code to execute
    • description (string, optional): Description of the code's purpose
  • Returns: A file:// URI pointing to the created snippet

Example usage:

# This would be passed as the 'code' argument
User.where(active: true).count

Executing Read-Only Operations

Use the mcp_ssh_rails_runner_execute_code_snippet_read_only tool:

  • Arguments:

    • uri (string): The file URI returned from the prepare step
  • Returns: The output of the Rails command

Executing Mutations

Use the mcp_ssh_rails_runner_execute_code_snippet_mutate tool:

  • Arguments:

    • uri (string): The file URI returned from the prepare step
  • Returns: The output of the Rails command

Warning: This tool executes mutations directly. Always review the prepared code (via the opened file from the prepare step) and confirm explicitly before executing any mutations.

Security Best Practices

  • Only use this tool with trusted SSH endpoints from your own local machine
  • Always review code snippets before executing any mutations
  • Remember that the responsibility for confirming mutations lies with you, the user

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "ssh-rails-runner" '{"command":"npx","args":["mcp-server-ssh-rails-runner"],"env":{"SSH_HOST":"your.remote.host","SSH_USER":"your_ssh_user","SSH_PRIVATE_KEY_PATH":"your_SSH_PRIVATE_KEY_PATH","RAILS_WORKING_DIR":"/path/to/rails/app/root","PROJECT_NAME_AS_CONTEXT":"Name that shows up in tool descriptions to help the LLM describe what kind of Rails project we're working with.","CODE_SNIPPET_FILE_DIRECTORY":"/path/to/store/code/snippets/locally"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "ssh-rails-runner": {
            "command": "npx",
            "args": [
                "mcp-server-ssh-rails-runner"
            ],
            "env": {
                "SSH_HOST": "your.remote.host",
                "SSH_USER": "your_ssh_user",
                "SSH_PRIVATE_KEY_PATH": "your_SSH_PRIVATE_KEY_PATH",
                "RAILS_WORKING_DIR": "/path/to/rails/app/root",
                "PROJECT_NAME_AS_CONTEXT": "Name that shows up in tool descriptions to help the LLM describe what kind of Rails project we're working with.",
                "CODE_SNIPPET_FILE_DIRECTORY": "/path/to/store/code/snippets/locally"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "ssh-rails-runner": {
            "command": "npx",
            "args": [
                "mcp-server-ssh-rails-runner"
            ],
            "env": {
                "SSH_HOST": "your.remote.host",
                "SSH_USER": "your_ssh_user",
                "SSH_PRIVATE_KEY_PATH": "your_SSH_PRIVATE_KEY_PATH",
                "RAILS_WORKING_DIR": "/path/to/rails/app/root",
                "PROJECT_NAME_AS_CONTEXT": "Name that shows up in tool descriptions to help the LLM describe what kind of Rails project we're working with.",
                "CODE_SNIPPET_FILE_DIRECTORY": "/path/to/store/code/snippets/locally"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later