Skip to main content
Glama
mohdhaji87

Nmap MCP Server

by mohdhaji87

nmap_network_discovery

Scan networks to identify active hosts and detect open ports or running services for security analysis and inventory management.

Instructions

Discover hosts and services on a network

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkYes
discovery_methodNoall
include_portsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main asynchronous handler function that implements the logic for the nmap_network_discovery tool. It constructs nmap arguments based on discovery method and port scanning options, executes via run_nmap_command, and returns formatted results.
    async def nmap_network_discovery(
        network: str,
        discovery_method: str = "all",
        include_ports: bool = True
    ) -> str:
        """Discover hosts and services on a network."""
        if discovery_method == "ping":
            args = ["-sn", network]
        elif discovery_method == "arp":
            args = ["-PR", network]
        elif discovery_method == "syn":
            args = ["-PS", network]
        else:  # all
            args = ["-sn", "-PS", "-PA", network]
        
        if include_ports:
            args.extend(["-sS", "-sV", "--top-ports=100"])
        
        result = run_nmap_command(args)
        
        if result["success"]:
            return f"Network discovery completed:\n\n{result['stdout']}"
        else:
            return f"Network discovery failed:\n\n{result['stderr']}"
  • server.py:292-295 (registration)
    FastMCP tool registration decorator that registers the nmap_network_discovery handler with the specified name and description.
    @app.tool(
        name="nmap_network_discovery",
        description="Discover hosts and services on a network"
    )
  • Utility function to execute nmap commands using subprocess, handle timeouts and errors, and return structured results (stdout, stderr, success). Used by multiple tool handlers including nmap_network_discovery.
    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?

With no annotations provided, the description carries full burden for behavioral disclosure but offers minimal information. It doesn't describe what 'discover' entails operationally (e.g., is it active scanning, passive listening, requires special permissions, has rate limits, affects network performance, returns structured data). The description is too generic for a network scanning tool that likely has significant behavioral 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 extremely concise at just 6 words, with no wasted language. It's front-loaded with the core purpose. However, this conciseness comes at the cost of completeness - every word earns its place but too few words are present for adequate tool documentation.

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 network discovery tools, 3 parameters with 0% schema coverage, no annotations, but with an output schema, the description is insufficient. While the output schema may document return values, the description doesn't provide enough context about the tool's behavior, parameter usage, or differentiation from siblings to enable effective tool selection and invocation.

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?

With 0% schema description coverage for all 3 parameters, the description provides no parameter semantics beyond what's implied by the tool name. It doesn't explain what 'network' expects (CIDR notation, IP range, hostname), what 'discovery_method' options exist, or what 'include_ports' controls. The description fails to compensate for the complete 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 'Discover hosts and services on a network' clearly states the tool's purpose with a specific verb ('Discover') and resources ('hosts and services'), but it doesn't distinguish this tool from its many siblings (e.g., nmap_basic_scan, nmap_ping_scan, nmap_port_scan) that likely perform similar discovery functions. The description is vague about what makes this tool unique within the NMPA toolset.

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?

The description provides no guidance on when to use this tool versus the 10 sibling tools listed. There's no mention of alternatives, prerequisites, or specific contexts where this discovery tool is preferred over other scanning/detection tools. This leaves the agent with no basis for selecting among similar-sounding 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