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

Indexing partitioned table - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Backend
Postgresql

Table partitioning types - Postgres Stories

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

SQL views in Ruby on Rails

14
.
11
.
2023
Jan Grela
Backend
Ruby
Ruby on Rails
Postgresql
Design your bathroom in React

Design your bathroom in React

07
.
05
.
2025
Bartosz Bazański
Frontend
React
Lazy Attributes in Ruby - Krzysztof Wawer

Lazy attributes in Ruby

07
.
05
.
2025
Krzysztof Wawer
Ruby
Software

Exporting CSV files using COPY - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Postgresql
Ruby
Ruby on Rails
Michał Łęcicki - From Celluloid to Concurrent Ruby

From Celluloid to Concurrent Ruby: Practical Examples Of Multithreading Calls

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

Super Slide Me - Game Written in React

07
.
05
.
2025
Antoni Smoliński
Frontend
React
Jarek Kowalewski - ILIKE vs LIKE/LOWER - Postgres Stories

ILIKE vs LIKE/LOWER - Postgres Stories

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

A look back at Friendly.rb 2023

14
.
11
.
2023
Cezary Kłos
Conferences
Ruby

Debugging Rails - Ruby Junior Chronicles

14
.
11
.
2023
Piotr Witek
Ruby on Rails
Backend
Tutorial

GraphQL in Ruby on Rails: How to Extend Connections

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

Tetris on Rails

17
.
03
.
2024
Paweł Strzałkowski
Ruby on Rails
Backend
Frontend
Hotwire

EURUKO 2023 - here's what you've missed

14
.
11
.
2023
Michał Łęcicki
Ruby
Conferences

Easy introduction to Connection Pool in ruby

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

When crazy ideas bring great time or how we organized our first Conference!

04
.
12
.
2023
Alexander Repnikov
Ruby on Rails
Conferences
Visuality

Stacey Matrix & Takeaways - why does your IT project suck?

02
.
10
.
2024
Wiktor De Witte
Project Management
Business

A simple guide to pessimistic locking in Rails

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

Poltrax design - story of POLTRAX (part 3)

04
.
12
.
2023
Mateusz Wodyk
Startups
Business
Design

Writing Chrome Extensions Is (probably) Easier Than You Think

07
.
05
.
2025
Antoni Smoliński
Tutorial
Frontend
Backend

Bounded Context - DDD in Ruby on Rails

17
.
03
.
2024
Paweł Strzałkowski
Ruby on Rails
Domain-Driven Design
Backend
Tutorial

The origin of Poltrax development - story of POLTRAX (part 2)

07
.
05
.
2025
Stanisław Zawadzki
Ruby on Rails
Startups
Business
Backend

Ruby Meetups in 2022 - Summary

14
.
11
.
2023
Michał Łęcicki
Ruby on Rails
Visuality
Conferences