xml_to_toml
Parse an XML string into TOML, preserving the root element name as the top-level table key.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | Yes | XML string to convert. Self-closing elements (which map to null) and mixed-type repeated elements may cause an error in the TOML output. |
Response
| Field | Type | Description |
|---|---|---|
output | string | The 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).
| Code | When | Delivered as |
|---|---|---|
invalid_arguments | input is missing or not a string. | protocol error (invalid_params) |
invalid_xml | The input string is not valid XML or has no root element. | tool error (isError) |
conversion_failed | The 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_error | An unexpected server error. | protocol error (internal_error) |
Mapping Convention
| XML | TOML |
|---|---|
Element <foo> | Table key foo |
Attribute id="1" | Key @id = "1" in the element's table |
| Repeated elements with same tag | Array 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_tomlandtoml_to_xmlare not guaranteed to be lossless. - Use
xml_to_jsonfirst if you need type coercion or the XML may contain self-closing (null) elements.