Module: ActionMCP::TaggedStreamLogging

Defined in:
lib/action_mcp/tagged_stream_logging.rb

Constant Summary collapse

CLR =

──────────── ANSI COLOURS ────────────

"\e[0m"
BLUE_TX =

outgoing JSON‑RPC (TX)

"\e[34m"
GREEN_RX =

incoming JSON‑RPC (RX)

"\e[32m"
YELLOW_ERR =

decode / validation warnings

"\e[33m"
RED_FATAL =

unexpected exceptions

"\e[31m"

Instance Method Summary collapse

Instance Method Details

#read(line) ⇒ Object

——— Inbound: every raw line handed to the JSON‑RPC handler ———



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/action_mcp/tagged_stream_logging.rb', line 23

def read(line)
  pretty = json_normalise(line)
  log_with_tags("MCP", "RX") { ActionMCP.logger.debug("#{GREEN_RX}#{pretty}#{CLR}") }
  super
rescue MultiJson::ParseError => e
  log_with_tags("MCP", "RX") { ActionMCP.logger.warn("#{YELLOW_ERR}Bad JSON → #{e.message}#{CLR}") }
  raise
rescue StandardError => e
  log_with_tags("MCP", "RX") { ActionMCP.logger.error("#{RED_FATAL}#{e.message}#{CLR}") }
  raise
end

#write_message(data) ⇒ Object

——— Outbound: any frame we ‘write’ to the wire ———



13
14
15
16
17
18
19
20
# File 'lib/action_mcp/tagged_stream_logging.rb', line 13

def write_message(data)
  pretty = json_normalise(data)
  log_with_tags("MCP", "TX") { ActionMCP.logger.debug("#{BLUE_TX}#{pretty}#{CLR}") }
  super
rescue StandardError => e
  log_with_tags("MCP", "TX") { ActionMCP.logger.error("#{RED_FATAL}#{e.message}#{CLR}") }
  raise
end