ruby_mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +2 -0
  3. data/LICENSE +21 -0
  4. data/README.md +71 -0
  5. data/Rakefile +8 -0
  6. data/exe/ruby_mcp +15 -0
  7. data/lib/ruby_mcp/capabilities/logging.rb +27 -0
  8. data/lib/ruby_mcp/handlers/completion_complete.rb +16 -0
  9. data/lib/ruby_mcp/handlers/initialize.rb +22 -0
  10. data/lib/ruby_mcp/handlers/logging_set_level.rb +10 -0
  11. data/lib/ruby_mcp/handlers/notifications_initialized.rb +6 -0
  12. data/lib/ruby_mcp/handlers/ping.rb +5 -0
  13. data/lib/ruby_mcp/handlers/prompts_get.rb +15 -0
  14. data/lib/ruby_mcp/handlers/prompts_list.rb +5 -0
  15. data/lib/ruby_mcp/handlers/resources_list.rb +5 -0
  16. data/lib/ruby_mcp/handlers/resources_read.rb +22 -0
  17. data/lib/ruby_mcp/handlers.rb +27 -0
  18. data/lib/ruby_mcp/prompts.rb +25 -0
  19. data/lib/ruby_mcp/request.rb +17 -0
  20. data/lib/ruby_mcp/requests/completion_complete.rb +19 -0
  21. data/lib/ruby_mcp/requests/initialize.rb +5 -0
  22. data/lib/ruby_mcp/requests/logging_set_level.rb +9 -0
  23. data/lib/ruby_mcp/requests/notifications_initialized.rb +5 -0
  24. data/lib/ruby_mcp/requests/ping.rb +2 -0
  25. data/lib/ruby_mcp/requests/prompts_get.rb +15 -0
  26. data/lib/ruby_mcp/requests/prompts_list.rb +5 -0
  27. data/lib/ruby_mcp/requests/resources_list.rb +5 -0
  28. data/lib/ruby_mcp/requests/resources_read.rb +13 -0
  29. data/lib/ruby_mcp/requests.rb +29 -0
  30. data/lib/ruby_mcp/resources.rb +28 -0
  31. data/lib/ruby_mcp/server/lifecycle.rb +33 -0
  32. data/lib/ruby_mcp/server.rb +84 -0
  33. data/lib/ruby_mcp/transport/stdio.rb +33 -0
  34. data/lib/ruby_mcp/transport/test.rb +25 -0
  35. data/lib/ruby_mcp/transport.rb +15 -0
  36. data/lib/ruby_mcp/version.rb +5 -0
  37. data/lib/ruby_mcp.rb +20 -0
  38. metadata +97 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 21d2e8bc121fd3b1156a684506219d5de9e7a8abe9f01c5ac0b40fa5638e5702
