Skip to main content
Glama

xml-format

Format and organize XML strings with customizable indentation for improved readability and structure. Ideal for developers working with XML data.

Instructions

Format and prettify XML

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indentNoNumber of spaces for indentation
xmlYesXML string to format

Implementation Reference

  • Handler function that takes XML string and optional indent, uses xml-formatter to prettify it, returns formatted XML or error message.
    }, 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 as unknown as (xml: string, options?: any) => string; 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`, }, ], }; } }
  • Zod schema defining input parameters: xml (string, required), indent (number, optional).
    inputSchema: { xml: z.string().describe("XML string to format"), indent: z.number().describe("Number of spaces for indentation").optional(), },
  • Registration of the 'format_xml' tool using McpServer.registerTool, including description, schema, annotations, and inline handler.
    export function registerFormatXml(server: McpServer) { server.registerTool("format_xml", { description: "Format and prettify 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", description: "Format and prettify 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 as unknown as (xml: string, options?: any) => string; 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`, }, ], }; } } ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wrenchpilot/it-tools-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server