[PR #12] [MERGED] Fix up args & add --debug #13

Closed
opened 2026-02-27 13:57:42 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/GH05TCREW/MetasploitMCP/pull/12
Author: @g0tmi1k
Created: 2/5/2026
Status: Merged
Merged: 2/5/2026
Merged by: @GH05TCREW

Base: mainHead: args


📝 Commits (3)

📊 Changes

1 file changed (+29 additions, -16 deletions)

View changed files

📝 MetasploitMCP.py (+29 -16)

📄 Description

Before:

$ python3 MetasploitMCP.py --help
2026-02-05 10:22:10,971 - metasploit_mcp_server - INFO - Attempting to initialize Metasploit RPC client...
2026-02-05 10:22:10,973 - retry.api - WARNING - HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2cc440>: Failed to establish a new connection: [Errno 111] Connection refused')), retrying in 1 seconds...
2026-02-05 10:22:11,974 - retry.api - WARNING - HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4410>: Failed to establish a new connection: [Errno 111] Connection refused')), retrying in 2 seconds...
2026-02-05 10:22:13,975 - metasploit_mcp_server - ERROR - An unexpected error occurred during MSF client initialization: HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused'))
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 198, in _new_conn
    sock = connection.create_connection(
        (self._dns_host, self.port),
    ...<2 lines>...
        socket_options=self.socket_options,
    )
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 85, in create_connection
    raise err
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
    ~~~~~~~~~~~~^^^^
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
        conn,
    ...<10 lines>...
        **response_kw,
    )
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 493, in _make_request
    conn.request(
    ~~~~~~~~~~~~^
        method,
        ^^^^^^^
    ...<6 lines>...
        enforce_content_length=enforce_content_length,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 494, in request
    self.endheaders()
    ~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/http/client.py", line 1353, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/http/client.py", line 1113, in _send_output
    self.send(msg)
    ~~~~~~~~~^^^^^
  File "/usr/lib/python3.13/http/client.py", line 1057, in send
    self.connect()
    ~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 325, in connect
    self.sock = self._new_conn()
                ~~~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 213, in _new_conn
    raise NewConnectionError(
        self, f"Failed to establish a new connection: {e}"
    ) from e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 644, in send
    resp = conn.urlopen(
        method=request.method,
    ...<9 lines>...
        chunked=chunked,
    )
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in urlopen
    retries = retries.increment(
        method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    )
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 519, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kali/metasploitmcp/MetasploitMCP.py", line 78, in initialize_msf_client
    client = MsfRpcClient(
        password=MSF_PASSWORD,
    ...<2 lines>...
        ssl=msf_ssl
    )
  File "/usr/lib/python3/dist-packages/pymetasploit3/msfrpc.py", line 205, in __init__
    self.login(kwargs.get('username', 'msf'), password)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pymetasploit3/msfrpc.py", line 253, in login
    auth = self.call(MsfRpcMethod.AuthLogin, [user, password])
  File "/usr/lib/python3/dist-packages/pymetasploit3/msfrpc.py", line 239, in call
    r = self.post_request(url, payload)
  File "/usr/lib/python3/dist-packages/decorator.py", line 235, in fun
    return caller(func, *(extras + args), **kw)
  File "/usr/lib/python3/dist-packages/retry/api.py", line 73, in retry_decorator
    return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
                            logger)
  File "/usr/lib/python3/dist-packages/retry/api.py", line 33, in __retry_internal
    return f()
  File "/usr/lib/python3/dist-packages/pymetasploit3/msfrpc.py", line 250, in post_request
    return requests.post(url, data=payload, headers=self.headers, verify=False)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/requests/api.py", line 115, in post
    return request("post", url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
           ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 677, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2026-02-05 10:22:13,979 - metasploit_mcp_server - CRITICAL - CRITICAL: Failed to initialize Metasploit client on startup: Unexpected error initializing MSF client: HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused')). Server cannot function.
$

After:

$ python3 MetasploitMCP.py --help
usage: MetasploitMCP.py [-h] [--transport {http,stdio}] [--host HOST] [--port PORT] [--reload] [--find-port] [--debug]

Run Streamlined Metasploit MCP Server

options:
  -h, --help            show this help message and exit
  --transport {http,stdio}
                        MCP transport mode to use (http=SSE, stdio=direct pipe)
  --host HOST           Host to bind the HTTP server to (default: 127.0.0.1)
  --port PORT           Port to listen on (default: find available from 8085)
  --reload              Enable auto-reload (for development)
  --find-port           Force finding an available port starting from --port or 8085
  --debug               Make output more verbose
$

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/GH05TCREW/MetasploitMCP/pull/12 **Author:** [@g0tmi1k](https://github.com/g0tmi1k) **Created:** 2/5/2026 **Status:** ✅ Merged **Merged:** 2/5/2026 **Merged by:** [@GH05TCREW](https://github.com/GH05TCREW) **Base:** `main` ← **Head:** `args` --- ### 📝 Commits (3) - [`0e64f3f`](https://github.com/GH05TCREW/MetasploitMCP/commit/0e64f3f02daddf899150e463273ecdbfb9cd9b95) parse args before running - [`7da73d9`](https://github.com/GH05TCREW/MetasploitMCP/commit/7da73d98fe0b4bfdf28b4239bf4aa2a440bd9444) Add --debug flag to be more verbose - [`4f65a26`](https://github.com/GH05TCREW/MetasploitMCP/commit/4f65a26245f01253f3379ecf0059b69806d0dc4a) Print out os env ### 📊 Changes **1 file changed** (+29 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `MetasploitMCP.py` (+29 -16) </details> ### 📄 Description **Before**: ```console $ python3 MetasploitMCP.py --help 2026-02-05 10:22:10,971 - metasploit_mcp_server - INFO - Attempting to initialize Metasploit RPC client... 2026-02-05 10:22:10,973 - retry.api - WARNING - HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2cc440>: Failed to establish a new connection: [Errno 111] Connection refused')), retrying in 1 seconds... 2026-02-05 10:22:11,974 - retry.api - WARNING - HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4410>: Failed to establish a new connection: [Errno 111] Connection refused')), retrying in 2 seconds... 2026-02-05 10:22:13,975 - metasploit_mcp_server - ERROR - An unexpected error occurred during MSF client initialization: HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused')) Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 198, in _new_conn sock = connection.create_connection( (self._dns_host, self.port), ...<2 lines>... socket_options=self.socket_options, ) File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 85, in create_connection raise err File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 73, in create_connection sock.connect(sa) ~~~~~~~~~~~~^^^^ ConnectionRefusedError: [Errno 111] Connection refused The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 787, in urlopen response = self._make_request( conn, ...<10 lines>... **response_kw, ) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 493, in _make_request conn.request( ~~~~~~~~~~~~^ method, ^^^^^^^ ...<6 lines>... enforce_content_length=enforce_content_length, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 494, in request self.endheaders() ~~~~~~~~~~~~~~~^^ File "/usr/lib/python3.13/http/client.py", line 1353, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/http/client.py", line 1113, in _send_output self.send(msg) ~~~~~~~~~^^^^^ File "/usr/lib/python3.13/http/client.py", line 1057, in send self.connect() ~~~~~~~~~~~~^^ File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 325, in connect self.sock = self._new_conn() ~~~~~~~~~~~~~~^^ File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 213, in _new_conn raise NewConnectionError( self, f"Failed to establish a new connection: {e}" ) from e urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/requests/adapters.py", line 644, in send resp = conn.urlopen( method=request.method, ...<9 lines>... chunked=chunked, ) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in urlopen retries = retries.increment( method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2] ) File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 519, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/kali/metasploitmcp/MetasploitMCP.py", line 78, in initialize_msf_client client = MsfRpcClient( password=MSF_PASSWORD, ...<2 lines>... ssl=msf_ssl ) File "/usr/lib/python3/dist-packages/pymetasploit3/msfrpc.py", line 205, in __init__ self.login(kwargs.get('username', 'msf'), password) ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/pymetasploit3/msfrpc.py", line 253, in login auth = self.call(MsfRpcMethod.AuthLogin, [user, password]) File "/usr/lib/python3/dist-packages/pymetasploit3/msfrpc.py", line 239, in call r = self.post_request(url, payload) File "/usr/lib/python3/dist-packages/decorator.py", line 235, in fun return caller(func, *(extras + args), **kw) File "/usr/lib/python3/dist-packages/retry/api.py", line 73, in retry_decorator return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter, logger) File "/usr/lib/python3/dist-packages/retry/api.py", line 33, in __retry_internal return f() File "/usr/lib/python3/dist-packages/pymetasploit3/msfrpc.py", line 250, in post_request return requests.post(url, data=payload, headers=self.headers, verify=False) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/requests/api.py", line 115, in post return request("post", url, data=data, json=json, **kwargs) File "/usr/lib/python3/dist-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) File "/usr/lib/python3/dist-packages/requests/adapters.py", line 677, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused')) 2026-02-05 10:22:13,979 - metasploit_mcp_server - CRITICAL - CRITICAL: Failed to initialize Metasploit client on startup: Unexpected error initializing MSF client: HTTPConnectionPool(host='127.0.0.1', port=55553): Max retries exceeded with url: /api/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f74ad2d4cd0>: Failed to establish a new connection: [Errno 111] Connection refused')). Server cannot function. $ ``` **After**: ```console $ python3 MetasploitMCP.py --help usage: MetasploitMCP.py [-h] [--transport {http,stdio}] [--host HOST] [--port PORT] [--reload] [--find-port] [--debug] Run Streamlined Metasploit MCP Server options: -h, --help show this help message and exit --transport {http,stdio} MCP transport mode to use (http=SSE, stdio=direct pipe) --host HOST Host to bind the HTTP server to (default: 127.0.0.1) --port PORT Port to listen on (default: find available from 8085) --reload Enable auto-reload (for development) --find-port Force finding an available port starting from --port or 8085 --debug Make output more verbose $ ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-27 13:57:42 -05:00
yindo closed this issue 2026-02-27 13:57:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: yindo/MetasploitMCP#13