Get the FREE Ultimate OpenClaw Setup Guide →

mcp_rails_template

A minimal Rails API template for creating MCP (Model Context Protocol) servers with robust tool execution capabilities and examples.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio seuros-mcp_rails_template docker run -i seuros/mcp_rails_template:latest

How to use

This MCP setup demonstrates integrating the ActionMCP gem into a Ruby on Rails project. The Rails app serves as a host for various MCP components (prompts, resource templates, and tools) that can be invoked by a language model through the MCP gateway. The ActionMCP server itself runs as a standalone MCP server on port 62770 and is typically proxied by Nginx at /mcp, allowing client requests to be forwarded to ActionMCP. To use it, first ensure the Rails application is configured and the MCP dependencies are installed, then run the embedded MCP server (as described in the README) or connect via the provided mcp.json configuration to an external MCP gateway. Tools available include dependency_info_tool (Bundler-based dependency extraction), fetch_weather_by_location_tool (Open-Meteo API access by coordinates), rubocop_tool (Ruby code quality analysis via RuboCop), and ruby_code_analyzer_tool (static analysis of Ruby code within the project). You can also fetch Gemfile dependencies through the Gemfile_template resource and render current_user-specific data via custom MCP tools when authenticated through JWT tokens.

How to install

Prerequisites:

  • Ruby (check .ruby-version in the project for the recommended version)
  • PostgreSQL (or use Docker to spin up a DB instance as shown in the README)
  • Bundler
  • Git

Installation steps:

  1. Clone the repository: git clone https://github.com/seuros/mcp_rails_template.git cd mcp_rails_template

  2. Install Ruby dependencies: bundle install

  3. Setup environment:

    • Copy the example env file and edit it with your credentials and API keys: cp .env.example .env
    • Ensure necessary environment variables are defined (e.g., database config, API keys for tools like fetch_weather_by_location_tool)
  4. Prepare the database:

    • If using Docker for PostgreSQL (as suggested in the README): make up This starts PostgreSQL on port 5466
    • Otherwise configure your own PostgreSQL instance by editing config/database.yml
  5. Set up the Rails app and load fixtures if needed: bin/setup bin/rails db:fixtures:load FIXTURES=users

  6. Run the Rails server: bin/rails s

  7. Ensure the MCP server is running or accessible through your gateway (as described in the MCP section of the README). By default, the standalone MCP server listens on port 62770, and your gateway (like Nginx) should proxy /mcp to that port.

Additional notes

Notes and tips:

  • The MCP gateway configuration is managed in config/mcp.yml and uses JWT-based authentication for the API calls in this Rails example.
  • Ensure Docker is running if you follow the Docker-based PostgreSQL option.
  • The .env file should contain keys for any external services used by tools (e.g., weather API keys for fetch_weather_by_location_tool).
  • The MCP client can be configured via a provided .mcp.json file or manually with curl commands to test tokens and endpoints.
  • If you run into port conflicts, verify that port 62770 (MCP server) and 3002 (Rails app) are not in use by other processes.
  • The npm-based MCP Inspector can be used to inspect the MCP endpoint once the server is up (npx @modelcontextprotocol/inspector --url http://localhost:8080/mcp).
  • Since this template focuses on demonstrating ActionMCP components, you can extend app/mcp/ to add more prompts, tools, or resources as needed.

Related MCP Servers

Sponsor this space

Reach thousands of developers