Sandbox
@funwarioisii/mcp-rb

Ruby framework for MCP servers

MCP-RB gives you a Ruby DSL for building MCP servers that expose resources, resource templates, and tools. It follows the MCP 2024-11-05 spec and supports stdio transport plus basic server methods like `ping`, `resources/list`, and `tools/call`.

204 stars14 forksRubyUpdated 1y ago
Who it's for

Builders who want to create MCP servers in Ruby for agents and other MCP clients.

What it delivers

You can package Ruby logic as MCP resources and tools that an agent can call.

What it does

Sinatra-like DSL

Define server name, version, resources, templates, and tools with a small Ruby DSL.

Resource and template support

Expose static resources and parameterized resource templates with `resource` and `resource_template` blocks.

Tool definitions

Create callable tools with typed arguments, required fields, and nested argument structures.

MCP 2024-11-05 support

Implements the base protocol, stdio transport, and server features listed in the 2024-11-05 spec.

Examples and test coverage

Includes sample servers in `examples/` and unit and integration tests in `test/`.

How to get it

  1. 1Any capabilities are not supported yet.
    rake test
    rake test:unit # run only the unit tests, skipping tests that test a running server
  2. 2Test with MCP Inspector
    bunx @modelcontextprotocol/inspector $(pwd)/examples/hello_world.rb
  3. 3Run
    bundle exec standardrb --fix
  4. 4You can also use rake tasks
    rake lint      # Run standardrb to check code style
    rake lint:fix  # Auto-fix standardrb issues
  5. 5Create a git tag
    git add .
    git commit -m "Release vx.y.z"
    git tag vx.y.z
    git push --tags
  6. 6Build and push to RubyGems
    gem build mcp-rb.gemspec
    gem push mcp-rb-*.gem

README

MCP-RB

A lightweight Ruby framework for implementing MCP (Model Context Protocol) servers with a Sinatra-like DSL.

Installation

Add this line to your application's Gemfile:

gem 'mcp-rb'

Usage

Here's a simple example of how to create an MCP server:

require 'mcp'

name "hello-world"

version "1.0.0"

# Define a resource
resource "hello://world" do
  name "Hello World"
  description "A simple hello world message"
  call { "Hello, World!" }
end

# Define a resource template
resource_template "hello://{user_name}" do
  name "Hello User"
  description "A simple hello user message"
  call { |args| "Hello, #{args[:user_name]}!" }
end

# Define a tool
tool "greet" do
  description "Greet someone by name"
  argument :name, String, required: true, description: "Name to greet"
  call do |args|
    "Hello, #{args[:name]}!"
  end
end

# Define a tool with nested arguments
tool "greet_full_name" do
  description "Greet someone by their full name"
  argument :person, required: true, description: "Person to greet" do
    argument :first_name, String, required: false, description: "First name"
    argument :last_name, String, required: false, description: "Last name"
  end
  call do |args|
    "Hello, First: #{args[:person][:first_name]} Last: #{args[:person][:last_name]}!"
  end
end

# Define a tool with an Array argument
tool "group_greeting" do
  description "Greet multiple people at once"
  argument :people, Array, required: true, items: String, description: "People to greet"
  call do |args|
    args[:people].map { |person| "Hello, #{person}!" }.join(", ")
  end
end

Supported specifications

Reference: MCP 2024-11-05

  • Base Protocol
    • ping
    • stdio transport
  • Server features
    • Resources
      • resources/read
      • resources/list
      • resources/templates/list
    • Tools
      • tools/list
      • tools/call

Any capabilities are not supported yet.

Testing

rake test
rake test:unit # run only the unit tests, skipping tests that test a running server

Test with MCP Inspector

bunx @modelcontextprotocol/inspector $(pwd)/examples/hello_world.rb

Formatting

bundle exec standardrb --fix

You can also use rake tasks:

rake lint      # Run standardrb to check code style
rake lint:fix  # Auto-fix standardrb issues

Release

To release a new version:

  1. Update version in lib/mcp/version.rb
  2. Update CHANGELOG.md
  3. Create a git tag
git add .
git commit -m "Release vx.y.z"
git tag vx.y.z
git push --tags
  1. Build and push to RubyGems
gem build mcp-rb.gemspec
gem push mcp-rb-*.gem

Changelog

See CHANGELOG.md

Files in the repo

Repository payload13 top-level entries
  • .github
  • examples
  • lib
  • schemas
  • test
  • .gitignore
  • CHANGELOG.md
  • Gemfile
  • Gemfile.lock
  • LICENSE.txt
  • mcp-rb.gemspec
  • Rakefile
  • README.md

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More frameworks & sdks

HKUDS/nanobotFrameworks & SDKs

Ultra-lightweight, open-source, self-hosted personal AI agent framework in Python with WebUI, tools, memory, MCP, multi-agent workflows, automation, and chat apps

48k
microsoft/
SkillOpt
microsoft/SkillOptFrameworks & SDKs

SkillOpt is a text-space optimizer that trains reusable natural-language skills for frozen LLM agents through trajectory-driven edits, validation-gated updates, and deployable best_skill.md artifacts.

17k
omnigent-ai/omnigentFrameworks & SDKs

Omnigent is an open-source AI agent framework and meta-harness: orchestrate Claude Code, Codex, Cursor, Pi, and custom agents — swap harnesses without rewriting, enforce policies and sandboxing, and collaborate in real time from any device.

9.8k
kyegomez/
OpenMythos
kyegomez/OpenMythosFrameworks & SDKs

A theoretical reconstruction of the Claude Mythos architecture, built from first principles using the available research literature.

15k
D4Vinci/ScraplingFrameworks & SDKs

🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl!

80k