A comprehensive Model Context Protocol (MCP) server that provides access to essential network operations and infrastructure tools through a standardized interface. - Ping: Test host connectivity with customizable packet count and timeout - Traceroute: Trace network path with configurable max hops - MTR: Monitor network path with real-time statistics - Telnet: Test port connectivity using telnet -
Add this skill
npx mdskills install alpadalar/netops-mcpComprehensive MCP server with excellent tool coverage, clear API documentation, and thorough setup instructions
1# NetOps MCP - Network Operations Tools MCP Server23A comprehensive Model Context Protocol (MCP) server that provides access to essential network operations and infrastructure tools through a standardized interface.45## ๐ Features67### Network Connectivity Tools8- **Ping**: Test host connectivity with customizable packet count and timeout9- **Traceroute**: Trace network path with configurable max hops10- **MTR**: Monitor network path with real-time statistics11- **Telnet**: Test port connectivity using telnet12- **Netcat**: Test port connectivity using netcat1314### HTTP/API Testing Tools15- **cURL**: Execute HTTP requests with full control over headers, methods, and data16- **HTTPie**: Alternative HTTP client with simplified syntax17- **API Testing**: Validate API endpoints with expected status codes1819### DNS Tools20- **nslookup**: Query DNS records with various record types21- **dig**: Advanced DNS querying tool22- **host**: Simple DNS lookup utility2324### Network Discovery Tools25- **Nmap**: Network scanning and service enumeration26- **Port Scanning**: Targeted port scanning capabilities27- **Service Discovery**: Identify running services on targets2829### System Monitoring Tools30- **SS**: Socket statistics and connection monitoring31- **Netstat**: Network statistics and connection information32- **ARP**: Address Resolution Protocol table management33- **ARPing**: Test ARP connectivity3435### System Information Tools36- **System Status**: CPU, memory, and disk usage monitoring37- **Process List**: Running process enumeration38- **Required Tools Check**: Verify system tool availability3940## ๐ Prerequisites4142### Required System Tools43The following tools must be installed on the system:4445```bash46# Network tools47curl, ping, traceroute, mtr, telnet, nc (netcat)4849# DNS tools50nslookup, dig, host5152# Network discovery53nmap5455# System tools56ss, netstat, arp, arping5758# HTTP tools59httpie (optional, for enhanced HTTP testing)60```6162### Python Requirements63- Python 3.8+64- uv package manager (recommended)6566## ๐ ๏ธ Installation6768### Using uv (Recommended)6970```bash71# Clone the repository72git clone https://github.com/alpadalar/NetOpsMCP.git73cd NetOpsMCP7475# Install dependencies using uv76uv venv77source .venv/bin/activate # On Windows: .venv\Scripts\activate78uv pip install -e .79```8081### Using pip8283```bash84# Clone the repository85git clone https://github.com/alpadalar/NetOpsMCP.git86cd NetOpsMCP8788# Create virtual environment89python -m venv .venv90source .venv/bin/activate # On Windows: .venv\Scripts\activate9192# Install dependencies93pip install -e .94```9596### Using Docker9798```bash99# Build and run with Docker Compose100docker compose up -d101102# Or build manually103docker build -t netopsmcp .104docker run -p 8815:8815 netopsmcp105```106107## ๐ Quick Start108109### 1. Start the Server110111```bash112# Using Python directly113python -m netops_mcp.server_http --host 0.0.0.0 --port 8815114115# Using Docker116docker compose up -d117118# Using the provided script119./start_http_server.sh120```121122### 2. Test the Server123124```bash125# Health check126curl http://localhost:8815/health127128# Test system requirements129curl -X POST http://localhost:8815/netops-mcp \130 -H "Content-Type: application/json" \131 -d '{"method": "check_required_tools", "params": {}}'132```133134### 3. Example Usage135136```python137# Ping a host138result = ping_host("google.com", count=4, timeout=10)139140# Test HTTP endpoint141result = curl_request("https://httpbin.org/get", method="GET")142143# DNS lookup144result = nslookup_query("google.com", record_type="A")145146# Network scan147result = nmap_scan("192.168.1.1", ports="1-1000", scan_type="basic")148```149150## ๐ API Reference151152### Network Connectivity153154#### `ping_host(host: str, count: int = 4, timeout: int = 10)`155Test connectivity to a host using ping.156157**Parameters:**158- `host`: Target hostname or IP address159- `count`: Number of ping packets (default: 4)160- `timeout`: Timeout in seconds (default: 10)161162**Returns:** Ping statistics and results163164#### `traceroute_path(target: str, max_hops: int = 30, timeout: int = 30)`165Trace network path to a target.166167**Parameters:**168- `target`: Target hostname or IP address169- `max_hops`: Maximum number of hops (default: 30)170- `timeout`: Timeout in seconds (default: 30)171172**Returns:** Network path information173174#### `mtr_monitor(target: str, count: int = 10, timeout: int = 30)`175Monitor network path using MTR.176177**Parameters:**178- `target`: Target hostname or IP address179- `count`: Number of probes (default: 10)180- `timeout`: Timeout in seconds (default: 30)181182**Returns:** MTR statistics and hop information183184### HTTP Testing185186#### `curl_request(url: str, method: str = "GET", headers: dict = None, data: dict = None, timeout: int = 30)`187Execute HTTP request using curl.188189**Parameters:**190- `url`: Target URL191- `method`: HTTP method (GET, POST, PUT, DELETE, PATCH)192- `headers`: HTTP headers dictionary193- `data`: Request data for POST/PUT requests194- `timeout`: Request timeout in seconds195196**Returns:** HTTP response and timing information197198#### `httpie_request(url: str, method: str = "GET", headers: dict = None, data: dict = None, timeout: int = 30)`199Execute HTTP request using HTTPie.200201**Parameters:** Same as curl_request202203**Returns:** HTTP response and timing information204205### DNS Tools206207#### `nslookup_query(domain: str, record_type: str = "A", server: str = None)`208Query DNS records using nslookup.209210**Parameters:**211- `domain`: Target domain name212- `record_type`: DNS record type (A, AAAA, MX, NS, TXT, CNAME)213- `server`: Custom DNS server (optional)214215**Returns:** DNS query results216217#### `dig_query(domain: str, record_type: str = "A", server: str = None)`218Query DNS records using dig.219220**Parameters:** Same as nslookup_query221222**Returns:** Detailed DNS query results223224### Network Discovery225226#### `nmap_scan(target: str, ports: str = None, scan_type: str = "basic", timeout: int = 300)`227Scan network using nmap.228229**Parameters:**230- `target`: Target hostname, IP, or network range231- `ports`: Port range (e.g., "1-1000", "80,443,8080")232- `scan_type`: Scan type (basic, full, stealth)233- `timeout`: Scan timeout in seconds234235**Returns:** Network scan results236237#### `port_scan(target: str, ports: str, timeout: int = 60)`238Perform targeted port scanning.239240**Parameters:**241- `target`: Target hostname or IP address242- `ports`: Port range to scan243- `timeout`: Scan timeout in seconds244245**Returns:** Port scan results246247### System Monitoring248249#### `system_status()`250Get system status information.251252**Returns:** CPU, memory, and disk usage statistics253254#### `ss_connections(state: str = None, protocol: str = None)`255Show network connections using ss.256257**Parameters:**258- `state`: Filter by connection state259- `protocol`: Filter by protocol260261**Returns:** Network connection information262263#### `netstat_connections(state: str = None, protocol: str = None)`264Show network connections using netstat.265266**Parameters:** Same as ss_connections267268**Returns:** Network connection information269270## ๐งช Testing271272### Run All Tests273274```bash275# Using pytest276pytest tests/ -v277278# Using uv279uv run pytest tests/ -v280281# With coverage282pytest tests/ --cov=src --cov-report=html --cov-report=term-missing283```284285### Test Categories286287- **Unit Tests**: Individual tool functionality288- **Integration Tests**: End-to-end workflow testing289- **Mock Tests**: Command execution simulation290- **Validation Tests**: Input validation and error handling291292### Test Coverage293294The test suite covers:295- โ All tool methods and functionality296- โ Input validation and error handling297- โ Command execution and output parsing298- โ Edge cases and error scenarios299- โ Mock testing for external dependencies300301To generate coverage reports:302```bash303# Generate HTML coverage report304pytest tests/ --cov=src --cov-report=html305306# Generate terminal coverage report307pytest tests/ --cov=src --cov-report=term-missing308309# Generate both reports310pytest tests/ --cov=src --cov-report=html --cov-report=term-missing311```312313## ๐ง Configuration314315### Environment Variables316317```bash318# Server configuration319NETOPS_MCP_HOST=0.0.0.0320NETOPS_MCP_PORT=8815321NETOPS_MCP_LOG_LEVEL=INFO322323# Tool timeouts324PING_TIMEOUT=10325TRACEROUTE_TIMEOUT=30326MTR_TIMEOUT=30327CURL_TIMEOUT=30328NMAP_TIMEOUT=300329```330331### Configuration File332333The server will automatically create a default configuration file from `config/config.example.json` on first run, or you can create `config/config.json` manually:334335```json336{337 "logging": {338 "level": "INFO",339 "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",340 "file": "logs/netops-mcp.log"341 },342 "security": {343 "allow_privileged_commands": false,344 "allowed_hosts": [],345 "rate_limit_requests": 100,346 "rate_limit_window": 60347 },348 "network": {349 "default_timeout": 30,350 "max_scan_timeout": 300,351 "allowed_ports": "1-65535"352 },353 "server": {354 "host": "0.0.0.0",355 "port": 8815,356 "path": "/netops-mcp"357 }358}359```360361## ๐ณ Docker Support362363### Docker Compose364365```yaml366version: '3.8'367services:368 netopsmcp:369 build: .370 ports:371 - "8815:8815"372 environment:373 - NETOPS_MCP_HOST=0.0.0.0374 - NETOPS_MCP_PORT=8815375 volumes:376 - ./logs:/app/logs377 - ./config:/app/config378 healthcheck:379 test: ["CMD", "curl", "-f", "http://localhost:8815/health"]380 interval: 30s381 timeout: 10s382 retries: 3383```384385### Docker Build386387```bash388# Build image389docker build -t netopsmcp .390391# Run container392docker run -d \393 --name netopsmcp \394 -p 8815:8815 \395 -v $(pwd)/logs:/app/logs \396 -v $(pwd)/config:/app/config \397 netopsmcp398```399400## ๐ Monitoring and Logging401402### Log Levels403404- **DEBUG**: Detailed debugging information405- **INFO**: General operational messages406- **WARNING**: Warning messages for potential issues407- **ERROR**: Error messages for failed operations408409### Log Files410411- `logs/netops-mcp.log`: Main application log412- `logs/access.log`: HTTP access log413- `logs/error.log`: Error log414415### Health Checks416417```bash418# Check server health419curl http://localhost:8815/health420421# Check system requirements422curl -X POST http://localhost:8815/netops-mcp \423 -H "Content-Type: application/json" \424 -d '{"method": "check_required_tools", "params": {}}'425```426427## ๐ Security Considerations428429### Network Security430431- **Firewall Rules**: Configure appropriate firewall rules for the server port432- **Access Control**: Implement authentication if needed433- **Network Isolation**: Run in isolated network environments when possible434435### Tool Security436437- **Privileged Operations**: Some tools require elevated privileges438- **Network Scanning**: Be aware of legal implications of network scanning439- **Rate Limiting**: Implement rate limiting for resource-intensive operations440441### Best Practices442443- **Input Validation**: All inputs are validated before processing444- **Error Handling**: Comprehensive error handling and logging445- **Timeout Management**: Configurable timeouts for all operations446- **Resource Limits**: Built-in resource usage limits447448## ๐ Production Deployment449450### Quick Production Setup4514521. **Generate API Keys**:453 ```bash454 python scripts/generate_api_key.py -n 2 --config config/config.json455 ```4564572. **Configure Security** (`config/config.json`):458 ```json459 {460 "security": {461 "require_auth": true,462 "api_keys": ["your-generated-key-here"],463 "rate_limit_requests": 100,464 "rate_limit_window": 60465 }466 }467 ```4684693. **Deploy with Docker Compose**:470 ```bash471 docker compose up -d472 ```4734744. **Verify Deployment**:475 ```bash476 curl http://localhost:8815/health477 ```478479### Authentication480481The server supports API key authentication for secure access:482483```bash484# Make authenticated request485curl -X POST http://localhost:8815/netops-mcp \486 -H "Authorization: Bearer YOUR_API_KEY" \487 -H "Content-Type: application/json" \488 -d '{"method": "ping_host", "params": {"host": "google.com"}}'489```490491### HTTPS Setup (Recommended)492493Use a reverse proxy (nginx or Caddy) for HTTPS:494495```nginx496server {497 listen 443 ssl http2;498 server_name your-domain.com;499500 ssl_certificate /path/to/cert.pem;501 ssl_certificate_key /path/to/key.pem;502503 location / {504 proxy_pass http://localhost:8815;505 proxy_set_header Host $host;506 proxy_set_header X-Real-IP $remote_addr;507 }508}509```510511### Production Features512513- โ **API Key Authentication**: Secure access control with Bearer tokens514- โ **Rate Limiting**: Built-in rate limiting (100 req/min default)515- โ **Input Validation**: Comprehensive input sanitization516- โ **Structured Logging**: JSON logging for production environments517- โ **Health Checks**: Built-in health check endpoints518- โ **Docker Support**: Production-ready Docker image with multi-stage build519- โ **Non-Root User**: Runs as unprivileged user in container520- โ **Resource Limits**: Configurable CPU and memory limits521- โ **CORS Support**: Configurable CORS for web applications522- โ **Security Headers**: Automatic security headers523524### CI/CD Pipeline525526GitHub Actions workflows included:527- **Tests**: Automated testing on Python 3.10, 3.11, 3.12528- **Linting**: Code quality checks (Black, Ruff, mypy)529- **Security**: Security scanning (Bandit, Safety, Trivy)530- **Release**: Automated Docker image publishing to GitHub Container Registry531532### Documentation533534- ๐ [Production Deployment Guide](docs/PRODUCTION_DEPLOYMENT.md)535- ๐ [API Authentication Guide](docs/API_AUTHENTICATION.md)536- ๐ก๏ธ [Security Policy](SECURITY.md)537538## ๐ค Contributing539540### Development Setup541542```bash543# Clone repository544git clone https://github.com/alpadalar/NetOpsMCP.git545cd NetOpsMCP546547# Install development dependencies548uv pip install -e .549550# Run tests551pytest tests/ -v552```553554### Code Style555556- **Black**: Code formatting557- **Ruff**: Linting and import sorting558- **mypy**: Type checking559560### Testing Guidelines561562- Write tests for all new functionality563- Maintain test coverage above 90%564- Use meaningful test names and descriptions565- Mock external dependencies566567### Pull Request Process5685691. Fork the repository5702. Create a feature branch5713. Make your changes5724. Add tests for new functionality5735. Update documentation5746. Submit a pull request575576## ๐ License577578This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.579580## ๐ Support581582### Documentation583584- API Reference: See the API Reference section above585- Configuration Guide: See the Configuration section above586- Troubleshooting: See the Support section above587588### Issues589590- **Bug Reports**: Use GitHub Issues591- **Feature Requests**: Submit via GitHub Issues592- **Security Issues**: Contact maintainers directly593594### Community595596- **Issues**: GitHub Issues for discussions and questions597- **Documentation**: See the sections above for comprehensive guides598599## ๐ Acknowledgments600601- **MCP Protocol**: Model Context Protocol specification602- **Network Tools**: Open source networking utilities603- **Testing Framework**: pytest and related tools604- **Community**: Contributors and users605606---607608**NetOps MCP** - Empowering network operations through standardized tool access.609
Full transparency โ inspect the skill content before installing.