Skip to main content
Glama
paladini

devutils-mcp-server

cidr_calculate

Calculate network details from CIDR notation. Get network address, broadcast, host range, and host count for IPv4 networks.

Instructions

Calculate network details from a CIDR notation (e.g., '192.168.1.0/24'). Returns network address, broadcast, host range, and host count.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cidrYesIPv4 CIDR notation (e.g., '192.168.1.0/24', '10.0.0.0/8')

Implementation Reference

  • The handler and registration for 'cidr_calculate' tool in src/tools/network.ts.
    server.tool(
      "cidr_calculate",
      "Calculate network details from a CIDR notation (e.g., '192.168.1.0/24'). Returns network address, broadcast, host range, and host count.",
      {
        cidr: z
          .string()
          .describe("IPv4 CIDR notation (e.g., '192.168.1.0/24', '10.0.0.0/8')"),
      },
      async ({ cidr }) => {
        try {
          const parts = cidr.split("/");
          if (parts.length !== 2) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: "Error: Invalid CIDR notation. Expected format: 'x.x.x.x/y'",
                },
              ],
              isError: true,
            };
          }
    
          const ip = parts[0];
          const prefix = parseInt(parts[1], 10);
    
          if (prefix < 0 || prefix > 32 || isNaN(prefix)) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: "Error: Prefix length must be between 0 and 32",
                },
              ],
              isError: true,
            };
          }
    
          const ipParts = ip.split(".").map(Number);
          if (
            ipParts.length !== 4 ||
            ipParts.some((p) => isNaN(p) || p < 0 || p > 255)
          ) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: "Error: Invalid IPv4 address",
                },
              ],
              isError: true,
            };
          }
    
          const ipNum =
            (ipParts[0] << 24) |
            (ipParts[1] << 16) |
            (ipParts[2] << 8) |
            ipParts[3];
          const mask = prefix === 0 ? 0 : (~0 << (32 - prefix)) >>> 0;
          const network = (ipNum & mask) >>> 0;
          const broadcast = (network | ~mask) >>> 0;
    
          const numToIp = (num: number): string =>
            [(num >>> 24) & 255, (num >>> 16) & 255, (num >>> 8) & 255, num & 255].join(".");
    
          const numHosts = prefix >= 31 ? (prefix === 32 ? 1 : 2) : Math.pow(2, 32 - prefix) - 2;
          const firstHost = prefix >= 31 ? network : (network + 1) >>> 0;
          const lastHost = prefix >= 31 ? broadcast : (broadcast - 1) >>> 0;
    
          const result = {
            cidr,
            network_address: numToIp(network),
            broadcast_address: numToIp(broadcast),
            subnet_mask: numToIp(mask),
            wildcard_mask: numToIp((~mask) >>> 0),
            first_host: numToIp(firstHost),
            last_host: numToIp(lastHost),
            total_hosts: numHosts,
            prefix_length: prefix,
            ip_class: ipParts[0] < 128 ? "A" : ipParts[0] < 192 ? "B" : ipParts[0] < 224 ? "C" : ipParts[0] < 240 ? "D" : "E",
            is_private:
              (ipParts[0] === 10) ||
              (ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
              (ipParts[0] === 192 && ipParts[1] === 168),
          };
    
          return {
            content: [
              { type: "text" as const, text: JSON.stringify(result, null, 2) },
            ],
          };
        } catch (e) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error: ${e instanceof Error ? e.message : String(e)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. Compensates well by disclosing exactly what gets returned (network address, broadcast, host range, host count). Could additionally mention idempotency or computational cost.

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?

Two sentences, zero waste. First sentence defines the operation and input format with example; second sentence specifies return values. Perfectly front-loaded and structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Appropriate for a single-parameter utility tool. Despite lacking output_schema, the description explicitly enumerates return values. Complete for its complexity level, though could note IPv4 specificity.

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 coverage is 100% with complete description and examples for the cidr parameter. With high schema coverage, baseline 3 is appropriate; description doesn't need to duplicate schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clear specific verb (Calculate) + resource (network details/CIDR notation). Distinct among siblings (differs from ip_validate which only validates, and completely separate from encoding/hash utilities).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implicit usage is clear from the specific function, but lacks explicit 'when to use vs alternatives' guidance. No mention of when to prefer ip_validate over this, or handling of IPv6 vs IPv4 edge cases.

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/paladini/devutils-mcp-server'

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