it-tools-mcp
Version:
MCP-compliant server access to over 100 IT tools and utilities commonly used by developers, system administrators, and IT professionals.
54 lines (50 loc) • 1.72 kB
JavaScript
import { z } from "zod";
export function registerFormatXml(server) {
server.registerTool("format_xml", {
inputSchema: {
xml: z.string().describe("XML string to format"),
indent: z.number().describe("Number of spaces for indentation").optional(),
},
// VS Code compliance annotations
annotations: {
title: "Format Xml",
readOnlyHint: false
}
}, async ({ xml, indent = 2 }) => {
try {
const xmlFormatterModule = await import("xml-formatter");
// Use double type assertion to work around NodeNext module resolution issues
const formatXML = xmlFormatterModule.default;
const formatted = formatXML(xml, {
indentation: ' '.repeat(indent),
collapseContent: true,
});
return {
content: [
{
type: "text",
text: `Formatted XML:
${formatted}
✅ XML formatted successfully
🎯 Features: ${indent}-space indentation, collapsed content, clean structure`,
},
],
};
}
catch (error) {
return {
content: [
{
type: "text",
text: `Error formatting XML: ${error instanceof Error ? error.message : 'Unknown error'}
💡 Common XML issues:
• Check that all tags are properly closed
• Ensure proper nesting of elements
• Validate attribute syntax (key="value")
• Check for special character encoding`,
},
],
};
}
});
}