Skip to content

Think of it giving AI assistant lighting-speed access to ruby console without the need to write script, reload or restart.

License

Notifications You must be signed in to change notification settings

apolloio/rack-mcp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rack-mcp

A Ruby gem that provides AI assistants with ruby code execution capabilities within the context of existing running application server. Think of it giving AI assistant lighting-speed access to ruby console without the need to write script, reload or restart.

Works with Rails, Sinatra, Hanami, Roda, and any other Rack-based framework. The code is executed in your application's context for debugging and investigation.

rails console mcp in cursor

Use cases

  1. Learn a new codebase or code areas quickly. With your AI client and a running server, you can ask it to research while executing snippets from your actual application code. It effectively acts as an in-loop code-verification block.
  2. Perform quick, preliminary investigations of customer escalations using a read-only copy of the production environment. It can execute your application code, locate models, and run relevant class methods or code paths from the codebase to do preliminary root-cause analysis (RCA). Even better if your application uses an event-sourcing framework (i.e., change logs). The AI client, together with the code-execution capabilities via rack-mcp, can deliver fast preliminary RCAs.
  3. Use it for quick data analytics and export reports as CSV.

Installation

Add this line to your application's Gemfile:

gem "rack_mcp", git: "https://github.com/raja-jamwal/rack-mcp.git"

Or install locally for development:

bundle install

Usage

Mounting the MCP Server

Rails (config/routes.rb):

require "rack_mcp/mcp/server"

Rails.application.routes.draw do
  mount RackMcp::MCP::Server.new => "/mcp"
end

Rack (config.ru):

require "rack_mcp"
require "rack_mcp/mcp/server"

map "/mcp" do
  run RackMcp::MCP::Server.new
end

Sinatra:

require "rack_mcp/mcp/server"

mount RackMcp::MCP::Server.new, at: "/mcp"

Starting the Server

# Standalone with Rackup
bundle exec rackup -p 9292

# With Rails
bundle exec rails server

MCP Protocol

Endpoint

The MCP server exposes a single JSON-RPC endpoint:

  • POST /mcp/rpc - JSON-RPC request and response

Available Tools

evaluate_ruby_code

  • Description: Evaluates Ruby code and returns the result with captured stdout/stderr
  • Parameters:
    • code (string, required): Ruby code to execute

Connecting AI Assistants

Cursor/ Claude Desktop

Add to your MCP client (cusor, claude etc).

{
  "mcpServers": {
    "rails-mcp": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:3001/mcp/rpc"
      ]
    }
  }
}

MCP integration in Cursor

Other MCP Clients

Any MCP-compatible client can connect to the server by making JSON-RPC requests to the /mcp/rpc endpoint.

Testing

Run the test suite:

bundle exec rspec

Security Warning

⚠️ This gem executes arbitrary Ruby code.

Important security considerations:

  • Only use in development environments
  • Never expose this endpoint to the public internet without authentication
  • Implement proper authentication and authorization in production
  • Consider running in a sandboxed or containerized environment
  • Use network-level restrictions to limit access

Concurrency Note

This gem uses global $stdout/$stderr redirection during evaluation, which can clash in multi-threaded servers. For production use with concurrency, consider:

  • Running in a single worker/thread mode
  • Isolating evaluation per request (e.g., via fork)
  • Using a dedicated job worker for code execution

License

MIT License - see LICENSE file for details.

About

Think of it giving AI assistant lighting-speed access to ruby console without the need to write script, reload or restart.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%