GitHub - modelcontextprotocol/ruby-sdk: The official Ruby SDK for the Model Context Protocol servers and clients. · GitHub
https://github.com/modelcontextprotocol/ruby-sdk • 344 KB fetched
Open original page
GitHub - modelcontextprotocol/ruby-sdk: The official Ruby SDK for the Model Context Protocol servers and clients. · GitHub
Skip to content
Navigation Menu
Sign in Appearance settings
* Platform
* AI CODE CREATION
* GitHub Copilot Write better code with AI
* GitHub Copilot app Direct agents from issue to merge
* MCP Registry Integrate external tools
* DEVELOPER WORKFLOWS
* Actions Automate any workflow
* Codespaces Instant dev environments
* Issues Plan and track work
* Code Review Manage code changes
* Code Quality Enforce quality at merge
* APPLICATION SECURITY
* GitHub Advanced Security Find and fix vulnerabilities
* Code security Secure your code as you build
* Secret protection Stop leaks before they start
* EXPLORE
* Why GitHub
* Documentation
* Blog
* Changelog
* Marketplace
View all features
* Solutions
* BY COMPANY SIZE
* Enterprises
* Small and medium teams
* Startups
* Nonprofits
* BY USE CASE
* App Modernization
* DevSecOps
* DevOps
* CI/CD
* View all use cases
* BY INDUSTRY
* Healthcare
* Financial services
* Manufacturing
* Government
* View all industries
View all solutions
* Resources
* EXPLORE BY TOPIC
* AI
* Software Development
* DevOps
* Security
* View all topics
* EXPLORE BY TYPE
* Customer stories
* Events & webinars
* Ebooks & reports
* Business insights
* GitHub Skills
* SUPPORT & SERVICES
* Documentation
* Customer support
* Community forum
* Trust center
* Partners
View all resources
* Open Source
* COMMUNITY
* GitHub Sponsors Fund open source developers
* PROGRAMS
* Security Lab
* Maintainer Community
* GitHub Stars
* Archive Program
* REPOSITORIES
* Topics
* Trending
* Collections
* Enterprise
* ENTERPRISE SOLUTIONS
* Enterprise platform AI-powered developer platform
* AVAILABLE ADD-ONS
* GitHub Advanced Security Enterprise-grade security features
* Copilot for Business Enterprise-grade AI features
* Premium Support Enterprise-grade 24/7 support
* Pricing
Search /
Sign in
Sign up Appearance settings
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.
You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
Uh oh!
There was an error while loading. Please reload this page .
modelcontextprotocol
/
ruby-sdk
Public
*
Notifications
You must be signed in to change notification settings
*
Fork
132
*
Star
906
*
Code
*
Issues
1
*
Pull requests
1
*
Discussions
*
Actions
*
Projects
*
Security and quality
7
*
Insights
Additional navigation options
*
Code
*
Issues
*
Pull requests
*
Discussions
*
Actions
*
Projects
*
Security and quality
*
Insights
main
Branches Tags
Go to file
Code Open more actions menu
Latest commit
History
929 Commits
929 Commits
Folders and files
Name Name Last commit message
Last commit date
.github
.github
bin
bin
conformance
conformance
docs
docs
examples
examples
lib
lib
test
test
.gitattributes
.gitattributes
.gitignore
.gitignore
.rubocop.yml
.rubocop.yml
AGENTS.md
AGENTS.md
CHANGELOG.md
CHANGELOG.md
CLAUDE.md
CLAUDE.md
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
Gemfile
Gemfile
LICENSE
LICENSE
README.md
README.md
RELEASE.md
RELEASE.md
ROADMAP.md
ROADMAP.md
Rakefile
Rakefile
SECURITY.md
SECURITY.md
VERSIONING.md
VERSIONING.md
dev.yml
dev.yml
mcp.gemspec
mcp.gemspec
View all files
Repository files navigation
*
* README
* Code of conduct
* Contributing
* License
* Security
More items
MCP Ruby SDK
The official Ruby SDK for Model Context Protocol servers and clients.
Detailed guides are available at https://ruby.sdk.modelcontextprotocol.io .
Features
* Build MCP servers that expose tools, prompts, and resources to any MCP host
* Build MCP clients that connect to any MCP server, with automatic lifecycle negotiation and OAuth 2.1 authorization
* Speak every standard transport: stdio and Streamable HTTP (including SSE), with a Rails integration
* Cover the full protocol surface: server-to-client requests, multi round-trip requests, notifications, progress, logging, cancellation, completions, and pagination
Installation
Add this line to your application's Gemfile:
gem "mcp"
And then execute:
$ bundle install
Or install it yourself as:
$ gem install mcp
You may need to add additional dependencies depending on which features you wish to access.
Quick Start
The following minimal programs show both sides of the protocol: a server that exposes a single tool,
and a client that spawns such a server and drives it over stdio.
MCP Server
A minimal server defines a tool and serves it over the stdio transport:
require "mcp"
# Create a simple tool
class ExampleTool < MCP :: Tool
description "A simple example tool that echoes back its arguments"
input_schema (
properties : {
message : { type : "string" } ,
} ,
required : [ "message" ]
)
class << self
def call ( message : , server_context : )
MCP :: Tool :: Response . new ( [ {
type : "text" ,
text : "Hello from example tool! Message: #{ message } " ,
} ] )
end
end
end
# Set up the server
server = MCP :: Server . new (
name : "example_server" ,
tools : [ ExampleTool ] ,
)
# Create and start the transport
transport = MCP :: Server :: Transports :: StdioTransport . new ( server )
transport . open
Save the script as server.rb , run it, and send JSON-RPC requests via stdin:
$ ruby server.rb
{"jsonrpc":"2.0","id":"1","method":"ping"}
{"jsonrpc":"2.0","id":"2","method":"tools/list"}
{"jsonrpc":"2.0","id":"3","method":"tools/call","params":{"name":"example_tool","arguments":{"message":"Hello"}}}
The same server can also run over Streamable HTTP, including mounted inside a Rails application;
see Server Transports .
MCP Client
A minimal client spawns a stdio server as a subprocess, connects, and lists and calls its tools:
stdio_transport = MCP :: Client :: Stdio . new (
command : "bundle" ,
args : [ "exec" , "ruby" , "path/to/server.rb" ] ,
env : { "API_KEY" => "my_secret_key" } ,
read_timeout : 30
)
client = MCP :: Client . new ( transport : stdio_transport )
# Perform the MCP initialization handshake before sending any requests.
client . connect
# List available tools.
tools = client . tools
tools . each do | tool |
puts "Tool: #{ tool . name } - #{ tool . description } "
end
# Call a specific tool.
response = client . call_tool (
tool : tools . first ,
arguments : { message : "Hello, world!" }
)
# Close the transport when done.
stdio_transport . close
The same client can connect to Streamable HTTP servers with MCP::Client::HTTP ;
see Client Transports .
Examples
Runnable examples are available in examples/ ,
including a complete Rails application in examples/rails .
Documentation
* SDK guides
* SDK API documentation
* Model Context Protocol documentation
License
This project is licensed under the Apache License 2.0 for new contributions, with existing code under MIT. See the LICENSE file for details.
About
The official Ruby SDK for the Model Context Protocol servers and clients.
ruby.sdk.modelcontextprotocol.io
Topics
mcp mcp-client mcp-server ruby
Resources
Readme
License
Code of conduct
Code of conduct
Contributing
Contributing
Security policy
Security policy
Activity
Custom properties
Stars
906 stars
Watchers
16 watching
Forks
132 forks
Report repository
Releases
Used by
Contributors
Languages
Footer
(c) 2026 GitHub, Inc.
Footer navigation
*
Terms
*
Privacy
*
Security
*
Status
*
Community
*
Docs
*
Contact
*
Manage cookies
*
Do not share my personal information
You can’t perform that action at this time.
Links found on this page
- Skip to content [direct]
- Sign in [direct]
- GitHub Copilot Write better code with AI [direct]
- GitHub Copilot app Direct agents from issue to merge [direct]
- MCP Registry Integrate external tools [direct]
- Actions Automate any workflow [direct]
- Codespaces Instant dev environments [direct]
- Issues Plan and track work [direct]
- Code Review Manage code changes [direct]
- Code Quality Enforce quality at merge [direct]
- GitHub Advanced Security Find and fix vulnerabilities [direct]
- Code security Secure your code as you build [direct]
- Secret protection Stop leaks before they start [direct]
- Why GitHub [direct]
- Documentation [direct]
- Blog [direct]
- Changelog [direct]
- Marketplace [direct]
- View all features [direct]
- Enterprises [direct]
- Small and medium teams [direct]
- Startups [direct]
- Nonprofits [direct]
- App Modernization [direct]
- DevSecOps [direct]
- DevOps [direct]
- CI/CD [direct]
- View all use cases [direct]
- Healthcare [direct]
- Financial services [direct]
- Manufacturing [direct]
- Government [direct]
- View all industries [direct]
- View all solutions [direct]
- AI [direct]
- Software Development [direct]
- DevOps [direct]
- Security [direct]
- View all topics [direct]
- Customer stories [direct]
- Events & webinars [direct]
- Ebooks & reports [direct]
- Business insights [direct]
- GitHub Skills [direct]
- Customer support [direct]
- Community forum [direct]
- Trust center [direct]
- Partners [direct]
- View all resources [direct]
- GitHub Sponsors Fund open source developers [direct]
- Security Lab [direct]
- Maintainer Community [direct]
- GitHub Stars [direct]
- Archive Program [direct]
- Topics [direct]
- Trending [direct]
- Collections [direct]
- Copilot for Business Enterprise-grade AI features [direct]
- Premium Support Enterprise-grade 24/7 support [direct]
- Pricing [direct]
- Sign up [direct]
- modelcontextprotocol [direct]
- Notifications [direct]
- Issues
1 [direct]
- Pull requests
1 [direct]
- Discussions [direct]
- Actions [direct]
- Projects [direct]
- Security and quality
7 [direct]
- Insights [direct]
- Branches [direct]
- Tags [direct]
- 929 Commits [direct]
- .github [direct]
- bin [direct]
- conformance [direct]
- docs [direct]
- examples [direct]
- lib [direct]
- test [direct]