Skip to content

Commit a0af881

Browse files
committed
Complete restructure for MCP protocol implementation
0 parents  commit a0af881

File tree

13 files changed

+340
-0
lines changed

13 files changed

+340
-0
lines changed

.github/workflows/test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
ruby-version: ['2.7', '3.0', '3.1', '3.2']
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up Ruby
19+
uses: ruby/setup-ruby@v1
20+
with:
21+
ruby-version: ${{ matrix.ruby-version }}
22+
bundler-cache: true
23+
- name: Run tests
24+
run: bundle exec rake

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
.env
10+
*.gem
11+
.rspec_status
12+
.DS_Store
13+
Gemfile.lock

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.3.0] - UNRELEASED
9+
10+
### Added
11+
- Complete rewrite to implement Model Context Protocol specification
12+
- JSON-RPC 2.0 bidirectional communication
13+
- Server implementation with tools, resources, prompts, and roots
14+
- Client implementation for connecting to MCP servers
15+
- HTTP and STDIO transport options
16+
- OAuth 2.1 authentication for remote connections
17+
- Comprehensive test suite
18+
- Detailed documentation
19+
20+
## [0.2.0] - 2024-xx-xx
21+
22+
### Added
23+
- Redis storage backend for conversation persistence
24+
- Improved error handling and reporting
25+
26+
## [0.1.0] - 2024-xx-xx
27+
28+
### Added
29+
- Initial release with basic REST API functionality

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gemspec

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# MCP on Ruby
2+
3+
<div align="center">
4+
5+
[![Gem Version](https://badge.fury.io/rb/mcp_on_ruby.svg)](https://badge.fury.io/rb/mcp_on_ruby)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7+
8+
<strong>Ruby implementation of the Model Context Protocol (MCP) specification</strong>
9+
</div>
10+
11+
## Overview
12+
13+
The [Model Context Protocol](https://modelcontextprotocol.io) provides a standardized way for AI applications to interact with external tools and data sources. This library implements the MCP specification in Ruby, allowing developers to create both MCP servers and clients.
14+
15+
## Features
16+
17+
- **Full MCP 2025-03-26 Protocol Support**: Implements the latest MCP specification
18+
- **JSON-RPC 2.0 Communication**: Bidirectional messaging using the JSON-RPC standard
19+
- **Transport Options**: HTTP and STDIO transports for maximum flexibility
20+
- **Server Capabilities**:
21+
- Tools (model-controlled actions)
22+
- Resources (application-controlled context)
23+
- Prompts (user-controlled interactions)
24+
- Roots (filesystem integration)
25+
- **Client Integration**: Connect to any MCP-compatible server
26+
- **OAuth 2.1 Authentication**: Secure access to remote servers
27+
- **Streaming Support**: Real-time bidirectional communication
28+
29+
## Installation
30+
31+
Add this line to your application's Gemfile:
32+
33+
```ruby
34+
gem 'mcp_on_ruby'
35+
```
36+
37+
And then execute:
38+
39+
```
40+
$ bundle install
41+
```
42+
43+
Or install it yourself as:
44+
45+
```
46+
$ gem install mcp_on_ruby
47+
```
48+
49+
## Quick Start: Server
50+
51+
Create a simple MCP server with tools:
52+
53+
```ruby
54+
require 'mcp_on_ruby'
55+
56+
# Create a server with tools
57+
server = MCP::Server.new do |s|
58+
# Define a tool
59+
s.tool "weather.get_forecast" do |params|
60+
location = params[:location]
61+
# ... fetch weather data ...
62+
{ forecast: "Sunny", temperature: 72, location: location }
63+
end
64+
65+
# Add a resource
66+
s.resource "user.profile" do
67+
{ name: "John", email: "[email protected]" }
68+
end
69+
end
70+
71+
# Start the server
72+
server.start
73+
```
74+
75+
## Quick Start: Client
76+
77+
Connect to an MCP server and use its tools:
78+
79+
```ruby
80+
require 'mcp_on_ruby'
81+
82+
# Create a client
83+
client = MCP::Client.new(url: "http://localhost:3000")
84+
85+
# Connect to the server
86+
client.connect
87+
88+
# List available tools
89+
tools = client.list_tools
90+
puts tools
91+
92+
# Call a tool
93+
result = client.call_tool("weather.get_forecast", location: "San Francisco")
94+
puts result.inspect
95+
96+
# Get a resource
97+
profile = client.get_resource("user.profile")
98+
puts profile.inspect
99+
100+
# Disconnect
101+
client.disconnect
102+
```
103+
104+
## Architecture
105+
106+
MCP on Ruby follows the MCP specification's architecture:
107+
108+
1. **Protocol Layer**: JSON-RPC 2.0 communication over multiple transports
109+
2. **Server**: Exposes tools, resources, and prompts to clients
110+
3. **Client**: Connects to servers and uses their capabilities
111+
4. **Authentication**: OAuth 2.1 for secure remote connections
112+
113+
## Advanced Usage
114+
115+
See the [wiki](https://github.com/nagstler/mcp_on_ruby/wiki) for advanced usage, including:
116+
117+
- Creating complex tool hierarchies
118+
- Implementing custom authentication
119+
- Streaming responses
120+
- Working with resources and prompts
121+
- File system integration with roots
122+
123+
## Development
124+
125+
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.
126+
127+
## Contributing
128+
129+
Bug reports and pull requests are welcome on GitHub at https://github.com/nagstler/mcp_on_ruby.
130+
131+
## License
132+
133+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rspec/core/rake_task"
5+
6+
RSpec::Core::RakeTask.new(:spec)
7+
8+
task default: :spec

bin/console

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "ruby_mcp"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
require "irb"
11+
IRB.start(__FILE__)

bin/setup

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install

lib/ruby_mcp/configuration.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module RubyMCP
4+
class Configuration
5+
attr_accessor :log_level, :transport, :port, :host
6+
attr_accessor :auth_enabled, :auth_method, :oauth_config
7+
attr_accessor :default_timeout
8+
9+
def initialize
10+
@log_level = Logger::INFO
11+
@transport = :http
12+
@port = 3000
13+
@host = '0.0.0.0'
14+
@auth_enabled = false
15+
@auth_method = :none
16+
@default_timeout = 30 # seconds
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)