1
.
06
.
2025
26
.
05
.
2025
LLM
Ruby on Rails

MCP Server with Rails and ActionMCP

Paweł Strzałkowski
Chief Technology Officer
Actionmcp in Ruby on Rails by Paweł Strzałkowski

Following the exploration of FastMCP, let's turn the attention to another promising gem for building Model Context Protocol (MCP) servers with Ruby on Rails: ActionMCP. This library is designed with deep Rails integration in mind and offers a robust solution for exposing your application's capabilities to AI agents.

ActionMCP gem

The ActionMCP gem, developed by seuros (who you might find on the Ruby AI Builders or Model Context Protocol Discord servers), provides a Rails-centric approach to implementing MCP. You can find its repository at https://github.com/seuros/action_mcp, and there's even a helpful Rails template to get you started: https://github.com/seuros/mcp_rails_template.

One of the unique aspects of ActionMCP is its implementation of the streamable-http transport method, which aligns with the latest MCP specifications.

Setting Up the Application

To begin, I generated a new Rails application, specifying PostgreSQL as the database:

rails _8.0.2_ new with-action-mcp -d postgresql

It's important to have a working database for your project because ActionMCP utilizes a database-centered approach for session handling. As outlined in the MCP specification - client has to establish one session per MCP server.

Adding ActionMCP

All the steps needed to install and run ActionMCP are described in the gem’s repository. I’ve started by adding the actionmcp gem to the project's Gemfile:

$ bundle add actionmcp

Configuring the gem

With the gem installed, the next step was to instal migrations

$ bin/rails action_mcp:install:migrations

Copied migration 20250517154542_consolidated_migration.action_mcp.rb from action_mcp

Then set up the database and run migrations

$ rails db:setup
$ rails db:migrate

With that finished, I ran the gem’s installation generator:

$ bin/rails generate action_mcp:install

Which created the following files:

create  app/mcp/prompts/application_mcp_prompt.rb
create  app/mcp/tools/application_mcp_tool.rb
create  app/mcp/resource_templates/application_mcp_res_template.rb
create  config/mcp.yml

These files provide the basic structure for defining your MCP prompts, tools, and resource templates.

Rackup File and Application Configuration

To be able to run the ActionMCP engine, I created a mcp.ru file in the root of my Rails application with the following content:

# Load the full Rails environment to access models, DB, Redis, etc.
require_relative "config/environment"

# No need to set a custom endpoint path. The MCP endpoint is always served at root ("/")
# when using ActionMCP::Engine directly.
run ActionMCP::Engine

Next, I added some configuration to config/application.rb:

config.action_mcp.name = "Friendly MCP (Master Control Program)"
config.action_mcp.version = "1.2.3"
config.action_mcp.logging_enabled = true
config.action_mcp.logging_level = :info
config.action_mcp.vibed_ignore_version = false 

For real-time communication, ActionMCP can leverage different pub/sub adapters. I configured it to use solid_cable by adding the following to config/mcp.yml:

development:
  adapter: solid_cable
  polling_interval: 0.1.seconds

Creating a Weather Forecast Tool

With the basic setup complete, it was time to create a simple tool. I used the provided generator to create a ForecastWeatherTool:

$ bin/rails generate action_mcp:tool ForecastWeatherTool

This created the file app/mcp/tools/forecast_weather_tool.rb. I then filled it with dummy logic:

# frozen_string_literal: true

class ForecastWeatherTool < ApplicationMCPTool
  tool_name "forecast-weather"
  description "Forecasts weather for the given location"

  property :location, type: "string", description: "Location for the weather forecast", required: true

  def perform
    render(text: "Weather in #{location} will be fine")

  rescue => e
    render(error: [ "Error: #{e.message}" ])
  end
end

This tool defines its name, description, and a required location property. The perform method contains the core logic, in this case, rendering a simple string in the tool’s response.

Running and testing the server

As per the ActionMCP documentation, I started the MCP server using a specific command that points to the mcp.ru file:

bin/rails s -c mcp.ru -p 62770 -P tmp/pids/mcps0.pid

I then launched the MCP Inspector:

npx @modelcontextprotocol/inspector

Connecting the inspector to http://localhost:62770 (the port I specified for the server) and setting streamable HTTP transport type, I could see and interact with my ForecastWeatherTool.

Here’s how it appeared in the MCP Inspector:

A More Railsy Example: Creating Blog Posts

To demonstrate an example similar to Rails tutorial’s use case, I created a tool adding blog posts. First, I generated a Post model with title and body attributes (e.g., bin/rails g model Post title:string body:text).

Then, I generated a new tool for creating posts:

$ bin/rails generate action_mcp:tool CreatePostTool

And implemented it in app/mcp/tools/create_post_tool.rb:

# frozen_string_literal: true

