Class: Msf::MCP::Server
- Inherits:
-
Object
- Object
- Msf::MCP::Server
- Defined in:
- lib/msf/core/mcp/server.rb
Overview
MCP Server Wrapper for Metasploit Framework
This class initializes and manages the MCP server with all registered tools. It provides a clean interface for starting/stopping the server and integrates with the Metasploit client and security layers.
The Server expects fully configured and authenticated dependencies to be provided during initialization. It does not handle configuration loading or client authentication - those are responsibilities of the calling code.
Instance Method Summary collapse
-
#initialize(msf_client:, rate_limiter:) ⇒ Server
constructor
Initialize the MCP server with required dependencies.
-
#shutdown ⇒ Object
Shutdown the MCP server and cleanup resources.
-
#start(transport: :stdio, host: 'localhost', port: 3000) ⇒ MCP::Server
Start the MCP server with specified transport.
Constructor Details
#initialize(msf_client:, rate_limiter:) ⇒ Server
Initialize the MCP server with required dependencies
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/msf/core/mcp/server.rb', line 23 def initialize(msf_client:, rate_limiter:) @msf_client = msf_client # Create server context (passed to all tool calls) # Tools only need msf_client and rate_limiter @server_context = { msf_client: @msf_client, rate_limiter: rate_limiter } # Create MCP configuration with request lifecycle callbacks mcp_config = ::MCP::Configuration.new mcp_config.around_request = create_around_request mcp_config.exception_reporter = create_exception_reporter # Initialize MCP server with all tools @mcp_server = ::MCP::Server.new( name: 'msfmcp', version: Msf::MCP::Application::VERSION, tools: [ Tools::SearchModules, Tools::ModuleInfo, Tools::HostInfo, Tools::ServiceInfo, Tools::VulnerabilityInfo, Tools::NoteInfo, Tools::CredentialInfo, Tools::LootInfo ], server_context: @server_context, configuration: mcp_config ) end |
Instance Method Details
#shutdown ⇒ Object
Shutdown the MCP server and cleanup resources
81 82 83 84 |
# File 'lib/msf/core/mcp/server.rb', line 81 def shutdown @msf_client&.shutdown @mcp_server = nil end |
#start(transport: :stdio, host: 'localhost', port: 3000) ⇒ MCP::Server
Start the MCP server with specified transport
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/msf/core/mcp/server.rb', line 67 def start(transport: :stdio, host: 'localhost', port: 3000) case transport when :stdio start_stdio when :http start_http(host, port) else raise ArgumentError, "Unknown transport: #{transport}. Use :stdio or :http" end end |