Get the FREE Ultimate OpenClaw Setup Guide →

ruby-sdk

The official Ruby SDK for the Model Context Protocol.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio modelcontextprotocol-ruby-sdk ruby -e require 'mcp'; server = MCP::Server.new(name: 'my_server'); # Configure transports and start the server according to your application setup; see MCP::Server documentation for details

How to use

The MCP Ruby SDK provides a server component for implementing the Model Context Protocol using Ruby. It exposes an MCP::Server that handles JSON-RPC 2.0 requests and responses, supports core MCP methods such as initialize, ping, tools/list, tools/call, prompts/list, prompts/get, resources/list, resources/read, and resources/templates/list, and allows you to register custom methods for your domain. The server can use stdio or Streamable HTTP transports, and it includes capabilities for tool, prompt, and resource registration and notifications when those lists change. Use this SDK when you want a Ruby-based MCP server that integrates with your Ruby applications and services, and you need to register tools, prompts, and resources that clients can discover and invoke via JSON-RPC.

To use the server in your application, require the mcp gem, instantiate MCP::Server with a name, register any custom methods you need (via define_custom_method), and attach a transport (e.g., StreamableHTTPTransport for HTTP-based streaming or StdioTransport for local testing). You can also configure logging via the provided notify_log_message mechanism and send structured log data to clients. The SDK emphasizes real-time updates through notifications like notify_tools_list_changed, notify_prompts_list_changed, and notify_resources_list_changed whenever the corresponding lists are updated, along with a general notify_log_message for logging events.

How to install

Prerequisites:

  • Ruby (2.7 or newer) and RubyGems installed on your system
  • Basic familiarity with Ruby Gem usage and Bundler

Install the MCP Ruby SDK:

  1. Add the gem to your Gemfile:

gem 'mcp'

  1. Install dependencies:

bundle install

Alternative: install the gem directly if you are not using Bundler:

gem install mcp

Basic usage snippet to get started:

require 'mcp'

server = MCP::Server.new(name: 'my_server')

Configure transports (example for testing with stdio)

transport = MCP::Server::Transports::StdioTransport.new(server) server.transport = transport

Start serving (your application will manage the full lifecycle as appropriate)

This may involve starting an event loop or integrating with your app's server framework

Additional notes

Notes and tips:

  • This SDK is gem-based; you integrate MCP::Server into your Ruby application rather than running a standalone binary.
  • To expose tools, prompts, or resources, register them on the server using the provided APIs (e.g., define_custom_method for custom RPC methods, and appropriate registrations for tools/prompts/resources).
  • Use the notification helpers (notify_tools_list_changed, notify_prompts_list_changed, notify_resources_list_changed) to push real-time updates to clients adopting the MCP streaming/notifications model.
  • If you want to enable structured logging, configure and use notify_log_message with a level and data payload; clients can filter messages based on the configured logging level.
  • For HTTP streaming transports, consider using StreamableHTTPTransport and understand the stateless mode option for easier multi-node deployments.
  • Ensure you handle error conditions such as MethodAlreadyDefinedError when attempting to override existing MCP protocol methods.

Related MCP Servers

Sponsor this space

Reach thousands of developers