Class: Msf::MCP::Middleware::RequestLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/mcp/middleware/request_logger.rb

Overview

Rack middleware that logs MCP HTTP request/response details via Rex logging.

Focuses on the HTTP transport layer: request method, status code, session ID, content type, and round-trip timing. For POST requests it also extracts JSON-RPC fields (method, id, params) and response result/error to provide DEBUG-level visibility into the exchange.

MCP-level business details (tool names, tool durations, and structured results) are handled by the SDK’s around_request callback configured in Server, avoiding duplication.

Examples:

Usage in a Rack::Builder

Rack::Builder.new do
  use Msf::MCP::Middleware::RequestLogger
  run transport
end

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestLogger

Returns a new instance of RequestLogger.

Parameters:

  • app (#call)

    The next Rack application in the middleware stack



28
29
30
# File 'lib/msf/core/mcp/middleware/request_logger.rb', line 28

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Array

Process the request, delegating to the next Rack app and logging transport-level details after the response is produced.

Parameters:

  • env (Hash)

    The Rack environment

Returns:

  • (Array)

    The Rack response triplet [status, headers, body]



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/msf/core/mcp/middleware/request_logger.rb', line 39

def call(env)
  request = Rack::Request.new(env)
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)

  response = @app.call(env)

  elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at
  log_exchange(request, response, elapsed)

  response
end