4
+ data.tar.gz: 205f2f1f5e46b7c1bb10530682d458fb1b62bf3315e8dae4705cc0e6c27958f8
5
+ SHA512:
6
+ metadata.gz: d72708bfcab861296da00c8476cb744e3b3ed69340a0074c02b2d587684bbc04af339ea407eb770d9e92ce7ce777be20d325c234bd2bb0311df4345c49fbb4a7
7
+ data.tar.gz: c1d9083dbab6b2a5a82f47f226122b9764637e0eb6362ac8b5a0b85a11ade854cc37ee9c743121dd5271d58d2173ebbd7783eb6d18f5c68474b3b45f3a6ac9cb
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ rubocop-rails-omakase: rubocop.yml
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Niklas Häusele
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # RubyMCP - Build a MCP Server with Ruby
2
+
3
+ A low-level Model-Context-Protocol implementation for Ruby. Supports [prompts](https://spec.modelcontextprotocol.io/specification/2025-03-26/server/prompts/) and [completions](https://spec.modelcontextprotocol.io/specification/2024-11-05/server/utilities/completion/#protocol-messages).
4
+
5
+ ```ruby
6
+ server = RubyMCP::Server.new
7
+
8
+ server.add_prompt(
9
+ name: "ruby_example",
10
+ description: "Example usage of a method",
11
+ arguments: [
12
+ {
13
+ name: "snippet",
14
+ description: "small ruby snippet",
15
+ required: true,
16
+ completions: ->(*) { [ 'String#split', 'Array#join', 'tally', 'unpack' ] }
17
+ }
18
+ ],
19
+ result: ->(snippet:) {
20
+ {
21
+ description: "Explain '#{snippet}'",
22
+ messages: [
23
+ {
24
+ role: "user",
25
+ content: {
26
+ type: "text",
27
+ text: <<~TXT
28
+ You're a coding assistant in the editor zed.
29
+ You give one practical example for the given ruby method.
30
+ Only answer with a single code snippet and one line of explanation.
31
+ For example:
32
+ INPUT: '''String#split'''
33
+ OUTPUT: 'abc'.split('') # ['a', 'b', 'c']\n Splits the string"
34
+ TXT
35
+ }
36
+ },
37
+ {
38
+ role: "user",
39
+ content: {
40
+ type: "text",
41
+ text: "INPUT: '''#{snippet}'''"
42
+ }
43
+ }
44
+ ]
45
+ }
46
+ },
47
+ )
48
+
49
+ transport = RubyMCP::Transport::Stdio.new
50
+ server.connect(transport)
51
+ ```
52
+
53
+ ## Logging
54
+
55
+ RubyMCP supports [mcp logging](https://spec.modelcontextprotocol.io/specification/2025-03-26/server/utilities/logging/). Each logging level has a corresponding method prefixed with `send_` and suffixed with `_log_message`.
56
+
57
+ - **Debug Level:**
58
+ ```ruby
59
+ server.send_debug_log_message({ text: "Debug information" })
60
+ ```
61
+
62
+ - **Info Level:**
63
+ ```ruby
64
+ server.send_info_log_message({ text: "Informational message" })
65
+ ```
66
+
67
+ A MCP client can configure change the log severity or it can be set during server creation. The default is "info".
68
+
69
+ ```ruby
70
+ server = Server.new(logging_verbosity: "debug")
71
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
data/exe/ruby_mcp ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_mcp"
5
+
6
+ server = RubyMCP::Server.new
7
+
8
+ if server_impl = ARGV[0]
9
+ server.instance_eval(File.read(server_impl))
10
+ else
11
+ RubyMCP.logger.info("No implementation given, starting default server")
12
+ end
13
+
14
+ transport = RubyMCP::Transport::Stdio.new
15
+ server.connect(transport)
@@ -0,0 +1,27 @@
1
+ module RubyMCP::Capabilities::Logging
2
+ LEVELS = {
3
+ "debug" => 0,
4
+ "info" => 1,
5
+ "notice" => 2,
6
+ "warning" => 3,
7
+ "error" => 4,
8
+ "critical" => 5,
9
+ "alert" => 6,
10
+ "emergency" => 7
11
+ }
12
+
13
+ def logging_verbosity
14
+ @level ||= @default_logging_verbosity
15
+ end
16
+
17
+ def logging_verbosity=(level)
18
+ @level = level
19
+ end
20
+
21
+ LEVELS.each do |name, value|
22
+ define_method("send_#{name}_log_message") do |msg|
23
+ send_message(
24
+ jsonrpc: "2.0", method: "notifications/message", params: msg.merge(level: name)) if value <= LEVELS[logging_verbosity]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ class RubyMCP::Handlers::CompletionComplete
2
+ def handle(server, request)
3
+ referenced_prompt = server.prompts.find_by_name(request.ref["name"])
4
+ RubyMCP.logger.debug(referenced_prompt[:arguments])
5
+ referenced_argument = referenced_prompt[:arguments].find { |argument| argument[:name] == request.argument_name }
6
+ computed_values = referenced_argument[:completions].call(**request.param)
7
+
8
+ server.answer(request,
9
+ completion: {
10
+ hasMore: false,
11
+ total: computed_values.count,
12
+ values: computed_values
13
+ }
14
+ )
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ class RubyMCP::Handlers::Initialize
2
+ def handle(server, request)
3
+ server.answer(request,
4
+ protocolVersion: "2024-11-05",
5
+ capabilities: {
6
+ logging: {},
7
+ prompts: {
8
+ listChanged: true
9
+ },
10
+ resources: {},
11
+ tools: {
12
+ listChanged: true
13
+ }
14
+ },
15
+ serverInfo: {
16
+ name: "RubyMCP",
17
+ version: RubyMCP::VERSION
18
+ }
19
+ )
20
+ server.lifecycle.initialize_response_sent!
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ class RubyMCP::Handlers::LoggingSetLevel
2
+ def handle(server, request)
3
+ if request.level_valid?
4
+ server.logging_verbosity = request.level
5
+ server.answer(request, {})
6
+ else
7
+ server.error(request, code: -32602, message: "Invalid loglevel")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class RubyMCP::Handlers::NotificationsInitialized
2
+ def handle(server, request)
3
+ server.lifecycle.operation_phase!
4
+ RubyMCP.logger.info "Operation Phase started"
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class RubyMCP::Handlers::Ping
2
+ def handle(server, request)
3
+ server.answer(request, {})
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ class RubyMCP::Handlers::PromptsGet
2
+ def handle(server, request)
3
+ if prompt = server.prompts.find_by_name(request.name)
4
+ required_arguments = prompt[:arguments].filter_map { _1[:name].to_sym if _1[:required] }
5
+ all_required_arguments_given = (required_arguments - request.arguments.keys).empty?
6
+ if all_required_arguments_given
7
+ server.answer(request, **prompt[:result].call(**request.arguments))
8
+ else
9
+ server.error(request, code: -32602, message: "Missing required param")
10
+ end
11
+ else
12
+ server.error(request, code: -32602, message: "Invalid params")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ class RubyMCP::Handlers::PromptsList
2
+ def handle(server, request)
3
+ server.answer(request, prompts: server.prompts.list)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RubyMCP::Handlers::ResourcesList
2
+ def handle(server, request)
3
+ server.answer(request, resources: server.resources.as_json)
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ class RubyMCP::Handlers::ResourcesRead
2
+ def handle(server, request)
3
+ if resource = server.resources.find(request.uri)
4
+ server.answer(request,
5
+ contents: [ {
6
+ uri: resource.uri,
7
+ mimeType: resource.mime_type,
8
+ text: resource.reader.call(resource)
9
+ } ]
10
+ )
11
+ else
12
+ server.error(
13
+ request,
14
+ code: -32002,
15
+ message: "Resource not found",
16
+ data: {
17
+ uri: request.uri
18
+ }
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module RubyMCP
2
+ class Handlers
3
+ def self.parse(json)
4
+ parsed = JSON.parse(json)
5
+ case parsed.fetch("method")
6
+ when "initialize"
7
+ Initialize
8
+ when "notifications/initialized"
9
+ NotificationsInitialized
10
+ when "ping"
11
+ Ping
12
+ when "prompts/get"
13
+ PromptsGet
14
+ when "prompts/list"
15
+ PromptsList
16
+ when "completion/complete"
17
+ CompletionComplete
18
+ when "resources/list"
19
+ ResourcesList
20
+ when "resources/read"
21
+ ResourcesRead
22
+ when "logging/setLevel"
23
+ LoggingSetLevel
24
+ end.new
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module RubyMCP
2
+ class Prompts
3
+ def initialize
4
+ @prompts = {}
5
+ end
6
+
7
+ def add(name:, description:, arguments: [], result: Proc.new { [] }, completions: nil)
8
+ @prompts[name] = { description:, arguments:, result:, completions: }
9
+ end
10
+
11
+ def list
12
+ @prompts.map do |name, details|
13
+ {
14
+ name: name,
15
+ description: details[:description],
16
+ arguments: details[:arguments].map { _1.slice(:name, :description, :required) }
17
+ }
18
+ end
19
+ end
20
+
21
+ def find_by_name(name)
22
+ @prompts[name]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ class RubyMCP::Request
2
+ def initialize(json)
3
+ @json = json
4
+ end
5
+
6
+ def method
7
+ @json["method"]
8
+ end
9
+
10
+ def id
11
+ @json["id"]
12
+ end
13
+
14
+ def allowed_in_lifecycle?(lifecycle)
15
+ true
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ class RubyMCP::Requests::CompletionComplete < RubyMCP::Request
2
+ def ref
3
+ @json.dig("params", "ref")
4
+ end
5
+
6
+ def argument_name
7
+ @json.dig("params", "argument", "name")
8
+ end
9
+
10
+ def param
11
+ {
12
+ @json.dig("params", "argument", "name").to_sym => @json.dig("params", "argument", "value")
13
+ }
14
+ end
15
+
16
+ def allowed_in_lifecycle?(lifecycle)
17
+ lifecycle.operation_phase?
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ class RubyMCP::Requests::Initialize < RubyMCP::Request
2
+ def allowed_in_lifecycle?(lifecycle)
3
+ lifecycle.initialization_pending?
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class RubyMCP::Requests::LoggingSetLevel < RubyMCP::Request
2
+ def level
3
+ @json.dig("params", "level")
4
+ end
5
+
6
+ def level_valid?
7
+ RubyMCP::Capabilities::Logging::LEVELS.keys.include? level
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class RubyMCP::Requests::NotificationsInitialized < RubyMCP::Request
2
+ def allowed_in_lifecycle?(lifecycle)
3
+ lifecycle.initialize_response_sent?
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ class RubyMCP::Requests::Ping < RubyMCP::Request
2
+ end
@@ -0,0 +1,15 @@
1
+ class RubyMCP::Requests::PromptsGet < RubyMCP::Request
2
+ attr_reader :json
3
+
4
+ def name
5
+ @json.dig("params", "name")
6
+ end
7
+
8
+ def arguments
9
+ @json.dig("params", "arguments").transform_keys(&:to_sym)
10
+ end
11
+
12
+ def allowed_in_lifecycle?(lifecycle)
13
+ lifecycle.operation_phase?
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ class RubyMCP::Requests::PromptsList < RubyMCP::Request
2
+ def allowed_in_lifecycle?(lifecycle)
3
+ lifecycle.operation_phase?
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RubyMCP::Requests::ResourcesList < RubyMCP::Request
2
+ def allowed_in_lifecycle?(lifecycle)
3
+ lifecycle.operation_phase?
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ class RubyMCP::Requests::ResourcesRead < RubyMCP::Request
2
+ def params
3
+ @json.dig("params")
4
+ end
5
+
6
+ def uri
7
+ params["uri"]
8
+ end
9
+
10
+ def allowed_in_lifecycle?(lifecycle)
11
+ lifecycle.operation_phase?
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module RubyMCP
2
+ class Requests
3
+ def self.parse(json)
4
+ parsed = JSON.parse(json)
5
+ case parsed.fetch("method")
6
+ when "initialize"
7
+ Initialize
8
+ when "notifications/initialized"
9
+ NotificationsInitialized
10
+ when "ping"
11
+ Ping
12
+ when "prompts/get"
13
+ PromptsGet
14
+ when "prompts/list"
15
+ PromptsList
16
+ when "completion/complete"
17
+ CompletionComplete
18
+ when "resources/list"
19
+ ResourcesList
20
+ when "resources/read"
21
+ ResourcesRead
22
+ when "logging/setLevel"
23
+ LoggingSetLevel
24
+ else
25
+ Request
26
+ end.new(parsed)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ module RubyMCP
2
+ Resource = Data.define(:uri, :name, :description, :mime_type, :reader)
3
+
4
+ class Resources
5
+ def initialize
6
+ @resources = {}
7
+ end
8
+
9
+ def add(uri:, name:, description: nil, mime_type: nil, reader: nil)
10
+ @resources[uri] = Resource.new(uri, name, description, mime_type, reader)
11
+ end
12
+
13
+ def find(uri)
14
+ @resources[uri]
15
+ end
16
+
17
+ def as_json
18
+ @resources.map do |uri, resource|
19
+ {
20
+ uri: uri,
21
+ name: resource.name,
22
+ description: resource.description,
23
+ mimeType: resource.mime_type
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ class RubyMCP::Server::Lifecycle
2
+ STATES = [ :initialization_pending, :initialize_response_sent, :operation_phase_started ]
3
+
4
+ def initialize
5
+ @current = 0
6
+ end
7
+
8
+ def initialize_response_sent!
9
+ @current = 1
10
+ end
11
+
12
+ def operation_phase!
13
+ @current = 2
14
+ end
15
+
16
+ def operation_phase?
17
+ current == :operation_phase_started
18
+ end
19
+
20
+ def initialization_pending?
21
+ current == :initialization_pending
22
+ end
23
+
24
+ def initialize_response_sent?
25
+ current == :initialize_response_sent
26
+ end
27
+
28
+ private
29
+
30
+ def current
31
+ STATES[@current]
32
+ end
33
+ end
@@ -0,0 +1,84 @@
1
+ module RubyMCP
2
+ class Server
3
+ include Capabilities::Logging
4
+
5
+ attr_reader :lifecycle, :prompts, :resources
6
+
7
+ def initialize(logging_verbosity: "info")
8
+ @lifecycle = Lifecycle.new
9
+ @prompts = Prompts.new
10
+ @resources = Resources.new
11
+
12
+ @default_logging_verbosity = logging_verbosity
13
+ end
14
+
15
+ def connect(transport)
16
+ @transport = transport
17
+
18
+ setup_trap
19
+ setup_message_handler
20
+ setup_close_handler
21
+ start_transport
22
+ end
23
+
24
+ def add_prompt(...)
25
+ @prompts.add(...)
26
+ end
27
+
28
+ def add_resource(...)
29
+ @resources.add(...)
30
+ end
31
+
32
+ def send_message(message)
33
+ RubyMCP.logger.debug "S -> C : #{message}"
34
+ @transport.send(message)
35
+ end
36
+
37
+ def answer(request, result)
38
+ send_answer(request, result:)
39
+ end
40
+
41
+ def error(request, error)
42
+ send_answer(request, error:)
43
+ end
44
+
45
+ private
46
+
47
+ def send_answer(request, **message)
48
+ send_message(
49
+ id: request.id,
50
+ jsonrpc: "2.0",
51
+ **message
52
+ )
53
+ end
54
+
55
+ def setup_trap
56
+ trap("INT") do
57
+ @transport.close
58
+ exit
59
+ end
60
+ end
61
+
62
+ def setup_message_handler
63
+ @transport.on_message do |message|
64
+ request = Requests.parse(message)
65
+ handler = Handlers.parse(message)
66
+
67
+ RubyMCP.logger.debug "C -> S : #{request.method}"
68
+
69
+ handler.handle(self, request) if request.allowed_in_lifecycle?(@lifecycle)
70
+ end
71
+ end
72
+
73
+ def setup_close_handler
74
+ @transport.on_close do
75
+ RubyMCP.logger.info "Server stopped"
76
+ end
77
+ end
78
+
79
+ def start_transport
80
+ RubyMCP.logger.info("Server connecting with #{@transport.class}")
81
+ @transport.start
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,33 @@
1
+ module RubyMCP
2
+ class Transport
3
+ class Stdio < Transport
4
+ def start
5
+ @running = true
6
+
7
+ while @running
8
+ begin
9
+ line = $stdin.gets
10
+
11
+ break if line.nil?
12
+
13
+ @on_message.call(line.strip)
14
+ rescue StandardError => e
15
+ RubyMCP.logger.error("Exception: #{e}")
16
+ end
17
+ end
18
+
19
+ @on_close.call
20
+ end
21
+
22
+ def send(message)
23
+ $stdout.puts(JSON.generate(message))
24
+ $stdout.flush
25
+ end
26
+
27
+
28
+ def on_close(&block)
29
+ @on_close = block
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ class RubyMCP::Transport::Test < RubyMCP::Transport
2
+ attr_reader :responses
3
+ attr_reader :client_message_queue
4
+
5
+ def initialize
6
+ @client_message_queue = []
7
+ @responses = []
8
+ end
9
+
10
+ def start
11
+ @running = true
12
+ end
13
+
14
+ def send(message)
15
+ @responses << JSON.generate(message)
16
+ end
17
+
18
+ def client_message(message)
19
+ @client_message_queue << JSON.generate(message)
20
+ end
21
+
22
+ def process_message
23
+ @on_message.call(@client_message_queue.shift)
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module RubyMCP
2
+ class Transport
3
+ def close
4
+ @running = false
5
+ end
6
+
7
+ def on_message(&block)
8
+ @on_message = block
9
+ end
10
+
11
+ def on_close(&block)
12
+ @on_close = block
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyMCP
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ruby_mcp.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "json"
2
+ require "securerandom"
3
+ require "logger"
4
+ require "zeitwerk"
5
+
6
+ loader = Zeitwerk::Loader.for_gem
7
+ loader.inflector.inflect("ruby_mcp" => "RubyMCP")
8
+ loader.setup
9
+
10
+ module RubyMCP
11
+ def self.logger
12
+ @logger ||= ::Logger.new($stderr).tap do |log|
13
+ log.formatter = proc do |severity, datetime, progname, msg|
14
+ "[RubyMCP] #{severity[0]}, #{msg}\n"
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ loader.eager_load
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_mcp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Niklas Häusele
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-03-30 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: zeitwerk
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.7'
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 2.7.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '2.7'
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 2.7.2
32
+ email:
33
+ - niklas.haeusele@hey.com
34
+ executables:
35
+ - ruby_mcp
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - ".rubocop.yml"
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - exe/ruby_mcp
44
+ - lib/ruby_mcp.rb
45
+ - lib/ruby_mcp/capabilities/logging.rb
46
+ - lib/ruby_mcp/handlers.rb
47
+ - lib/ruby_mcp/handlers/completion_complete.rb
48
+ - lib/ruby_mcp/handlers/initialize.rb
49
+ - lib/ruby_mcp/handlers/logging_set_level.rb
50
+ - lib/ruby_mcp/handlers/notifications_initialized.rb
51
+ - lib/ruby_mcp/handlers/ping.rb
52
+ - lib/ruby_mcp/handlers/prompts_get.rb
53
+ - lib/ruby_mcp/handlers/prompts_list.rb
54
+ - lib/ruby_mcp/handlers/resources_list.rb
55
+ - lib/ruby_mcp/handlers/resources_read.rb
56
+ - lib/ruby_mcp/prompts.rb
57
+ - lib/ruby_mcp/request.rb
58
+ - lib/ruby_mcp/requests.rb
59
+ - lib/ruby_mcp/requests/completion_complete.rb
60
+ - lib/ruby_mcp/requests/initialize.rb
61
+ - lib/ruby_mcp/requests/logging_set_level.rb
62
+ - lib/ruby_mcp/requests/notifications_initialized.rb
63
+ - lib/ruby_mcp/requests/ping.rb
64
+ - lib/ruby_mcp/requests/prompts_get.rb
65
+ - lib/ruby_mcp/requests/prompts_list.rb
66
+ - lib/ruby_mcp/requests/resources_list.rb
67
+ - lib/ruby_mcp/requests/resources_read.rb
68
+ - lib/ruby_mcp/resources.rb
69
+ - lib/ruby_mcp/server.rb
70
+ - lib/ruby_mcp/server/lifecycle.rb
71
+ - lib/ruby_mcp/transport.rb
72
+ - lib/ruby_mcp/transport/stdio.rb
73
+ - lib/ruby_mcp/transport/test.rb
74
+ - lib/ruby_mcp/version.rb
75
+ homepage: https://github.com/codergeek121/ruby_mcp
76
+ licenses: []
77
+ metadata:
78
+ homepage_uri: https://github.com/codergeek121/ruby_mcp
79
+ source_code_uri: https://github.com/codergeek121/ruby_mcp
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.1.0
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.6.6
95
+ specification_version: 4
96
+ summary: Low-level MCP protocol sdk for Ruby.
97
+ test_files: []