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

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