DEV Community

xbill for Google Developer Experts

Posted on • Originally published at Medium on

MCP Development with Ruby, Cloud Run, and Gemini CLI

Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications in Ruby deployed to Google Cloud Run.

Why not just use Python?

Python has traditionally been the main coding language for ML and AI tools. One of the strengths of the MCP protocol is that the actual implementation details are independent of the development language. The reality is that not every project is coded in Python- and MCP allows you to use the latest AI approaches with other coding languages.

Ruby? For AI? Is this even possible?

The goal of this article is to provide a minimal viable basic working MCP stdio server in Ruby that can be run locally without any unneeded extra code or extensions. The official Ruby MCP SDK is here:

GitHub - modelcontextprotocol/ruby-sdk: The official Ruby SDK for the Model Context Protocol. Maintained in collaboration with Shopify.

What Is Ruby?

Ruby is a dynamic, general-purpose programming language known for its focus on simplicity and developer happiness. It is an open-source, object-oriented language that aims for an elegant syntax which is natural to read and easy to write, almost like English.

The full details of the language can be found here:

Ruby Programming Language

What is Ruby Gems?

RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries.

The main download site is here:

RubyGems.org | your community gem host

Ruby Version Management

One of the downsides of the wide deployment of Ruby has been managing the language versions across platforms and maintaining a supported version. There are several Ruby version managers- a good starting point is rvm :

RVM: Ruby Version Manager - RVM Ruby Version Manager - Documentation

Install rvm :

xbill@penguin:~$ gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D69
56105BD0E739499BDB
gpg: directory '/home/xbill/.gnupg' created
gpg: keybox '/home/xbill/.gnupg/pubring.kbx' created
gpg: key 105BD0E739499BDB: 2 duplicate signatures removed
gpg: /home/xbill/.gnupg/trustdb.gpg: trustdb created
gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported
gpg: key 3804BB82D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: Total number processed: 2
gpg: imported: 2
xbill@penguin:~$ \curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
gpg: Signature made Fri 15 Jan 2021 01:46:22 PM EST
gpg: using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: Good signature from "Piotr Kuczynski <piotr.kuczynski@gmail.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB
GPG verified '/home/xbill/.rvm/archives/rvm-1.29.12.tgz'
Installing RVM to /home/xbill/.rvm/
    Adding rvm PATH line to /home/xbill/.profile /home/xbill/.mkshrc /home/xbill/.bashrc /home/xbill/.zshrc.
    Adding rvm loading line to /home/xbill/.profile /home/xbill/.bash_profile /home/xbill/.zlogin.
Installation of RVM in /home/xbill/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/xbill/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
/home/xbill/.bashrc:127:export PATH=/home/xbill/.local/bin:/home/xbill/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/xbill/bin:/home/xbill/bin/gyb

  * WARNING: Above files contains PATH= with no $PATH inside, this can break RVM,
    for details check [https://github.com/rvm/rvm/issues/1351#issuecomment-10939525](https://github.com/rvm/rvm/issues/1351#issuecomment-10939525)
    to avoid this warning prepend $PATH

Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

👉 Donate: [https://opencollective.com/rvm/donate](https://opencollective.com/rvm/donate)
Enter fullscreen mode Exit fullscreen mode

Then download the latest Ruby- as of writing it is 3.4.8:

xbill@penguin:~$ source /home/xbill/.rvm/scripts/rvm
xbill@penguin:~$ rvm install 3.4.8
Searching for binary rubies, this might take some time.
No binary rubies available for: debian/12/x86_64/ruby-3.4.8.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for debian.
Installing requirements for debian.
Updating system....
Enter fullscreen mode Exit fullscreen mode

Gemini CLI

If not pre-installed you can download the Gemini CLI to interact with the source files and provide real-time assistance:

npm install -g @google/gemini-cli
Enter fullscreen mode Exit fullscreen mode

Testing the Gemini CLI Environment

Once you have all the tools and the correct Node.js version in place- you can test the startup of Gemini CLI. You will need to authenticate with a Key or your Google Account:

gemini
Enter fullscreen mode Exit fullscreen mode

Node Version Management

Gemini CLI needs a consistent, up to date version of Node. The nvm command can be used to get a standard Node environment:

GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Ruby MCP Documentation

The official MCP GitHub Repo provides samples and documentation for getting started:

ruby-sdk/README.md at main · modelcontextprotocol/ruby-sdk

Where do I start?

The strategy for starting MCP development is a incremental step by step approach.

First, the basic development environment is setup with the required system variables, and a working Gemini CLI configuration.

Then, a minimal Hello World Style Ruby MCP Server is built with HTTP transport. This server is validated with Gemini CLI in the local environment.

This setup validates the connection from Gemini CLI to the local process via MCP. The MCP client (Gemini CLI) and the Ruby MCP server both run in the same local environment.

Next- the basic MCP server is Deployed to Google Cloud Run. This remote HTTP server is validated with the local Gemini CLI MCP client.

Setup the Basic Environment

At this point you should have a working Ruby environment and a working Gemini CLI installation. The next step is to clone the GitHub samples repository with support scripts:

cd ~
git clone https://github.com/xbill9/gemini-cli-codeassist
Enter fullscreen mode Exit fullscreen mode

Then run init.sh from the cloned directory.

The script will attempt to determine your shell environment and set the correct variables:

cd gemini-cli-codeassist
source init.sh
Enter fullscreen mode Exit fullscreen mode

If your session times out or you need to re-authenticate- you can run the set_env.sh script to reset your environment variables:

cd gemini-cli-codeassist
source set_env.sh
Enter fullscreen mode Exit fullscreen mode

Variables like PROJECT_ID need to be setup for use in the various build scripts- so the set_env script can be used to reset the environment if you time-out.

Hello World with HTTP Transport

One of the key features that the standard MCP libraries provide is abstracting various transport methods.

The high level MCP tool implementation is the same no matter what low level transport channel/method that the MCP Client uses to connect to a MCP Server.

The simplest transport that the SDK supports is the stdio (stdio/stdout) transport — which connects a locally running process. Both the MCP client and MCP Server must be running in the same environment.

The HTTP transport allows the MCP client and server to be on the same machine or distributed over the Internet.

The connection over HTTP will look similar to this:

# Create the Fixed Streamable HTTP transport
transport = FixedStreamableHTTPTransport.new(server)
server.transport = transport
Enter fullscreen mode Exit fullscreen mode

Gemfile

The Ruby Gemfile includes the MCP and logging gems:

# frozen_string_literal: true

Gem::Specification.new do |spec|
  spec.name = 'mcp-https-ruby'
  spec.version = '0.1.0'
  spec.authors = ['xbill']
  spec.email = ['xbill9@gmail.com']

  spec.summary = 'A simple Model Context Protocol (MCP) server implemented in Ruby.'
  spec.description = 'Exposes tools over HTTP (SSE) using the MCP SDK.'
  spec.homepage = 'https://github.com/xbill9/gemini-cli-codeassist/mcp-https-ruby'
  spec.license = 'MIT'
  spec.required_ruby_version = '>= 3.0.0'
Enter fullscreen mode Exit fullscreen mode

Running the Ruby Code

First- switch the directory with the Ruby MCP sample code:

cd ~/gemini-cli-codeassist/mcp-stdio-ruby
Enter fullscreen mode Exit fullscreen mode

Run the install make target on the local system:

xbill@penguin:~/gemini-cli-codeassist/mcp-https-ruby$ make install
Installing dependencies...
Bundle complete! 4 Gemfile dependencies, 35 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
xbill@penguin:~/gemini-cli-codeassist/mcp-https-ruby$ make run
Running the application...
{"timestamp":"2026-01-07T15:37:13-05:00","severity":"INFO","progname":null,"message":"Starting MCP server: hello-world-server (v1.0.0) on HTTP port 8080"}
Enter fullscreen mode Exit fullscreen mode

To test the Ruby code:

xbill@penguin:~/gemini-cli-codeassist/mcp-https-ruby$ make test
Running tests...
I, [2026-01-07T15:37:43.131201 #11820] INFO -- : GreetTool called with message: Hello, World!
.

Finished in 0.00237 seconds (files took 0.13931 seconds to load)
1 example, 0 failures
Enter fullscreen mode Exit fullscreen mode

To style check / lint the code:

xbill@penguin:~/gemini-cli-codeassist/mcp-https-ruby$ make lint
Linting the code...
Inspecting 7 files
.......

7 files inspected, no offenses detected
Enter fullscreen mode Exit fullscreen mode

Gemini CLI settings.json

The default Gemini CLI settings.json has an entry for the Ruby source:

 {
    "mcpServers": {
    "hello-https-ruby": {
      "httpUrl": "http://127.0.0.1:8080/mcp"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Review the Project with Gemini CLI

Start-up Gemini CLI and review the entire project:

> what does this project do?

✦ This project is a Model Context Protocol (MCP) server written in Ruby.

  Its purpose is to expose executable tools to LLM clients (like Gemini or Claude) over an HTTP interface using Server-Sent
  Events (SSE).

  Key Details:
   * Functionality: Currently provides a single tool named greet (defined in lib/tools/greet_tool.rb), which likely echoes a
     message back to the user.
   * Tech Stack:
       * Language: Ruby
       * SDK: mcp (Model Context Protocol SDK)
       * Server: Uses Puma and Rack to serve the MCP endpoint on port 8080 (default).
       * Transport: Implements a FixedStreamableHTTPTransport for handling SSE connections.
   * Entry Point: The server is started via bin/mcp-https-ruby (though README.md references a main.rb, which seems to have been
     moved or renamed to bin/mcp-https-ruby).

  In short, it's a backend service that allows an AI assistant to "call" the greet function.
Enter fullscreen mode Exit fullscreen mode

Start the Local MCP Server

To check the MCP connection — open a new terminal and start the MCP Server:

xbill@penguin:~/gemini-cli-codeassist/mcp-https-ruby$ make run
Running the application...
{"timestamp":"2026-01-07T15:45:24-05:00","severity":"INFO","progname":null,"message":"Starting MCP server: hello-world-server (v1.0.0) on HTTP port 8080"}
Enter fullscreen mode Exit fullscreen mode

Validation with Gemini CLI

Open a second window for the MCP client using Gemini CLI. The full Gemini CLI Session will start:

gemini
> /mcp list

Configured MCP servers:

🟢 hello-https-ruby - Ready (1 tool)
  Tools:
  - greet

> /mcp schema

Configured MCP servers:

🟢 hello-https-ruby - Ready (1 tool)
  Tools:
  - greet
    Get a greeting from a local server.
      Parameters:
      {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "The message to repeat."
          }
        },
        "required": [
          "message"
        ]
      }

> greet Red Gem!

✦ I will call the greet tool with the message "Red Gem!".

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? greet (hello-https-ruby MCP Server) {"message":"Red Gem!"} ← │
│ │
│ MCP Server: hello-https-ruby │
│ Tool: greet │
│ │
│ Allow execution of MCP tool "greet" from server "hello-https-ruby"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ ● 3. Allow all server tools for this session │
│ 4. No, suggest changes (esc) │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (hello-https-ruby MCP Server) {"message":"Red Gem!"} │
│ │
│ Red Gem! │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ OK. I've greeted "Red Gem!".

Enter fullscreen mode Exit fullscreen mode

Deploying to Cloud Run

After the HTTP version of the MCP server has been tested locally — it can be deployed remotely to Google Cloud Run.

First- switch to the directory with the HTTP MCP sample code:

cd ~/gemini-cli-codeassist/mcp-https-ruby
Enter fullscreen mode Exit fullscreen mode

Deploy the project to Google Cloud Run with the pre-built cloudbuild.yaml and Dockerfile:

cd ~/gemini-cli-codeassist/mcp-https-ruby
xbill@penguin:~/gemini-cli-codeassist/mcp-https-ruby$ make deploy
Enter fullscreen mode Exit fullscreen mode

The Cloud Build will start:

xbill@penguin:~/gemini-cli-codeassist/mcp-https-ruby$ make deploy
Submitting build to Google Cloud Build...
Creating temporary archive of 17 file(s) totalling 12.7 KiB before compression.
Some files were not included in the source upload.

Check the gcloud log [/home/xbill/.config/gcloud/logs/2026.01.07/15.49.37.223214.log] to see which files and the contents of the
default gcloudignore file used (see `$ gcloud topic gcloudignore` to learn
more).

Uploading tarball of [.] to [gs://comglitn_cloudbuild/source/1767818977.344383-5186c5f3af7b4d4b9e66734819c01f8b.tgz]
Created [https://cloudbuild.googleapis.com/v1/projects/comglitn/locations/global/builds/cc07f14e-38cb-4453-a067-3a6296f6ede2].
Logs are available at [https://console.cloud.google.com/cloud-build/builds/cc07f14e-38cb-4453-a067-3a6296f6ede2?project=1056842563084].
Waiting for build to complete. Polling interval: 1 second(s).
-
Enter fullscreen mode Exit fullscreen mode

It can take 5–10 minutes to complete the build.

When the build is complete- an endpoint will be returned:

Starting Step #2
Step #2: Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #2: Deploying container to Cloud Run service [mcp-https-ruby] in project [comglitn] region [us-central1]
Step #2: Deploying...
Step #2: Setting IAM Policy............done
Step #2: Creating Revision.....................................................................................................................................................................................................done
Step #2: Routing traffic.....done
Step #2: Done.
Step #2: Service [mcp-https-ruby] revision [mcp-https-ruby-00005-w8n] has been deployed and is serving 100 percent of traffic.
Step #2: Service URL: https://mcp-https-ruby-1056842563084.us-central1.run.app
Finished Step #2
Enter fullscreen mode Exit fullscreen mode

The service endpoint in this example is :

https://mcp-https-ruby-1056842563084.us-central1.run.app
Enter fullscreen mode Exit fullscreen mode

The actual endpoint will vary based on your project settings.

Review Service in Cloud Run

Navigate to the Google Cloud console and search for Cloud Run -

and then you can detailed information on the Cloud Run Service:

Cloud Logging

The remote server writes logs to stderr in standard JSON format. These logs are available from the deployed Cloud Run Service:

Validate HTTP connection

Once you have the Endpoint — you can attempt a connection- navigate to in your browser:

https://mcp-https-ruby-1056842563084.us-central1.run.app
Enter fullscreen mode Exit fullscreen mode

You will need to adjust the exact URL to match the URL returned from Cloud Build.

You will get an error- this connection is expecting a message in the MCP format:

Not Found
Enter fullscreen mode Exit fullscreen mode

Gemini CLI settings.json.cloudrun

Replace the default Gemini CLI configuration file —  settings.json with a pre-configured sample- settings.json.cloudrun to use the Cloud Run version of the connection:

 {
    "mcpServers": {
    "hello-cloudrun-ruby": {
      "httpUrl": "https://mcp-https-ruby-$PROJECT_NUMBER.us-central1.run.app/mcp"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Copy the Cloud Run version of the Gemini CLI configuration file:

xbill@penguin:~/gemini-cli-codeassist/mcp-https-ruby$ cd .gemini
cp settings.json.cloudrun settings.json
xbill@penguin:~/gemini-cli-codeassist/mcp-https-ruby/.gemini$
Enter fullscreen mode Exit fullscreen mode

Validation with Gemini CLI

The final connection test uses Gemini CLI as a MCP client with the deployed Cloud Run Service in Ruby providing the MCP server. Startup Gemini CLI with the updated settings :

gemini

Configured MCP servers:

🟢 hello-cloudrun-ruby - Ready (1 tool)
  Tools:
  - greet
    Get a greeting from a local server.
      Parameters:
      {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "The message to repeat."
          }
        },
        "required": [
          "message"
        ]
      }

> /mcp list

Configured MCP servers:

🟢 hello-cloudrun-ruby - Ready (1 tool)
  Tools:
  - greet

> greet Hello Red Gem!

✦ I will call the greet tool with your message.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ? greet (hello-cloudrun-ruby MCP Server) {"message":"Hello Red Gem!"} ← │
│ │
│ MCP Server: hello-cloudrun-ruby │
│ Tool: greet │
│ │
│ Allow execution of MCP tool "greet" from server "hello-cloudrun-ruby"? │
│ │
│ 1. Allow once │
│ 2. Allow tool for this session │
│ ● 3. Allow all server tools for this session │
│ 4. No, suggest changes (esc) │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will call the greet tool with your message.

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ greet (hello-cloudrun-ruby MCP Server) {"message":"Hello Red Gem!"} │
│ │
│ Hello Red Gem! │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ OK. The greet tool returned: "Hello Red Gem!"

Enter fullscreen mode Exit fullscreen mode

Summary

MCP development with Ruby using Gemini CLI was validated with an incremental step by step approach.

A minimal streaming HTTP transport MCP Server was built from source code and validated with Gemini CLI running as a MCP client in the same local environment.

Then — the MCP server was wrapped in a container and submitted to Google Cloud Build for deployment to Google Cloud Run. The remote MCP server was validated with a standard browser, and Gemini CLI.

Finally- remote MCP operations were performed from the local Gemini CLI installation to the Ruby MCP server hosted in Google Cloud Run.

This approach can be extended to more complex deployments and Cloud based options.

Top comments (0)