Nmap MCP Server

Nmap MCP Server

Exposes Nmap network scanning capabilities through a Model Context Protocol (MCP) server, allowing users to perform various types of network scans including vulnerability assessment, service detection, and OS fingerprinting.

Category
访问服务器

README

Nmap MCP Server

A Model Context Protocol (MCP) server that exposes Nmap CLI functionality as MCP tools using FastMCP with stdio transport. This server provides comprehensive network scanning capabilities through the Nmap command-line tool.

🚀 FastMCP Implementation

This server is built using FastMCP, a modern, high-performance MCP framework that provides:

  • Simplified API: Clean decorator-based tool registration
  • Type Safety: Full type hints and validation
  • Stdio Transport: Efficient communication via standard input/output
  • Async Support: Non-blocking operations with proper error handling

Features

The Nmap MCP Server exposes the following tools using FastMCP decorators:

1. Basic Scan (nmap_basic_scan)

Perform basic Nmap scans with different intensity levels:

  • Quick: Fast scan with high throughput
  • Comprehensive: Full scan with service detection and OS detection
  • Stealth: Low-profile scan to avoid detection

2. Service Detection (nmap_service_detection)

Detect services and versions running on target hosts with configurable intensity levels (0-9).

3. OS Detection (nmap_os_detection)

Detect operating systems running on target hosts with configurable retry attempts.

4. Script Scanning (nmap_script_scan)

Run NSE (Nmap Scripting Engine) scripts for advanced reconnaissance and vulnerability assessment.

5. Stealth Scan (nmap_stealth_scan)

Perform SYN scans with minimal detection using configurable timing templates.

6. Comprehensive Scan (nmap_comprehensive_scan)

Perform full-featured scans combining multiple detection methods.

7. Ping Scan (nmap_ping_scan)

Discover live hosts using various ping methods (ICMP, TCP, or both).

8. Port Scan (nmap_port_scan)

Scan specific ports using different methods (SYN, Connect, UDP).

9. Vulnerability Scan (nmap_vulnerability_scan)

Run vulnerability detection scripts with different categories.

10. Network Discovery (nmap_network_discovery)

Discover hosts and services on entire networks.

11. Custom Scan (nmap_custom_scan)

Perform scans with user-defined Nmap options for maximum flexibility.

Prerequisites

  • Python 3.10 or higher
  • Nmap installed and available in your system PATH

Installing Nmap

macOS:

brew install nmap

Ubuntu/Debian:

sudo apt update
sudo apt install nmap

CentOS/RHEL:

sudo yum install nmap
# or for newer versions:
sudo dnf install nmap

Windows: Download and install from nmap.org

Installation

  1. Clone this repository:
git clone <repository-url>
cd nmap-mcp-server
  1. Install dependencies:
pip install -e .

Usage

Running the FastMCP Server

The server can be run directly with stdio transport:

python server.py

Or using the installed script:

nmap-mcp-server

Claude Desktop Configuration

Add the following configuration to your Claude Desktop MCP settings:

{
  "mcpServers": {
    "NmapMCP": {
      "command": "uv",
      "args": [
        "--directory",
        "/Users/haji/mcp-servers/nmap-mcp-server",
        "run",
        "server.py"
      ]
    }
  }
}

Configuration Steps:

  1. Open Claude Desktop
  2. Go to Settings → MCP Servers
  3. Add the JSON configuration above
  4. Restart Claude Desktop
  5. Verify the server is connected

FastMCP Tool Examples

Basic Network Scan

# The tool is called with typed parameters
result = await nmap_basic_scan(
    targets="192.168.1.0/24",
    ports="common",
    scan_type="quick"
)

Service Detection

result = await nmap_service_detection(
    targets="example.com",
    ports="80,443,8080",
    intensity=7
)

Vulnerability Assessment

result = await nmap_vulnerability_scan(
    targets="192.168.1.100",
    ports="common",
    vuln_category="all"
)

Custom Scan

result = await nmap_custom_scan(
    targets="example.com",
    custom_options="-sS -p 1-1000 -A --script=vuln",
    output_format="normal"
)

FastMCP Architecture

The server uses FastMCP's clean decorator pattern:

@app.tool(
    name="nmap_basic_scan",
    description="Perform a basic Nmap scan of specified targets"
)
async def nmap_basic_scan(
    targets: str,
    ports: str = "common",
    scan_type: str = "quick"
) -> str:
    """Perform a basic Nmap scan of specified targets."""
    # Implementation here
    return result

Security Considerations

⚠️ Important Security Notes:

  1. Legal Compliance: Only scan networks and systems you own or have explicit permission to scan.
  2. Network Impact: Some scans can be resource-intensive and may impact network performance.
  3. Detection: Aggressive scans may trigger security systems and firewalls.
  4. Rate Limiting: The server includes timeouts and rate limiting to prevent abuse.

Error Handling

The FastMCP server includes comprehensive error handling for:

  • Nmap command not found
  • Command timeouts
  • Invalid arguments
  • Network connectivity issues
  • Permission errors

Logging

The server uses Python's built-in logging system. Logs include:

  • Command execution details
  • Error messages
  • Performance metrics

Testing

Test the FastMCP server:

# Test tool registration and functionality
python test_fastmcp.py

# Test examples
python example_usage.py

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This tool is for educational and authorized security testing purposes only. Users are responsible for ensuring they have proper authorization before scanning any network or system.

Support

For issues and questions:

  1. Check the error logs
  2. Verify Nmap is installed and accessible
  3. Ensure you have proper permissions
  4. Open an issue on the repository

Changelog

Version 1.0.0

  • Initial release with FastMCP implementation
  • Support for all major Nmap scanning techniques
  • Comprehensive error handling
  • Stdio transport mode
  • Type-safe tool definitions
  • Claude Desktop configuration with uv

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选