Class: Harbor::MCP::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/harbor/mcp/server.rb

Constant Summary collapse

PROTOCOL_VERSION =
"2024-11-05"

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Server

Returns a new instance of Server.



11
12
13
14
# File 'lib/harbor/mcp/server.rb', line 11

def initialize(config)
  @config = config
  @tools = Harbor::Tools.new(config)
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/harbor/mcp/server.rb', line 16

def run
  $stdout.sync = true
  log("Harbor MCP server starting...")

  $stdin.each_line do |line|
    line = line.strip
    next if line.empty?

    begin
      request = JSON.parse(line)
    rescue JSON::ParserError => e
      write_error(nil, -32700, "Parse error: #{e.message}")
      next
    end

    # Notifications have no id
    unless request.key?("id")
      log("Notification: #{request['method']}")
      next
    end

    response = handle_request(request)
    write_response(response) if response
  end
rescue Interrupt, SignalException
  log("Shutting down...")
end