[PR #7] [MERGED] Fix timeout handling and add debugging for MCP tools #11

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/7
Author: @cbdmaul
Created: 8/17/2025
Status: Merged
Merged: 8/17/2025
Merged by: @GH05TCREW

Base: mainHead: fix/timeout-handling-and-debugging


📝 Commits (4)

📊 Changes

13 files changed (+1966 additions, -25 deletions)

View changed files

Makefile (+95 -0)
📝 MetasploitMCP.py (+241 -25)
📝 README.md (+123 -0)
bash.exe.stackdump (+16 -0)
conftest.py (+157 -0)
pytest.ini (+38 -0)
requirements-test.txt (+6 -0)
📝 requirements.txt (+1 -0)
run_tests.py (+129 -0)
tests/__init__.py (+1 -0)
tests/test_helpers.py (+341 -0)
tests/test_options_parsing.py (+247 -0)
tests/test_tools_integration.py (+571 -0)

📄 Description

Problem

The list_exploits call was hanging for 3+ minutes when the Metasploit server was slow or unresponsive, with no debug logs or user feedback about the issue.

Solution

Added comprehensive timeout handling and debugging improvements:

Timeout Handling

  • Added RPC_CALL_TIMEOUT = 30 seconds constant for RPC operations
  • Wrapped critical RPC calls with asyncio.wait_for() to prevent hanging:
    • list_exploits() and list_payloads()
    • list_active_sessions() and list_listeners()
    • Health check endpoint
  • Calls now fail fast with clear error messages after 30 seconds

Debug Logging & Error Handling

  • Added debug logging for all RPC calls with timeout information
  • Improved error messages distinguishing between timeout, RPC, and connection errors
  • Added check_msf_connection() helper function for connection status
  • Enhanced MSF client initialization logging

User Feedback

  • Clear timeout error messages: "Timeout (30s) while listing exploits from Metasploit server. Server may be slow or unresponsive."
  • Specific error types for better troubleshooting
  • Connection status information in health checks

Testing

  • All 50 unit tests pass - Core functionality verified
  • Timeout behavior tested - No more indefinite hangs
  • Error handling tested - Proper error messages and logging

Impact

  • Fixes the 3+ minute timeout issue - Now fails fast after 30 seconds
  • Better user experience - Clear feedback instead of silent hanging
  • Improved debugging - Comprehensive logging for troubleshooting MSF server issues
  • Backward compatible - No breaking changes to existing functionality

Files Changed

  • MetasploitMCP.py - Core timeout and debugging improvements
  • tests/test_helpers.py - Fixed unit test expectations
  • tests/test_tools_integration.py - Improved integration test mocking

Resolves the timeout issue where list_exploits would hang indefinitely.


🔄 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/7 **Author:** [@cbdmaul](https://github.com/cbdmaul) **Created:** 8/17/2025 **Status:** ✅ Merged **Merged:** 8/17/2025 **Merged by:** [@GH05TCREW](https://github.com/GH05TCREW) **Base:** `main` ← **Head:** `fix/timeout-handling-and-debugging` --- ### 📝 Commits (4) - [`fe2eeb0`](https://github.com/GH05TCREW/MetasploitMCP/commit/fe2eeb083e3c8e26a0bfe4c28e0abb8e402675d6) minor fixes - [`fd4911a`](https://github.com/GH05TCREW/MetasploitMCP/commit/fd4911a3c6f5bbb5fbcd846e913dded766154cd7) Merge branch 'main' of https://github.com/GH05TCREW/MetasploitMCP - [`1aec612`](https://github.com/GH05TCREW/MetasploitMCP/commit/1aec6127e6f675b9bb64fbe3639abbd65a3896bb) Fix timeout handling and add debugging for MCP tools - [`4bed20d`](https://github.com/GH05TCREW/MetasploitMCP/commit/4bed20d54d753e52a37c5e310fc383b6068c37a8) Fix failing unit tests and improve integration test setup ### 📊 Changes **13 files changed** (+1966 additions, -25 deletions) <details> <summary>View changed files</summary> ➕ `Makefile` (+95 -0) 📝 `MetasploitMCP.py` (+241 -25) 📝 `README.md` (+123 -0) ➕ `bash.exe.stackdump` (+16 -0) ➕ `conftest.py` (+157 -0) ➕ `pytest.ini` (+38 -0) ➕ `requirements-test.txt` (+6 -0) 📝 `requirements.txt` (+1 -0) ➕ `run_tests.py` (+129 -0) ➕ `tests/__init__.py` (+1 -0) ➕ `tests/test_helpers.py` (+341 -0) ➕ `tests/test_options_parsing.py` (+247 -0) ➕ `tests/test_tools_integration.py` (+571 -0) </details> ### 📄 Description ## Problem The `list_exploits` call was hanging for 3+ minutes when the Metasploit server was slow or unresponsive, with no debug logs or user feedback about the issue. ## Solution Added comprehensive timeout handling and debugging improvements: ### ✅ **Timeout Handling** - Added `RPC_CALL_TIMEOUT = 30` seconds constant for RPC operations - Wrapped critical RPC calls with `asyncio.wait_for()` to prevent hanging: - `list_exploits()` and `list_payloads()` - `list_active_sessions()` and `list_listeners()` - Health check endpoint - Calls now fail fast with clear error messages after 30 seconds ### ✅ **Debug Logging & Error Handling** - Added debug logging for all RPC calls with timeout information - Improved error messages distinguishing between timeout, RPC, and connection errors - Added `check_msf_connection()` helper function for connection status - Enhanced MSF client initialization logging ### ✅ **User Feedback** - Clear timeout error messages: "Timeout (30s) while listing exploits from Metasploit server. Server may be slow or unresponsive." - Specific error types for better troubleshooting - Connection status information in health checks ## Testing - **✅ All 50 unit tests pass** - Core functionality verified - **✅ Timeout behavior tested** - No more indefinite hangs - **✅ Error handling tested** - Proper error messages and logging ## Impact - **Fixes the 3+ minute timeout issue** - Now fails fast after 30 seconds - **Better user experience** - Clear feedback instead of silent hanging - **Improved debugging** - Comprehensive logging for troubleshooting MSF server issues - **Backward compatible** - No breaking changes to existing functionality ## Files Changed - `MetasploitMCP.py` - Core timeout and debugging improvements - `tests/test_helpers.py` - Fixed unit test expectations - `tests/test_tools_integration.py` - Improved integration test mocking Resolves the timeout issue where list_exploits would hang indefinitely. --- <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:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: yindo/MetasploitMCP#11