Lightweight Ruby framework for MCP servers with Sinatra-like DSL including resources and tools
MCP-RB (Model Context Protocol) is a lightweight Ruby framework designed to implement MCP servers with ease, offering developers a convenient and flexible tool to integrate their applications into the Model Context Protocol ecosystem. Inspired by Sinatra's DSL, it provides a straightforward way to define resources, tools, and templates using intuitive code.
MCP-RB focuses on enabling developers to quickly set up servers that can communicate with various AI applications through the Model Context Protocol. The server supports defining resources, which represent specific data sources or tools that can be accessed via API endpoints. Tools are function-like components used for performing actions based on user input. MCP-RB also supports resource templates, which enable more dynamic responses by allowing placeholders to be substituted with actual values.
Resources in MCP-RB are defined using a simple DSL. For example:
resource "hello://world" do
name "Hello World"
description "A simple hello world message"
call { "Hello, World!" }
end
This resource defines an endpoint that, when accessed, will return the string "Hello, World!".
Tools allow for more complex interactions. They can take arguments and return specific outputs based on user input:
tool "greet" do
description "Greet someone by name"
argument :name, String, required: true, description: "Name to greet"
call do |args|
"Hello, #{args[:name]}!"
end
end
This tool allows for greeting a person by their name and returns a personalized message.
Complex interactions can be handled using nested structures:
tool "greet_full_name" do
description "Greet someone by their full name"
argument :person, required: true, description: "Person to greet" do
argument :first_name, String, required: false, description: "First name"
argument :last_name, String, required: false, description: "Last name"
end
call do |args|
"Hello, First: #{args[:person][:first_name]} Last: #{args[:person][:last_name]}!"
end
end
This tool allows for greeting someone by their full name, handling cases where the first and/or last name might not be provided.
Dynamic interactions can also be achieved using arrays:
tool "group_greeting" do
description "Greet multiple people at once"
argument :people, Array, required: true, items: String, description: "People to greet"
call do |args|
args[:people].map { |person| "Hello, #{person}!" }.join(", ")
end
end
This tool allows for greeting multiple people by their names and returns a concatenated message.
MCP-RB is built to adhere strictly to the Model Context Protocol specifications. It includes support for base protocol features such as ping
and stdio transport
. Additionally, it supports server-specific features like defining resources, tools, and templates. Every operation in an MCP-RB server starts with a clear delineation of what each component does.
To install MCP-RB, add the following line to your application's Gemfile:
gem 'mcp-rb'
Run bundle install
to install the gem. Once installed, you can start defining resources and tools using the provided DSL.
Here’s how you may define a resource and tool in config.ru
or within your main application file:
require 'mcp'
name "hello-world"
version "1.0.0"
resource "hello://world" do
name "Hello World"
description "A simple hello world message"
call { "Hello, World!" }
end
tool "greet" do
description "Greet someone by name"
argument :name, String, required: true, description: "Name to greet"
call do |args|
"Hello, #{args[:name]}!"
end
end
Suppose you run a customer service application that needs to provide personalized greetings. MCP-RB can help by defining tools like greet
and greet_full_name
, allowing the app to dynamically generate personalized messages based on user input.
Imagine an AI application that requires real-time data processing for news analytics. By defining resources and tools within MCP-RB, you can enable seamless integration of data sources like APIs or files, processing them as needed with custom logic defined in your tools.
MCP-RB is designed to be fully compatible with leading MCP clients such as Claude Desktop, Continue, Cursor, etc. The framework ensures that the server can handle the request flows necessary for these applications to interact effectively and efficiently.
MCP Client | Resources | Tools | Prompts |
---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ |
Continue | ✅ | ✅ | ✅ |
Cursor | ❌ | ✅ | ❌ |
This matrix highlights the level of support each client offers, showing which features are fully supported and which need further development.
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
To configure MCP-RB effectively and ensure security, you can customize several settings in the mcp-rb
file:
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
This configuration sets the command, arguments, and environment variables for your server.
Do I need a separate API key for each MCP client?
How do I handle errors in my tools and resources?
Can I define my own prompt templates?
Does MCP-RB support multiple languages in its tools and resources?
What happens if an MCP client cannot find a resource or tool I’ve defined?
MCP-RB is open for contributions from developers who want to enhance its features and fix bugs. To contribute:
Contributors are also encouraged to read the CONTRIBUTING.md
file for additional guidelines and best practices.
MCP-RB integrates seamlessly into the broader Model Context Protocol ecosystem, making it easier for developers to build applications that can interact with multiple AI tools. Explore other resources such as the official modelcontextprotocol.io documentation and community forums for more information and support.
By leveraging the capabilities of MCP-RB, you can unlock a world of possibilities in building robust, integrated AI solutions.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods