Module: ActionMCP::Server::MessagingService

Includes:
BaseMessaging
Included in:
TransportHandler
Defined in:
lib/action_mcp/server/messaging_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messaging_modeObject

Returns the value of attribute messaging_mode.



8
9
10
# File 'lib/action_mcp/server/messaging_service.rb', line 8

def messaging_mode
  @messaging_mode
end

Instance Method Details

#send_jsonrpc_error(request_id, symbol, message, data = nil) ⇒ Object



25
26
27
28
# File 'lib/action_mcp/server/messaging_service.rb', line 25

def send_jsonrpc_error(request_id, symbol, message, data = nil)
  error = JSON_RPC::JsonRpcError.new(symbol, message: message, data: data)
  send_jsonrpc_response(request_id, error: error)
end

#send_jsonrpc_notification(method, params = nil) ⇒ Object



21
22
23
# File 'lib/action_mcp/server/messaging_service.rb', line 21

def send_jsonrpc_notification(method, params = nil)
  send_message(:notification, method: method, params: params)
end

#send_jsonrpc_request(method, params: nil, id: SecureRandom.uuid_v7) ⇒ Object



10
11
12
# File 'lib/action_mcp/server/messaging_service.rb', line 10

def send_jsonrpc_request(method, params: nil, id: SecureRandom.uuid_v7)
  send_message(:request, method: method, params: params, id: id)
end

#send_jsonrpc_response(request_id, result: nil, error: nil) ⇒ Object



14
15
16
17
18
19
# File 'lib/action_mcp/server/messaging_service.rb', line 14

def send_jsonrpc_response(request_id, result: nil, error: nil)
  args = { id: request_id }
  args[:result] = result unless result.nil?
  args[:error] = error unless error.nil?
  send_message(:response, **args)
end

#send_logging_message_notification(level:, data:, logger: nil) ⇒ Object



47
48
49
50
51
# File 'lib/action_mcp/server/messaging_service.rb', line 47

def send_logging_message_notification(level:, data:, logger: nil)
  params = { level: level, data: data }
  params[:logger] = logger if logger.present?
  send_jsonrpc_notification("notifications/logging/message", params)
end

#send_progress_notification(progressToken:, progress:, total: nil, message: nil, **options) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/action_mcp/server/messaging_service.rb', line 53

def send_progress_notification(progressToken:, progress:, total: nil, message: nil, **options)
  params = { progressToken: progressToken, progress: progress }
  params[:total] = total unless total.nil?
  params[:message] = message if message.present?
  params.merge!(options) if options.any?
  send_jsonrpc_notification("notifications/progress", params)
end

#send_prompts_list_changed_notificationObject



43
44
45
# File 'lib/action_mcp/server/messaging_service.rb', line 43

def send_prompts_list_changed_notification
  send_jsonrpc_notification("notifications/prompts/list_changed")
end

#send_resource_updated_notification(uri) ⇒ Object



35
36
37
# File 'lib/action_mcp/server/messaging_service.rb', line 35

def send_resource_updated_notification(uri)
  send_jsonrpc_notification("notifications/resources/updated", { uri: uri })
end

#send_resources_list_changed_notificationObject

Specific notifications



31
32
33
# File 'lib/action_mcp/server/messaging_service.rb', line 31

def send_resources_list_changed_notification
  send_jsonrpc_notification("notifications/resources/list_changed")
end

#send_tools_list_changed_notificationObject



39
40
41
# File 'lib/action_mcp/server/messaging_service.rb', line 39

def send_tools_list_changed_notification
  send_jsonrpc_notification("notifications/tools/list_changed")
end