Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0x4m4 Hexstrike ai HexStrikeClient safe post

From Leeroopedia
Knowledge Sources
Domains Networking, HTTP, Tool_Execution
Last Updated 2026-10-10 00:00 GMT

Overview

HTTP client method that forwards JSON payloads from MCP tool functions to the HexStrike Flask server with error handling and retry logic.

Description

The HexStrikeClient class provides safe_post and safe_get methods for communicating with the HexStrike Flask API server. safe_post sends JSON data to a server endpoint, raises on HTTP errors, and returns the parsed JSON response. On any request failure, it returns a structured error dict with success: False instead of raising, so MCP tool functions can handle errors gracefully. The client uses a persistent requests.Session and includes connection retry logic in __init__.

Usage

Use this client when you need to forward tool execution requests from the MCP layer to the Flask server:

  • Tool execution: Every @mcp.tool() function calls safe_post to forward its parameters to the corresponding /api/tools/* endpoint
  • Workflow requests: Bug bounty, CTF, and intelligence workflows use safe_post to invoke their respective endpoints
  • Health checks: Use safe_get("health") to verify server connectivity

Code Reference

Source Location

  • Repository: HexStrike AI
  • File: hexstrike_mcp.py
  • Lines: L147-243 (HexStrikeClient class); safe_post at L220-243

Signature

class HexStrikeClient:
    def __init__(self, server_url: str, timeout: int = DEFAULT_REQUEST_TIMEOUT):
        """Initialize with server URL and request timeout. Retries connection on startup."""

    def safe_post(self, endpoint: str, json_data: Dict[str, Any]) -> Dict[str, Any]:
        """
        Perform a POST request with JSON data.

        Args:
            endpoint: API endpoint path (without leading slash)
            json_data: JSON data to send

        Returns:
            Response data as dictionary; on failure returns {"error": str, "success": False}
        """

    def safe_get(self, endpoint: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
        """
        Perform a GET request with optional query parameters.

        Args:
            endpoint: API endpoint path (without leading slash)
            params: Optional query parameters

        Returns:
            Response data as dictionary; on failure returns {"error": str, "success": False}
        """

Import

from hexstrike_mcp import HexStrikeClient

I/O Contract

Inputs

Name Type Required Description
endpoint str Yes API path without leading slash (e.g. "api/tools/nmap")
json_data Dict[str, Any] Yes (safe_post) POST body payload with tool parameters
params Dict[str, Any] No (safe_get) Query parameters for GET requests

Outputs

Name Type Description
return value Dict[str, Any] Parsed JSON response from server; or {"error": str, "success": False} on failure

Usage Examples

Forwarding a Tool Request

from hexstrike_mcp import HexStrikeClient

# Initialize client
client = HexStrikeClient(server_url="http://localhost:5000")

# Forward an nmap scan request to the server
result = client.safe_post("api/tools/nmap", {
    "target": "192.168.1.1",
    "scan_type": "-sV",
    "use_recovery": True
})

if result.get("success"):
    print("Scan completed:", result.get("stdout"))
    if result.get("recovery_info", {}).get("recovery_applied"):
        print("Recovery was applied")
else:
    print("Scan failed:", result.get("error"))

Health Check

# Verify server is running
health = client.safe_get("health")
print(f"Server status: {health.get('status', 'unknown')}")
print(f"Server version: {health.get('version', 'unknown')}")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment