Skip to main content
Glama
badchars

osint-mcp-server

by badchars

shodan_search

Query Shodan to find internet-connected devices and services matching specific criteria. Retrieve host IPs, open ports, banners, and metadata for reconnaissance and attack surface analysis.

Instructions

Search Shodan for hosts matching a query (e.g. 'apache port:443 country:US'). Requires SHODAN_API_KEY.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesShodan search query
pageNoResults page number (default: 1)
facetsNoFacets to include (e.g. 'country,org')

Implementation Reference

  • The actual implementation of shodanSearch — calls the Shodan API /shodan/host/search endpoint, parses the response into ShodanSearchResult (total, matches, facets).
    export async function shodanSearch(query: string, apiKey: string, page = 1, facets?: string): Promise<ShodanSearchResult> {
      await limiter.acquire();
      const params = new URLSearchParams({ key: apiKey, query, page: String(page) });
      if (facets) params.set("facets", facets);
    
      const res = await fetch(`https://api.shodan.io/shodan/host/search?${params}`);
      if (!res.ok) throw new Error(`Shodan search failed: ${res.status} ${res.statusText}`);
      const data = await res.json();
    
      return {
        total: data.total ?? 0,
        matches: (data.matches ?? []).map((m: any) => ({
          ip_str: m.ip_str,
          port: m.port,
          org: m.org,
          hostnames: m.hostnames ?? [],
          product: m.product,
          os: m.os,
          asn: m.asn,
          domains: m.domains ?? [],
        })),
        facets: data.facets,
      };
    }
  • Type definitions for ShodanSearchMatch and ShodanSearchResult — the input/output shapes used by the search handler.
    interface ShodanSearchMatch {
      ip_str: string;
      port: number;
      org?: string;
      hostnames: string[];
      product?: string;
      os?: string;
      asn?: string;
      domains: string[];
    }
    
    interface ShodanSearchResult {
      total: number;
      matches: ShodanSearchMatch[];
      facets?: Record<string, [string, number][]>;
    }
  • Tool registration definition for shodan_search — maps the name, description, Zod schema (query, page, facets), and execute handler that calls the shodanSearch function.
    const shodanSearchTool: ToolDef = {
      name: "shodan_search",
      description: "Search Shodan for hosts matching a query (e.g. 'apache port:443 country:US'). Requires SHODAN_API_KEY.",
      schema: {
        query: z.string().describe("Shodan search query"),
        page: z.number().optional().describe("Results page number (default: 1)"),
        facets: z.string().optional().describe("Facets to include (e.g. 'country,org')"),
      },
      execute: async (args, ctx) => {
        const key = requireApiKey(ctx.config.shodanApiKey, "Shodan", "SHODAN_API_KEY");
        return json(await shodanSearch(args.query as string, key, args.page as number | undefined, args.facets as string | undefined));
      },
    };
  • Import of shodanSearch from the shodan module into the tools registry.
    import { shodanHost, shodanSearch, shodanDnsResolve, shodanExploits } from "../shodan/index.js";
  • The shodanSearchTool is included in the allTools array for export.
    shodanSearchTool,

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.2.0

TDQS

A3.5/5.0
Behavior2/5

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

With no annotations, the description carries full burden. It only mentions the API key requirement, omitting details like rate limits, pagination behavior, and whether the operation is read-only. Users are left uninformed about potential side effects or limitations.

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 extremely concise: a single sentence with an example. Every word earns its place, and critical information (requires API key) is front-loaded.

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

Completeness3/5

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

For a search tool with three parameters and no output schema, the description covers the basic function and authentication but lacks detail on return format, pagination, and facet usage. It is adequate for simple use but not comprehensive for complex scenarios.

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%, and the description adds value by providing a concrete query example for the 'query' parameter. However, it adds no additional context for 'page' or 'facets' beyond the schema descriptions.

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?

The description clearly states the tool searches Shodan for hosts matching a query, with an explicit example. This verb-resource combination distinguishes it from sibling tools like shodan_host (specific host details) and shodan_exploits (exploit search).

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?

The description gives a query example but no explicit guidance on when to use this tool versus alternatives. It does not specify prerequisites or typical use cases beyond the required API key.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.