Ruby implementation of the Model Context Protocol (MCP).
Add this line to your application's Gemfile:
gem 'mcp'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install mcp
Here's a simple example of creating an MCP server with a calculator tool:
require 'mcp'
# Create an MCP server
server = MCP::Server.new(
name: "Demo",
version: "1.0.0"
)
# Add an addition tool
server.add_tool("add") do |params|
result = params["a"] + params["b"]
{
content: [{ type: "text", text: result.to_s }]
}
end
# Add a dynamic greeting resource
server.add_resource("greeting") do |uri, params|
{
contents: [{
uri: uri,
text: "Hello, #{params['name']}!"
}]
}
end
# Start the server using stdio transport
transport = MCP::Transport::Stdio.new
server.connect(transport)
- Full implementation of the MCP specification
- Support for Resources, Tools, and Prompts
- Multiple transport options (stdio, HTTP/SSE)
- Easy-to-use high-level interfaces
- Async/await support
- Comprehensive type system
For detailed documentation, please visit:
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Bug reports and pull requests are welcome on GitHub at https://github.com/modelcontextprotocol/ruby-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.