UNPKG

@aashari/boilerplate-mcp-server

Version:

TypeScript MCP server boilerplate with STDIO and HTTP transport support, CLI tools, and extensible architecture

80 lines (79 loc) 3.34 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js"); 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 * Uses the modern registerResource API (SDK v1.22.0+) with ResourceTemplate * * @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 using modern registerResource API // ResourceTemplate enables parameterized URIs with {ipAddress} placeholder server.registerResource('ip-lookup', new mcp_js_1.ResourceTemplate('ip://{ipAddress}', { list: async () => { // Return example IPs that can be looked up return { resources: [ { uri: 'ip://8.8.8.8', name: 'Google DNS', description: 'Lookup Google DNS server', mimeType: 'text/markdown', }, { uri: 'ip://1.1.1.1', name: 'Cloudflare DNS', description: 'Lookup Cloudflare DNS server', mimeType: 'text/markdown', }, ], }; }, }), { title: 'IP Address Lookup', // Display name for UI description: 'Retrieve geolocation and network information for a public IP address', mimeType: 'text/markdown', }, async (uri, variables) => { const methodLogger = logger.forMethod('ipLookupResource'); try { // Extract ipAddress from template variables const ipAddress = variables.ipAddress; methodLogger.debug('IP lookup resource called', { uri: uri.href, ipAddress, }); // 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.href, text: result.content, mimeType: 'text/markdown', }, ], }; } catch (error) { methodLogger.error('Resource error', error); return (0, error_util_js_1.formatErrorForMcpResource)(error, uri.href); } }); registerLogger.debug('IP lookup resources registered successfully'); } exports.default = { registerResources };