Skip to main content
Glama

htb-mcp

CI

An MCP server for Hack The Box that lets an AI agent inspect machines, spawn and reset targets, resolve/download/connect the VPN, submit flags, and browse challenges.

IMPORTANT

This project is unofficial and is not affiliated with Hack The Box. Use it only against machines you are allowed to access. Spawning, resetting, and switching VPN servers are real account actions and can terminate a running target.

Features

  • Machine discovery and details

  • Spawn, stop, reset, and extend machines

  • Active-machine status with IP and expiry

  • VPN server listing, least-busy selection, server switching, and config download

  • VPN hostname resolution and optional OpenVPN connect/disconnect

  • Machine and challenge flag submission

  • Auth/status diagnostics with retry and rate-limit handling

The server talks to the same API used by app.hackthebox.com: https://labs.hackthebox.com/api/v4 and /api/v5. The old app.hackthebox.com/api/v4 path now serves the web app rather than JSON.

Related MCP server: htb-mcp

Requirements

  • Node.js 22+

  • A Hack The Box App Token

  • Optional: openvpn and passwordless sudo if you want the server to establish the tunnel for you

Setup

git clone https://github.com/Jerit3787/htb-mcp.git
cd htb-mcp
npm ci
npm run build

Or let npm build it directly from GitHub:

npx --yes github:Jerit3787/htb-mcp

Create a token in HTB under Settings → App Tokens, then run:

HTB_TOKEN="your-token" node dist/src/index.js

The process speaks MCP over stdio. Logs go to stderr so they never corrupt the protocol stream.

OpenCode

Add this to opencode.jsonc (OpenCode V2 uses mcp.servers):

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "htb": {
        "type": "local",
        "command": ["node", "/absolute/path/to/htb-mcp/dist/src/index.js"],
        "environment": {
          "HTB_TOKEN": "{env:HTB_TOKEN}"
        }
      }
    }
  }
}

Then export HTB_TOKEN in the environment that starts OpenCode.

Claude Desktop / other clients

{
  "mcpServers": {
    "htb": {
      "command": "node",
      "args": ["/absolute/path/to/htb-mcp/dist/src/index.js"],
      "env": {
        "HTB_TOKEN": "your-token"
      }
    }
  }
}

Tools

Tool

What it does

htb_status

Account, active machine, VPN assignments, and API health

htb_list_machines

Search/filter the machine catalogue

htb_get_machine

Machine details by ID or name

htb_launch_machine

Spawn a machine and wait for its IP

htb_stop_machine

Terminate the active machine

htb_reset_machine

Reset the active machine

htb_extend_machine

Extend the active machine's lifetime

htb_vpn_servers

List VPN servers and current assignments

htb_vpn_switch

Switch VPN server (refuses while a machine is active unless forced)

htb_vpn_resolve

Pick the least-busy server, download config, resolve the endpoint

htb_vpn_download

Download a UDP/TCP OpenVPN profile

htb_vpn_status

HTB-side and local OpenVPN status

htb_vpn_connect

Start OpenVPN with a downloaded profile

htb_vpn_disconnect

Stop the OpenVPN process started by this server

htb_submit_flag

Submit a machine or challenge flag

htb_list_challenges

Search/filter challenges

htb_get_challenge

Challenge details by ID or slug

See docs/tools.md for inputs, side effects, and error codes.

Configuration

Environment variable

Default

Description

HTB_TOKEN

—

App Token (required unless a session cookie is supplied)

HTB_SESSION_COOKIE

—

Optional browser cookie for endpoints that reject token auth; supply the whole Cookie header from an app.hackthebox.com request

HTB_LABS_URL

https://labs.hackthebox.com

API host; useful for mocks/proxies

HTB_TIMEOUT_MS

30000

Per-request timeout

HTB_MAX_RETRIES

2

Retries for GET/429 responses

HTB_VPN_DIR

~/.config/htb-mcp/vpn

Downloaded profiles, PID files, and logs

HTB_OPENVPN_BIN

openvpn

OpenVPN executable

HTB_OPENVPN_USE_SUDO

1

Prefix OpenVPN with sudo -n when not root

Profiles contain private keys and are written with mode 0600. Do not commit them.

If App Token auth returns AUTH_FAILED, copy the full Cookie request header from a logged-in app.hackthebox.com request into HTB_SESSION_COOKIE. The token and cookie can also be used together.

VPN notes

  • HTB lets one VPN session be assigned per product. Switching servers can terminate an active machine; htb_vpn_switch blocks this unless force is true.

  • htb_vpn_resolve downloads the profile, resolves the remote hostname, and reports latency. It does not connect unless connect: true is passed.

  • Auto-connect uses sudo -n, so it fails cleanly instead of prompting for a password. Configure a narrowly scoped sudoers rule or start OpenVPN yourself.

  • Only profiles inside the configured VPN directory can be passed to htb_vpn_connect.

Development

npm ci
npm run typecheck
npm test

Tests use a local mock HTB API and do not touch your account.

License

MIT

