Class: RailsMcp::MCP::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_mcp/mcp/server.rb

Overview

Minimal MCP-over-HTTP (JSON-RPC) server. Single-session, single-process demo: fine for local/dev usage.

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails_mcp/mcp/server.rb', line 12

def initialize
  @tools = [
    {
      "name" => "evaluate_ruby_code",
      "description" => "Evaluate the Ruby code in the context of the current application, returns the result of the code execution",
      "inputSchema" => {
        "type" => "object",
        "properties" => {
          "code" => {
            "type" => "string",
            "description" => "The Ruby code to evaluate, must be a valid Ruby expression or statement"
          }
        },
        "required" => ["code"]
      }
    }
  ]
end

Instance Method Details

#call(env) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/rails_mcp/mcp/server.rb', line 31

def call(env)
  req = Rack::Request.new(env)

  case [req.request_method, req.path_info]
  when ["POST", "/rpc"] then handle_rpc(req)
  else
    [404, {"content-type" => "text/plain"}, ["Not Found\n"]]
  end
end