1
.
06
.
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

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