Skip to main content
Glama
mohdhaji87

Nmap MCP Server

by mohdhaji87

nmap_basic_scan

Perform basic network scans to identify open ports and services on specified targets using common scanning techniques.

Instructions

Perform a basic Nmap scan of specified targets

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetsYes
portsNocommon
scan_typeNoquick

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the nmap_basic_scan tool. It constructs Nmap command arguments based on the scan_type parameter (quick, comprehensive, or stealth) and executes the scan using the run_nmap_command helper.
    async def nmap_basic_scan(
        targets: str,
        ports: str = "common",
        scan_type: str = "quick"
    ) -> str:
        """Perform a basic Nmap scan of specified targets."""
        args = ["-p", ports]
        
        if scan_type == "quick":
            args.extend(["-T4", "--min-rate=1000"])
        elif scan_type == "comprehensive":
            args.extend(["-sS", "-sV", "-O", "--script=default"])
        elif scan_type == "stealth":
            args.extend(["-sS", "-T2", "--min-rate=100"])
        
        args.append(targets)
        
        result = run_nmap_command(args)
        
        if result["success"]:
            return f"Basic scan completed successfully:\n\n{result['stdout']}"
        else:
            return f"Basic scan failed:\n\n{result['stderr']}"
  • server.py:93-96 (registration)
    Registers the nmap_basic_scan tool with the FastMCP app using the @app.tool decorator, specifying the name and description.
    @app.tool(
        name="nmap_basic_scan",
        description="Perform a basic Nmap scan of specified targets"
    )
  • Shared helper function used by nmap_basic_scan (and other tools) to execute Nmap commands via subprocess, handling timeouts, errors, and parsing output.
    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 only states the action without detailing critical traits such as network impact, permissions required, rate limits, output format, or whether it's safe for production use. This is inadequate for a network scanning tool with potential security implications.

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, direct sentence with no wasted words, making it highly concise and front-loaded. It efficiently communicates the core action without unnecessary elaboration, though this brevity contributes to gaps in other dimensions.

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 tool's complexity (network scanning with 3 parameters), lack of annotations, and 0% schema coverage, the description is insufficient. While an output schema exists, the description fails to address behavioral risks, parameter meanings, or differentiation from siblings, making it incomplete for safe and effective use.

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%, meaning parameters are undocumented in the schema. The description does not compensate by explaining what 'targets', 'ports', or 'scan_type' mean, their formats, or acceptable values (e.g., what 'common' ports or 'quick' scan type entail). This leaves key input semantics unclear.

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's purpose as 'Perform a basic Nmap scan of specified targets,' which clearly indicates the verb ('Perform'), resource ('Nmap scan'), and scope ('basic'). However, it does not differentiate this tool from its many siblings (e.g., nmap_port_scan, nmap_network_discovery), leaving ambiguity about what makes it 'basic' versus other scan types.

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?

The description provides no guidance on when to use this tool versus its alternatives. With multiple sibling tools available (e.g., nmap_comprehensive_scan, nmap_stealth_scan), there is no indication of scenarios where a 'basic' scan is preferred, prerequisites, or exclusions, leading to potential misuse.

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