UNPKG

it-tools-mcp

Version:

Full MCP 2025-06-18 compliant server with 121+ IT tools, logging, ping, progress tracking, cancellation, and sampling utilities

62 lines (58 loc) 2.4 kB
import { z } from "zod"; export function registerFangUrl(server) { server.registerTool("fang_url", { description: "Defang or refang URLs for safe sharing (security analysis)", inputSchema: { text: z.string().describe("Text containing URLs to fang/defang"), operation: z.enum(["defang", "refang"]).describe("Whether to defang (make safe) or refang (restore) URLs") }, // VS Code compliance annotations annotations: { title: "Fang Url", description: "Defang or refang URLs for safe sharing (security analysis)", readOnlyHint: false } }, async ({ text, operation }) => { try { let result = text; if (operation === "defang") { // Defang URLs to make them safe result = result .replace(/https?:\/\//g, 'hxxp://') // Replace http/https with hxxp .replace(/\./g, '[.]') // Replace dots with [.] .replace(/@/g, '[@]') // Replace @ with [@] .replace(/:/g, '[:]'); // Replace colons with [:] } else { // Refang URLs to restore them result = result .replace(/hxxp:\/\//g, 'http://') // Restore http .replace(/hxxps:\/\//g, 'https://') // Restore https .replace(/\[\.\]/g, '.') // Restore dots .replace(/\[@\]/g, '@') // Restore @ .replace(/\[:\]/g, ':'); // Restore colons } return { content: [{ type: "text", text: `URL ${operation === "defang" ? "Defanging" : "Refanging"} Results: Original: ${text} ${operation === "defang" ? "Defanged" : "Refanged"}: ${result} Note: ${operation === "defang" ? "Defanged URLs are safe to share and won't be clickable." : "Refanged URLs have been restored to their original form."}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error processing URLs: ${error instanceof Error ? error.message : 'Unknown error'}` }] }; } }); }