Skip to main content
Glama

get_host_info

Retrieve detailed host information, including IP address, open ports, and geographical data, to perform cybersecurity research and threat intelligence analysis.

Instructions

Get detailed information about a specific IP address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldsNoList of fields to include in the results (e.g., ['ip_str', 'ports', 'location.country_name'])
ipYesIP address to look up
max_itemsNoMaximum number of items to include in arrays (default: 5)

Implementation Reference

  • Core handler function in ShodanClient that executes the Shodan API call to retrieve host information for the given IP address, applies response sampling and field filtering.
    async getHostInfo(ip: string, maxItems: number = 5, selectedFields?: string[]): Promise<any> { try { const response = await this.axiosInstance.get(`/shodan/host/${ip}`); return this.sampleResponse(response.data, maxItems, selectedFields); } catch (error: unknown) { if (axios.isAxiosError(error)) { throw new McpError( ErrorCode.InternalError, `Shodan API error: ${error.response?.data?.error || error.message}` ); } throw error; } }
  • MCP CallToolRequestSchema handler case for 'get_host_info' that validates input parameters, calls ShodanClient.getHostInfo, and formats the response.
    case "get_host_info": { const ip = String(request.params.arguments?.ip); if (!ip) { throw new McpError( ErrorCode.InvalidParams, "IP address 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 hostInfo = await shodanClient.getHostInfo(ip, maxItems, fields); return { content: [{ type: "text", text: JSON.stringify(hostInfo, null, 2) }] }; } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Error getting host info: ${(error as Error).message}` ); } }
  • Input schema definition for the get_host_info tool, specifying parameters ip (required), max_items, and fields.
    inputSchema: { type: "object", properties: { ip: { type: "string", description: "IP address to look up" }, max_items: { type: "number", description: "Maximum number of items to include in arrays (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: ["ip"] }
  • src/index.ts:878-902 (registration)
    Tool registration in ListToolsRequestSchema response, defining name, description, and input schema for get_host_info.
    { name: "get_host_info", description: "Get detailed information about a specific IP address", inputSchema: { type: "object", properties: { ip: { type: "string", description: "IP address to look up" }, max_items: { type: "number", description: "Maximum number of items to include in arrays (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: ["ip"] } },
  • Helper method used by getHostInfo to truncate large arrays in the response (matches, data, ports) and filter specific fields to reduce token usage.
    private sampleResponse(data: any, maxItems: number = 5, selectedFields?: string[]): any { if (!data) return data; // Clone the data to avoid modifying the original const result = JSON.parse(JSON.stringify(data)); // Sample matches array if it exists and is longer than maxItems if (result.matches && Array.isArray(result.matches) && result.matches.length > maxItems) { result.matches = result.matches.slice(0, maxItems); result._sample_note = `Response truncated to ${maxItems} matches. Original count: ${data.matches.length}`; } // Sample data array if it exists and is longer than maxItems if (result.data && Array.isArray(result.data) && result.data.length > maxItems) { result.data = result.data.slice(0, maxItems); result._sample_note = `Response truncated to ${maxItems} data items. Original count: ${data.data.length}`; } // Sample ports array if it exists and is longer than maxItems if (result.ports && Array.isArray(result.ports) && result.ports.length > maxItems) { result.ports = result.ports.slice(0, maxItems); if (!result._sample_note) { result._sample_note = `Ports truncated to ${maxItems} items. Original count: ${data.ports.length}`; } } // Filter fields if selectedFields is provided if (selectedFields && selectedFields.length > 0 && typeof result === 'object') { this.filterFields(result, selectedFields); } return result; }

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