A Ruby implementation of the Model Context Protocol (MCP) specification, enabling standardized AI application interactions with external tools and data sources.
Documentation |
- Features
- Installation
- Quick Start
- Core Concepts
- Security
- Advanced Usage
- Development
- Contributing
- License
- Full MCP Protocol Support - Implements the latest MCP specification
- Multiple Transport Options - HTTP and STDIO transports
- Comprehensive Capabilities
- 🛠️ Tools (model-controlled actions)
- 📚 Resources (application-controlled context)
- 💬 Prompts (user-controlled interactions)
- 📁 Roots (filesystem integration)
- Security First
- OAuth 2.1 Authentication
- JWT Implementation
- Scope-based Authorization
- Real-time Communication
- Bidirectional messaging
- Streaming support
- JSON-RPC 2.0 standard
Add to your Gemfile:
gem 'mcp_on_ruby'Then run:
bundle installOr install directly:
gem install mcp_on_rubyCreate a basic MCP server with tools:
require 'mcp_on_ruby'
server = MCP::Server.new do |s|
# Define a tool
s.tool "weather.get_forecast" do |params|
location = params[:location]
{ forecast: "Sunny", temperature: 72, location: location }
end
# Add a resource
s.resource "user.profile" do
{ name: "John", email: "john@example.com" }
end
end
server.startConnect to an MCP server:
require 'mcp_on_ruby'
client = MCP::Client.new(url: "http://localhost:3000")
client.connect
# List available tools
tools = client.tools.list
# Call a tool
result = client.tools.call("weather.get_forecast",
{ location: "San Francisco" }
)Model-controlled functions with JSON Schema-defined parameters:
server.tools.define('example') do
parameter :name, :string
execute do |params|
"Hello, #{params[:name]}!"
end
endApplication-controlled data sources:
server.resource "user.profile" do
{ name: "John", email: "john@example.com" }
endSecure your server with OAuth 2.1:
oauth_provider = MCP::Server::Auth::OAuth.new(
client_id: 'your-client-id',
client_secret: 'your-client-secret',
token_expiry: 3600,
jwt_secret: 'your-jwt-secret',
issuer: 'your-server'
)- Token-based authentication
- JWT validation
- Automatic token refresh
- Scope-based authorization
- Method-level permissions
- Scope requirements
- Middleware architecture
Check out our
Simple Server Authentication Rails Integration Streaming
For more advanced topics, visit our Wiki.
# Clone the repository
git clone https://github.com/nagstler/mcp_on_ruby.git
# Install dependencies
bundle install
# Run tests
bundle exec rspec
# Start console
bundle exec bin/console- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please read our
This project is licensed under the MIT License - see the