class CreatePostTool < ApplicationMCPTool
  tool_name "create-post"
  description "Creates a post with the given title and body"

  property :title, type: "string", description: "Title of the post", required: true
  property :body, type: "string", description: "Body of the post", required: true

  def perform
    post = Post.create!(title:, body:)

    render(text: "Post #{title} was created")
  rescue => e
    render(error: [ "Error: #{e.message}" ])
  end
end

This tool takes title and body as inputs, creates a Post record, and returns a confirmation message.

After restarting the MCP server, I connected to it again with the MCP Inspector and called the create-post tool.

Here’s the result in the inspector:

A quick check using the Rails console confirmed that the post was successfully created:

with-action-mcp(dev)> Post.last
  Post Load (1.1ms)  SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC LIMIT 1 /*application='WithActionMcp'*/
=>
#<Post:0x000000011fd0ee70
 id: 1,
 title: "Ruby on Rails taking over the world",
 body: "The post needs some body",
 created_at: "2025-05-21 17:55:21.274883000 +0000",
 updated_at: "2025-05-21 17:55:21.274883000 +0000">

Summary

ActionMCP offers a mature, production-ready solution for building MCP servers in a Rails environment. Its sole reliance on the streamable-http transport type adheres closely to the latest MCP specifications, making it a forward-looking choice.

One current consideration is that not all MCP clients may fully support this advanced transport method yet, as many existing clients are built around stdio and/or sse. However, as the MCP ecosystem evolves, broader support for streamable-http is surely coming.

Overall, ActionMCP presents a compelling option for Rails developers looking to integrate their applications with AI systems, and I'm looking forward to seeing how it develops and how it can be leveraged in future projects.

Articles in this series

Paweł Strzałkowski
Chief Technology Officer

Check my Twitter

Check my Linkedin

Did you like it? 

Sign up To VIsuality newsletter

READ ALSO

Hot topic: Progressive Web Apps instead of native mobile apps

02
.
10
.
2024
Michał Krochecki
Ruby on Rails
Business
Backend
Frontend

Docker hosted on Jelastic

14
.
11
.
2023
Marcin Prokop
Ruby on Rails
Backend
Tutorial

All the pieces matter - Visuality DNA

14
.
11
.
2023
Michał Piórkowski
Visuality
HR

Tech conferences 2018/2019 you definitely should attend

02
.
10
.
2024
Michał Krochecki
Conferences

Visuality Poznań is here!

14
.
11
.
2023
Michał Piórkowski
Visuality
Business
HR

Why we chose Ruby on Rails and React.js for our main technologies? (FAQ).

02
.
10
.
2024
Michał Krochecki
Ruby on Rails
Backend
Frontend
Visuality

Branding: How to style your Jira?

14
.
11
.
2023
Lukasz Jackiewicz
Tutorial
Design
Project Management

How to start your UX/UI designer career

14
.
11
.
2023
Bartłomiej Bednarski
Design
Tutorial
HR

WebUSB - Bridge between USB devices and web browsers

14
.
11
.
2023
Burak Aybar
Ruby on Rails
Frontend
Backend
Tutorial

Visuality comes to town - this time it's Poznań

14
.
11
.
2023
Michał Piórkowski
Visuality
HR

How to choose a software house.

14
.
11
.
2023
Michał Piórkowski
Ruby on Rails
Business
Visuality

CSS Modules in Rails

14
.
11
.
2023
Adam Król
Ruby on Rails
Tutorial
Backend
Frontend

JSON API versus the NIH syndrome

14
.
11
.
2023
Nadia Miętkiewicz
Backend
Frontend
Tutorial

From Idea to Concept

02
.
10
.
2024
Michał Krochecki
Ruby on Rails
Business
Startups

Styling React Components

14
.
11
.
2023
Umit Naimian
Ruby on Rails
Frontend
Tutorial

How good design can help your business grow

14
.
11
.
2023
Lukasz Jackiewicz
Design
Business
Marketing

TODO not. Do, or do not.

07
.
05
.
2025
Stanisław Zawadzki
Ruby on Rails
Software

CS Lessons #003: Density map in three ways

14
.
11
.
2023
Michał Młoźniak
Ruby
Backend
Tutorial
Software

Clean code for the win

14
.
11
.
2023
Michał Piórkowski
Ruby on Rails
Backend
Frontend
Business

Crowd-operated Christmas Lights

14
.
11
.
2023
Nadia Miętkiewicz
Ruby on Rails
Backend

How to startup and be mature about it

14
.
11
.
2023
Rafał Maliszewski
Ruby on Rails
Startups
Business

A journey of a thousand miles begins with workshops

14
.
11
.
2023
Michał Piórkowski
Software
HR

CS Lessons #002: Data structures

14
.
11
.
2023
Michał Młoźniak
Ruby
Software