Skip to main content

xml_to_toml

Parse an XML string into TOML, preserving the root element name as the top-level table key.

Parameters​

ParameterTypeRequiredDescription
inputstringYesXML string to convert. Self-closing elements (which map to null) and mixed-type repeated elements may cause an error in the TOML output.

Response​

FieldTypeDescription
outputstringThe converted TOML string.

Example​

{
"input": "<config><db><host>localhost</host><port>5432</port></db></config>"
}

Result:

{
"output": "[config.db]\nhost = \"localhost\"\nport = \"5432\"\n"
}

Errors​

Each failure carries a precise code in the response. Argument-schema and server errors are JSON-RPC protocol errors; a rejected value is returned as a tool result with isError: true (so the agent can read the code and self-correct).

CodeWhenDelivered as
invalid_argumentsinput is missing or not a string.protocol error (invalid_params)
invalid_xmlThe input string is not valid XML or has no root element.tool error (isError)
conversion_failedThe XML is valid but cannot be represented as TOML (e.g. self-closing elements that map to null, or mixed-type arrays).tool error (isError)
internal_errorAn unexpected server error.protocol error (internal_error)

Mapping Convention​

XMLTOML
Element <foo>Table key foo
Attribute id="1"Key @id = "1" in the element's table
Repeated elements with same tagArray of tables under that key
Text-only element <foo>bar</foo>String key foo = "bar"
Self-closing element <foo/>Not representable in TOML; will cause an error

Notes​

  • All text values are returned as strings. Type inference (e.g. "5432" → 5432) is not performed.
  • Round-trips between xml_to_toml and toml_to_xml are not guaranteed to be lossless.
  • Use xml_to_json first if you need type coercion or the XML may contain self-closing (null) elements.