Skip to main content

IPv4 subnet calculator MCP server for host planning, wildcard masks, and IP validation

Project description

Subnet Calculator MCP Server

subnet-calculator-mcp is a production-ready Model Context Protocol server that delivers reliable IPv4 subnet planning utilities to LLM-powered assistants. It eliminates tedious manual math by exposing fast, well-tested tools for subnet sizing, wildcard mask generation, gateway selection, and host validation.

Why Use This Server?

  • 🔢 Convert host requirements into accurate subnet masks and CIDR prefixes
  • 🌐 Produce Cisco-friendly OSPF wildcard masks and network statements
  • ✅ Verify whether an IP belongs to a subnet, including gateway hints and address position
  • 🔄 Reverse-calculations from dotted masks or find the Nth usable address instantly
  • ⚙️ Built on the official Python MCP SDK with thorough type hints, validation, and tests

Install & Run

The package is published on PyPI: https://pypi.org/project/subnet-calculator-mcp/

Install with pip

pip install subnet-calculator-mcp
python -m subnet_calculator_mcp.server

Run instantly (no install)

uvx subnet-calculator-mcp

Client Configuration

Claude Desktop / Claude for Windows

Add the server to claude_desktop_config.json.

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "subnet-calculator": {
      "command": "uvx",
      "args": ["subnet-calculator-mcp"]
    }
  }
}

If you installed via uv tool install or pip, change the command to "subnet-calculator-mcp" and omit args.

Generic mcp.json

Many editors (Cursor, Windsurf, etc.) use an mcp.json file. Add the following entry:

{
  "subnet-calculator": {
    "command": "uvx",
    "args": ["subnet-calculator-mcp"],
    "env": {}
  }
}

Set command to "subnet-calculator-mcp" if the binary is installed globally.

Tool Reference

calculate_subnet

  • Inputs: network_base (IPv4 address), hosts_needed (int), optional return_format ("detailed" or "simple").
  • Returns: CIDR prefix, dotted mask, wildcard mask, usable range, broadcast, binary representations, total/usable host counts.
  • Use it for: deriving the smallest subnet that can host the requested number of usable addresses.

calculate_wildcard_mask

  • Inputs: ip_address (any IP in the subnet), cidr_prefix (0–32), optional include_ospf_command (bool).
  • Returns: network address, mask, wildcard mask, binary wildcard string, and optional network ... area 0 statement.
  • Use it for: creating OSPF configurations or ACLs that rely on wildcard masks.

validate_ip_in_subnet

  • Inputs: ip_address, network (CIDR string), optional return_gateway (bool).
  • Returns: membership flag, mask, prefix, network/broadcast flags, usability, likely gateway, position index, and remaining usable addresses.
  • Use it for: quickly verifying assignments and identifying first-hop router addresses.

calculate_subnet_from_mask

  • Inputs: ip_address, subnet_mask (dotted decimal).
  • Returns: network boundary, prefix, wildcard mask, usable range, broadcast, and host counts.
  • Use it for: analysing legacy configurations that provide dotted masks instead of CIDR notation.

get_nth_usable_ip

  • Inputs: network (CIDR string), position (1-based index).
  • Returns: IP address at that position, whether it is last usable, total usable hosts, and associated network address.
  • Use it for: allocating deterministic host positions (first server, second router, etc.).

Example invocation:

{
  "tool": "calculate_subnet",
  "arguments": {
    "network_base": "172.16.0.16",
    "hosts_needed": 14
  }
}

Development Workflow

git clone https://github.com/sanjayshreeyans/subnet-calculator-mcp.git
cd subnet-calculator-mcp

# Install dependencies (dev extras include pytest, mypy, ruff, black)
uv sync --group dev

# Run the automated test suite
uv run --with .[dev] pytest

# Type-check, lint, and format
uv run --with mypy mypy src
uv run --with ruff ruff check src tests
uv run --with black black src tests

# Build distribution artifacts
uv build

License

MIT License – see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subnet_calculator_mcp-0.1.1.tar.gz (38.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

subnet_calculator_mcp-0.1.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file subnet_calculator_mcp-0.1.1.tar.gz.

File metadata

File hashes

Hashes for subnet_calculator_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ae6b8e46ef093a754439ea0dbfbdf0bd44702898904bf18b9a706513a8abd6f6
MD5 b3337fe31adff9d654b701cf1af5bb76
BLAKE2b-256 4a2b9962e9b99d1fb39aafd3896b7c907a1aa6d2a1dca437258f5d6d0543ceda

See more details on using hashes here.

File details

Details for the file subnet_calculator_mcp-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for subnet_calculator_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 486470d568422519de1035c38c4423b708a744245c3fb028851d87bb42a6b5b8
MD5 f150dd6f44a2a2c0245203ac6685c45c
BLAKE2b-256 b6539bbc5270db775347177daf74f79561cbb629f097363387985e3571604acf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page