This MCP (Model Context Protocol) server provides tools for interacting with ContainerLab Linux containers acting as network clients. It enables network configuration, connectivity testing, and routing management for network clients in the lab environments. This MCP server is limited to discovering and automating tasks on clab nodes of type Linux.
docker build . -t clab-mcp-serverdocker build . --build-arg HTTP_PROXY=<proxy server> --build-arg HTTPS_PROXY=<proxy server> --build-arg NO_PROXY=<subnets to skip> -t clab-mcp-serverThe MCP server needs to connect to a Docker daemon to manage ContainerLab containers. You can configure the Docker host IP address in several ways:
-
Environment Variable (recommended for Docker runs):
export DOCKER_HOST_IP=your.docker.host.ip -
Command Line Argument (for direct Python execution):
python clab_mcp_server.py --docker-host-ip your.docker.host.ip
-
Default Behavior: If neither is specified, it defaults to
localhost
python clab_mcp_server.py --help--docker-host-ip: Docker host IP address (default: localhost, or set DOCKER_HOST_IP env var)--docker-port: Docker daemon port (default: 2375)--docker-tls: Use TLS for Docker connection (default: False)--mcp-host: MCP server host (default: 0.0.0.0)--mcp-port: MCP server port (default: 8989)
Important: This MCP server connects to the CLAB server using Docker TCP transport. The CLAB Docker service must be enabled to be managed by Docker TCP-based commands.
docker run -d -p 8989:8989 clab-mcp-serverdocker run -d --name clab-mcp-server -p 8989:8989 -e DOCKER_HOST_IP=<docker-host-ip> clab-mcp-serverdocker run -d -p 8989:8989 \
-e DOCKER_HOST_IP=<docker-host-ip> \
-e DOCKER_PORT=2375 \
--name clab-mcp-server \
clab-mcp-serverPort 8989 is used because the MCP server inside the container listens on port 8989. The port mapping -p 8989:8989 makes the server accessible from the host.
- get_clab_linux_nodes - Discover and inventory all ContainerLab Linux nodes with their network interface details
- set_ip - Configure network connectivity by creating VLAN interfaces and assigning IP addresses
- delete_vlan_interface - Remove VLAN interfaces and clean up network configuration
- create_bond_interface - Create bond interfaces for network redundancy and load balancing
- delete_bond_interface - Delete bond interfaces and restore slave interfaces to their original state
- get_interface_info - Retrieve comprehensive configuration and status information for network interfaces (supports physical, VLAN, and bond interfaces)
- test_connectivity - Verify network connectivity between containers using ping
- lldp_neighbor_discovery - Discover LLDP neighbors and network topology around containers
- add_static_route - Add static routes to container routing tables for L3 domain testing
- check_routes - Retrieve and analyze container routing tables for troubleshooting
- route_delete - Remove static routes from container routing tables
Discovers all running ContainerLab containers with the clab-node-kind label set to "linux" and retrieves detailed network interface information including IP addresses, MAC addresses, and interface states.
Use Cases:
- Network topology discovery
- Interface configuration verification
- MAC address learning
- Connectivity troubleshooting
Creates VLAN interfaces and assigns IP addresses with optional gateway configuration.
Parameters:
container_name: Target container nameinterface_name: Base interface name (e.g., 'eth1')ip_with_mask: IP address with CIDR notation (e.g., '192.168.1.10/24')vlan_id: VLAN ID number (1-4094)gateway_ip: Optional default gateway IP address
Operations:
- Creates VLAN interface (e.g., eth1.100 for VLAN 100)
- Brings the interface up
- Assigns IP address
- Optionally configures default gateway
Removes VLAN interfaces and cleans up associated configuration.
Parameters:
container_name: Target container nameinterface_name: Base interface namevlan_id: VLAN ID to delete
Creates bonded network interfaces for redundancy and load balancing.
Parameters:
container_name: Target container namebond_name: Bond interface name (e.g., 'bond0')slave_interfaces: List of interfaces to bond (e.g., ['eth1', 'eth2'])bond_mode: Bonding mode (default: 'active-backup')miimon: MII monitoring interval in milliseconds (default: 100)
Supported Bond Modes:
active-backup: One interface active, others standbybalance-rr: Round-robin load balancingbalance-xor: XOR hash load balancingbroadcast: Transmit on all interfaces802.3ad: IEEE 802.3ad dynamic link aggregation (LACP)balance-tlb: Adaptive transmit load balancingbalance-alb: Adaptive load balancing
Removes bond interfaces and restores slave interfaces to independent operation.
Parameters:
container_name: Target container namebond_name: Bond interface name to deleteslave_interfaces: List of slave interfaces to restore
Operations:
- Brings down bond interface
- Removes slave interfaces from bond
- Deletes bond interface
- Restores slave interfaces as independent interfaces
Provides comprehensive inspection of network interfaces with specialized support for different interface types.
Parameters:
container_name: Target container nameinterface_name: Interface to analyze (e.g., 'eth1', 'bond0', 'eth1.100')
Returns detailed information about:
- Basic Properties: State (up/down), MAC address, MTU
- IP Configuration: All assigned IP addresses with CIDR notation
- Bond Details (for bond interfaces):
- Bond mode and configuration parameters
- Slave interface status and active/backup states
- MII monitoring status and link state
- Currently active slave identification
- VLAN Details (for VLAN interfaces):
- VLAN ID and parent interface
- VLAN-specific configuration
- Statistics: RX/TX packets, bytes, errors, dropped packets
Use Cases:
- Post-configuration verification after
set_iporcreate_bond_interface - Network troubleshooting and diagnostics
- Bond interface health monitoring
- Interface performance analysis
Tests network reachability between containers using ICMP ping.
Parameters:
container_name: Source container namedestination_ip: Target IP address to test
Features:
- Sends 3 ping packets with 2-second timeout
- Provides detailed connectivity diagnostics
- Includes troubleshooting guidance for common failure scenarios
Discovers Link Layer Discovery Protocol (LLDP) neighbors connected to a container's network interfaces, providing visibility into network topology and directly connected devices.
Parameters:
container_name: Target container name
Automatic Setup (Idempotent):
- Attempts to run
lldpcli show neighbors - If lldpcli not found, automatically installs lldpd package
- If daemon not running, automatically starts lldpd daemon
- Retries neighbor discovery after setup is complete
LLDP Information Provided:
- Neighbor device chassis ID and system name
- Connected port identifiers and descriptions
- Device capabilities (router, switch, bridge, etc.)
- Management IP addresses
- VLAN information
- System description and version details
Returns:
status: 'success' or 'error'neighbors_output: Raw LLDP output showing neighbor informationneighbors_found: Boolean indicating if neighbors were discoveredmessages: List of operations performed (installation, daemon start, etc.)lldpd_installed: Boolean indicating if lldpd was installed during this rundaemon_started: Boolean indicating if lldpd daemon was started during this runerror: Error message if operation failed
Use Cases:
- Network topology discovery and mapping
- Cable tracing and port identification
- Verifying physical/logical connectivity to network devices
- Identifying which switch ports containers are connected to
- Network troubleshooting and validation
- Lab environment verification
- Network device inventory and documentation
Important Notes:
- Fully idempotent - can be safely run multiple times without errors
- If package installation fails, the container may need proxy settings configured
- Check
/etc/environmentand proxy configuration if installation errors occur
Adds static routes to container routing tables for custom network topologies.
Parameters:
container_name: Target container namedestination_network: Target network in CIDR notationgateway_ip: Next-hop gateway IP addressinterface_name: Interface to use for the route
Use Cases:
- L3 domain testing in ContainerLab
- Custom routing policies
- Multi-homed network configurations
- Network segmentation and isolation
Retrieves and analyzes the routing table from a container for network troubleshooting.
Parameters:
container_name: Target container namedestination_filter: Optional filter for specific destinations (e.g., 'default', '192.168.10.0/24')
Returns:
- Structured Route Data: Parsed route entries with destination, gateway, interface, metric, protocol, and scope
- Raw Output: Complete
ip route showcommand output - Route Statistics: Total number of routes found
- Filter Information: Applied destination filter details
Use Cases:
- Inter-VLAN Testing: Verify routing between different VLANs and subnets
- Route Validation: Confirm static routes added with
add_static_route - Connectivity Troubleshooting: Understand traffic flow paths in complex topologies
- Network Diagnostics: Debug routing problems and validate configurations
- Topology Analysis: Analyze routing paths for network optimization
- Gateway Verification: Confirm default gateway and specific route configurations
Removes static routes from a container's routing table for cleanup and reconfiguration.
Parameters:
container_name: Target container namedestination_network: Target network in CIDR notation to remove routes forgateway_ip: Optional gateway IP to match for route deletion (if not specified, matches any gateway)interface_name: Optional interface name to match for route deletion (if not specified, matches any interface)
Flexible Deletion Options:
- Destination Only: Remove all routes to a specific destination (
route_delete("container1", "192.168.10.0/24")) - Destination + Gateway: Remove route via specific gateway (
route_delete("container1", "192.168.10.0/24", "10.0.0.1")) - Destination + Interface: Remove route via specific interface (
route_delete("container1", "192.168.10.0/24", None, "eth1.100")) - Complete Specification: Remove exact route match (
route_delete("container1", "192.168.10.0/24", "10.0.0.1", "eth1.100"))
Use Cases:
- Route Cleanup: Remove obsolete or incorrect static routes after testing
- Configuration Changes: Remove old routes before adding new ones for reconfiguration
- Troubleshooting: Remove conflicting routes that are causing connectivity problems
- Network Reset: Restore default routing behavior by removing custom routes
- Lab Management: Clean up routing tables between different test scenarios
- Error Recovery: Remove routes that were added incorrectly or are causing issues
- eth0 Protection: All interface modification tools prevent accidental changes to eth0 (management interface)
- Input Validation: Comprehensive parameter validation and error handling
- Safe Operations: Graceful handling of missing interfaces and existing configurations