Skip to main content
Glama
mohdhaji87

Nmap MCP Server

by mohdhaji87

nmap_stealth_scan

Perform stealth SYN scans to identify open ports on network targets while minimizing detection by security systems.

Instructions

Perform stealth scan (SYN scan) with minimal detection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetsYes
portsNocommon
timingNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function that executes the nmap stealth scan using SYN scan (-sS) with configurable timing template (-T), ports, and targets. It calls the shared run_nmap_command helper and formats the output.
    async def nmap_stealth_scan(
        targets: str,
        ports: str = "common",
        timing: int = 3
    ) -> str:
        """Perform stealth scan (SYN scan) with minimal detection."""
        args = ["-sS", f"-T{timing}", "-p", ports, targets]
        
        result = run_nmap_command(args)
        
        if result["success"]:
            return f"Stealth scan completed:\n\n{result['stdout']}"
        else:
            return f"Stealth scan failed:\n\n{result['stderr']}"
  • server.py:178-181 (registration)
    FastMCP tool registration decorator specifying the tool name and description. Input schema is inferred from function type hints.
    @app.tool(
        name="nmap_stealth_scan",
        description="Perform stealth scan (SYN scan) with minimal detection"
    )
  • Shared utility function used by all Nmap tools to execute subprocess nmap commands safely with timeout handling, logging, and result parsing.
    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?

No annotations are provided, so the description carries full burden. It mentions 'stealth scan (SYN scan)' and 'minimal detection', which hints at network behavior, but lacks details on permissions needed, rate limits, output format (though output schema exists), or potential risks like network disruption. More context on what 'stealth' entails operationally would help.

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?

Extremely concise with a single sentence that front-loads the core action. Every word earns its place: 'Perform stealth scan' states the purpose, '(SYN scan)' clarifies the method, and 'with minimal detection' adds context. No wasted verbiage.

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

Completeness3/5

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

Given 3 parameters with 0% schema coverage, no annotations, but an output schema exists, the description is incomplete. It covers the tool's purpose and stealth aspect but misses parameter explanations and behavioral details. The output schema mitigates some gaps, but for a network scanning tool with siblings, more guidance on usage and params is needed.

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. It adds no information about parameters like 'targets', 'ports', or 'timing'. Without param details, users can't infer what values to provide (e.g., format for 'targets', meaning of 'timing' levels). The description fails to explain these beyond the bare schema.

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

Purpose4/5

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

The description clearly states the action ('Perform stealth scan') and method ('SYN scan'), with the goal of 'minimal detection'. It distinguishes from siblings by specifying the stealth/SYN technique, though it doesn't explicitly contrast with other nmap tools like 'nmap_basic_scan' or 'nmap_port_scan'.

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 explicit guidance on when to use this tool versus alternatives like 'nmap_basic_scan' or 'nmap_port_scan'. The mention of 'minimal detection' implies a use case for stealth, but it doesn't specify scenarios, prerequisites, or exclusions compared to sibling 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