Class: ActiveMcp::Server::ProtocolHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/active_mcp/server/protocol_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ ProtocolHandler

Returns a new instance of ProtocolHandler.



8
9
10
11
12
# File 'lib/active_mcp/server/protocol_handler.rb', line 8

def initialize(server)
  @server = server
  @initialized = false
  @supported_protocol_versions = [PROTOCOL_VERSION]
end

Instance Attribute Details

#initializedObject (readonly)

Returns the value of attribute initialized.



6
7
8
# File 'lib/active_mcp/server/protocol_handler.rb', line 6

def initialized
  @initialized
end

Instance Method Details

#process_message(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_mcp/server/protocol_handler.rb', line 14

def process_message(message)
  message = message.to_s.force_encoding("UTF-8")
  result = begin
    request = JSON.parse(message, symbolize_names: true)
    handle_request(request)
  rescue JSON::ParserError => e
    log_error("JSON parse error", e)
    error_response(nil, ErrorCode::PARSE_ERROR, "Invalid JSON format")
  rescue => e
    log_error("Internal error during message processing", e)
    error_response(nil, ErrorCode::INTERNAL_ERROR, "An internal error occurred")
  end

  json_result = JSON.generate(result).force_encoding("UTF-8") if result
  json_result
end