Class: Tickrb::McpServer

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tickrb/mcp_server.rb

Constant Summary collapse

JSONRPC =
"2.0"
PROTOCOL_VERSION =
"2024-11-05"
SERVER_INFO =
{
  name: "tickrb-mcp-server",
  version: VERSION
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMcpServer

Returns a new instance of McpServer.



30
31
32
33
34
35
36
37
# File 'lib/tickrb/mcp_server.rb', line 30

def initialize
  @tools = {}
  @resources = {}
  @client = nil

  register_default_tools
  register_ticktick_tools
end

Class Method Details

.startObject



24
25
26
# File 'lib/tickrb/mcp_server.rb', line 24

def start
  new.start
end

Instance Method Details

#startObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/tickrb/mcp_server.rb', line 40

def start
  loop do
    input = $stdin.gets
    break if input.nil?

    begin
      request = JSON.parse(input.strip)
      response = handle_request(request)
      puts response.to_json if response
      $stdout.flush
    rescue JSON::ParserError => e
      error_response = {
        jsonrpc: JSONRPC,
        error: {
          code: -32700,
          message: "Parse error",
          data: e.message
        },
        id: nil
      }
      puts error_response.to_json
    rescue => e
      error_response = {
        jsonrpc: JSONRPC,
        error: {
          code: -32603,
          message: "Internal error",
          data: e.message
        },
        id: request&.dig("id")
      }
      puts error_response.to_json
    end
  end
end