whodis-mcp-server
Version:
Whodis MCP Server for checking the availability of domain names using WHOIS lookups.
87 lines (86 loc) • 3.97 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const vendor_ip_api_com_service_js_1 = __importDefault(require("../services/vendor.ip-api.com.service.js"));
const logger_util_js_1 = require("../utils/logger.util.js");
const ipaddress_formatter_js_1 = require("./ipaddress.formatter.js");
const error_handler_util_js_1 = require("../utils/error-handler.util.js");
const defaults_util_js_1 = require("../utils/defaults.util.js");
/**
* @namespace IpAddressController
* @description Controller responsible for handling IP address lookup logic.
* It orchestrates calls to the ip-api.com service, applies defaults,
* maps options, and formats the response using the formatter.
*/
/**
* @function get
* @description Fetches details for a specific IP address or the current device's IP.
* Handles mapping controller options (like includeExtendedData) to service parameters (fields).
* @memberof IpAddressController
* @param {string} [ipAddress] - Optional IP address to look up. If omitted, the service will fetch the current device's public IP.
* @param {GetIpOptions} [options={}] - Optional configuration for the request, such as `includeExtendedData` and `useHttps`.
* @returns {Promise<ControllerResponse>} A promise that resolves to the standard controller response containing the formatted IP details in Markdown.
* @throws {McpError} Throws an McpError (handled by `handleControllerError`) if the service call fails or returns an error.
*/
async function get(ipAddress, options = {}) {
const methodLogger = logger_util_js_1.Logger.forContext('controllers/ipaddress.controller.ts', 'get');
methodLogger.debug(`Getting IP address details for ${ipAddress || 'current device'}...`);
try {
// Define controller defaults
const defaults = {
includeExtendedData: false,
useHttps: false,
};
// Apply defaults to provided options
const mergedOptions = (0, defaults_util_js_1.applyDefaults)(options, defaults);
methodLogger.debug('Using options after defaults:', mergedOptions);
// Map controller options to service options
const serviceOptions = {
useHttps: mergedOptions.useHttps,
};
// If extended data is requested, include additional fields
if (mergedOptions.includeExtendedData) {
serviceOptions.fields = [
'status',
'message',
'country',
'countryCode',
'region',
'regionName',
'city',
'zip',
'lat',
'lon',
'timezone',
'isp',
'org',
'as',
'asname',
'reverse',
'mobile',
'proxy',
'hosting',
'query',
];
}
// Call the service with the mapped options
const ipData = await vendor_ip_api_com_service_js_1.default.get(ipAddress, serviceOptions);
methodLogger.debug(`Got the response from the service`, ipData);
// Format the data using the formatter
const formattedContent = (0, ipaddress_formatter_js_1.formatIpDetails)(ipData);
// Return the standard ControllerResponse structure
return { content: formattedContent };
}
catch (error) {
// Use the standardized error handler with return
return (0, error_handler_util_js_1.handleControllerError)(error, {
entityType: 'IP Address Details',
operation: 'retrieving',
source: 'controllers/ipaddress.controller.ts@get',
additionalInfo: { ipAddress },
});
}
}
exports.default = { get };
;