@aashari/boilerplate-mcp-server
Version:
TypeScript MCP server boilerplate with STDIO and HTTP transport support, CLI tools, and extensible architecture
92 lines (88 loc) • 3.91 kB
JavaScript
"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 error_util_js_1 = require("../utils/error.util.js");
const formatter_util_js_1 = require("../utils/formatter.util.js");
const zod_1 = require("zod");
const ipaddress_controller_js_1 = __importDefault(require("../controllers/ipaddress.controller.js"));
const ipaddress_types_js_1 = require("./ipaddress.types.js");
const logger = logger_util_js_1.Logger.forContext('tools/ipaddress-link.tool.ts');
/**
* Zod schema for the resource-link tool arguments
* Keep argument shape aligned with ip_get_details for consistency.
*/
const GetIpDetailsLinkToolSchema = zod_1.z.object({
ipAddress: zod_1.z
.string()
.optional()
.describe('IP address to lookup (omit for current IP)'),
...ipaddress_types_js_1.IpAddressToolArgs.shape,
});
/**
* Tool description for ip_get_details_link
*/
const IP_GET_DETAILS_LINK_DESCRIPTION = `Retrieve IP address details and return both direct content and a resource link.
**Consistency with ip_get_details:**
- Uses the same arguments: \`ipAddress\`, \`includeExtendedData\`, \`useHttps\`, \`jq\`, \`outputFormat\`
- Uses the same output rendering pipeline (TOON by default, JSON when \`outputFormat: "json"\`)
**What this returns:**
- A normal text response (same rendered output as \`ip_get_details\`)
- A \`resource_link\` entry pointing to \`ip://<resolved-ip>\` for resource-style clients
**Note:** Cannot lookup private IPs (192.168.x.x, 10.x.x.x). Powered by ip-api.com.`;
/**
* Handle IP lookup with resource-link + text output consistency.
*/
async function handleGetIpDetailsLink(args) {
const methodLogger = logger.forMethod('handleGetIpDetailsLink');
methodLogger.debug(`Getting IP address details link for ${args.ipAddress || 'current IP'}...`, args);
try {
const result = await ipaddress_controller_js_1.default.get(args);
const actualIp = result.resolvedIp ||
(typeof args.ipAddress === 'string' ? args.ipAddress : 'current');
methodLogger.debug(`Resolved IP for resource URI: ${actualIp}`);
const textContent = (0, formatter_util_js_1.truncateForAI)(result.content, result.rawResponsePath);
const mimeType = args.outputFormat === 'json' ? 'application/json' : 'text/plain';
return {
content: [
{
type: 'text',
text: textContent,
},
{
type: 'resource_link',
uri: `ip://${actualIp}`,
name: `IP lookup ${actualIp}`,
description: `Resource link for IP lookup result ${actualIp}`,
mimeType,
},
],
};
}
catch (error) {
methodLogger.error(`Error getting details link for IP: ${args.ipAddress || 'current IP'}`, error);
return (0, error_util_js_1.formatErrorForMcpTool)(error);
}
}
/**
* Register the ResourceLink pattern tool
*/
function registerTools(server) {
const methodLogger = logger.forMethod('registerTools');
methodLogger.debug(`Registering IP address ResourceLink tool...`);
server.registerTool('ip_get_details_link', {
title: 'IP Address Lookup (ResourceLink)',
description: IP_GET_DETAILS_LINK_DESCRIPTION,
inputSchema: GetIpDetailsLinkToolSchema,
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: true,
},
}, handleGetIpDetailsLink);
methodLogger.debug('Successfully registered ip_get_details_link tool.');
}
exports.default = { registerTools };