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.
Install and build the server with npm:
npm install
npm run build
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
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"
}
}
}
}
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 descriptionsThe server operates with a Prepare -> Execute workflow through the following tools:
Use the mcp_ssh_rails_runner_prepare_code_snippet
tool:
Arguments:
name
(string): Filename for the snippettype
(enum): Either "readOnly" or "mutate"code
(string): The Ruby code to executedescription
(string, optional): Description of the code's purposeReturns: A file://
URI pointing to the created snippet
Example usage:
# This would be passed as the 'code' argument
User.where(active: true).count
Use the mcp_ssh_rails_runner_execute_code_snippet_read_only
tool:
Arguments:
uri
(string): The file URI returned from the prepare stepReturns: The output of the Rails command
Use the mcp_ssh_rails_runner_execute_code_snippet_mutate
tool:
Arguments:
uri
(string): The file URI returned from the prepare stepReturns: 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.
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.
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.
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"
}
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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