Class: ActiveMcp::Server::ProtocolHandler
- Inherits:
-
Object
- Object
- ActiveMcp::Server::ProtocolHandler
- Defined in:
- lib/active_mcp/server/protocol_handler.rb
Instance Attribute Summary collapse
-
#initialized ⇒ Object
readonly
Returns the value of attribute initialized.
Instance Method Summary collapse
-
#initialize(server) ⇒ ProtocolHandler
constructor
A new instance of ProtocolHandler.
- #process_message(message) ⇒ Object
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
#initialized ⇒ Object (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 () = .to_s.force_encoding("UTF-8") result = begin request = JSON.parse(, 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 |