Class: Msf::MCP::Application
- Inherits:
-
Object
- Object
- Msf::MCP::Application
- Defined in:
- lib/msf/core/mcp/application.rb
Overview
Main application class that orchestrates the MCP server startup and lifecycle
Constant Summary collapse
- VERSION =
'0.1.0'- BANNER =
<<~BANNER MSF MCP Server v#{VERSION} Model Context Protocol server for Metasploit Framework BANNER
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
For testing purposes:.
-
#mcp_server ⇒ Object
readonly
For testing purposes:.
-
#msf_client ⇒ Object
readonly
For testing purposes:.
-
#options ⇒ Object
readonly
For testing purposes:.
-
#rate_limiter ⇒ Object
readonly
For testing purposes:.
-
#rpc_manager ⇒ Object
readonly
For testing purposes:.
Instance Method Summary collapse
-
#initialize(argv = ARGV, output: $stderr) ⇒ Application
constructor
Initialize the application with command-line arguments.
-
#run ⇒ void
Run the application.
-
#shutdown(signal = 'INT') ⇒ void
Shutdown the application gracefully.
Constructor Details
#initialize(argv = ARGV, output: $stderr) ⇒ Application
Initialize the application with command-line arguments
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/msf/core/mcp/application.rb', line 22 def initialize(argv = ARGV, output: $stderr) @argv = argv.dup @output = output @options = {} @config = nil @msf_client = nil @mcp_server = nil @rate_limiter = nil @rpc_manager = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
For testing purposes:
16 17 18 |
# File 'lib/msf/core/mcp/application.rb', line 16 def config @config end |
#mcp_server ⇒ Object (readonly)
For testing purposes:
16 17 18 |
# File 'lib/msf/core/mcp/application.rb', line 16 def mcp_server @mcp_server end |
#msf_client ⇒ Object (readonly)
For testing purposes:
16 17 18 |
# File 'lib/msf/core/mcp/application.rb', line 16 def msf_client @msf_client end |
#options ⇒ Object (readonly)
For testing purposes:
16 17 18 |
# File 'lib/msf/core/mcp/application.rb', line 16 def @options end |
#rate_limiter ⇒ Object (readonly)
For testing purposes:
16 17 18 |
# File 'lib/msf/core/mcp/application.rb', line 16 def rate_limiter @rate_limiter end |
#rpc_manager ⇒ Object (readonly)
For testing purposes:
16 17 18 |
# File 'lib/msf/core/mcp/application.rb', line 16 def rpc_manager @rpc_manager end |
Instance Method Details
#run ⇒ void
This method returns an undefined value.
Run the application
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/msf/core/mcp/application.rb', line 36 def run parse_arguments install_signal_handlers load_configuration validate_configuration initialize_logger initialize_rate_limiter ensure_rpc_server initialize_mcp_server start_mcp_server rescue Msf::MCP::Config::ValidationError, Msf::MCP::Config::ConfigurationError => e handle_configuration_error(e) rescue Msf::MCP::Metasploit::ConnectionError => e handle_connection_error(e) rescue Msf::MCP::Metasploit::APIError => e handle_api_error(e) rescue Msf::MCP::Metasploit::AuthenticationError => e handle_authentication_error(e) rescue Msf::MCP::Metasploit::RpcStartupError => e handle_rpc_startup_error(e) rescue StandardError => e handle_fatal_error(e) end |
#shutdown(signal = 'INT') ⇒ void
This method returns an undefined value.
Shutdown the application gracefully
Performs cleanup operations before process termination:
-
Logs shutdown event via Rex
-
Closes MCP server and Metasploit client connections
-
Cleans up resources
71 72 73 74 75 76 77 78 79 |
# File 'lib/msf/core/mcp/application.rb', line 71 def shutdown(signal = 'INT') ilog({ message: 'Shutting down', context: { signal: "SIG#{signal}" } }, LOG_SOURCE, LOG_INFO) @mcp_server&.shutdown @rpc_manager&.stop_rpc_server @output.puts "\nShutdown complete" end |