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
| Name | Required | Description | Default |
|---|---|---|---|
| fields | No | List of fields to include in the results (e.g., ['ip_str', 'ports', 'location.country_name']) | |
| ip | Yes | IP address to look up | |
| max_items | No | Maximum number of items to include in arrays (default: 5) |
Implementation Reference
- src/index.ts:137-150 (handler)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; } }
- src/index.ts:1284-1316 (handler)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}` ); } }
- src/index.ts:881-901 (schema)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"] } },
- src/index.ts:52-84 (helper)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; }