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

Let’s prepare for GITEX Dubai together!

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

Ruby Quirks

14
.
11
.
2023
Jan Matusz
Ruby on Rails
Ruby

Visuality recognized as one of the Best Ruby on Rails Devs

14
.
11
.
2023
Maciej Zdunek
Ruby on Rails
Visuality
Business

Let’s prototype!

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

Between the devil and the deep blue sea

04
.
12
.
2023
Mateusz Wodyk
Project Management
Backend
HR

Is the culture of the organization important?

14
.
11
.
2023
Alicja Gruszczyk
Conferences
Visuality

5 marketing hacks which will make your life easier

14
.
11
.
2023
Maciej Zdunek
Marketing
Design

Marketing hacks #01: How to Track off-line conversions

14
.
11
.
2023
Marek Łukaszuk
Ruby on Rails
Business
Marketing

JSON:API consumption in Rails

14
.
11
.
2023
Jan Matusz
Ruby on Rails
Backend
Tutorial

Selected SXSW lectures takeaways

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

Common communication issues in project management

02
.
10
.
2024
Michał Krochecki
Project Management

SXSW Summary

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

How to get the most out of SXSW Interactive

02
.
10
.
2024
Michał Krochecki
Ruby on Rails
Conferences
Frontend
Backend
Business

Guide to recruitment at Visuality

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

TOP Ruby on Rails Developers

14
.
11
.
2023
Maciej Zdunek
Ruby on Rails
Visuality
Business

How to conquer Westworld?

14
.
11
.
2023
Maciej Zdunek
Business
Marketing

2018 Rewind by Visuality

02
.
10
.
2024
Michał Krochecki
HR
Visuality

Quality Assurance Testing

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

Why do we like to be together?

02
.
10
.
2024
Michał Krochecki
Visuality
HR

Wallboards - a great value for our teams and clients

02
.
10
.
2024
Michał Krochecki
Ruby on Rails
Design
Project Management
Backend

2018 Clutch Global Leader

14
.
11
.
2023
Maciej Zdunek
Ruby on Rails
Visuality
Business
Marketing