modelcontextprotocol/ruby-sdk

The official Ruby SDK for the Model Context Protocol servers and clients.

What it solves

Large language models (LLMs) often need to reach outside their own knowledge — to call tools, fetch resources, or follow prompts. The Model Context Protocol (MCP) is a standard way for AI applications ("hosts") to talk to such capabilities. This project is the official Ruby SDK for building both sides of that conversation: programs that provide tools and data to AI hosts (servers), and programs that connect to those providers (clients). It saves Ruby developers from hand-writing the protocol, authentication, and transport plumbing.

How it works

The SDK implements the full MCP protocol in Ruby. On the server side, you define tools as Ruby classes (with a description and an input schema), bundle them into an MCP::Server, and attach a transport — either stdio (reading JSON-RPC requests from standard input) or Streamable HTTP, which can be mounted inside a Rails app. On the client side, you create an MCP::Client with a transport (e.g., spawning a server as a subprocess over stdio), call connect to negotiate the protocol lifecycle, then list and invoke the server's tools. The SDK handles the details: OAuth 2.1 authentication, lifecycle negotiation, server-to-client requests, multi-round-trip requests, notifications, progress reporting, logging, cancellation, completions, and pagination.

Who it's for

Ruby developers who want to expose their application's capabilities (tools, prompts, resources) to MCP-compatible AI hosts, or who want to build Ruby applications that consume tools from any MCP server. It's also useful for teams running Rails applications that need to serve MCP endpoints, since a Rails integration is included.

Highlights

  • Official SDK for the Model Context Protocol, maintained under the modelcontextprotocol organization
  • Build MCP servers exposing tools, prompts, and resources, with OAuth 2.1 resource-server protection
  • Build MCP clients that connect to any server, with automatic lifecycle negotiation and OAuth 2.1 authorization
  • Supports both standard transports: stdio and Streamable HTTP (including SSE), with a Rails integration
  • Covers the full protocol surface: server-to-client requests, multi round-trip requests, notifications, progress, logging, cancellation, completions, and pagination
  • Minimal quick-start examples show a working server and client in a few lines of Ruby
  • Runnable examples included, including a complete Rails application
  • Dual-licensed: Apache 2.0 for new contributions, MIT for existing code

Related

  • Project
  • Project
  • Project
  • Project
  • Project