home / mcp / mcp ruby sdk mcp server
Provides a Ruby-based MCP server framework to expose tools, prompts, and resources via JSON-RPC 2.0.
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.
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.
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.rbConfigure 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.
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.rbA simple example tool that echoes back its arguments.
This tool performs specific functionality described in the examples.
Calculate statistics for a dataset using defined input and output schemas.
Get current weather for a specified location using a defined weather tool.
Example tool for structured content handling and responses.