Class: Msf::MCP::Tools::SessionStop

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

Overview

MCP Tool: Stop an Active Session

Wraps the ‘session.stop` RPC endpoint to terminate a running Metasploit session.

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

Stop a session

Parameters:

  • session_id (Integer)

    Session ID

  • server_context (Hash)

    Server context with msf_client, rate_limiter

Returns:

  • (MCP::Tool::Response)

    Structured response with stop result



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

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

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

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

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