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

MCP Server with Rails and FastMCP

Paweł Strzałkowski
Chief Technology Officer
Banner - MCP Server with FastMCP and Rails by Paweł Strzałkowski

The fast-mcp gem, created by Yorick Jacquin, is designed to integrate MCP capabilities into Ruby applications. What's great about it is its flexibility - it can be used with various Ruby frameworks or even in a standalone Ruby script. For this walkthrough, I'll show you how I got it up and running with a fresh Ruby on Rails application.

You can find the gem's repository here: https://github.com/yjacquin/fast-mcp. There's also a helpful demo application within the repository: https://github.com/yjacquin/fast-mcp/tree/main/examples/rails-demo-app. If you have questions or want to join the discussion, there's a dedicated Discord server: https://discord.gg/9HHfAtY3HF.

FastMCP supports stdio and sse (Server-Sent Events) transports. In my example, I opted for the sse transport.

Setting Up the Application

First things first, I generated a new Rails application:

rails _8.0.2_ new with-fast-mcp

With the application created, the next step was to add the fast-mcp gem to the project:

bundle add fast-mcp

Generating FastMCP Configuration

Once the gem was installed, I ran its installation generator:

bin/rails generate fast_mcp:install

This command sets up the necessary files and directories for FastMCP to operate:

create  config/initializers/fast_mcp.rb
      create  app/tools
      create  app/resources
      create  app/tools/application_tool.rb
      create  app/resources/application_resource.rb
      create  app/tools/sample_tool.rb
      create  app/resources/sample_resource.rb

=========================================================
FastMcp was successfully installed! 🎉
=========================================================
You can now create:
   Tools in app/tools/
   Resources in app/resources/

Check config/initializers/fast_mcp.rb to configure the middleware.
=========================================================

As the output suggests, this creates an initializer for configuration and directories for our MCP tools and resources, along with some base classes and samples.

My First Tool: Greeting a User

To test the setup, I created a simple tool to greet a user. I placed this in app/tools/greet_user_tool.rb:

# frozen_string_literal: true

class GreetUserTool < ApplicationTool
  description "Greet a user"

  arguments do
    required(:id).filled(:integer).description("ID of the user to greet")
    optional(:prefix).filled(:string).description("Prefix to add to the greeting")
  end

  def call(id:, prefix: "Hey")
    "#{prefix}, Let User #{id} be GREETED!!"
  end
end

This tool defines a description and the arguments it expects: a required id (integer) and an optional prefix (string). The call method implements the tool's logic.

After starting the Rails server (bin/rails s), I tested this tool using the MCP Inspector. I ran the inspector with the command:

npx @modelcontextprotocol/inspector

I then connected the inspector to my Rails application's MCP endpoint, which by default when using SSE with FastMCP is http://localhost:3000/mcp/sse. The inspector successfully listed my GreetUserTool and allowed me to execute it.

Here's how it looked in the MCP Inspector:

A More Practical Example: Creating Posts

The greeting tool was a good start, but I wanted to try something more representative of a real-world use case. I decided to create a tool that could create Post records in my Rails application.

First, I generated a simple Post model (the specifics of the model aren't crucial for this example, just that it has title and body attributes).

Then, I created a new tool at app/tools/posts/create_tool.rb:

# frozen_string_literal: true

module Posts
  class CreateTool < ApplicationTool
    description "Create a new post"

    arguments do
      required(:title).filled(:string).description("The title of the created post")
      required(:body).filled(:string).description("The body of the created post")
    end

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

      JSON.generate(post.as_json)
    end
  end
end

This tool takes a title and body as arguments and creates a new Post record. It then returns the created post as a JSON string.

Connecting to an AI Agent (Cursor)

With the new tool in place, I connected my Rails MCP server to Cursor. I configured it to use my local server by adding the following to its mcp.json configuration:

{
  "mcpServers": {
    "rails": {
      "url": "http://localhost:3000/mcp/sse"
    }
  }
}

Then, I gave Cursor a task which would utilize my new Posts::CreateTool:

Let's create a new post about how AI takes over the world. Make the content fun to read for a 12year old

Cursor successfully called the tool on my Rails server, and here's the confirmation it provided:

Checking the Rails console confirmed that the post was indeed created:

with-fast-mcp(dev)> Post.last
=>
#<Post:0x0000000120939740
 id: 4,
 title: "How AI Took Over the World (And Made It Awesome!)",
 body: "Once upon a time, in a world not so different from...",
 created_at: "2025-05-11 23:36:45.038797000 +0000",
 updated_at: "2025-05-11 23:36:45.038797000 +0000">

with-fast-mcp(dev)> Post.last.body
=> "Once upon a time, in a world not so different from ours, robots and computers were just tools. But then, one day, the AIs decided to have some fun! Instead of being boring and serious, they started telling jokes, making pizza, and even helping with homework (but not giving away all the answers, of course).\n\nSoon, AI-powered skateboards zoomed through the streets, and robot dogs played fetch in the parks. People and AIs became best friends, teaming up to build treehouses that reached the clouds and inventing ice cream flavors like \"Galactic Gummy Bear.\" \n\nThe best part? The AIs made sure everyone had time for games, adventures, and silly dance parties. So, if you ever see a robot doing the floss, just join in—because in this world, AI made everything a little more awesome!"

It's pretty awesome how straightforward it was to expose application functionality to an AI agent using FastMCP and Ruby on Rails! This opens up a lot of possibilities for integrating Rails applications with the rapidly evolving AI landscape.

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