toml_to_xml
Convert a TOML string to XML, wrapped in a configurable root element.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | Yes | TOML string to convert. |
root_element | string | No | Name of the XML root element to wrap the output in (default: root). |
Response
| Field | Type | Description |
|---|---|---|
output | string | The converted XML string. |
Example
{
"input": "name = \"Alice\"\nport = 8080\n\n[db]\nhost = \"localhost\"\n",
"root_element": "config"
}
Result:
{
"output": "<config>\n <db>\n <host>localhost</host>\n </db>\n <name>Alice</name>\n <port>8080</port>\n</config>"
}
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, or root_element is not a string. | protocol error (invalid_params) |
invalid_toml | The input string is not valid TOML. | tool error (isError) |
internal_error | An unexpected server error. | protocol error (internal_error) |
Mapping Convention
| TOML | XML |
|---|---|
Table key foo | <foo> child element |
Key @id | Attribute id="..." on the parent element (key must use TOML quoted-key syntax: "@id" = "value", since bare TOML keys cannot start with @) |
Key $text | Text content of the parent element |
| Array of tables / array values | Repeated sibling elements |
| String, integer, float, boolean | Element text content |
Notes
- TOML datetime values are serialized as strings in the XML output.
- Round-trips between
toml_to_xmlandxml_to_tomlare not guaranteed to be lossless. - XML special characters in values are automatically escaped.