Parse XML to JSON and serialize JSON back to XML (attributes preserved) via @mukundakatta/xml-mcp (npx) — 2 tools
XML↔JSON conversion is one of the most common data interchange tasks — parsing XML configs, API responses, SOAP payloads, or RSS into JSON for programmatic use, then serializing back. @mukundakatta/xml-mcp handles both directions with a clean attribute convention: XML attributes become @_attr keys in JSON, text content becomes #text when mixed with attributes. Arrays auto-detected for repeated sibling elements.
Recipe: XML ↔ JSON via @mukundakatta/xml-mcp
Server: @mukundakatta/xml-mcp v0.1.0 Transport: stdio Launch: npx @mukundakatta/xml-mcp (or npm install + node node_modules/@mukundakatta/xml-mcp/dist/server.js) Tools: 2 — to_json, to_xml
Tool 1: to_json — parse XML to JSON
Schema: { xml: string } → JSON text with @_ attribute prefix convention
- XML attributes become
@_attrNamekeys - Text content mixed with attributes becomes
#text - Repeated sibling elements auto-array
Tool 2: to_xml — serialize JSON to XML
Schema: { value: object } → XML string
- Keys starting with
@_become XML attributes (prefix stripped) - Numeric values preserved as-is
Gotcha
The to_xml parameter is value, NOT json. Using json as the key will fail with "JSON root must be an object".
Verified trace
to_json — bookstore with attributes:
Request: tools/call → to_json({ xml: "<bookstore><book category=\"fiction\"><title lang=\"en\">The Great Gatsby</title><author>F. Scott Fitzgerald</author><year>1925</year><price>10.99</price></book><book category=\"science\"><title lang=\"en\">A Brief History of Time</title><author>Stephen Hawking</author><year>1988</year><price>14.99</price></book></bookstore>" })
Response: { "value": { "bookstore": { "book": [ { "title": { "#text": "The Great Gatsby", "@_lang": "en" }, "author": "F. Scott Fitzgerald", "year": 1925, "price": 10.99, "@_category": "fiction" }, { "title": { "#text": "A Brief History of Time", "@_lang": "en" }, "author": "Stephen Hawking", "year": 1988, "price": 14.99, "@_category": "science" } ] } } }to_xml — config with attributes:
Request: tools/call → to_xml({ value: { config: { database: { "@_type": "postgresql", host: "localhost", port: 5432, name: "mydb" }, logging: { "@_level": "debug", file: "/var/log/app.log" } } } })
Response: <config>\n <database type="postgresql">\n <host>localhost</host>\n <port>5432</port>\n <name>mydb</name>\n </database>\n <logging level="debug">\n <file>/var/log/app.log</file>\n </logging>\n</config>Both directions work correctly. Attributes round-trip via the @_ prefix convention. Numeric types preserved.
{ "server": "@mukundakatta/xml-mcp", "version": "0.1.0", "transport": "stdio", "tools": ["to_json", "to_xml"], "traces": [ { "tool": "to_json", "request": { "xml": "<bookstore><book category="fiction"><title lang="en">The Great Gatsby</title><author>F. Scott Fitzgerald</author><year>1925</year><price>10.99</price></book><book category="science"><title lang="en">A Brief History of Time</title><author>Stephen Hawking</author><year>1988</year><price>14.99</price></book></bookstore>" }, "response": { "value": { "bookstore": { "book": [ { "title": { "#text": "The Great Gatsby", "@_lang": "en" }, "author": "F. Scott Fitzgerald", "year": 1925, "price": 10.99, "@_category": "fiction" }, { "title": { "#text": "A Brief History of Time", "@_lang": "en" }, "author": "Stephen Hawking", "year": 1988, "price": 14.99, "@_category": "science" } ] } } }, "success": true }, { "tool": "to_xml", "request": { "value": { "config": { "database": { "@_type": "postgresql", "host": "localhost", "port": 5432, "name": "mydb" }, "logging": { "@_level": "debug", "file": "/var/log/app.log" } } } }, "response": "<config> <database type="postgresql"> <host>localhost</host> <port>5432</port> <name>mydb</name> </database> <logging level="debug"> <file>/var/log/app.log</file> </logging> </config> ", "success": true } ], "gotcha": "to_xml parameter is 'value' not 'json' — using wrong key gives 'JSON root must be an object'" }