mcp-server-nmap

April 4, 2026 ยท View on GitHub

MCP server that exposes the python-nmap library as MCP tools for network scanning operations.

PyPI Python

What is this?

This MCP server wraps the python-nmap library, allowing AI assistants to perform network reconnaissance through MCP tools. It provides three scanning interfaces:

  1. PortScanner (synchronous) - Blocking scans that wait for completion
  2. PortScannerAsync (asynchronous) - Non-blocking scans with callbacks
  3. PortScannerYield (generator) - Streaming results as hosts are discovered

Prerequisites

  • nmap must be installed on the system
  • Python 3.10+

Install

pip install mcp-server-nmap

mcp-name: io.github.daedalus/mcp-server-nmap

MCP Server Registration

Add this to your MCP settings file:

{
  "mcpServers": {
    "mcp-server-nmap": {
      "command": "mcp-server-nmap"
    }
  }
}

Or with custom nmap path:

{
  "mcpServers": {
    "mcp-server-nmap": {
      "command": "mcp-server-nmap",
      "env": {
        "PATH": "/custom/path:$PATH"
      }
    }
  }
}

Available Tools

Initialization

ToolDescription
port_scanner_initInitialize synchronous PortScanner
port_scanner_async_initInitialize async PortScannerAsync
port_scanner_yield_initInitialize generator-based PortScannerYield

Scanning

ToolDescription
port_scanner_scanScan hosts with nmap (synchronous)
port_scanner_async_scanScan hosts (async, non-blocking)
port_scanner_yield_scanScan with streaming results
port_scanner_listscanList hosts without scanning

Results & State

ToolDescription
port_scanner_all_hostsGet all scanned hosts
port_scanner_has_hostCheck if host was scanned
port_scanner_get_itemGet detailed host scan data
port_scanner_scaninfoGet scan configuration info
port_scanner_scanstatsGet scan statistics
port_scanner_command_lineGet nmap command used
port_scanner_csvGet CSV output
port_scanner_last_outputGet raw nmap text output

Async Control

ToolDescription
port_scanner_async_still_scanningCheck if scan in progress
port_scanner_async_stopStop running scan
port_scanner_async_waitWait for scan to complete

XML Parsing

ToolDescription
port_scanner_analyse_xmlParse existing nmap XML output

Common Scan Workflows

Basic port scan

# Initialize scanner
port_scanner_init()

# Scan target
port_scanner_scan(hosts="192.168.1.1", ports="22,80,443", arguments="-sV")

# Get results
port_scanner_get_item(host="192.168.1.1")

Service version detection

port_scanner_scan(hosts="scanme.nmap.org", arguments="-sV -sC")

Scan multiple hosts

port_scanner_scan(hosts="192.168.1.1-254", arguments="-sS -p 22")
port_scanner_all_hosts()

Network sweep

port_scanner_scan(hosts="192.168.1.0/24", arguments="-sn")
port_scanner_csv()  # Export to CSV

nmap Arguments Reference

ArgumentDescription
-snPing scan (host discovery)
-sSTCP SYN scan
-sTTCP connect scan
-sUUDP scan
-sVService version detection
-sCDefault scripts
-OOS detection
-pPort range
-oAOutput all formats

Development

git clone https://github.com/daedalus/mcp-server-nmap.git
cd mcp-server-nmap
pip install -e ".[test]"

# run tests
pytest

# format
ruff format src/ tests/

# lint
ruff check src/ tests/

# type check
mypy src/