Class: RailsPgExtras::MCPApp

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_pg_extras/mcp_app.rb

Class Method Summary collapse

Class Method Details

.buildObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rails_pg_extras/mcp_app.rb', line 78

def self.build
  app = lambda do |_env|
    [200, { "Content-Type" => "text/html" },
     ["<html><body><h1>Hello from Rack!</h1><p>This is a simple Rack app with MCP middleware.</p></body></html>"]]
  end

  # Create the MCP middleware
  mcp_app = FastMcp.rack_middleware(
    app,
    name: "rails-pg-extras", version: RailsPgExtras::VERSION,
    path_prefix: "/pg-extras-mcp",
    logger: Logger.new($stdout),
  ) do |server|
    server.register_tools(DiagnoseTool)
    server.register_tools(MissingFkConstraintsTool)
    server.register_tools(MissingFkIndexesTool)
    server.register_tools(*QUERY_TOOL_CLASSES)

    server.register_resource(ReadmeResource)

    Rack::Builder.new { run mcp_app }
  end
end