Skip to main content
Glama

nmap_scan

Scan network targets with nmap and automatically import results into Metasploit database for penetration testing workflows.

Instructions

Run an nmap scan and import results into Metasploit database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetYesTarget IP address or CIDR range
portsNoOptional: port range or specific ports (e.g., '80,443' or '1-1000')
scanTypeNoOptional: type of scan to performquick

Implementation Reference

  • Handler for the nmap_scan tool. Validates inputs, checks nmap availability, builds nmap command arguments based on scan type, executes db_nmap via msfconsole to scan target and import results into Metasploit database.
    case "nmap_scan": {
      const { target, ports, scanType } = args as {
        target: string;
        ports?: string;
        scanType?: string;
      };
    
      const nmapAvailable = await checkNmapAvailable();
      if (!nmapAvailable) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                success: false,
                error: "nmap not found. Please install nmap.",
                hint: process.platform === "win32"
                  ? "Download nmap from https://nmap.org/"
                  : "Install with: sudo apt-get install nmap",
              }),
            },
          ],
        };
      }
    
      let nmapArgs: string[] = [];
    
      switch (scanType) {
        case "quick":
          nmapArgs.push("-F");
          break;
        case "stealth":
          nmapArgs.push("-sS");
          break;
        case "full":
          nmapArgs.push("-sV", "-sC");
          break;
        case "udp":
          nmapArgs.push("-sU");
          break;
      }
    
      if (ports) {
        nmapArgs.push("-p", ports);
      }
    
      nmapArgs.push(target);
    
      // Run nmap through msfconsole to automatically import results
      const dbNmapCommand = `db_nmap ${nmapArgs.join(" ")}`;
    
      try {
        const results = await executeMsfCommand([dbNmapCommand]);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  success: true,
                  target,
                  ports: ports || "default",
                  scanType: scanType || "quick",
                  results,
                },
                null,
                2
              ),
            },
          ],
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                success: false,
                error: error.message,
              }),
            },
          ],
        };
      }
    }
  • Input schema for nmap_scan tool defining parameters: target (required), ports (optional), scanType (optional with enum).
    inputSchema: {
      type: "object",
      properties: {
        target: {
          type: "string",
          description: "Target IP address or CIDR range",
        },
        ports: {
          type: "string",
          description: "Optional: port range or specific ports (e.g., '80,443' or '1-1000')",
        },
        scanType: {
          type: "string",
          enum: ["quick", "stealth", "full", "udp"],
          description: "Optional: type of scan to perform",
          default: "quick",
        },
      },
      required: ["target"],
    },
  • src/index.ts:179-202 (registration)
    Registration of the nmap_scan tool in the MCP tools array, including name, description, and input schema.
    {
      name: "nmap_scan",
      description: "Run an nmap scan and import results into Metasploit database",
      inputSchema: {
        type: "object",
        properties: {
          target: {
            type: "string",
            description: "Target IP address or CIDR range",
          },
          ports: {
            type: "string",
            description: "Optional: port range or specific ports (e.g., '80,443' or '1-1000')",
          },
          scanType: {
            type: "string",
            enum: ["quick", "stealth", "full", "udp"],
            description: "Optional: type of scan to perform",
            default: "quick",
          },
        },
        required: ["target"],
      },
    },
  • Helper function specifically used by nmap_scan to verify nmap is installed and available on the system.
    // Check if nmap is available
    async function checkNmapAvailable(): Promise<boolean> {
      try {
        if (process.platform === "win32") {
          await execAsync("where nmap");
        } else {
          await execAsync("which nmap");
        }
        return true;
      } catch {
        return 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. It mentions running a scan and importing results, but lacks details on behavioral traits like permissions needed, whether it's destructive (e.g., modifies the database), rate limits, or error handling. This is a significant gap for a 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, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded and appropriately sized, making it easy to understand quickly.

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 network scanning tool with no annotations and no output schema, the description is incomplete. It does not cover important aspects like what the scan results include, how they are imported into the database, or any prerequisites, leaving gaps for effective agent use.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters (target, ports, scanType) with descriptions and defaults. The description does not add any additional meaning beyond what the schema provides, such as explaining scan types in more detail or providing examples, resulting in a baseline score.

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 ('Run an nmap scan') and the outcome ('import results into Metasploit database'), which is specific and actionable. However, it does not explicitly differentiate from sibling tools like 'db_hosts' or 'db_services', which might handle database queries rather than scans, so it lacks sibling differentiation.

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. For example, it does not mention when to choose this over other scanning tools or database tools in the sibling list, such as 'search_exploits' or 'db_status', leaving usage context implied at best.

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/andreransom58-coder/kali-metasploit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server