Available Tools

17 tools
htb_extend_machineExtend the active machineA

Extend the active machine's lifetime by 24 hours. Returns HTB's new expiration date.

Inputs: target.

htb_get_challengeGet challenge detailsA
Read-only

Get challenge details by ID or slug, including category, difficulty, description, docker status, and solve state.

Inputs: target (required).

htb_get_machineGet machine detailsA
Read-only

Get a machine's profile by name or ID, including OS, difficulty, points, ownership, maker, and active play info.

Inputs: target (required), include_raw.

htb_launch_machineSpawn a machineA
Destructive

Spawn an active or retired machine and wait for its IP. If another machine is active, set replace=true to terminate it first. HTB limits machine actions to roughly one per minute.

Inputs: target (required), replace, wait_seconds.

htb_list_challengesList challengesC
Read-only

Search and filter HTB challenges by state, difficulty, category, name, and completion.

Inputs: page, state, keyword, category, +3 more.

htb_list_machinesList Hack The Box machinesB
Read-only

Search and filter machines by state, difficulty, OS, name, free/VIP, and completion. Returns compact machine summaries with pagination metadata.

Inputs: os, free, page, todo, +7 more.

htb_reset_machineReset the active machineA
Destructive

Request a reset of the active machine. HTB applies a cooldown between machine actions; the reset can take a minute.

Inputs: target.

htb_statusHTB account and lab statusA
Read-only

Check authentication, account summary, active machine (IP/expiry), and current VPN assignments. Start here when something fails.

Inputs: no named parameters.

htb_stop_machineTerminate the active machineA
Destructive

Terminate the currently active machine. Optionally verify a target first. This ends the machine session immediately.

Inputs: target.

htb_submit_flagSubmit a flagA

Submit a machine or challenge flag. For machines, target defaults to the active machine. Returns HTB's acceptance message, points, and ownership state.

Inputs: flag (required), kind (required), target.

htb_vpn_connectConnect OpenVPNA

Start OpenVPN using a profile in the configured VPN directory. If config_path is omitted, the assigned profile is downloaded first. Uses sudo -n when not root; it never prompts for a password.

Inputs: force, product, protocol, server_id, +1 more.

htb_vpn_disconnectDisconnect OpenVPNA

Stop the OpenVPN process started by this server. With no PID file, stops all HTB OpenVPN processes managed by this server.

Inputs: pid_file.

htb_vpn_downloadDownload a VPN profileA

Download the OpenVPN profile for the assigned server (or server_id) without auto-selecting a new server. Returns only the local path and endpoint metadata, never the private key.

Inputs: force, product, protocol, server_id.

htb_vpn_resolveResolve and download the VPNA
Destructive

Pick the least-busy server (or use server_id), switch if needed, download the OpenVPN profile, resolve its remote hostname, and optionally connect. Blocks switching while a machine is active unless force=true. Does not connect unless connect=true.

Inputs: force, probe, connect, product, +3 more.

htb_vpn_serversList VPN serversB
Read-only

List available VPN servers, client counts, full status, and the server currently assigned to each HTB product.

Inputs: product.

htb_vpn_statusVPN statusA
Read-only

Show HTB-side VPN connections plus local OpenVPN processes, profiles, and PID state.

Inputs: no named parameters.

htb_vpn_switchSwitch VPN serverA
Destructive

Assign your account to another VPN server. HTB may terminate an active machine when the server changes, so this tool refuses unless force=true. Prefer htb_vpn_resolve for automatic least-busy selection.

Inputs: server_id (required), force, product.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 17 tools

    Disambiguation4/5

    Machine and challenge tools are cleanly separated by resource+action (list/get/launch/stop/reset/extend), so those are easy to choose between. The VPN cluster has layered overlap: htb_vpn_resolve internally performs switch+download+connect, which can be confused with htb_vpn_switch, htb_vpn_download, and htb_vpn_connect, though descriptions explicitly disambiguate the preferred tool.

    Naming Consistency4/5

    Names follow a predictable htb_verb_noun pattern with a consistent htb_vpn_ namespace for the VPN subgroup. The only deviation is htb_status, which omits a verb, but it remains readable and snake_case throughout.

    Tool Count4/5

    Seventeen tools is slightly on the heavy side but justified by covering three distinct areas (machines, VPN lifecycle, challenges/flags). Each tool maps to a real operation rather than redundant wrappers.

    Completeness4/5

    Machine lifecycle (list/get/launch/stop/reset/extend), VPN setup/teardown, and flag submission are fully covered. Challenge support is thinner (only list/get, no docker start/spawn or dedicated challenge workflow), a minor gap an agent can work around.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Enables AI agents to interact with the FlagForge REST API, allowing them to search solved CTF challenges, work on live event challenges, record evidence, submit flag candidates, and write markdown writeups.
      19
      ISC
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI assistants and agents to search bug bounty programs, retrieve policies and scopes, and check targets against active scope across HackerOne, YesWeHack, and Intigriti using personal API credentials.
      5
      MIT