Leveraging Gemini CLI and the underlying Gemini LLM to build Model Context Protocol (MCP) AI applications with Ruby with a local development environment.
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:
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:
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)
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....
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
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
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:
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 stdio 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 extended with Gemini CLI to add several new tools in standard code.
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
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
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
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 STDIO 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 connection over stdio will look similar to this:
LOGGER.info "Starting MCP server: #{server.name} (v#{server.version})"
transport = MCP::Server::Transports::StdioTransport.new(server)
transport.open
Gemfile
The Ruby Gemfile includes the MCP and logging gems:
# frozen_string_literal: true
source 'https://rubygems.org'
ruby '3.4.8'
gem 'logger'
gem 'mcp'
group :development, :test do
gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'rubocop-rspec'
end
Running the Ruby Code
First- switch the directory with the Ruby MCP sample code:
cd ~/gemini-cli-codeassist/mcp-stdio-ruby
Run the install make target on the local system:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-ruby$ make install
Installing dependencies...
Fetching gem metadata from https://rubygems.org/...........
Bundle complete! 6 Gemfile dependencies, 31 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
To test the Ruby code:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-ruby$ make test
Running tests...
I, [2026-01-04T20:54:45.789485 #27473] INFO -- : GreetTool called with message: Hello, World!
.
Finished in 0.00188 seconds (files took 0.16243 seconds to load)
1 example, 0 failures
To style check / lint the code:
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-ruby$ make lint
Linting the code...
Inspecting 4 files
....
4 files inspected, no offenses detected
xbill@penguin:~/gemini-cli-codeassist/mcp-stdio-ruby$
Gemini CLI settings.json
The default Gemini CLI settings.json has an entry for the Ruby source:
{
"mcpServers": {
"hello-stdio-ruby": {
"command": "ruby",
"args": [
"$HOME/gemini-cli-codeassist/mcp-stdio-ruby/main.rb"
]
}
}
}
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 implemented in Ruby.
Its primary purpose is to act as a bridge between an MCP client (like Claude Desktop or a Gemini IDE extension) and local tools
or data.
Core Functionality
- Exposes Tools: Currently, it provides a greet tool that accepts a string and echoes it back. This serves as a template for
adding more complex tools (e.g., database access, API integrations, or local file processing).
- Communication: It uses the stdio (standard input/output) transport, which is the standard way MCP clients communicate with
local server processes.
- Architecture: It is structured as a modular Ruby application with:
- Namespacing: All code is contained within the McpStdioRuby module to prevent conflicts.
- Logging: A centralized logger that outputs to stderr (preserving stdout for protocol communication).
- Test-Driven: Includes an RSpec suite and RuboCop linting to ensure code quality.
How it works
When started (via ruby main.rb), the server waits for JSON-RPC messages from a client over stdin. When the client calls the
greet tool, the server processes the request and sends the response back over stdout.
Validation with Gemini CLI
Finally- Gemini CLI is restarted and the MCP connection over stdio to the Ruby Code is validated, The full Gemini CLI Session will start:
> /mcp list
Configured MCP servers:
🟢 hello-stdio-ruby - Ready (1 tool)
Tools:
- greet
> greet Red Gem!!!
✦ I will read the greet_tool.rb file to understand how it is implemented.
╭────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile lib/mcp_stdio_ruby/greet_tool.rb │
╰────────────────────────────────────────────────────────────────╯
✦ I will call the greet tool with the name "Red Gem!!!".
╭────────────────────────────────────────────────────────────────╮
│ ? greet (hello-stdio-ruby MCP Server) {"name":"Red Gem!!!"} ← │
│ │
│ MCP Server: hello-stdio-ruby │
│ Tool: greet │
│ │
│ Allow execution of MCP tool "greet" from server "hello-stdio-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-stdio-ruby MCP Server) {"name":"Red Gem!!!"} │
│ │
│ Hello, Red Gem!!!! │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ OK. Hello, Red Gem!!!
Extending the Ruby MCP Server with Gemini CLI
Now that the basic MCP functionality has been tested and verified with Gemini CLI- the Ruby server code can be extended with new MCP tools:
> add new Ruby MCP tools- one that gets the system time,
one that gets the system specs,
one that gets detailled ruby runtime informaton
Gemini CLI will get right to work:
✦ I will create the TimeTool, SystemSpecsTool, and RubyRuntimeInfoTool files.
✦ I have successfully added the new Ruby MCP tools (get_time, get_system_specs, get_ruby_info), registered them in the server,
and verified everything with tests and linting.
Restart Gemini CLI and check for the new MCP tools:
> /mcp list
Configured MCP servers:
🟢 hello-stdio-ruby - Ready (4 tools)
Tools:
- get_ruby_info
- get_system_specs
- get_time
- greet
The new MCP tools can be used in the current context:
> get_ruby_info
✦ I will now retrieve the Ruby runtime information for your environment.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ get_ruby_info (hello-stdio-ruby MCP Server) {} │
│ │
│ version: 3.4.8 │
│ patch_level: 72 │
│ platform: x86_64-linux │
│ release_date: 2025-12-17 │
│ engine: ruby │
│ description: ruby 3.4.8 (2025-12-17 revision 995b59f666) +PRISM [x86_64-linux] │
│ env_home: /home/xbill │
│ gem_home: /home/xbill/.rvm/gems/ruby-3.4.8 │
│ loaded_gems_count: 28 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Ruby 3.4.8 is running on your linux system. I'm ready for your first command.
> is there a ruby gem for this file?
✦ I will check the project directory for a gemspec file and examine its contents to see if this project is a Ruby gem.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFolder . │
│ │
│ Listed 14 item(s). (1 ignored) │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ I will read the mcp_stdio_ruby.gemspec file to confirm the gem's details.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile mcp_stdio_ruby.gemspec │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Yes, this project is a Ruby gem named mcp_stdio_ruby (version 1.0.1), as defined in mcp_stdio_ruby.gemspec. It is designed as
an MCP server using the mcp SDK.
and the time tool:
> get_time
✦ I will now retrieve the current system time.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ get_time (hello-stdio-ruby MCP Server) {} │
│ │
│ 2026-01-04 21:31:26 -0500 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ The current system time is 2026-01-04 21:31:26 -0500.
> is it 5 o clock somewhere? if so where is that?
✦ Based on the current time of 9:31 PM EST (UTC-5), it is approximately 5:30 in the following time zones:
* 5:31 PM (Yesterday/Today) in UTC-9:
* Anchorage, Alaska
* Gambier Islands, French Polynesia
* 5:31 AM (Tomorrow) in UTC+3:
* Moscow, Russia
* Istanbul, Turkey
* Riyadh, Saudi Arabia
* Nairobi, Kenya
So yes, it is "5 o'clock" (give or take 30 minutes) in Alaska right now
Using: 2 GEMINI.md files | 1 MCP server
and system information:
> get_system_specs
✦ I will now retrieve your system's basic specifications.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ get_system_specs (hello-stdio-ruby MCP Server) {} │
│ │
│ os: linux │
│ cpu_arch: x86_64 │
│ ruby_platform: x86_64-linux │
│ processors: 12 │
│ user: xbill │
│ uname: {sysname: "Linux", nodename: "penguin", release: "6.6.99-09000-gd3ae1caecf39", version: "#1 SMP PREEMPT_DYNAMIC Thu, │
│ 27 Nov 2025 21:00:42 -0800", machine: "x86_64"} │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Your system is running Linux on an x86_64 architecture with 12 processors.
> what can I do with all my cores? do all the bases belong to us?
✦ I will check the Gemfile to see if there are any gems installed that facilitate parallel processing, such as parallel_tests, to
provide a more specific recommendation for utilizing your 12 cores.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ ReadFile Gemfile │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ With 12 cores on an x86_64 Linux machine, you have plenty of power! Here is what you can do:
1. Parallel Testing: You aren't currently using parallel_tests in your Gemfile, but adding it could significantly speed up
your test suite by running specs across multiple cores.
2. Compilation: If you ever need to compile Ruby or other software from source, using make -j12 will fly.
3. Background Jobs: In a production version of your server, you could handle many concurrent client requests or background
processing jobs efficiently (though standard Ruby threads are limited by the GIL, processes or Ractors can bypass this).
And regarding your strategic inquiry: AYBABTU.
(Yes, "All your base are belong to us.")
The information from the MCP tool execution comes back into the current Gemini CLI context. You can use the information returned from the tools along with the underlying Gemini Models.
Summary
The strategy for using Ruby for MCP development with Gemini CLI was validated with a incremental step by step approach.
A minimal stdio transport MCP Server was started from Ruby source code and validated with Gemini CLI running as a MCP client in the same local environment.
Gemini CLI was then used to extend the sample Ruby code with several MCP tools and use these tools inside the context for the underlying LLM.
This approach can be extended to more complex deployments using other MCP transports and Cloud based options.


Top comments (0)