Skip to main content
Glama
Cyreslab-AI

Shodan MCP Server

scan_network_range

Scan a network range in CIDR notation to discover internet-connected devices and gather cybersecurity intelligence using Shodan's database.

Instructions

Scan a network range (CIDR notation) for devices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cidrYesNetwork range in CIDR notation (e.g., 192.168.1.0/24)
max_itemsNoMaximum number of items to include in results (default: 5)
fieldsNoList of fields to include in the results (e.g., ['ip_str', 'ports', 'location.country_name'])

Implementation Reference

  • MCP CallToolRequestSchema handler case for 'scan_network_range' that validates input parameters (cidr required), calls shodanClient.scanNetworkRange, handles 401 unauthorized responses from Shodan paid API, and returns JSON-formatted results or errors.
    case "scan_network_range": {
      const cidr = String(request.params.arguments?.cidr);
      if (!cidr) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "CIDR notation is required"
        );
      }
    
      const maxItems = Number(request.params.arguments?.max_items) || 5;
      const fields = Array.isArray(request.params.arguments?.fields)
        ? request.params.arguments?.fields.map(String)
        : undefined;
    
      try {
        const scanResults = await shodanClient.scanNetworkRange(cidr, maxItems, fields);
    
        // Check if we got an error response from the scan method
        if (scanResults.error && scanResults.status === 401) {
          return {
            content: [{
              type: "text",
              text: JSON.stringify(scanResults, null, 2)
            }]
          };
        }
    
        return {
          content: [{
            type: "text",
            text: JSON.stringify(scanResults, null, 2)
          }]
        };
      } catch (error) {
        if (error instanceof McpError) {
          throw error;
        }
        throw new McpError(
          ErrorCode.InternalError,
          `Error scanning network range: ${(error as Error).message}`
        );
      }
    }
  • Core implementation in ShodanClient class that translates CIDR to Shodan 'net:' query, performs API search, samples/truncates results using sampleResponse, filters fields if specified, and handles API errors including requirement for paid Shodan membership.
    async scanNetworkRange(cidr: string, maxItems: number = 5, selectedFields?: string[]): Promise<any> {
      try {
        // Convert CIDR to Shodan search query format
        const query = `net:${cidr}`;
        const response = await this.axiosInstance.get("/shodan/host/search", {
          params: { query }
        });
        return this.sampleResponse(response.data, maxItems, selectedFields);
      } catch (error: unknown) {
        if (axios.isAxiosError(error)) {
          if (error.response?.status === 401) {
            return {
              error: "Unauthorized: The Shodan search API requires a paid membership. Your API key does not have access to this endpoint.",
              message: "The network scanning functionality requires a Shodan membership subscription with API access. Please upgrade your Shodan plan to use this feature.",
              status: 401
            };
          }
          throw new McpError(
            ErrorCode.InternalError,
            `Shodan API error: ${error.response?.data?.error || error.message}`
          );
        }
        throw error;
      }
    }
  • Zod/JSON schema definition for tool inputs: requires 'cidr' string, optional 'max_items' number for result limiting, optional 'fields' array for response filtering.
    inputSchema: {
      type: "object",
      properties: {
        cidr: {
          type: "string",
          description: "Network range in CIDR notation (e.g., 192.168.1.0/24)"
        },
        max_items: {
          type: "number",
          description: "Maximum number of items to include in results (default: 5)"
        },
        fields: {
          type: "array",
          items: {
            type: "string"
          },
          description: "List of fields to include in the results (e.g., ['ip_str', 'ports', 'location.country_name'])"
        }
      },
      required: ["cidr"]
    }
  • src/index.ts:943-967 (registration)
    Tool registration entry in ListToolsRequestSchema handler's tools array, defining name, description, and complete inputSchema for client discovery.
    {
      name: "scan_network_range",
      description: "Scan a network range (CIDR notation) for devices",
      inputSchema: {
        type: "object",
        properties: {
          cidr: {
            type: "string",
            description: "Network range in CIDR notation (e.g., 192.168.1.0/24)"
          },
          max_items: {
            type: "number",
            description: "Maximum number of items to include in results (default: 5)"
          },
          fields: {
            type: "array",
            items: {
              type: "string"
            },
            description: "List of fields to include in the results (e.g., ['ip_str', 'ports', 'location.country_name'])"
          }
        },
        required: ["cidr"]
      }
    },
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It mentions scanning for devices but doesn't disclose critical traits like rate limits, authentication needs, potential network impact, output format, or whether it's a read-only operation. This leaves significant gaps for safe and effective tool invocation.

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?

The description is a single, efficient sentence that front-loads the core functionality ('Scan a network range for devices') and includes essential format detail ('CIDR notation') without redundancy. Every word earns its place, making it easy to parse and understand quickly.

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

Completeness2/5

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

Given the complexity of network scanning (3 parameters, no output schema, no annotations), the description is insufficient. It lacks details on behavioral traits, output expectations, error handling, and differentiation from siblings. For a tool that could have significant operational impact, more context is needed to ensure proper use.

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 description coverage is 100%, providing clear documentation for all three parameters (cidr, max_items, fields). The description adds no additional parameter semantics beyond implying CIDR notation usage, which is already covered in the schema. Baseline score of 3 is appropriate as the schema adequately handles parameter explanations.

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

Purpose4/5

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

The description clearly states the action ('Scan') and target ('a network range for devices'), specifying CIDR notation as the required format. It distinguishes from most siblings like DNS lookup or CVE search, though not explicitly from network-related tools like reverse_dns_lookup or list_ports. The purpose is specific but could better differentiate from similar scanning operations.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like get_host_info, search_iot_devices, or list_ports, which might overlap in network discovery contexts. The description implies usage for device scanning but lacks explicit conditions, prerequisites, or exclusions, leaving the agent to infer based on parameter names alone.

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/Cyreslab-AI/shodan-mcp-server'

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