ruby-sdk
The official Ruby SDK for the Model Context Protocol.
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:
- Add the gem to your Gemfile:
gem 'mcp'
- 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
fast
A Ruby Implementation of the Model Context Protocol
rails
A Ruby gem implementation of a Model Context Protocol (MCP) server for Rails projects. This server allows LLMs (Large Language Models) to interact with Rails projects through the Model Context Protocol.
mcp-rb
A lightweight Ruby framework for building MCP servers with a Sinatra-like DSL
sketchup
Sketchup Model Context Protocol
rails-pg-extras
MCP (Model Context Protocol) LLM interface for rails-pg-extras gem
nvim
A Ruby implementation of the MCP server protocol for Neovim