The Nmap Model Control Protocol (MCP) server provides access to nmap network scanning functionality, allowing you to run scans on specified targets, store results, and analyze them using AI prompts - all through a standardized protocol interface.
Before installing the MCP server, ensure you have:
Install the required Python library:
pip install python-libnmap
Install nmap on your system:
# On Debian/Ubuntu
sudo apt-get install nmap
# On Fedora/CentOS
sudo dnf install nmap
You can run the server in two different ways:
python -m src.nmap_mcp
pip install -e .
nmap-mcp
The Nmap MCP server provides several tools and prompts that you can use.
Run an nmap scan on specified targets.
Parameters:
target
: Target host or network (e.g., 192.168.1.1 or 192.168.1.0/24)options
: Nmap options (e.g., -sV -p 1-1000)Get detailed information about a specific scan.
Parameters:
scan_id
: ID of the scan to retrieveList all available scan results.
No parameters required.
Analyze an nmap scan result with AI assistance.
Parameters:
scan_id
: ID of the scan to analyzefocus
: Focus area (security/services/overview)Scan results are available as resources with the nmap://scan/{scan_id}
URI scheme.
Call tool: run-nmap-scan
Parameters: {"target": "192.168.1.0/24", "options": "-sV -p 22,80,443"}
Call tool: get-scan-details
Parameters: {"scan_id": "<scan_id from previous step>"}
Call tool: list-all-scans
Get prompt: analyze-scan
Parameters: {"scan_id": "<scan_id>", "focus": "security"}
For easier deployment, you can run the MCP server in a Docker container:
# Build the Docker image
docker build -t nmap-mcp-server .
# Run the Docker container
docker run -it --rm nmap-mcp-server
If you encounter errors related to nmap:
Be aware that this server executes nmap commands on your system. Only scan networks you own or have permission to scan, as unauthorized scanning may be illegal in some jurisdictions.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.