26
.
05
.
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

Actionmcp in Ruby on Rails by Paweł Strzałkowski

MCP Server with Rails and ActionMCP

17
.
03
.
2024
Paweł Strzałkowski
LLM
Ruby on Rails
Banner - MCP Server with FastMCP and Rails by Paweł Strzałkowski

MCP Server with Rails and FastMCP

17
.
03
.
2024
Paweł Strzałkowski
LLM
Ruby
Ruby on Rails

Ruby on Rails and Model Context Protocol

17
.
03
.
2024
Paweł Strzałkowski
Ruby on Rails
LLM
Title image

Highlights from wroclove.rb 2025

02
.
10
.
2024
Kaja Witek
Conferences
Ruby
Jarosław Kowalewski - Migration from Heroku using Kamal

Migration from Heroku using Kamal

14
.
11
.
2023
Jarosław Kowalewski
Backend
store-vs-store_accessor by Michał Łęcicki

Active Record - store vs store_accessor

14
.
11
.
2023
Michał Łęcicki
Ruby
Ruby on Rails
How to become a Ruby Certified Programmer Title image

How to become a Ruby Certified Programmer

14
.
11
.
2023
Michał Łęcicki
Ruby
Visuality
Vector Search in Ruby - Paweł Strzałkowski

Vector Search in Ruby

17
.
03
.
2024
Paweł Strzałkowski
ChatGPT
Embeddings
Postgresql
Ruby
Ruby on Rails
LLM Embeddings in Ruby - Paweł Strzałkowski

LLM Embeddings in Ruby

17
.
03
.
2024
Paweł Strzałkowski
Ruby
LLM
Embeddings
ChatGPT
Ollama
Handling Errors in Concurrent Ruby, Michał Łęcicki

Handling Errors in Concurrent Ruby

14
.
11
.
2023
Michał Łęcicki
Ruby
Ruby on Rails
Tutorial
Recap of Friendly.rb 2024 conference

Insights and Inspiration from Friendly.rb: A Ruby Conference Recap

02
.
10
.
2024
Kaja Witek
Conferences
Ruby on Rails

Covering indexes - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Ruby on Rails
Postgresql
Backend
Ula Sołogub - SQL Injection in Ruby on Rails

The Deadly Sins in RoR security - SQL Injection

14
.
11
.
2023
Urszula Sołogub
Backend
Ruby on Rails
Software
Michal - Highlights from Ruby Unconf 2024

Highlights from Ruby Unconf 2024

14
.
11
.
2023
Michał Łęcicki
Conferences
Visuality
Cezary Kłos - Optimizing Cloud Infrastructure by $40 000 Annually

Optimizing Cloud Infrastructure by $40 000 Annually

14
.
11
.
2023
Cezary Kłos
Backend
Ruby on Rails

Smooth Concurrent Updates with Hotwire Stimulus

14
.
11
.
2023
Michał Łęcicki
Hotwire
Ruby on Rails
Software
Tutorial

Freelancers vs Software house

02
.
10
.
2024
Michał Krochecki
Visuality
Business

Table partitioning in Rails, part 2 - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Backend
Postgresql
Ruby on Rails

N+1 in Ruby on Rails

14
.
11
.
2023
Katarzyna Melon-Markowska
Ruby on Rails
Ruby
Backend

Turbo Streams and current user

07
.
05
.
2025
Mateusz Bilski
Hotwire
Ruby on Rails
Backend
Frontend

Showing progress of background jobs with Turbo

14
.
11
.
2023
Michał Łęcicki
Ruby on Rails
Ruby
Hotwire
Frontend
Backend

Table partitioning in Rails, part 1 - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Postgresql
Backend
Ruby on Rails