Skip to main content
Glama
mohdhaji87

Nmap MCP Server

by mohdhaji87

nmap_os_detection

Identify operating systems on network targets using Nmap's OS fingerprinting capabilities to enhance network security analysis and inventory management.

Instructions

Perform operating system detection scan

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetsYes
portsNocommon
max_retriesNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the nmap_os_detection tool, decorated with @app.tool for registration. It constructs Nmap arguments for OS detection (-O flag) and executes via run_nmap_command helper, returning scan results or error.
    @app.tool(
        name="nmap_os_detection",
        description="Perform operating system detection scan"
    )
    async def nmap_os_detection(
        targets: str,
        ports: str = "common",
        max_retries: int = 2
    ) -> str:
        """Perform operating system detection scan."""
        args = ["-O", f"--osscan-retries={max_retries}", "-p", ports, targets]
        
        result = run_nmap_command(args)
        
        if result["success"]:
            return f"OS detection scan completed:\n\n{result['stdout']}"
        else:
            return f"OS detection scan failed:\n\n{result['stderr']}"
  • server.py:140-143 (registration)
    Registration of the nmap_os_detection tool using FastMCP's @app.tool decorator, specifying the tool name and description.
    @app.tool(
        name="nmap_os_detection",
        description="Perform operating system detection scan"
    )
  • Shared helper function used by nmap_os_detection and other tools to execute Nmap commands via subprocess, handling output, errors, and timeouts.
    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 the full burden of behavioral disclosure. It states the action ('Perform operating system detection scan') but lacks details on traits like required permissions, network impact, rate limits, or output format. For a network scanning tool with potential security implications, this is a significant gap in transparency.

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: 'Perform operating system detection scan'. It is front-loaded with the core action and wastes no words, making it highly concise and well-structured for quick comprehension.

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 the tool's complexity (network scanning with 3 parameters) and the presence of an output schema, the description is minimally adequate. However, with no annotations and 0% schema coverage, it lacks crucial context like behavioral traits and parameter meanings. The output schema may help with return values, but overall completeness is limited.

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?

The schema description coverage is 0%, meaning parameters are undocumented in the schema. The description adds no information about parameters like 'targets', 'ports', or 'max_retries', failing to compensate for the coverage gap. This leaves the agent without semantic understanding of inputs beyond their titles.

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 tool's purpose: 'Perform operating system detection scan'. It specifies the verb ('Perform') and the resource/action ('operating system detection scan'), making it understandable. However, it doesn't explicitly differentiate from sibling tools like 'nmap_service_detection' or 'nmap_comprehensive_scan', which might also involve OS detection, so it doesn't reach a 5.

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 alternatives. With multiple sibling tools like 'nmap_basic_scan', 'nmap_comprehensive_scan', and 'nmap_service_detection', there's no indication of specific contexts, prerequisites, or exclusions. This leaves the agent without clear usage 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