Skip to main content
Glama

nmap_scan

Perform comprehensive port scanning to identify open ports and services on target systems for security assessment and penetration testing.

Instructions

Perform comprehensive port scan using Nmap

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetYesTarget IP or domain
scan_typeNoType of scan to perform

Implementation Reference

  • Core handler function that executes Nmap scans with configurable scan types, parses XML output, and returns structured ScanResult.
    async nmapScan(target: string, scanType: string = 'quick'): Promise<ScanResult> {
      try {
        let nmapArgs = '';
        
        switch (scanType) {
          case 'quick':
            nmapArgs = '-F -sV';
            break;
          case 'full':
            nmapArgs = '-p- -sV -sC';
            break;
          case 'stealth':
            nmapArgs = '-sS -T2 -f';
            break;
          case 'aggressive':
            nmapArgs = '-A -T4';
            break;
          default:
            nmapArgs = '-F -sV';
        }
    
        const command = `nmap ${nmapArgs} -oX - ${target}`;
        console.error(`Executing: ${command}`);
        
        const { stdout, stderr } = await execAsync(command, { timeout: 300000 }); // 5 min timeout
        
        // Parse XML output
        const ports = this.parseNmapXML(stdout);
        
        return {
          target,
          timestamp: new Date().toISOString(),
          tool: 'nmap',
          results: {
            scan_type: scanType,
            open_ports: ports,
            raw_output: stdout
          },
          status: 'success'
        };
      } catch (error) {
        return {
          target,
          timestamp: new Date().toISOString(),
          tool: 'nmap',
          results: {},
          status: 'error',
          error: error instanceof Error ? error.message : String(error)
        };
      }
    }
  • Input schema definition for the nmap_scan tool, specifying required target and optional scan_type parameters.
      name: "nmap_scan",
      description: "Perform comprehensive port scan using Nmap",
      inputSchema: {
        type: "object",
        properties: {
          target: { type: "string", description: "Target IP or domain" },
          scan_type: { 
            type: "string", 
            enum: ["quick", "full", "stealth", "aggressive"],
            description: "Type of scan to perform" 
          }
        },
        required: ["target"]
      }
    },
  • src/index.ts:505-506 (registration)
    Tool dispatch registration in the main CallToolRequestSchema handler switch statement.
    case "nmap_scan":
      return respond(await this.reconTools.nmapScan(args.target, args.scan_type || "quick"));
  • Output type definition (ScanResult interface) used by the nmapScan handler.
    export interface ScanResult {
      target: string;
      timestamp: string;
      tool: string;
      results: any;
      status: 'success' | 'error';
      error?: string;
    }
  • Input validation logic for nmap_scan tool arguments, including target validation and scan_type enum check.
        case 'nmap_scan':
          this.validateNmapArgs(args);
          break;
        case 'nuclei_scan':
          this.validateNucleiArgs(args);
          break;
        case 'exploit_attempt':
          this.validateExploitArgs(args);
          break;
        // Add more tool-specific validations as needed
      }
    }
    
    private validateNmapArgs(args: any): void {
      if (args.target) {
        const validation = this.targetValidator.validateTarget(args.target);
        if (!validation.isValid) {
          throw new ValidationError(`Invalid nmap target: ${validation.error}`, 'INVALID_NMAP_TARGET');
        }
      }
    
      const allowedScanTypes = ['quick', 'full', 'stealth', 'aggressive'];
      if (args.scan_type && !allowedScanTypes.includes(args.scan_type)) {
        throw new ValidationError('Invalid scan type', 'INVALID_SCAN_TYPE');
      }
    }
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 mentions 'comprehensive port scan' but doesn't specify what that entails—e.g., whether it's intrusive, time-consuming, requires special permissions, or has rate limits. For a security tool with potential impact, this lack of detail is a significant gap.

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 with zero waste—'Perform comprehensive port scan using Nmap'—front-loading the core action and tool. Every word earns its place, making it highly concise and well-structured.

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 security scanning tool with no annotations and no output schema, the description is incomplete. It lacks details on behavior, output format, risks, or integration with sibling tools, failing to provide enough context for safe and effective use in this multi-tool environment.

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 both parameters ('target' and 'scan_type') with descriptions and enum values. The description adds no additional meaning beyond implying a port scan focus, which aligns with the schema but doesn't enhance parameter understanding, meeting the baseline for high coverage.

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 comprehensive port scan') and tool used ('using Nmap'), which is specific and unambiguous. However, it doesn't differentiate this tool from sibling scanning tools like 'nikto_scan' or 'directory_scan' in terms of scope or methodology, preventing a perfect score.

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 many sibling tools available for scanning (e.g., 'nikto_scan', 'directory_scan', 'subdomain_enum'), there's no indication of whether this is for network-level scans, initial reconnaissance, or specific contexts, leaving the agent without 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/adriyansyah-mf/mcp-pentest'

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