Class: Msf::MCP::Tools::SessionRead

Inherits:
MCP::Tool
  • Object
show all
Extended by:
ToolHelper
Defined in:
lib/msf/core/mcp/tools/session_read.rb

Overview

MCP Tool: Read Output from an Interactive Session

Wraps the ‘session.interactive_read` RPC endpoint. Works for meterpreter, DB, SMB, LDAP, and shell/powershell session types.

Constant Summary

Constants included from ToolHelper

ToolHelper::DANGEROUS_MODE_DISABLED_MESSAGE

Class Method Summary collapse

Methods included from ToolHelper

dangerous_mode_required!, tool_error_response, with_tool_context

Class Method Details

.call(session_id:, server_context:) ⇒ MCP::Tool::Response

Read from an interactive session

Parameters:

  • session_id (Integer)

    Session ID

  • server_context (Hash)

    Server context with msf_client, rate_limiter

Returns:

  • (MCP::Tool::Response)

    Structured response with session output



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/msf/core/mcp/tools/session_read.rb', line 63

def call(session_id:, server_context:)
  with_tool_context(server_context, 'session_read') do |msf_client|
    Msf::MCP::Security::InputValidator.validate_session_id!(session_id)

    raw_result, elapsed = Rex::Stopwatch.elapsed_time do
      msf_client.session_read(session_id)
    end

    data = { data: raw_result['data'].to_s }
     = { query_time: elapsed.round(3) }

    ::MCP::Tool::Response.new(
      [{ type: 'text', text: JSON.generate(metadata: , data: data) }],
      structured_content: { metadata: , data: data }
    )
  end
end