Module: VectorMCP::Server::MessageHandling
- Included in:
- VectorMCP::Server
- Defined in:
- lib/vector_mcp/server/message_handling.rb
Overview
Handles message processing and request/notification dispatching
Instance Method Summary collapse
-
#handle_message(message, session, session_id) ⇒ Object?
Handles an incoming JSON-RPC message (request or notification).
-
#on_notification(method) {|params, session, server| ... } ⇒ self
Registers a handler for a specific JSON-RPC notification method.
-
#on_request(method) {|params, session, server| ... } ⇒ self
Registers a handler for a specific JSON-RPC request method.
Instance Method Details
#handle_message(message, session, session_id) ⇒ Object?
Handles an incoming JSON-RPC message (request or notification). This is the main dispatch point for messages received by a transport.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vector_mcp/server/message_handling.rb', line 18 def (, session, session_id) id = ["id"] method = ["method"] params = ["params"] || {} if id && method # Request logger.info("[#{session_id}] Request [#{id}]: #{method} with params: #{params.inspect}") handle_request(id, method, params, session) elsif method # Notification logger.info("[#{session_id}] Notification: #{method} with params: #{params.inspect}") handle_notification(method, params, session) nil # Notifications do not have a return value to send back to client elsif id # Invalid: Has ID but no method logger.warn("[#{session_id}] Invalid message: Has ID [#{id}] but no method. #{.inspect}") raise VectorMCP::InvalidRequestError.new("Request object must include a 'method' member.", request_id: id) else # Invalid: No ID and no method logger.warn("[#{session_id}] Invalid message: Missing both 'id' and 'method'. #{.inspect}") raise VectorMCP::InvalidRequestError.new("Invalid message format", request_id: nil) end end |
#on_notification(method) {|params, session, server| ... } ⇒ self
Registers a handler for a specific JSON-RPC notification method.
56 57 58 59 |
# File 'lib/vector_mcp/server/message_handling.rb', line 56 def on_notification(method, &handler) @notification_handlers[method.to_s] = handler self end |
#on_request(method) {|params, session, server| ... } ⇒ self
Registers a handler for a specific JSON-RPC request method.
46 47 48 49 |
# File 'lib/vector_mcp/server/message_handling.rb', line 46 def on_request(method, &handler) @request_handlers[method.to_s] = handler self end |