UNPKG

it-tools-mcp

Version:

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

57 lines (55 loc) 2.04 kB
import { z } from "zod"; export function registerPrettifyHtml(server) { server.registerTool("format_html", { description: "Format and beautify HTML code", inputSchema: { html: z.string().describe("HTML code to prettify"), indentSize: z.number().optional().default(2).describe("Number of spaces for indentation") }, // VS Code compliance annotations annotations: { title: "Format Html", description: "Format and beautify HTML code", readOnlyHint: false } }, async ({ html, indentSize }) => { try { // Simple HTML prettifier let formatted = html; let indentLevel = 0; const indent = ' '.repeat(indentSize); // Remove extra whitespace formatted = formatted.replace(/>\s*</g, '><'); // Add line breaks and indentation formatted = formatted.replace(/(<\/?[^>]+>)/g, (match) => { if (match.startsWith('</') && !match.includes('/>')) { indentLevel--; } const result = '\n' + indent.repeat(indentLevel) + match; if (!match.startsWith('</') && !match.includes('/>') && !match.includes('<input') && !match.includes('<img') && !match.includes('<br') && !match.includes('<hr')) { indentLevel++; } return result; }); // Clean up formatted = formatted.trim(); return { content: [{ type: "text", text: `Prettified HTML: \`\`\`html ${formatted} \`\`\`` }] }; } catch (error) { return { content: [{ type: "text", text: `Error formatting HTML: ${error instanceof Error ? error.message : 'Unknown error'}` }] }; } }); }