ruby_mcp_server_template

berrydev-ai/ruby_mcp_server_template

3.2

If you are the rightful owner of ruby_mcp_server_template and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The MyMCPServer is a minimal Model Context Protocol (MCP) server implemented as a Ruby gem, designed to be transport-agnostic and easily integrated into Rails applications or used via a command-line interface.

Tools
1
Resources
0
Prompts
0

my_mcp_server (example)

A minimal MCP server in a Ruby gem that provides:

  • Core transport-agnostic MCP handlers
  • Rails Engine you can mount at /my-mcp
  • CLI over stdio for editor/clients that spawn a process

1) Install & Build the Gem

cd my_mcp_server
bundle install
rake build   # or: gem build my_mcp_server.gemspec

Optionally install it locally:

rake install # or: gem install ./pkg/my_mcp_server-0.1.0.gem

2) Use in a Rails app

Add to your Rails app's Gemfile using a local path while you iterate:

gem "my_mcp_server", path: "../my_mcp_server"

Bundle and mount the engine in config/routes.rb of the host app:

mount MyMCPServer::Engine => "/my-mcp"

Boot your Rails app and POST a JSON-RPC request:

curl -X POST http://localhost:3000/my-mcp/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":"1","method":"initialize","params":{}}'

List tools:

curl -X POST http://localhost:3000/my-mcp/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":"2","method":"tools/list"}'

Call the hello tool:

curl -X POST http://localhost:3000/my-mcp/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":"3","method":"tools/call","params":{"name":"hello","arguments":{"name":"Athena"}}}'

3) Run the stdio CLI

You can also talk to the same server as a spawned process:

./bin/my_mcp-server <<'JSON'
{"jsonrpc":"2.0","id":"1","method":"initialize","params":{}}
{"jsonrpc":"2.0","id":"2","method":"tools/list"}
{"jsonrpc":"2.0","id":"3","method":"tools/call","params":{"name":"hello","arguments":{"name":"World"}}}
JSON

4) Where to add features

  • Add new tools in lib/my_mcp_server/core/tools.rb
  • Extend protocol handling in lib/my_mcp_server/core/handlers.rb
  • Keep transports thin: the Rails engine controller and the CLI both call the same core dispatcher.

5) Notes

  • This is intentionally tiny; add auth around the Rails route if you expose it publicly.
  • If your MCP client expects a specific protocolVersion, set it in handlers.rb.
  • To support notifications or streaming later, you can add WebSocket transport in the engine without touching Core.

6) Run with Sinatra

You can boot a Sinatra server exposing the same MCP endpoint:

# config.ru
require "bundler/setup"
require "my_mcp_server/sinatra/app"

run MyMCPServer::Sinatra::App

Then run:

bundle exec rackup -p 9292
curl -X POST http://localhost:9292/mcp       -H "Content-Type: application/json"       -d '{"jsonrpc":"2.0","id":"1","method":"initialize"}'