Skip to main content
Glama
mohdhaji87

Nmap MCP Server

by mohdhaji87

nmap_vulnerability_scan

Scan network targets for security vulnerabilities using Nmap detection scripts to identify potential weaknesses and misconfigurations.

Instructions

Run vulnerability detection scripts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetsYes
portsNocommon
vuln_categoryNoall

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • server.py:268-271 (registration)
    Registration of the nmap_vulnerability_scan tool using FastMCP @app.tool decorator.
    @app.tool(
        name="nmap_vulnerability_scan",
        description="Run vulnerability detection scripts"
    )
  • The main handler function that constructs Nmap arguments for vulnerability scripts based on parameters and executes via run_nmap_command.
    async def nmap_vulnerability_scan(
        targets: str,
        ports: str = "common",
        vuln_category: str = "all"
    ) -> str:
        """Run vulnerability detection scripts."""
        if vuln_category == "all":
            scripts = "vuln"
        else:
            scripts = f"vuln and {vuln_category}"
        
        args = [f"--script={scripts}", "-p", ports, targets]
        
        result = run_nmap_command(args, timeout=600)
        
        if result["success"]:
            return f"Vulnerability scan completed:\n\n{result['stdout']}"
        else:
            return f"Vulnerability scan failed:\n\n{result['stderr']}"
  • Helper function that executes nmap commands using subprocess, handles timeouts and errors, and returns structured results. Used by all nmap tools including this one.
    def run_nmap_command(args: List[str], timeout: int = 300) -> Dict[str, Any]:
        """
        Execute an nmap command and return the results.
        
        Args:
            args: List of nmap command arguments
            timeout: Command timeout in seconds
        
        Returns:
            Dictionary containing command output, error, and exit code
        """
        try:
            # Construct the full nmap command
            cmd = ["nmap"] + args
            
            logger.info(f"Executing nmap command: {' '.join(cmd)}")
            
            # Run the command with timeout
            result = subprocess.run(
                cmd,
                capture_output=True,
                text=True,
                timeout=timeout,
                check=False
            )
            
            return {
                "stdout": result.stdout,
                "stderr": result.stderr,
                "exit_code": result.returncode,
                "success": result.returncode == 0
            }
            
        except subprocess.TimeoutExpired:
            return {
                "stdout": "",
                "stderr": f"Command timed out after {timeout} seconds",
                "exit_code": -1,
                "success": False
            }
        except FileNotFoundError:
            return {
                "stdout": "",
                "stderr": "nmap command not found. Please ensure nmap is installed and in PATH",
                "exit_code": -1,
                "success": False
            }
        except Exception as e:
            return {
                "stdout": "",
                "stderr": f"Error executing nmap command: {str(e)}",
                "exit_code": -1,
                "success": False
            }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'Run vulnerability detection scripts' but fails to describe critical traits like potential network impact, security implications, output format, error handling, or execution time. This is inadequate for a tool that likely performs active scanning.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It is front-loaded and appropriately sized for its minimal content, though this conciseness comes at the cost of detail.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of vulnerability scanning, no annotations, and an output schema (which might cover return values), the description is incomplete. It lacks essential context like safety warnings, performance considerations, and differentiation from siblings, making it insufficient for effective tool use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning parameters are undocumented in the schema. The description adds no information about parameters like 'targets', 'ports', or 'vuln_category', such as their formats, allowed values, or effects. It does not compensate for the lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Run vulnerability detection scripts' states a general purpose (running scripts for vulnerability detection) but lacks specificity about what resource it acts on (e.g., network targets) and how it differs from sibling tools like 'nmap_script_scan' or 'nmap_comprehensive_scan'. It's vague about scope and implementation details.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives such as 'nmap_script_scan' or 'nmap_comprehensive_scan'. The description offers no context, prerequisites, or exclusions, leaving the agent without direction for selection among similar tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mohdhaji87/Nmap-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server