Skip to main content
Glama
mohdhaji87

Nmap MCP Server

by mohdhaji87

nmap_custom_scan

Execute custom network scans with user-defined Nmap options to identify open ports, services, and vulnerabilities on specified targets.

Instructions

Perform custom Nmap scan with user-defined options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetsYes
custom_optionsYes
output_formatNonormal

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the nmap_custom_scan tool. It parses custom options, appends targets, executes via run_nmap_command, and returns formatted output or error.
    async def nmap_custom_scan(
        targets: str,
        custom_options: str,
        output_format: str = "normal"
    ) -> str:
        """Perform custom Nmap scan with user-defined options."""
        # Parse custom options
        args = custom_options.split()
        
        # Add output format if specified
        if output_format == "xml":
            args.append("-oX")
            args.append("-")
        elif output_format == "grepable":
            args.append("-oG")
            args.append("-")
        
        args.append(targets)
        
        result = run_nmap_command(args)
        
        if result["success"]:
            return f"Custom scan completed:\n\n{result['stdout']}"
        else:
            return f"Custom scan failed:\n\n{result['stderr']}"
  • server.py:321-324 (registration)
    Registration of the nmap_custom_scan tool using the @app.tool decorator with name and description.
    @app.tool(
        name="nmap_custom_scan",
        description="Perform custom Nmap scan with user-defined options"
    )
  • Shared helper function used by all nmap tools, including nmap_custom_scan, to execute nmap commands via subprocess and handle results/errors.
    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
            }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the action without disclosing behavioral traits. It lacks details on permissions, rate limits, output behavior, or potential impacts (e.g., network effects, security considerations), which are critical for a scanning tool.

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, making it appropriately sized and front-loaded. Every part contributes directly to the tool's purpose, earning its place without redundancy.

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 a custom Nmap scan with 3 parameters, 0% schema coverage, no annotations, and sibling tools, the description is incomplete. It does not address usage context, parameter details, or behavioral aspects, despite having an output schema that might cover return values.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate but adds minimal meaning. It mentions 'user-defined options' which loosely relates to 'custom_options', but does not explain parameters like 'targets' format, 'output_format' options, or provide examples, leaving significant gaps.

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 states the tool performs a custom Nmap scan with user-defined options, which provides a basic purpose (verb+resource). However, it lacks specificity about what distinguishes it from siblings like nmap_basic_scan or nmap_port_scan, making it vague in context.

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

Usage Guidelines2/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 the many sibling alternatives (e.g., nmap_basic_scan, nmap_vulnerability_scan). The description implies usage for custom options but does not specify scenarios, exclusions, or comparisons, leaving the agent without clear direction.

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