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

Summary of Phoenix workshop at Visuality

14
.
11
.
2023
Karol Słuszniak
Ruby on Rails
Visuality
Backend

CS Lessons #001: Working with binary files

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

CS Lessons #000: Introduction and motivation

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

Working with 40-minute intervals

14
.
11
.
2023
Sakir Temel
Software
HR

THE MATURE TECH STARTUP DILEMMA: WHAT'S NEXT

14
.
11
.
2023
Susanna Romantsova
Startups

Win MVP workshop!

14
.
11
.
2023
Susanna Romantsova
Startups

FINTECH WEEK IN OSLO: WHATs & WHYs

14
.
11
.
2023
Susanna Romantsova
Conferences

MY FIRST MONTH AT VISUALITY

14
.
11
.
2023
Susanna Romantsova
Visuality
HR

NASA 1st global hackaton in Poland? Visuality Created it!

14
.
11
.
2023
Rafał Maliszewski
Ruby on Rails

Berlin StartupCamp 2016 summary

14
.
11
.
2023
Michał Piórkowski
Conferences
Startups

Investment Days for productivity

14
.
11
.
2023
Rafał Maliszewski
Visuality
HR

Happy new year

14
.
11
.
2023
Michał Piórkowski
Visuality

Does Norway need Polish software development?

14
.
11
.
2023
Rafał Maliszewski
Ruby on Rails

Visuality is 8 years old

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

Use less javascript plugins

14
.
11
.
2023
Michał Młoźniak
Frontend

Front-Trends 2015

14
.
11
.
2023
Adam Król
Frontend

Automatic door opener controlled through slack

14
.
11
.
2023
Sakir Temel
Backend
Software
Tutorial

Wolves Summit

14
.
11
.
2023
Michał Piórkowski
Conferences
Business

Berlin Startup Camp

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

Why you shouldn't work at Visuality

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

SaaS Meetup #People

14
.
11
.
2023
Michał Piórkowski
Conferences

Startup Safary Berlin 2015

14
.
11
.
2023
Michał Piórkowski
Conferences

Optional dependencies in gems

14
.
11
.
2023
Karol Słuszniak
Ruby on Rails
Backend

Emmet makes HTML and CSS easier

14
.
11
.
2023
Michał Piórkowski
Frontend
Tutorial