home / mcp / mcp ruby sdk mcp server

MCP Ruby SDK MCP Server

Provides a Ruby-based MCP server framework to expose tools, prompts, and resources via JSON-RPC 2.0.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "modelcontextprotocol-ruby-sdk": {
      "command": "ruby",
      "args": [
        "examples/stdio_server.rb"
      ]
    }
  }
}

You can build and run an MCP server in Ruby using the MCP Ruby SDK. This kit gives you a framework to expose tools, prompts, and resources over JSON-RPC 2.0, with support for stdio and HTTP-like transports, along with real-time notifications and customization hooks for instrumentation and error reporting.

How to use

Set up your MCP server in Ruby to expose tools, prompts, and resources to MCP clients. Create your server instance, register tools and prompts, and choose a transport that fits your deployment needs. You can also customize behavior with an exception reporter and an instrumentation callback to monitor runtime events.

How to install

Prerequisites: you need Ruby installed on your system. You will also use a Gemfile to manage the MCP gem.

1) Create a new project directory and navigate into it.

2) Add the MCP gem to your Gemfile.

3) Install dependencies with bundler or install the gem directly.

4) Run a sample Ruby script that starts an MCP server using stdio transport.

# Gemfile
gem 'mcp'
```

```bash
# Install dependencies
bundle install
```

```ruby
# Example minimal server usage (save as stdio_server_example.rb)
require "mcp"

server = MCP::Server.new(name: "ruby_example_server")
transport = MCP::Server::Transports::StdioTransport.new(server)
transport.open
```

```bash
# Run the example
ruby stdio_server_example.rb

Configuration and usage details

Configure how the server reports exceptions and how instrumentation data is collected. You can set a global configuration block or pass a configuration object when creating the server. The server supports setting a protocol version, exception reporting, and an instrumentation callback to observe method calls, errors, and durations.

The server can also be extended with custom JSON-RPC methods that you define at runtime. You can register these methods to handle new requests without impacting built‑in MCP methods.

Starting with the stdio transport (example)

If you want to run a local, command-line MCP server, you can use the stdio transport. This approach is convenient for development and local testing.

require "mcp"

# Create a simple server
server = MCP::Server.new(name: "example_server")

# Create and start the stdio transport
transport = MCP::Server::Transports::StdioTransport.new(server)
transport.open
```

```bash
ruby examples/stdio_server.rb

Available tools

example_tool

A simple example tool that echoes back its arguments.

my_tool

This tool performs specific functionality described in the examples.

calculate_stats

Calculate statistics for a dataset using defined input and output schemas.

get_weather

Get current weather for a specified location using a defined weather tool.

data_tool

Example tool for structured content handling and responses.