UNPKG

@aashari/boilerplate-mcp-server

Version:

TypeScript Model Context Protocol (MCP) server boilerplate providing IP lookup tools/resources. Includes CLI support and extensible structure for connecting AI systems (LLMs) to external data sources like ip-api.com. Ideal template for creating new MCP in

55 lines (54 loc) 2.41 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const logger_util_js_1 = require("../utils/logger.util.js"); const ipaddress_controller_js_1 = __importDefault(require("../controllers/ipaddress.controller.js")); const error_util_js_1 = require("../utils/error.util.js"); const logger = logger_util_js_1.Logger.forContext('resources/ipaddress.resource.ts'); /** * Register an IP address lookup resource with the MCP server * * @param server The MCP server instance */ function registerResources(server) { const registerLogger = logger.forMethod('registerResources'); registerLogger.debug('Registering IP lookup resources...'); // Register the IP lookup resource server.resource('ip-lookup', 'Lookup IP address details, returning formatted text result', async (uri) => { const methodLogger = logger.forMethod('ipLookupResource'); try { // Extract the IP address from the request path (if present) // Format of the URI would be ip://<ip-address> or ip:// methodLogger.debug('IP lookup resource called', { uri: uri.toString(), }); // Get everything after the ip:// protocol const ipAddress = uri.toString().replace(/^ip:\/\//, ''); // Call the controller to get the IP details const result = await ipaddress_controller_js_1.default.get({ ipAddress: ipAddress || undefined, includeExtendedData: false, useHttps: true, }); // Return the content as a text resource return { contents: [ { uri: uri.toString(), text: result.content, mimeType: 'text/markdown', description: `IP Details for ${ipAddress || 'current'}`, }, ], }; } catch (error) { methodLogger.error('Resource error', error); return (0, error_util_js_1.formatErrorForMcpResource)(error, uri.toString()); } }); registerLogger.debug('IP lookup resources registered successfully'); } exports.default = { registerResources };