yaml_to_xml
Convert a YAML string to XML, wrapped in a configurable root element.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | Yes | YAML 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\nage: 30\n",
"root_element": "person"
}
Result:
{
"output": "<person>\n <name>Alice</name>\n <age>30</age>\n</person>"
}
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_yaml | The input string is not valid YAML. | tool error (isError) |
internal_error | An unexpected server error. | protocol error (internal_error) |
Mapping Convention
| YAML | XML |
|---|---|
Mapping key foo | <foo> child element |
Mapping key @id | Attribute id="..." on the parent element |
Mapping key $text | Text content of the parent element |
Sequence [a, b] | Repeated sibling elements |
null / ~ | Self-closing element <foo/> |
| String, integer, float, boolean | Element text content |
Notes
- Round-trips between
yaml_to_xmlandxml_to_yamlare not guaranteed to be lossless. In particular, numbers are serialized as text and parsed back as strings. - XML special characters in values are automatically escaped.